Fix license name and clean buildroot on install.
[wammu.git] / wammu.iss
blob5e6e0ae45f0e128c23329481655ee03aee6f5151
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"
18 [Setup]
19 AppName={#MyAppName}
20 AppVerName={#MyAppName} {#MyAppVersion}
21 AppPublisher={#MyAppPublisher}
22 AppPublisherURL={#MyAppPublisherURL}
23 AppSupportURL={#MyAppBugsURL}
24 AppUpdatesURL={#MyAppURL}
25 DefaultDirName={pf}\{#MyAppName}
26 DefaultGroupName={#MyAppName}
27 AllowNoIcons=true
28 LicenseFile=COPYING
29 OutputBaseFilename={#MyAppDosName}-{#MyAppVersion}-setup
30 Compression=lzma/ultra
31 SolidCompression=true
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
41 [Languages]
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
61 [Tasks]
62 Name: desktopicon; Description: {cm:CreateDesktopIcon}; GroupDescription: {cm:AdditionalIcons}; Flags: unchecked
64 [Files]
65 Source: dist\*; DestDir: {app}; Flags: ignoreversion recursesubdirs createallsubdirs
66 Source: uninst.isl; DestDir: {app}
68 [INI]
69 Filename: {app}\{#MyAppUrlName}; Section: InternetShortcut; Key: URL; String: {#MyAppURL}
70 Filename: {app}\{#MyAppBugsUrlName}; Section: InternetShortcut; Key: URL; String: {#MyAppBugsURL}
72 [Icons]
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
80 [Run]
81 Filename: {app}\{#MyAppExeName}; Description: {cm:LaunchProgram,{#MyAppName}}; Flags: nowait postinstall skipifsilent unchecked
82 Filename: {uninstallexe}; Parameters: /langsetup; Description: "{cm:SelectLanguage}"; Flags: postinstall nowait
84 [UninstallDelete]
85 Type: files; Name: {app}\{#MyAppUrlName}
86 Type: files; Name: {app}\{#MyAppBugsUrlName}
88 [CustomMessages]
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
94 [Registry]
95 Root: HKCU; Subkey: Environment; ValueType: string; ValueName: LANG; ValueData: {language}; Check: UsingWinNT
97 ; Following part is heavily based on GTK+ 2 setup
98 [Code]
99 program 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;
107 const
108 WM_SETTINGCHANGE = 26;
109 //HWND_BROADCAST = $FFFF;
110 SMTO_ABORTIFHUNG = 2;
112 function RevPos(const SearchStr, Str: string): Integer;
113 var i: Integer;
114 begin
116 if (Length(SearchStr) < Length(Str)) and (Pos(SearchStr, Str) > 0) then
117 for i := (Length(Str) - Length(SearchStr) + 1) downto 1 do
118 begin
120 if Copy(Str, i, Length(SearchStr)) = SearchStr then
121 begin
122 Result := i;
123 exit;
124 end;
126 end;
128 Result := 0;
129 end;
132 function ExtractLang(const Txt: String): String;
133 var S: String;
134 i: Integer;
135 begin
136 S := LowerCase(Txt);
137 if (S[Length(S)] = ')') then
138 begin
139 i := RevPos('(',S);
140 if (i > 0) then
141 S := Copy(Txt,i+1,Length(Txt)-i-1)
142 else
143 S := Txt;
144 end else
145 S := Txt;
147 Result := S;
148 end;
151 function GetLangIndex(Items: TStrings; Lang: String): Integer;
152 var i: Integer;
153 s: String;
154 begin
155 Lang := LowerCase(Lang);
156 for i := 0 to Items.Count - 1 do
157 begin
158 S := LowerCase(ExtractLang(Items.Strings[i]));
159 if (S = Lang) then
160 break;
161 end;
163 if (i >= Items.Count) then
164 Result := -1
165 else
166 Result := i;
167 end;
170 function GetTransStr(const Str: String): String; //ExpandConstant('{cm:...}') doesn't work on uninstall
171 begin
172 Result := GetIniString('CustomMessages',Str,'',ExpandConstant('{app}\uninst.isl'));
174 if (Result = '') then
175 RaiseException(Str + ' not found in translation file.');
176 end;
179 procedure LanguageForm;
180 var lblInfo, lblUser, lblSystem: TLabel;
181 btnOK,btnCancel: TButton;
182 frMsgs: TFindRec;
183 i,j: Integer;
184 lang1,lang2,regSys,regUser: String;
185 AutoExec: TArrayOfString;
186 MsgResult: DWORD;
187 begin
189 frmLangChooser := CreateCustomForm();
191 with frmLangChooser do
192 begin
193 ClientWidth := ScaleX(321);
194 ClientHeight := ScaleY(119);
195 Caption := GetTransStr('LangTitle');
196 Position := poScreenCenter;
197 end;
199 { lblInfo }
200 lblInfo := TLabel.Create(frmLangChooser);
201 with lblInfo do
202 begin
203 Parent := frmLangChooser;
204 Left := ScaleX(8);
205 Top := ScaleY(8);
206 Width := ScaleX(283);
207 Height := ScaleY(13);
208 Caption := GetTransStr('LangText');
209 end;
211 { lblUser }
212 lblUser := TLabel.Create(frmLangChooser);
213 with lblUser do
214 begin
215 Parent := frmLangChooser;
216 Left := ScaleX(8);
217 Top := ScaleY(34);
218 Width := ScaleX(119);
219 Height := ScaleY(13);
220 Caption := GetTransStr('LangUser');
221 FocusControl := cbUser;
222 end;
224 { lblSystem }
225 lblSystem := TLabel.Create(frmLangChooser);
226 with lblSystem do
227 begin
228 Parent := frmLangChooser;
229 Left := ScaleX(8);
230 Top := ScaleY(58);
231 Width := ScaleX(93);
232 Height := ScaleY(13);
233 Caption := GetTransStr('LangSystem');
234 FocusControl := cbSystem;
235 end;
237 { cbUser }
238 cbUser := TComboBox.Create(frmLangChooser);
239 with cbUser do
240 begin
241 Parent := frmLangChooser;
242 Style := csDropDownList;
243 Left := ScaleX(144);
244 Top := ScaleY(32);
245 Width := ScaleX(169);
246 Height := ScaleY(16);
247 Hint := GetTransStr('LangUserHint');
248 ShowHint := True;
249 TabOrder := 0;
250 Sorted := True;
251 end;
253 { cbSystem }
254 cbSystem := TComboBox.Create(frmLangChooser);
255 with cbSystem do
256 begin
257 Parent := frmLangChooser;
258 Style := csDropDownList;
259 Left := ScaleX(144);
260 Top := ScaleY(56);
261 Width := ScaleX(169);
262 Height := ScaleY(16);
263 Hint := GetTransStr('LangSystemHint');
264 ShowHint := True;
265 TabOrder := 1;
266 Sorted := True;
267 end;
269 { btnOK }
270 btnOK := TButton.Create(frmLangChooser);
271 with btnOK do
272 begin
273 Parent := frmLangChooser;
274 Left := ScaleX(82);
275 Top := ScaleY(88);
276 Width := ScaleX(75);
277 Height := ScaleY(23);
278 Caption := SetupMessage(msgButtonOK);
279 Default := True;
280 TabOrder := 2;
281 ModalResult := 1;
282 end;
284 { btnCancel }
285 btnCancel := TButton.Create(frmLangChooser);
286 with btnCancel do
287 begin
288 Parent := frmLangChooser;
289 Left := ScaleX(164);
290 Top := ScaleY(88);
291 Width := ScaleX(75);
292 Height := ScaleY(23);
293 Caption := SetupMessage(msgButtonCancel);
294 Cancel := True;
295 TabOrder := 3;
296 ModalResult := 2;
297 end;
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
304 begin
307 repeat
308 if ((frMsgs.Attributes and FILE_ATTRIBUTE_DIRECTORY) = FILE_ATTRIBUTE_DIRECTORY) and ((frMsgs.Name <> '.') and (frMsgs.Name <> '..')) then
309 begin
312 lang1 := frMsgs.Name;
313 StringChange(lang1,'@','_'); //custom messages only support letters,numbers and _
314 lang1 := GetTransStr('Lang_'+lang1+'');
315 except
316 lang1 := '';
317 end;
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))
324 except
325 lang1 := '';
326 end;
328 if (lang1 = '') and (Length(frMsgs.Name) > 2) then
330 lang1 := GetTransStr('Lang_'+Copy(frMsgs.Name,1,2)+'');
331 except
332 lang1 := '';
333 end;
335 case lowercase(lang2) of
336 'latn': lang2 := 'Latin';
337 end;
339 if (lang1 <> '') then
340 begin
341 if (lang2 <> '') then
342 begin
343 cbUser.Items.Add(lang1+' '+lang2+' ('+frMsgs.Name+')');
344 end else
345 begin
346 cbUser.Items.Add(lang1+' ('+frMsgs.Name+')');
348 end else
349 begin
350 cbUser.Items.Add(frMsgs.Name);
351 end;
353 end;
354 until not FindNext(frMsgs);
356 cbSystem.Items := cbUser.Items;
358 finally
359 FindClose(frMsgs);
360 end;
361 end;
363 if UsingWinNT then
364 begin
365 if not IsAdminLoggedOn then //only admins can change system-wide environment variables
366 begin
367 cbSystem.Enabled := False;
368 lblSystem.Enabled := False;
369 end;
371 if RegQueryStringValue(HKEY_LOCAL_MACHINE,'SYSTEM\CurrentControlSet\Control\Session Manager\Environment','LANG',regSys) then
372 cbSystem.ItemIndex := GetLangIndex(cbSystem.Items,regSys)
373 else
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)
382 else
383 cbUser.ItemIndex := 0;
385 if cbUser.ItemIndex = -1 then
386 cbUser.ItemIndex := cbUser.Items.Add(regUser);
387 end;
390 if frmLangChooser.ShowModal = 1 then
391 begin
392 regSys := ExtractLang(cbSystem.Items.Strings[cbSystem.ItemIndex]);
394 if UsingWinNT then
395 begin
396 regUser := ExtractLang(cbUser.Items.Strings[cbUser.ItemIndex]);
398 if cbUser.ItemIndex <> 0 then
399 begin
400 if not RegWriteStringValue(HKEY_CURRENT_USER,'Environment','LANG',regUser) then
401 MsgBox(GetTransStr('LangRegUserFailed'),mbCriticalError,mb_ok);
402 end else
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
408 begin
409 if cbSystem.ItemIndex <> 0 then
410 begin
411 if not RegWriteStringValue(HKEY_LOCAL_MACHINE,'SYSTEM\CurrentControlSet\Control\Session Manager\Environment','LANG',regSys) then
412 MsgBox(GetTransStr('LangRegSysFailed'),mbCriticalError,mb_ok);
413 end else
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);
417 end;
419 //straight from the Inno source
420 SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 'Environment', SMTO_ABORTIFHUNG, 5000, MsgResult);
422 end else
423 begin
424 if not FileCopy(ExpandConstant('{sd}\AutoExec.bat'),ExpandConstant('{sd}\AutoExec.WAM'),False) then
425 if MsgBox(GetTransStr('LangAutoExecBackupFailed'),mbConfirmation,mb_yesno) = idno then
426 exit;
428 if LoadStringsFromFile(ExpandConstant('{sd}\Autoexec.bat'), AutoExec) then
429 begin
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
435 begin
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);
439 end;
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)
449 else
450 MsgBox(GetTransStr('LangErrorSavingAutoExec'),mbCriticalError,mb_ok);
452 end else
453 MsgBox(GetTransStr('LangErrorLoadingAutoExec'), mbCriticalError, MB_OK);
454 end;
455 end;
457 end;
460 function InitializeUninstall(): Boolean;
461 var i: Integer;
462 begin
464 Result := True;
466 for i := 1 to ParamCount do
467 begin
468 if LowerCase(ParamStr(i)) = '/langsetup' then
469 begin
470 LanguageForm;
471 Result := False;
472 break;
473 end;
474 end;
477 end;
479 begin
480 end.