Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.95 KB | None | 0 0
  1. [Code]
  2. // Function generated by ISTool.
  3. function NextButtonClick(CurPage: Integer): Boolean;
  4. begin
  5. Result := istool_download(CurPage);
  6. end;
  7.  
  8.  
  9. type
  10. TPositionStorage = array of Integer;
  11.  
  12. var
  13. CompPageModified: Boolean;
  14. CompPagePositions: TPositionStorage;
  15.  
  16. procedure SaveComponentsPage(out Storage: TPositionStorage);
  17. begin
  18. SetArrayLength(Storage, 15);
  19.  
  20. Storage[0] := WizardForm.Height;
  21. Storage[1] := WizardForm.NextButton.Top;
  22. Storage[2] := WizardForm.BackButton.Top;
  23. Storage[3] := WizardForm.CancelButton.Top;
  24. Storage[4] := WizardForm.ComponentsList.Height;
  25. Storage[5] := WizardForm.OuterNotebook.Height;
  26. Storage[6] := WizardForm.InnerNotebook.Height;
  27. Storage[7] := WizardForm.Bevel.Top;
  28. Storage[8] := WizardForm.BeveledLabel.Top;
  29. Storage[9] := WizardForm.ComponentsDiskSpaceLabel.Top;
  30. end;
  31.  
  32. procedure LoadComponentsPage(const Storage: TPositionStorage;
  33. HeightOffset: Integer);
  34. begin
  35. if GetArrayLength(Storage) <> 15 then
  36. RaiseException('Invalid storage array length.');
  37.  
  38. WizardForm.Height := Storage[0] + HeightOffset;
  39. WizardForm.NextButton.Top := Storage[1] + HeightOffset;
  40. WizardForm.BackButton.Top := Storage[2] + HeightOffset;
  41. WizardForm.CancelButton.Top := Storage[3] + HeightOffset;
  42. WizardForm.ComponentsList.Height := Storage[4] + HeightOffset;
  43. WizardForm.OuterNotebook.Height := Storage[5] + HeightOffset;
  44. WizardForm.InnerNotebook.Height := Storage[6] + HeightOffset;
  45. WizardForm.Bevel.Top := Storage[7] + HeightOffset;
  46. WizardForm.BeveledLabel.Top := Storage[8] + HeightOffset;
  47. WizardForm.ComponentsDiskSpaceLabel.Top := Storage[9] + HeightOffset;
  48. end;
  49.  
  50. procedure InitializeWizard;
  51. begin
  52. CompPageModified := False;
  53. end;
  54.  
  55. procedure CurPageChanged(CurPageID: Integer);
  56. begin
  57. if CurpageID = wpSelectComponents then
  58. begin
  59. SaveComponentsPage(CompPagePositions);
  60. LoadComponentsPage(CompPagePositions, 300);
  61. CompPageModified := True;
  62. end
  63. else
  64. if CompPageModified then
  65. begin
  66. LoadComponentsPage(CompPagePositions, 0);
  67. CompPageModified := False;
  68. end;
  69. end;
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89. procedure ExitProcess(exitCode:integer);
  90. external 'ExitProcess@kernel32.dll stdcall';
  91.  
  92. var progress:TOutputProgressWizardPage;
  93.  
  94. var
  95. NewInstallerPath:string;
  96.  
  97. procedure DownloadFinished(downloadPage:TWizardPage);
  98. var ErrorCode:integer;
  99. (* text:string; *)
  100. begin
  101. (*
  102. Tell the user about the new installer. The message is pretty ugly if
  103. NewInstallerPath is left at the default (The {tmp} directory)
  104.  
  105. text:=ITD_GetString(ITDS_Update_WillLaunchWithPath);
  106.  
  107. StringChangeEx(text, '%1', NewInstallerPath, true);
  108.  
  109. MsgBox(text, mbInformation, MB_OK);
  110. *)
  111.  
  112. MsgBox(ITD_GetString(ITDS_Update_WillLaunch), mbInformation, MB_OK);
  113.  
  114. if ShellExec('open', NewInstallerPath, '/updated',
  115. ExtractFilePath(NewInstallerPath), SW_SHOW, ewNoWait, ErrorCode) then
  116. ExitProcess(1);
  117. end;
  118.  
  119. { Compare the version string 'this' against the version string 'that'. A version
  120. string looks like: 1.3.2.100. Or possibly truncated: 1.3.
  121.  
  122. Returns a positive number if this>that, 0 if this=that and a negative number
  123. if this<that.
  124. }
  125. function CompareVersions(this, that:string):integer;
  126. var thisField, thatField:integer;
  127. begin
  128. while (length(this)>0) or (length(that)>0) do begin
  129. if (pos('.',this)>0) then begin
  130. //Read the first field from the string
  131. thisField:=StrToIntDef(Copy(this, 1, pos('.',this)-1),0);
  132. //Remove the first field from the string
  133. this:=Copy(this, pos('.',this)+1, length(this));
  134. end else begin
  135. thisField:=StrToIntDef(this, 0);
  136. this:='';
  137. end;
  138.  
  139. if (pos('.',that)>0) then begin
  140. //Read the first field from the string
  141. thatField:=StrToIntDef(Copy(that, 1, pos('.',that)-1),0);
  142. //Remove the first field from the string
  143. that:=Copy(that, pos('.',that)+1, length(that));
  144. end else begin
  145. thatField:=StrToIntDef(that, 0);
  146. that:='';
  147. end;
  148.  
  149. if thisField>thatField then begin
  150. result:=1;
  151. exit;
  152. end else if thisField<thatField then begin
  153. result:=-1;
  154. exit;
  155. end;
  156. end;
  157.  
  158. result:=0;
  159. end;
  160.  
  161. procedure InitializeWizard();
  162. var
  163. downloadPage:TWizardpage;
  164. begin
  165. itd_init;
  166.  
  167. //Where the new installer should be saved to, can be anywhere.
  168. NewInstallerPath:=ExpandConstant('{tmp}\NewInstaller.exe');
  169.  
  170. {Create our own progress page for the initial download of a small
  171. textfile from the server which says what the latest version is}
  172. progress:=CreateOutputProgressPage(ITD_GetString(ITDS_Update_Caption),
  173. ITD_GetString(ITDS_Update_Description));
  174.  
  175. //Create the ITD GUI so that we have it if we decide to download a new intaller version
  176. downloadPage:=itd_downloadafter(wpWelcome);
  177.  
  178. {If the download succeeds, we will need to launch the new installer. The
  179. callback is called if the download is successful.}
  180. itd_afterSuccess:=@downloadfinished;
  181.  
  182. {If the download of the new installer fails, we still want to give the
  183. user the option of continuing with the original installation}
  184. itd_setoption('UI_AllowContinue','1');
  185. end;
  186.  
  187. function NextButtonClick(curPageID:integer):boolean;
  188. var
  189. list, line:TStringList;
  190. newavail:boolean;
  191. i:integer;
  192. ourVersion:string;
  193. checkedSuccessfully:boolean;
  194. text:string;
  195. begin
  196. result:=true;
  197. if curPageID=wpWelcome then begin
  198.  
  199. //Are we being called by an updating setup? If so, don't ask to check for updates again!
  200. for i:=1 to ParamCount do begin
  201. if uppercase(ParamStr(i))='/UPDATED' then begin
  202. exit;
  203. end;
  204. end;
  205.  
  206. //Offer to check for a new version for the user..
  207. if MsgBox(ITD_GetString(ITDS_Update_WantToCheck), mbConfirmation, MB_YESNO) = IDYES then
  208. begin
  209. wizardform.show;
  210. progress.Show;
  211. progress.SetText(ITD_GetString(ITDS_Update_Checking),'');
  212. progress.SetProgress(2,10);
  213. try
  214. newavail:=false;
  215.  
  216. checkedSuccessfully:=false;
  217. GetVersionNumbersString(expandconstant('{srcexe}'), ourVersion);
  218.  
  219. if itd_downloadfile('http://www.sherlocksoftware.org/innotools/latestver.txt',expandconstant('{tmp}\latestver.txt'))=ITDERR_SUCCESS then begin
  220. { Now read the version from that file and see if it is newer.
  221. The file has a really simple format:
  222.  
  223. 2.0,"http://www.sherlocksoftware.org/innotools/example3%202.0.exe"
  224.  
  225. The installer version, a comma, and the URL where the new version can be downloaded.
  226. }
  227. list:=TStringList.create;
  228. try
  229. list.loadfromfile(expandconstant('{tmp}\latestver.txt'));
  230.  
  231. if list.count>0 then begin
  232. line:=TStringList.create;
  233. try
  234. line.commatext:=list[0]; //Break down the line into its components
  235.  
  236. if line.count>=2 then begin
  237. checkedSuccessfully:=true;
  238. if CompareVersions(trim(line[0]), trim(ourVersion))>0 then begin
  239. //Version is newer
  240. text:=ITD_GetString(ITDS_Update_NewAvailable);
  241.  
  242. StringChangeEx(text, '%1', ourVersion, true); //"Current version" part of the string
  243. StringChangeEx(text, '%2', line[0], true); //"New version" part of the string
  244.  
  245. if MsgBox(text, mbConfirmation, MB_YESNO)=IDYES then begin
  246. itd_addFile(trim(line[1]), NewInstallerPath);
  247. end;
  248. end else begin
  249. MsgBox(ITD_GetString(ITDS_Update_NoNewAvailable), mbInformation, MB_OK);
  250. end;
  251. end;
  252. finally
  253. line.free;
  254. end;
  255. end;
  256. finally
  257. list.free;
  258. end;
  259. end;
  260.  
  261. if not checkedSuccessfully then begin
  262. text:=ITD_GetString(ITDS_Update_Failed);
  263. StringChangeEx(text, '%1', ourVersion, true);
  264. MsgBox(text, mbInformation, MB_OK);
  265. end;
  266. finally
  267. progress.Hide;
  268. end;
  269. end;
  270. end;
  271. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement