1 ; Inno Setup Script for Wammu installation
2 ; Copyright (c) 2006 Michal Èihaø
3 ; Language selection code based on GTK+ 2 installation script
4 ; made by Jernej Simoncic, <jernej.simoncic@guest.arnes.si>
6 #define MyAppDosName
"wammu"
7 #define MyAppName
"Wammu"
8 #define MyAppVersion
"0.30"
9 #define MyAppPublisher
"Micha Èihaø"
10 #define MyAppURL
"http://wammu.eu/"
11 #define MyAppPublisherURL
"http://cihar.com/"
12 #define MyAppBugsURL
"http://bugs.wammu.eu/"
13 #define MyAppDescription
"Wammu Mobile Phone Manager"
14 #define MyAppExeName
"wammu.exe"
15 #define MyAppUrlName
"wammu.url"
16 #define MyAppBugsUrlName
"wammu-bugs.url"
20 AppVerName
={#MyAppName} {#MyAppVersion}
21 AppPublisher
={#MyAppPublisher}
22 AppPublisherURL
={#MyAppPublisherURL}
23 AppSupportURL
={#MyAppBugsURL}
24 AppUpdatesURL
={#MyAppURL}
25 DefaultDirName
={pf}\
{#MyAppName}
26 DefaultGroupName
={#MyAppName}
29 OutputBaseFilename
={#MyAppDosName}-{#MyAppVersion}-setup
30 Compression
=lzma
/ultra
32 InternalCompressLevel
=ultra
33 VersionInfoVersion
={#MyAppVersion}
34 VersionInfoCompany
={#MyAppPublisher}
35 VersionInfoDescription
={#MyAppDescription}
36 ShowLanguageDialog
=yes
37 AppVersion
={#MyAppVersion}
38 UninstallDisplayIcon
={app}\share\pixmaps\wammu
.ico
39 AppModifyPath
="{uninstallexe}" /langsetup
42 Name
: en
; MessagesFile
: compiler
:Default
.isl
43 Name
: pt_BR
; MessagesFile
: compiler
:Languages\BrazilianPortuguese
.isl
44 Name
: ca
; MessagesFile
: compiler
:Languages\Catalan
.isl
45 Name
: cs
; MessagesFile
: compiler
:Languages\Czech
.isl
46 ;Name: da; MessagesFile: compiler:Languages\Danish.isl
47 Name
: nl
; MessagesFile
: compiler
:Languages\Dutch
.isl
48 Name
: fi
; MessagesFile
: compiler
:Languages\Finnish
.isl
49 Name
: fr
; MessagesFile
: compiler
:Languages\French
.isl
50 Name
: de
; MessagesFile
: compiler
:Languages\German
.isl
51 Name
: hu
; MessagesFile
: compiler
:Languages\Hungarian
.isl
52 Name
: it
; MessagesFile
: compiler
:Languages\Italian
.isl
53 ;Name: no; MessagesFile: compiler:Languages\Norwehian.isl
54 Name
: pl
; MessagesFile
: compiler
:Languages\Polish
.isl
55 ;Name: pt; MessagesFile: compiler:Languages\Portuguese.isl
56 ;Name: ru; MessagesFile: compiler:Languages\Russian.isl
57 Name
: sk
; MessagesFile
: compiler
:Languages\Slovak
.isl
58 ;Name: sl; MessagesFile: compiler:Languages\Slovenian.isl
59 ;Name: sv; MessagesFile: compiler:Languages\Swedish.isl
62 Name
: desktopicon; Description
: {cm:CreateDesktopIcon}; GroupDescription
: {cm:AdditionalIcons}; Flags
: unchecked
65 Source
: dist\
*; DestDir
: {app}; Flags
: ignoreversion recursesubdirs createallsubdirs
66 Source
: uninst
.isl
; DestDir
: {app}
69 Filename
: {app}\
{#MyAppUrlName}; Section
: InternetShortcut
; Key
: URL
; String: {#MyAppURL}
70 Filename
: {app}\
{#MyAppBugsUrlName}; Section
: InternetShortcut
; Key
: URL
; String: {#MyAppBugsURL}
73 Name
: {group}\
{#MyAppName}; Filename
: {app}\
{#MyAppExeName}; IconFilename
: {app}\share\pixmaps\wammu
.ico
; IconIndex
: 0
74 Name
: {group}\
{cm:ProgramOnTheWeb,{#MyAppName}}
; Filename
: {app}\
{#MyAppUrlName}
75 Name
: {group}\
{cm:ReportBug,{#MyAppName}}
; Filename
: {app}\
{#MyAppBugsUrlName}
76 Name
: {group}\
{cm:UninstallProgram,{#MyAppName}}
; Filename
: {uninstallexe}
77 Name
: {userdesktop}\
{#MyAppName}; Filename
: {app}\
{#MyAppExeName}; Tasks
: desktopicon
78 Name
: {group}\
{cm:SelectLanguage}; Filename
: {uninstallexe}; Parameters
: /langsetup
; IconFilename
: {app}\share\pixmaps\wammu
.ico
; IconIndex
: 0
81 Filename
: {app}\
{#MyAppExeName}; Description
: {cm:LaunchProgram,{#MyAppName}}
; Flags
: nowait postinstall skipifsilent unchecked
82 Filename
: {uninstallexe}; Parameters
: /langsetup
; Description
: "{cm:SelectLanguage}"; Flags
: postinstall nowait
85 Type: files; Name
: {app}\
{#MyAppUrlName}
86 Type: files; Name
: {app}\
{#MyAppBugsUrlName}
89 en
.ReportBug
=Report bug
in application
%1
90 cs
.ReportBug
=Nahlásit chybu v aplikaci
%1
91 en
.SelectLanguage
=Select application language
92 cs
.SelectLanguage
=Zvolit jazyk aplikace
95 Root
: HKCU
; Subkey
: Environment
; ValueType
: string; ValueName
: LANG
; ValueData
: {language}; Check
: UsingWinNT
97 ; Following part is heavily based on GTK+ 2 setup
101 function SendMessageTimeout(hWnd
: HWND
; Msg
: Cardinal; wParam
: DWORD
; lParam
: String; fuFlags
, uTimeout
: Cardinal; lpdwResult
: DWORD
): {Int64}Cardinal; external 'SendMessageTimeoutA@user32 stdcall';
104 frmLangChooser
: TForm
;
105 cbUser
, cbSystem
: TComboBox
;
108 WM_SETTINGCHANGE
= 26;
109 //HWND_BROADCAST
= $FFFF;
110 SMTO_ABORTIFHUNG
= 2;
112 function RevPos(const SearchStr
, Str
: string): Integer;
116 if (Length(SearchStr
) < Length(Str
)) and (Pos(SearchStr
, Str
) > 0) then
117 for i
:= (Length(Str
) - Length(SearchStr
) + 1) downto 1 do
120 if Copy(Str
, i
, Length(SearchStr
)) = SearchStr
then
132 function ExtractLang(const Txt
: String): String;
137 if (S
[Length(S
)] = ')') then
141 S
:= Copy(Txt
,i
+1,Length(Txt
)-i
-1)
151 function GetLangIndex(Items
: TStrings
; Lang
: String): Integer;
155 Lang
:= LowerCase(Lang
);
156 for i
:= 0 to Items
.Count
- 1 do
158 S
:= LowerCase(ExtractLang(Items
.Strings
[i
]));
163 if (i
>= Items
.Count
) then
170 function GetTransStr(const Str
: String): String; //ExpandConstant('{cm:...}') doesn
't work on uninstall
172 Result := GetIniString('CustomMessages
',Str,'',ExpandConstant('{app}\uninst
.isl
'));
174 if (Result = '') then
175 RaiseException(Str + ' not found
in translation
file.');
179 procedure LanguageForm;
180 var lblInfo, lblUser, lblSystem: TLabel;
181 btnOK,btnCancel: TButton;
184 lang1,lang2,regSys,regUser: String;
185 AutoExec: TArrayOfString;
189 frmLangChooser := CreateCustomForm();
191 with frmLangChooser do
193 ClientWidth := ScaleX(321);
194 ClientHeight := ScaleY(119);
195 Caption := GetTransStr('LangTitle
');
196 Position := poScreenCenter;
200 lblInfo := TLabel.Create(frmLangChooser);
203 Parent := frmLangChooser;
206 Width := ScaleX(283);
207 Height := ScaleY(13);
208 Caption := GetTransStr('LangText
');
212 lblUser := TLabel.Create(frmLangChooser);
215 Parent := frmLangChooser;
218 Width := ScaleX(119);
219 Height := ScaleY(13);
220 Caption := GetTransStr('LangUser
');
221 FocusControl := cbUser;
225 lblSystem := TLabel.Create(frmLangChooser);
228 Parent := frmLangChooser;
232 Height := ScaleY(13);
233 Caption := GetTransStr('LangSystem
');
234 FocusControl := cbSystem;
238 cbUser := TComboBox.Create(frmLangChooser);
241 Parent := frmLangChooser;
242 Style := csDropDownList;
245 Width := ScaleX(169);
246 Height := ScaleY(16);
247 Hint := GetTransStr('LangUserHint
');
254 cbSystem := TComboBox.Create(frmLangChooser);
257 Parent := frmLangChooser;
258 Style := csDropDownList;
261 Width := ScaleX(169);
262 Height := ScaleY(16);
263 Hint := GetTransStr('LangSystemHint
');
270 btnOK := TButton.Create(frmLangChooser);
273 Parent := frmLangChooser;
277 Height := ScaleY(23);
278 Caption := SetupMessage(msgButtonOK);
285 btnCancel := TButton.Create(frmLangChooser);
288 Parent := frmLangChooser;
292 Height := ScaleY(23);
293 Caption := SetupMessage(msgButtonCancel);
299 cbUser.Items.Add(GetTransStr('LangDefault
'));
300 cbUser.Items.Add('English (C
)');
301 //cbSystem.Items.Add(GetTransStr('LangDefault
'));
303 if FindFirst(ExpandConstant('{app}\share\locale\
*'),frMsgs) then
308 if ((frMsgs.Attributes and FILE_ATTRIBUTE_DIRECTORY) = FILE_ATTRIBUTE_DIRECTORY) and ((frMsgs.Name <> '.') and (frMsgs.Name <> '..')) then
312 lang1 := frMsgs.Name;
313 StringChange(lang1,'@','_
'); //custom messages only support letters,numbers and _
314 lang1 := GetTransStr('Lang_
'+lang1+'');
319 i := pos('@',frMsgs.Name);
320 if (lang1 = '') and (i > 0) then
322 lang1 := GetTransStr('Lang_
'+Copy(frMsgs.Name,1,i-1)+'');
323 lang2 := Copy(frMsgs.Name,i+1,length(frMsgs.Name))
328 if (lang1 = '') and (Length(frMsgs.Name) > 2) then
330 lang1 := GetTransStr('Lang_
'+Copy(frMsgs.Name,1,2)+'');
335 case lowercase(lang2) of
336 'latn
': lang2 := 'Latin
';
339 if (lang1 <> '') then
341 if (lang2 <> '') then
343 cbUser.Items.Add(lang1+' '+lang2+' ('+frMsgs.Name+')');
346 cbUser.Items.Add(lang1+' ('+frMsgs.Name+')');
350 cbUser.Items.Add(frMsgs.Name);
354 until not FindNext(frMsgs);
356 cbSystem.Items := cbUser.Items;
365 if not IsAdminLoggedOn then //only admins can change system-wide environment variables
367 cbSystem.Enabled := False;
368 lblSystem.Enabled := False;
371 if RegQueryStringValue(HKEY_LOCAL_MACHINE,'SYSTEM\CurrentControlSet\Control\Session Manager\Environment
','LANG
',regSys) then
372 cbSystem.ItemIndex := GetLangIndex(cbSystem.Items,regSys)
374 cbSystem.ItemIndex := 0;
376 if cbSystem.ItemIndex = -1 then
377 cbSystem.ItemIndex := cbSystem.Items.Add(regSys);
380 if RegQueryStringValue(HKEY_CURRENT_USER,'Environment
','LANG
',regUser) then
381 cbUser.ItemIndex := GetLangIndex(cbSystem.Items,regUser)
383 cbUser.ItemIndex := 0;
385 if cbUser.ItemIndex = -1 then
386 cbUser.ItemIndex := cbUser.Items.Add(regUser);
390 if frmLangChooser.ShowModal = 1 then
392 regSys := ExtractLang(cbSystem.Items.Strings[cbSystem.ItemIndex]);
396 regUser := ExtractLang(cbUser.Items.Strings[cbUser.ItemIndex]);
398 if cbUser.ItemIndex <> 0 then
400 if not RegWriteStringValue(HKEY_CURRENT_USER,'Environment
','LANG
',regUser) then
401 MsgBox(GetTransStr('LangRegUserFailed
'),mbCriticalError,mb_ok);
403 if RegValueExists(HKEY_CURRENT_USER,'Environment
','LANG
') and
404 (not RegDeleteValue(HKEY_CURRENT_USER,'Environment
','LANG
')) then
405 MsgBox(GetTransStr('LangRegUserFailed
'),mbCriticalError,mb_ok);
407 if IsAdminLoggedOn then
409 if cbSystem.ItemIndex <> 0 then
411 if not RegWriteStringValue(HKEY_LOCAL_MACHINE,'SYSTEM\CurrentControlSet\Control\Session Manager\Environment
','LANG
',regSys) then
412 MsgBox(GetTransStr('LangRegSysFailed
'),mbCriticalError,mb_ok);
414 if RegValueExists(HKEY_LOCAL_MACHINE,'SYSTEM\CurrentControlSet\Control\Session Manager\Environment
','LANG
') and
415 (not RegDeleteValue(HKEY_LOCAL_MACHINE,'SYSTEM\CurrentControlSet\Control\Session Manager\Environment
','LANG
')) then
416 MsgBox(GetTransStr('LangRegSysFailed
'),mbCriticalError,mb_ok);
419 //straight from the Inno source
420 SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 'Environment
', SMTO_ABORTIFHUNG, 5000, MsgResult);
424 if not FileCopy(ExpandConstant('{sd}\AutoExec
.bat
'),ExpandConstant('{sd}\AutoExec
.WAM
'),False) then
425 if MsgBox(GetTransStr('LangAutoExecBackupFailed
'),mbConfirmation,mb_yesno) = idno then
428 if LoadStringsFromFile(ExpandConstant('{sd}\Autoexec
.bat
'), AutoExec) then
430 for i := GetArrayLength(AutoExec) - 1 downto 0 do
431 if pos('set lang
=',LowerCase(AutoExec[i])) > 0 then
432 if (i>0) and (i<(GetArrayLength(AutoExec)-1))
433 and (LowerCase(AutoExec[i-1]) = 'REM
/=== by Wammu Language Setup
===\')
434 and (LowerCase(AutoExec
[i
+1]) = 'REM \=== by Wammu Language Setup ===/') then
436 for j
:= i
to GetArrayLength(AutoExec
) - 2 do //remove previous setting
437 AutoExec
[j
-1] := AutoExec
[j
+1];
438 SetArrayLength(AutoExec
,GetArrayLength(AutoExec
) - 3);
441 i
:= GetArrayLength(AutoExec
);
442 SetArrayLength(AutoExec
,i
+ 3);
443 AutoExec
[i
] := 'REM /=== by Wammu Language Setup ===\';
444 AutoExec[i+1] := 'SET LANG
='+regSys;
445 AutoExec[i+2] := 'REM \
=== by Wammu Language Setup
===/';
447 if SaveStringsToFile(ExpandConstant('{sd}\AutoExec
.bat
'),AutoExec,False) then
448 MsgBox(GetTransStr('LangRestartRequired
'),mbInformation,mb_ok)
450 MsgBox(GetTransStr('LangErrorSavingAutoExec
'),mbCriticalError,mb_ok);
453 MsgBox(GetTransStr('LangErrorLoadingAutoExec
'), mbCriticalError, MB_OK);
460 function InitializeUninstall(): Boolean;
466 for i := 1 to ParamCount do
468 if LowerCase(ParamStr(i)) = '/langsetup
' then