Changeset 433
- Timestamp:
- Nov 2, 2012, 12:11:21 PM (12 years ago)
- Location:
- UpdateChecker
- Files:
-
- 14 added
- 1 deleted
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
UpdateChecker/Languages/UUpdateChecker.cs.po
r379 r433 9 9 "MIME-Version: 1.0\n" 10 10 "Content-Transfer-Encoding: 8bit\n" 11 "X-Generator: Poedit 1.5.4\n" 11 12 12 13 #: uupdatechecker.scantexecutefile … … 14 15 msgstr "Nelze spustit instalátor \"%s\"" 15 16 17 #: uupdatechecker.schangesinnewversion 18 #| msgid "Changes in new version" 19 msgid "Changes in new version:" 20 msgstr "Změny v nové verzi:" 21 22 #: uupdatechecker.scheckupdates 23 msgid "Check updates" 24 msgstr "Kontrola aktualizací" 25 16 26 #: uupdatechecker.sdownloadprogress 17 27 msgid "Download progress" 18 28 msgstr "Průběh stahování" 29 30 #: uupdatechecker.serrorcheckingnewversion 31 msgid "New version check failed." 32 msgstr "Kontrola nové verze selhala." 19 33 20 34 #: uupdatechecker.sfile … … 23 37 msgstr "Soubor:" 24 38 39 #: uupdatechecker.snewversionavailable 40 msgid "New version available: %s. Do you want to download and install it now?" 41 msgstr "Je dostupná nová verze: %s. Chcete ji nyní stáhnout a nainstalovat?" 42 43 #: uupdatechecker.sno 44 #| msgid "No" 45 msgid "Later" 46 msgstr "Později" 47 25 48 #: uupdatechecker.sprogress 26 49 #| msgid "Progress" … … 28 51 msgstr "Průběh:" 29 52 53 #: uupdatechecker.swhatsnew 54 msgid "What's new?" 55 msgstr "Co je nového?" 56 30 57 #: uupdatechecker.swrongfileformat 31 58 msgid "Wrong file format" 32 59 msgstr "Nesprávný formát souboru" 33 60 61 #: uupdatechecker.syes 62 #| msgid "Yes" 63 msgid "Update" 64 msgstr "Aktualizovat" 65 66 #: uupdatechecker.syouhavelatestversion 67 msgid "You have latest version" 68 msgstr "Máte nejnovější verzi" -
UpdateChecker/Languages/UUpdateChecker.po
r379 r433 6 6 msgstr "" 7 7 8 #: uupdatechecker.schangesinnewversion 9 msgid "Changes in new version:" 10 msgstr "" 11 12 #: uupdatechecker.scheckupdates 13 msgid "Check updates" 14 msgstr "" 15 8 16 #: uupdatechecker.sdownloadprogress 9 17 msgid "Download progress" 18 msgstr "" 19 20 #: uupdatechecker.serrorcheckingnewversion 21 msgid "New version check failed." 10 22 msgstr "" 11 23 … … 14 26 msgstr "" 15 27 28 #: uupdatechecker.snewversionavailable 29 msgid "New version available: %s. Do you want to download and install it now?" 30 msgstr "" 31 32 #: uupdatechecker.sno 33 msgid "Later" 34 msgstr "" 35 16 36 #: uupdatechecker.sprogress 17 37 msgid "Progress:" 38 msgstr "" 39 40 #: uupdatechecker.swhatsnew 41 msgid "What's new?" 18 42 msgstr "" 19 43 … … 22 46 msgstr "" 23 47 48 #: uupdatechecker.syes 49 msgid "Update" 50 msgstr "" 51 52 #: uupdatechecker.syouhavelatestversion 53 msgid "You have latest version" 54 msgstr "" 55 -
UpdateChecker/ReadMe.txt
r379 r433 1 = Application information=1 =UpdateChecker= 2 2 3 * Application name 4 * Application group 5 * Version 6 * Release notes 7 * Architecture 8 * OS version 9 * Branch 10 * File location (Mirrors) 11 * Dependencies 3 Allow users to check for new application updates. If new version is available then information windows is shown and use can proceed to download and install refered setup program. 12 4 13 = Possible update methods=5 ==Features== 14 6 15 * Download and execute installer (NSIS, InnoSetup, etc.) 16 * Download and extract archive, rename exe file, restart application 7 * Can download setup from http or filesystem location 8 * Can read latest version description file and determine newest version 9 * Show new version changes 10 * Allow run setup with elevated privileges and exit currently running program 11 12 13 * Require Lazarus 1.0 FPC 2.6.0 14 -
UpdateChecker/UFormDownloadProgress.lfm
r379 r433 1 1 object FormDownloadProgress: TFormDownloadProgress 2 Left = 5992 Left = 410 3 3 Height = 75 4 Top = 2 124 Top = 278 5 5 Width = 376 6 6 Caption = 'Download progress' … … 20 20 object Label1: TLabel 21 21 Left = 7 22 Height = 1 422 Height = 13 23 23 Top = 8 24 Width = 2 124 Width = 20 25 25 Caption = 'File:' 26 26 ParentColor = False … … 28 28 object LabelFileName: TLabel 29 29 Left = 72 30 Height = 1 430 Height = 13 31 31 Top = 8 32 Width = 1 332 Width = 12 33 33 Caption = ' ' 34 34 ParentColor = False … … 36 36 object Label2: TLabel 37 37 Left = 8 38 Height = 1 438 Height = 13 39 39 Top = 25 40 Width = 4 740 Width = 46 41 41 Caption = 'Progress:' 42 42 ParentColor = False … … 44 44 object LabelProgress: TLabel 45 45 Left = 72 46 Height = 1 446 Height = 13 47 47 Top = 25 48 Width = 1 348 Width = 12 49 49 Caption = ' ' 50 50 ParentColor = False -
UpdateChecker/UFormDownloadProgress.lrs
r379 r433 2 2 3 3 LazarusResources.Add('TFormDownloadProgress','FORMDATA',[ 4 'TPF0'#21'TFormDownloadProgress'#20'FormDownloadProgress'#4'Left'#3 'W'#2#6'He'5 +' ight'#2'K'#3'Top'#3#212#0#5'Width'#3'x'#1#7'Caption'#6#17'Download progress'4 'TPF0'#21'TFormDownloadProgress'#20'FormDownloadProgress'#4'Left'#3#154#1#6'H' 5 +'eight'#2'K'#3'Top'#3#22#1#5'Width'#3'x'#1#7'Caption'#6#17'Download progress' 6 6 +#12'ClientHeight'#2'K'#11'ClientWidth'#3'x'#1#8'OnCreate'#7#10'FormCreate'#8 7 7 +'Position'#7#14'poScreenCenter'#10'LCLVersion'#6#3'1.1'#0#12'TProgressBar'#12 8 8 +'ProgressBar1'#4'Left'#2#8#6'Height'#2#20#3'Top'#2'0'#5'Width'#3'h'#1#7'Anch' 9 9 +'ors'#11#6'akLeft'#7'akRight'#8'akBottom'#0#8'TabOrder'#2#0#0#0#6'TLabel'#6 10 +'Label1'#4'Left'#2#7#6'Height'#2#1 4#3'Top'#2#8#5'Width'#2#21#7'Caption'#6#510 +'Label1'#4'Left'#2#7#6'Height'#2#13#3'Top'#2#8#5'Width'#2#20#7'Caption'#6#5 11 11 +'File:'#11'ParentColor'#8#0#0#6'TLabel'#13'LabelFileName'#4'Left'#2'H'#6'Hei' 12 +'ght'#2#1 4#3'Top'#2#8#5'Width'#2#13#7'Caption'#6#4' '#11'ParentColor'#8#013 +#0#6'TLabel'#6'Label2'#4'Left'#2#8#6'Height'#2#1 4#3'Top'#2#25#5'Width'#2'/'#712 +'ght'#2#13#3'Top'#2#8#5'Width'#2#12#7'Caption'#6#4' '#11'ParentColor'#8#0 13 +#0#6'TLabel'#6'Label2'#4'Left'#2#8#6'Height'#2#13#3'Top'#2#25#5'Width'#2'.'#7 14 14 +'Caption'#6#9'Progress:'#11'ParentColor'#8#0#0#6'TLabel'#13'LabelProgress'#4 15 +'Left'#2'H'#6'Height'#2#1 4#3'Top'#2#25#5'Width'#2#13#7'Caption'#6#4' '#1115 +'Left'#2'H'#6'Height'#2#13#3'Top'#2#25#5'Width'#2#12#7'Caption'#6#4' '#11 16 16 +'ParentColor'#8#0#0#0 17 17 ]); -
UpdateChecker/UUpdateChecker.pas
r404 r433 6 6 7 7 uses 8 {$IFDEF Windows}Windows, ShellApi, {$ENDIF}Forms, Classes, SysUtils, httpsend, DOM, XMLWrite, XMLRead, UXMLUtils, 9 FileUtil, Dialogs, Process, Blcksock, UFormDownloadProgress; 8 {$IFDEF Windows}Windows, ShellApi, {$ENDIF}Forms, Classes, SysUtils, 9 httpsend, DOM, XMLWrite, XMLRead, UXMLUtils, 10 FileUtil, Dialogs, Process, Blcksock, UFormDownloadProgress, Controls; 10 11 11 12 type … … 18 19 end; 19 20 21 TVersionInfoItem = (viiId, viiVersion, viiSourceURL, viiReleaseTime, 22 viiReleaseNotes); 23 TVersionInfoItems = set of TVersionInfoItem; 24 20 25 { TUpdateChecker } 21 26 … … 23 28 private 24 29 FBranchId: Integer; 30 FShowReleaseNotes: Boolean; 25 31 FVersionInfo: TVersionInfo; 26 32 HTTPSender: THTTPSend; 27 33 FOnTerminate: TNotifyEvent; 28 34 FVersionInfoURL: string; 35 InstallerFileName: string; 29 36 function DownloadHTTP(URL, TargetFile: string): Boolean; 30 function InstallerFileName: string;31 37 function IsSystemAdmin: Boolean; 32 38 procedure SockStatus(Sender: TObject; Reason: THookSocketReason; 33 const Value: String); 39 const Value: String); 40 function StripTags(XMLText: string): string; 41 function GetFile(URI: string; Content: TMemoryStream): Boolean; 34 42 public 35 43 FormDownloadProgress: TFormDownloadProgress; 36 44 constructor Create(AOwner: TComponent); override; 37 45 destructor Destroy; override; 38 function LoadVersionInfo : Boolean;46 function LoadVersionInfo(Items: TVersionInfoItems = []): Boolean; 39 47 { Download source file using HTTP protocol and save it to temp folder } 40 48 procedure Download; 41 49 procedure Install; 50 procedure Check(CurrentReleaseDate: TDateTime); 42 51 property VersionInfo: TVersionInfo read FVersionInfo write FVersionInfo; 43 52 published 44 53 property VersionInfoURL: string read FVersionInfoURL write FVersionInfoURL; 45 54 property BranchId: Integer read FBranchId write FBranchId; 55 property ShowReleaseNotes: Boolean read FShowReleaseNotes write FShowReleaseNotes; 46 56 property OnTerminate: TNotifyEvent read FOnTerminate write FOnTerminate; 47 57 end; … … 55 65 SFile = 'File:'; 56 66 SProgress = 'Progress:'; 67 SYouHaveLatestVersion = 'You have latest version'; 68 SNewVersionAvailable = 'New version available: %s. Do you want to download and install it now?'; 69 SErrorCheckingNewVersion = 'New version check failed.'; 70 SCheckUpdates = 'Check updates'; 71 SChangesInNewVersion = 'Changes in new version:'; 72 SWhatsNew = 'What''s new?'; 73 SYes = 'Update'; 74 SNo = 'Later'; 57 75 58 76 implementation 77 78 uses 79 UFormNewVersionOffer; 59 80 60 81 {$IFDEF Windows} … … 72 93 end; 73 94 95 function RunAsAdmin(const Handle: Hwnd; const Path, Params: string): Boolean; 96 var 97 sei: TShellExecuteInfoA; 98 begin 99 FillChar(sei, SizeOf(sei), 0); 100 sei.cbSize := SizeOf(sei); 101 sei.Wnd := Handle; 102 sei.fMask := SEE_MASK_FLAG_DDEWAIT or SEE_MASK_FLAG_NO_UI; 103 sei.lpVerb := 'runas'; 104 sei.lpFile := PAnsiChar(Path); 105 sei.lpParameters := PAnsiChar(Params); 106 sei.nShow := SW_SHOWNORMAL; 107 Result := ShellExecuteExA(@sei); 108 end; 109 74 110 { TUpdateChecker } 75 111 76 function TUpdateChecker.LoadVersionInfo: Boolean; 77 var 78 Content: string; 112 function TUpdateChecker.LoadVersionInfo(Items: TVersionInfoItems = []): Boolean; 113 var 79 114 URL: string; 80 115 XmlDocument: TXMLDocument; … … 82 117 Node2: TDOMNode; 83 118 Node3: TDOMNode; 84 begin 119 Content: TMemoryStream; 120 begin 121 Result := False; 85 122 FVersionInfo.Version := ''; 86 123 FVersionInfo.Id := 0; 87 124 FVersionInfo.SourceURL := ''; 88 with HTTPSender do begin 89 Clear; 90 URL := VersionInfoURL + '?BranchId=' + IntToStr(BranchId) + 91 '&Id&Version&SourceURL&ReleaseTime&Limit=1'; 92 if HTTPMethod('GET', URL) then begin 93 Document.Position := 0; 125 URL := VersionInfoURL; 126 if Pos('://', VersionInfoURL) > 0 then begin 127 URL := URL + '?BranchId=' + IntToStr(BranchId) + 128 '&Limit=1'; 129 if viiVersion in Items then URL := URL + '&Version'; 130 if viiReleaseNotes in Items then URL := URL + '&ReleaseNotes'; 131 if viiReleaseTime in Items then URL := URL + '&ReleaseTime'; 132 if viiSourceURL in Items then URL := URL + '&SourceURL'; 133 if viiId in Items then URL := URL + '&Id'; 134 end; 135 try 136 Content := TMemoryStream.Create; 137 if GetFile(URL, Content) then begin 94 138 try 95 ReadXMLFile(XmlDocument, Document);139 ReadXMLFile(XmlDocument, Content); 96 140 if XmlDocument.DocumentElement.NodeName <> 'SourceList' then 97 141 raise Exception.Create(SWrongFileFormat); … … 112 156 if Assigned(Node3) then 113 157 FVersionInfo.ReleaseTime := XMLTimeToDateTime(Node3.TextContent); 158 Node3 := Node2.FindNode('ReleaseNotes'); 159 if Assigned(Node3) then 160 FVersionInfo.ReleaseNotes := UTF8Encode(string(Node3.TextContent)); 114 161 Node2 := Node2.NextSibling; 115 162 end; 116 163 end; 164 Result := True; 117 165 finally 118 166 XmlDocument.Free; 119 167 end; 120 168 end; 121 end;122 Result := (FVersionInfo.Version <> '') and (VersionInfo.Id <> 0) and123 (VersionInfo.SourceURL <> '');169 finally 170 Content.Free; 171 end; 124 172 end; 125 173 … … 127 175 begin 128 176 if FVersionInfo.SourceURL <> '' then begin 129 HTTPSender.Clear; 130 try 131 FormDownloadProgress.Show; 132 FormDownloadProgress.ProgressBar1.Max := 0; 133 FormDownloadProgress.LabelFileName.Caption := VersionInfo.SourceURL; 134 HTTPSender.Sock.OnStatus := SockStatus; 135 if HTTPSender.HTTPMethod('GET', FVersionInfo.SourceURL) then 136 HTTPSender.Document.SaveToFile(InstallerFileName); 137 finally 138 FormDownloadProgress.Hide; 139 HTTPSender.Sock.OnStatus := nil; 177 if FileExistsUTF8(FVersionInfo.SourceURL) then 178 InstallerFileName := FVersionInfo.SourceURL 179 else begin 180 InstallerFileName := UTF8Encode(GetTempDir) + DirectorySeparator + 181 ExtractFileName(FVersionInfo.SourceURL); 182 HTTPSender.Clear; 183 try 184 FormDownloadProgress.Show; 185 FormDownloadProgress.ProgressBar1.Max := 0; 186 FormDownloadProgress.LabelFileName.Caption := VersionInfo.SourceURL; 187 HTTPSender.Sock.OnStatus := SockStatus; 188 if HTTPSender.HTTPMethod('GET', FVersionInfo.SourceURL) then 189 HTTPSender.Document.SaveToFile(InstallerFileName); 190 finally 191 FormDownloadProgress.Hide; 192 HTTPSender.Sock.OnStatus := nil; 193 end; 140 194 end; 141 195 end; … … 147 201 begin 148 202 if FileExistsUTF8(InstallerFileName) then begin 149 if not IsSystemAdmin then 150 try 203 if not IsSystemAdmin then begin 204 RunAsAdmin(FormNewVersionOffer.Handle, InstallerFileName, ''); 205 (*try 151 206 Process := TProcess.Create(nil); 152 207 Process.CommandLine := 'runas ' + InstallerFileName; 153 208 Process.Options := Process.Options + []; 154 Process.Execute;209 //Process.Execute; 155 210 finally 156 211 Process.Free; 157 end 158 //ShellExecute(0, PChar('runas'), PChar(InstallerFileName), 159 // 0, 0, SW_SHOWNORMAL) 160 else 212 end*) 213 end else 161 214 try 162 215 Process := TProcess.Create(nil); … … 171 224 end; 172 225 226 procedure TUpdateChecker.Check(CurrentReleaseDate: TDateTime); 227 begin 228 if LoadVersionInfo([viiReleaseTime]) then begin 229 if VersionInfo.ReleaseTime > CurrentReleaseDate then begin 230 LoadVersionInfo([viiVersion, viiReleaseTime, viiReleaseNotes, viiSourceURL]); 231 try 232 FormNewVersionOffer := TFormNewVersionOffer.Create(nil); 233 FormNewVersionOffer.LabelQuestion.Caption := Format(SNewVersionAvailable, [VersionInfo.Version]); 234 FormNewVersionOffer.MemoReleaseNotes.Lines.Text := Trim(StripTags(VersionInfo.ReleaseNotes)); 235 if ShowReleaseNotes then FormNewVersionOffer.BitBtnWhatsNew.Click; 236 if FormNewVersionOffer.ShowModal = mrYes then begin 237 Download; 238 Install; 239 end; 240 finally 241 FormNewVersionOffer.Free; 242 end; 243 end else ShowMessage(SYouHaveLatestVersion); 244 end else ShowMessage(SErrorCheckingNewVersion); 245 end; 246 173 247 function TUpdateChecker.DownloadHTTP(URL, TargetFile: string): Boolean; 174 248 // Download file; retry if necessary. … … 180 254 var 181 255 HTTPGetResult: Boolean; 182 HTTPSender: THTTPSend;183 256 RetryAttempt: Integer; 184 257 begin … … 221 294 end; 222 295 223 function TUpdateChecker.InstallerFileName: string;224 begin225 Result := UTF8Encode(GetTempDir) + DirectorySeparator +226 ExtractFileName(FVersionInfo.SourceURL);227 end;228 229 296 constructor TUpdateChecker.Create(AOwner: TComponent); 230 297 begin … … 260 327 end; 261 328 262 263 329 if bSuccess then 264 330 begin … … 299 365 Num: Integer; 300 366 begin 301 if (Reason = HR_SocketCreate) then begin367 if (Reason = HR_SocketCreate) and TryStrToInt(Value, Num) then begin 302 368 FormDownloadProgress.ProgressBar1.Position := Num; 303 369 Application.ProcessMessages; … … 315 381 end; 316 382 383 function TUpdateChecker.StripTags(XMLText: string): string; 384 begin 385 Result := ''; 386 while Pos('<', XMLText) > 0 do begin 387 Result := Result + Copy(XMLText, 1, Pos('<', XMLText) - 1); 388 Delete(XMLText, 1, Pos('<', XMLText)); 389 Delete(XMLText, 1, Pos('>', XMLText)); 390 end; 391 Result := Result + XMLText; 392 end; 393 394 function TUpdateChecker.GetFile(URI: string; Content: TMemoryStream): Boolean; 395 var 396 Buffer: array of Byte; 397 FileStream: TFileStream; 398 begin 399 Result := False; 400 Content.Size := 0; 401 if FileExistsUTF8(URI) then 402 try 403 FileStream := TFileStream.Create(URI, fmOpenRead); 404 Content.CopyFrom(FileStream, FileStream.Size); 405 Content.Position := 0; 406 Result := True; 407 finally 408 FileStream.Free; 409 end else 410 if (Copy(URI, 1, 7) = 'http://') or (Copy(URI, 1, 8) = 'https://') then 411 with THTTPSend.Create do 412 try 413 Clear; 414 if HTTPMethod('GET', URI) then begin 415 Document.Position := 0; 416 Content.CopyFrom(Document, Document.Size); 417 Content.Position := 0; 418 Result := True; 419 end; 420 finally 421 Free; 422 end; 423 end; 424 317 425 end. 318 426 -
UpdateChecker/UpdateChecker.lpk
r379 r433 19 19 </CompilerOptions> 20 20 <Description Value="Check for updates and perform application update"/> 21 <License Value="GNU/GPL "/>22 <Version Minor=" 1"/>23 <Files Count=" 3">21 <License Value="GNU/GPLv3"/> 22 <Version Minor="2"/> 23 <Files Count="4"> 24 24 <Item1> 25 25 <Filename Value="UUpdateChecker.pas"/> … … 35 35 <UnitName Value="UFormDownloadProgress"/> 36 36 </Item3> 37 <Item4> 38 <Filename Value="UFormNewVersionOffer.pas"/> 39 <UnitName Value="UFormNewVersionOffer"/> 40 </Item4> 37 41 </Files> 38 42 <i18n> -
UpdateChecker/UpdateChecker.pas
r379 r433 8 8 9 9 uses 10 UUpdateChecker, UFormDownloadProgress, LazarusPackageIntf; 10 UUpdateChecker, UFormDownloadProgress, UFormNewVersionOffer, 11 LazarusPackageIntf; 11 12 12 13 implementation
Note:
See TracChangeset
for help on using the changeset viewer.