Code cleanup

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5673 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
gbamber
2017-01-17 12:26:03 +00:00
parent 6dba1cf993
commit c3a3d7edd1
2 changed files with 271 additions and 250 deletions

View File

@ -10,7 +10,7 @@
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="2"/> <EditorIndex Value="2"/>
<CursorPos X="33" Y="27"/> <CursorPos X="33" Y="27"/>
<UsageCount Value="50"/> <UsageCount Value="51"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit0> </Unit0>
<Unit1> <Unit1>
@ -21,7 +21,7 @@
<ResourceBaseClass Value="Form"/> <ResourceBaseClass Value="Form"/>
<TopLine Value="64"/> <TopLine Value="64"/>
<CursorPos X="19" Y="103"/> <CursorPos X="19" Y="103"/>
<UsageCount Value="50"/> <UsageCount Value="51"/>
<Loaded Value="True"/> <Loaded Value="True"/>
<LoadedDesigner Value="True"/> <LoadedDesigner Value="True"/>
</Unit1> </Unit1>
@ -32,7 +32,7 @@
<WindowIndex Value="1"/> <WindowIndex Value="1"/>
<TopLine Value="3"/> <TopLine Value="3"/>
<CursorPos X="76" Y="8"/> <CursorPos X="76" Y="8"/>
<UsageCount Value="33"/> <UsageCount Value="34"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit2> </Unit2>
<Unit3> <Unit3>
@ -44,15 +44,15 @@
<Unit4> <Unit4>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<IsVisibleTab Value="True"/> <IsVisibleTab Value="True"/>
<EditorIndex Value="1"/> <WindowIndex Value="1"/>
<TopLine Value="45"/> <TopLine Value="547"/>
<CursorPos X="42" Y="72"/> <CursorPos X="45" Y="572"/>
<ExtraEditorCount Value="2"/> <ExtraEditorCount Value="2"/>
<ExtraEditor1> <ExtraEditor1>
<IsVisibleTab Value="True"/> <IsVisibleTab Value="True"/>
<WindowIndex Value="1"/> <EditorIndex Value="1"/>
<TopLine Value="389"/> <TopLine Value="45"/>
<CursorPos X="41" Y="399"/> <CursorPos X="42" Y="72"/>
</ExtraEditor1> </ExtraEditor1>
<ExtraEditor2> <ExtraEditor2>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
@ -60,7 +60,7 @@
<TopLine Value="-1"/> <TopLine Value="-1"/>
<CursorPos X="-1" Y="-1"/> <CursorPos X="-1" Y="-1"/>
</ExtraEditor2> </ExtraEditor2>
<UsageCount Value="24"/> <UsageCount Value="25"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit4> </Unit4>
<Unit5> <Unit5>
@ -147,7 +147,7 @@
<WindowIndex Value="1"/> <WindowIndex Value="1"/>
<TopLine Value="35"/> <TopLine Value="35"/>
<CursorPos X="40" Y="51"/> <CursorPos X="40" Y="51"/>
<UsageCount Value="14"/> <UsageCount Value="15"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit16> </Unit16>
<Unit17> <Unit17>
@ -159,126 +159,129 @@
<UsageCount Value="11"/> <UsageCount Value="11"/>
</Unit17> </Unit17>
</Units> </Units>
<General>
<ActiveWindowIndexAtStart Value="1"/>
</General>
<JumpHistory Count="30" HistoryIndex="29"> <JumpHistory Count="30" HistoryIndex="29">
<Position1> <Position1>
<Filename Value="..\open_ssl.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="26" Column="8" TopLine="2"/> <Caret Line="55" Column="19" TopLine="28"/>
</Position1> </Position1>
<Position2> <Position2>
<Filename Value="..\open_ssl.pas"/> <Filename Value="umainform.pas"/>
<Caret Line="16" TopLine="3"/> <Caret Line="53" Column="103" TopLine="32"/>
</Position2> </Position2>
<Position3> <Position3>
<Filename Value="..\open_ssl.pas"/> <Filename Value="umainform.pas"/>
<Caret Line="26" Column="2" TopLine="5"/> <Caret Line="82" Column="9" TopLine="47"/>
</Position3> </Position3>
<Position4> <Position4>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="umainform.pas"/>
<Caret Line="56" Column="27" TopLine="28"/> <Caret Line="89" Column="30" TopLine="58"/>
</Position4> </Position4>
<Position5> <Position5>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="umainform.pas"/>
<Caret Line="52" Column="19" TopLine="28"/> <Caret Line="15" Column="23"/>
</Position5> </Position5>
<Position6> <Position6>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="umainform.pas"/>
<Caret Line="56" Column="19" TopLine="28"/> <Caret Line="79" Column="26" TopLine="53"/>
</Position6> </Position6>
<Position7> <Position7>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="umainform.pas"/>
<Caret Line="926" Column="38" TopLine="889"/> <Caret Line="157" Column="94" TopLine="115"/>
</Position7> </Position7>
<Position8> <Position8>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="umainform.pas"/>
<Caret Line="55" Column="27" TopLine="29"/> <Caret Line="95" TopLine="64"/>
</Position8> </Position8>
<Position9> <Position9>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="926" Column="38" TopLine="892"/> <Caret Line="518" Column="16" TopLine="483"/>
</Position9> </Position9>
<Position10> <Position10>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="1083" Column="39" TopLine="1045"/> <Caret Line="1823" Column="4" TopLine="1796"/>
</Position10> </Position10>
<Position11> <Position11>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="51" Column="22" TopLine="28"/> <Caret Line="577" Column="7" TopLine="544"/>
</Position11> </Position11>
<Position12> <Position12>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="52" Column="19" TopLine="28"/> <Caret Line="539" Column="7" TopLine="516"/>
</Position12> </Position12>
<Position13> <Position13>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="55" Column="19" TopLine="28"/> <Caret Line="331" Column="71" TopLine="300"/>
</Position13> </Position13>
<Position14> <Position14>
<Filename Value="umainform.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="53" Column="103" TopLine="32"/> <Caret Line="1869" TopLine="1830"/>
</Position14> </Position14>
<Position15> <Position15>
<Filename Value="umainform.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="82" Column="9" TopLine="47"/> <Caret Line="228" Column="23" TopLine="199"/>
</Position15> </Position15>
<Position16> <Position16>
<Filename Value="umainform.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="89" Column="30" TopLine="58"/> <Caret Line="331" Column="88" TopLine="309"/>
</Position16> </Position16>
<Position17> <Position17>
<Filename Value="umainform.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="15" Column="23"/> <Caret Line="1514" TopLine="1489"/>
</Position17> </Position17>
<Position18> <Position18>
<Filename Value="umainform.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="79" Column="26" TopLine="53"/> <Caret Line="61" Column="80" TopLine="37"/>
</Position18> </Position18>
<Position19> <Position19>
<Filename Value="umainform.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="157" Column="94" TopLine="115"/> <Caret Line="757" Column="2" TopLine="718"/>
</Position19> </Position19>
<Position20> <Position20>
<Filename Value="umainform.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="95" TopLine="64"/> <Caret Line="2282" Column="46" TopLine="2250"/>
</Position20> </Position20>
<Position21> <Position21>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="518" Column="16" TopLine="483"/> <Caret Line="592" Column="3" TopLine="567"/>
</Position21> </Position21>
<Position22> <Position22>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="1823" Column="4" TopLine="1796"/> <Caret Line="982" TopLine="966"/>
</Position22> </Position22>
<Position23> <Position23>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="577" Column="7" TopLine="544"/> <Caret Line="1745" Column="17" TopLine="1720"/>
</Position23> </Position23>
<Position24> <Position24>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="539" Column="7" TopLine="516"/> <Caret Line="1898" Column="17" TopLine="1873"/>
</Position24> </Position24>
<Position25> <Position25>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="331" Column="71" TopLine="300"/> <Caret Line="2267" TopLine="2247"/>
</Position25> </Position25>
<Position26> <Position26>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="1869" TopLine="1830"/> <Caret Line="2286" Column="17" TopLine="2247"/>
</Position26> </Position26>
<Position27> <Position27>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="228" Column="23" TopLine="199"/> <Caret Line="2270" TopLine="2246"/>
</Position27> </Position27>
<Position28> <Position28>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="331" Column="88" TopLine="309"/> <Caret Line="2273" Column="17" TopLine="2246"/>
</Position28> </Position28>
<Position29> <Position29>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="1514" TopLine="1489"/> <Caret Line="2269" TopLine="2244"/>
</Position29> </Position29>
<Position30> <Position30>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="61" Column="80" TopLine="37"/> <Caret Line="592" Column="3" TopLine="567"/>
</Position30> </Position30>
</JumpHistory> </JumpHistory>
</ProjectSession> </ProjectSession>

View File

@ -115,7 +115,8 @@ const
V0.2.0: Rewritten for 2017 V0.2.0: Rewritten for 2017
V0.2.4: GitHub integration with branches V0.2.4: GitHub integration with branches
V0.2.5: IsWindowsAdministrator check added and property to control it V0.2.5: IsWindowsAdministrator check added and property to control it
V0.2.6: V0.2.6: Enabled GitHub tags (GitHubBranchOrTag property)
V0.2.7:
} }
C_TThreadedDownloadComponentVersion = '0.0.3'; C_TThreadedDownloadComponentVersion = '0.0.3';
{ {
@ -201,7 +202,7 @@ type
type type
// This type is currently unused
TProjectType = (auSourceForge, auGitHubReleaseZip, auOther); TProjectType = (auSourceForge, auGitHubReleaseZip, auOther);
// Array of these records used for multiple updates // Array of these records used for multiple updates
UpdateListRecord = record UpdateListRecord = record
@ -210,7 +211,9 @@ type
VersionString: string; VersionString: string;
VersionNumber: cardinal; VersionNumber: cardinal;
end; end;
TThreadedDownload = class; // Forward declaration TThreadedDownload = class; // Forward declaration
{TLAZAUTOUPDATE} {TLAZAUTOUPDATE}
TOnNewVersionAvailable = procedure(Sender: TObject; Newer: boolean; TOnNewVersionAvailable = procedure(Sender: TObject; Newer: boolean;
OnlineVersion: string) of object; OnlineVersion: string) of object;
@ -222,9 +225,9 @@ type
TLazAutoUpdate = class(TAboutLazAutoUpdate) TLazAutoUpdate = class(TAboutLazAutoUpdate)
private private
fSourceForgeProjectName: string; fSourceForgeProjectName: string;
fGitHubProjectName:String; fGitHubProjectName: string;
fGitHubRepositoryName:String; fGitHubRepositoryName: string;
fGitHubBranch:String; fGitHubBranchOrTag: string;
fApplicationVersionString: string; fApplicationVersionString: string;
fApplicationVersionQuad: TVersionQuad; fApplicationVersionQuad: TVersionQuad;
fGuiQuad: TVersionQuad; fGuiQuad: TVersionQuad;
@ -243,7 +246,7 @@ type
fGUIOnlineVersion: string; fGUIOnlineVersion: string;
fShowDialogs: boolean; fShowDialogs: boolean;
fDownloadInprogress: boolean; fDownloadInprogress: boolean;
fWindowsAdminCheck:Boolean; fWindowsAdminCheck: boolean;
{$IFDEF UNIX} {$IFDEF UNIX}
FUpdateHMProcess: TAsyncProcess; FUpdateHMProcess: TAsyncProcess;
{$ENDIF} {$ENDIF}
@ -265,7 +268,7 @@ type
// fQuad: TVersionQuad; // fQuad: TVersionQuad;
fProgVersion: TProgramVersion; fProgVersion: TProgramVersion;
objFileVerInfo: TFileVersionInfo; objFileVerInfo: TFileVersionInfo;
fUpdateExe,fUpdateSilentExe:String; fUpdateExe, fUpdateSilentExe: string;
procedure SetProjectType(AValue: TProjectType); procedure SetProjectType(AValue: TProjectType);
// projectype=auOther property Sets // projectype=auOther property Sets
procedure SetauOtherSourceFilename(AValue: string); procedure SetauOtherSourceFilename(AValue: string);
@ -278,7 +281,8 @@ type
procedure SetDebugMode(AValue: boolean); procedure SetDebugMode(AValue: boolean);
function GetThreadDownloadReturnCode: integer; function GetThreadDownloadReturnCode: integer;
function IsOnlineVersionNewer(const sznewINIPath: string): boolean; function IsOnlineVersionNewer(const sznewINIPath: string): boolean;
function VersionStringToNumber(AVersionString: string): integer; // No longer needed
// function VersionStringToNumber(AVersionString: string): integer;
function DoSilentUpdate: boolean; function DoSilentUpdate: boolean;
protected protected
@ -346,7 +350,7 @@ type
property FPCVersion: string read fFPCVersion; property FPCVersion: string read fFPCVersion;
property LastCompiled: string read fLastCompiled; property LastCompiled: string read fLastCompiled;
property TargetOS: string read fTargetOS; property TargetOS: string read fTargetOS;
property WindowsAdminCheck:Boolean read fWindowsAdminCheck write fWindowsAdminCheck; property WindowsAdminCheck: boolean read fWindowsAdminCheck write fWindowsAdminCheck;
published published
// Events // Events
property OnNewVersionAvailable: TOnNewVersionAvailable property OnNewVersionAvailable: TOnNewVersionAvailable
@ -391,15 +395,16 @@ type
// Default is application filename.zip // Default is application filename.zip
property ZipfileName: string read fZipfileName write fZipfileName; property ZipfileName: string read fZipfileName write fZipfileName;
// Name of Console app // Name of Console app
property UpdateExe:String read fUpdateExe; property UpdateExe: string read fUpdateExe;
// Name of Console app // Name of Console app
property UpdateExeSilent:String read fUpdateSilentExe; property UpdateExeSilent: string read fUpdateSilentExe;
// Main project name/UserName // Main project name/UserName
property GitHubProjectname:String read fGitHubProjectName write fGitHubProjectName; property GitHubProjectname: string read fGitHubProjectName write fGitHubProjectName;
// Name of your GitHub repository within the project/username // Name of your GitHub repository within the project/username
Property GitHubRepositoryName:String read fGitHubRepositoryName write fGitHubRepositoryName; property GitHubRepositoryName: string read fGitHubRepositoryName
// Default=master but any branchname is OK write fGitHubRepositoryName;
Property GitHubBranchOrTag:String read fGitHubBranch write fGitHubBranch; // Default=master but any branchname or tagname is OK
property GitHubBranchOrTag: string read fGitHubBranchOrTag write fGitHubBranchOrTag;
end; end;
{TThreadedDownload } {TThreadedDownload }
@ -463,8 +468,7 @@ type
// Non-threaded version (redundant v0.0.1) // Non-threaded version
function DownloadHTTP(URL, TargetFile: string; var ReturnCode, DownloadSize: integer; function DownloadHTTP(URL, TargetFile: string; var ReturnCode, DownloadSize: integer;
bIsSourceForge, fDebugMode: boolean): boolean; bIsSourceForge, fDebugMode: boolean): boolean;
@ -478,6 +482,7 @@ begin
RegisterComponents('System', [TLazAutoUpdate]); RegisterComponents('System', [TLazAutoUpdate]);
end; end;
// Dummy thread to initialise the threading process
procedure tc.Execute; procedure tc.Execute;
begin begin
@ -496,13 +501,16 @@ procedure TLazAutoUpdate.DebugTest;
begin begin
ShowMessage(fApplicationVersionString); ShowMessage(fApplicationVersionString);
end; end;
{$IFDEF WINDOWS}
{$IFDEF WINDOWS}
// === START WINDOWS PROCS =====================================================
// This is all about permissions in Windows 10
procedure ShowAdminCheckMessage; procedure ShowAdminCheckMessage;
Var sMessage:String; var
sMessage: string;
begin begin
sMessage := Format(rsOnlyWindowsU, [lineending, lineending, lineending]); sMessage := Format(rsOnlyWindowsU, [lineending, lineending, lineending]);
MessageDlg(rsApplicationU, sMessage, mtInformation, [MBOK], 0); MessageDlg(rsApplicationU, sMessage, mtInformation, [mbOK], 0);
end; end;
function IsXP: boolean; function IsXP: boolean;
@ -519,7 +527,7 @@ begin
Result := False; Result := False;
end; end;
function IsWindowsAdmin: Boolean; function IsWindowsAdmin: boolean;
const const
SECURITY_NT_AUTHORITY: TSIDIdentifierAuthority = SECURITY_NT_AUTHORITY: TSIDIdentifierAuthority =
(Value: (0, 0, 0, 0, 0, 5)); (Value: (0, 0, 0, 0, 0, 5));
@ -530,7 +538,7 @@ var
ptgGroups: PTokenGroups; ptgGroups: PTokenGroups;
dwInfoBufferSize: DWORD; dwInfoBufferSize: DWORD;
psidAdministrators: PSID; psidAdministrators: PSID;
x: Integer; x: integer;
bSuccess: BOOL; bSuccess: BOOL;
LastError: integer; LastError: integer;
begin begin
@ -542,13 +550,11 @@ begin
end; end;
Result := False; Result := False;
bSuccess := OpenThreadToken(GetCurrentThread, TOKEN_QUERY, True, bSuccess := OpenThreadToken(GetCurrentThread, TOKEN_QUERY, True, hAccessToken);
hAccessToken);
if not bSuccess then if not bSuccess then
begin begin
if GetLastError = ERROR_NO_TOKEN then if GetLastError = ERROR_NO_TOKEN then
bSuccess := OpenProcessToken(GetCurrentProcess, TOKEN_QUERY, bSuccess := OpenProcessToken(GetCurrentProcess, TOKEN_QUERY, hAccessToken);
hAccessToken);
end; end;
if bSuccess then if bSuccess then
begin begin
@ -557,7 +563,7 @@ begin
ptgGroups, 1024, @dwInfoBufferSize); ptgGroups, 1024, @dwInfoBufferSize);
LastError := GetLastError; LastError := GetLastError;
if not bSuccess then if not bSuccess then
showmessage(format('GetLastError %d',[LastError])); ShowMessage(format('GetLastError %d', [LastError]));
CloseHandle(hAccessToken); CloseHandle(hAccessToken);
if bSuccess then if bSuccess then
begin begin
@ -579,7 +585,7 @@ begin
end; end;
function IsWindowsAdminWinXP: boolean; function IsWindowsAdminWinXP: boolean;
CONST const
GENERIC_READ = $80000000; GENERIC_READ = $80000000;
GENERIC_WRITE = $40000000; GENERIC_WRITE = $40000000;
GENERIC_EXECUTE = $20000000; GENERIC_EXECUTE = $20000000;
@ -595,6 +601,8 @@ begin
CloseServiceHandle(hSC); CloseServiceHandle(hSC);
end; end;
{$ENDIF} {$ENDIF}
// === END WINDOWS PROCS =======================================================
constructor TLazAutoUpdate.Create(AOwner: TComponent); constructor TLazAutoUpdate.Create(AOwner: TComponent);
var var
sz: string; sz: string;
@ -608,16 +616,21 @@ begin
Free; Free;
end; end;
// Freed in Destroy
fThreadDownload := TThreadedDownload.Create(); fThreadDownload := TThreadedDownload.Create();
// Leave URL and Filename to be set via properties // Leave URL and Filename to be set via properties
fComponentVersion := C_TLazAutoUpdateComponentVersion; fComponentVersion := C_TLazAutoUpdateComponentVersion;
// Unused
ClearUpdateList; ClearUpdateList;
fUpdateListCount := 0; fUpdateListCount := 0;
// Grab the application and form objects from the application // Grab the application and form objects from the application
fParentApplication := Tapplication(AOwner.Owner); fParentApplication := Tapplication(AOwner.Owner);
fParentForm := TForm(AOwner); fParentForm := TForm(AOwner);
// Set default
fApplicationVersionString := 'No build information available'; fApplicationVersionString := 'No build information available';
// Get Versioninfo
objFileVerInfo := TFileVersionInfo.Create(fParentApplication); objFileVerInfo := TFileVersionInfo.Create(fParentApplication);
try try
try try
@ -636,7 +649,6 @@ begin
finally finally
objFileVerInfo.Free; objFileVerInfo.Free;
end; end;
// fApplicationVersionString := GetFileVersion;
if (fApplicationVersionString = 'No build information available') then if (fApplicationVersionString = 'No build information available') then
fApplicationVersionString := '0.0.0.0'; fApplicationVersionString := '0.0.0.0';
@ -670,6 +682,7 @@ begin
fZipfileName := ''; // assign later fZipfileName := ''; // assign later
// BE SURE TO CHANGE THE CONSTANTS IF YOU CHANGE THE UPDATE EXE NAME
fUpdateExe := C_UPDATER; fUpdateExe := C_UPDATER;
fUpdateSilentExe := C_LOCALUPDATER; fUpdateSilentExe := C_LOCALUPDATER;
@ -680,7 +693,7 @@ begin
fFPCVersion := GetCompilerInfo; fFPCVersion := GetCompilerInfo;
fLastCompiled := GetCompiledDate; fLastCompiled := GetCompiledDate;
fTargetOS := GetOS; fTargetOS := GetOS;
fWindowsAdminCheck:=TRUE; fWindowsAdminCheck := True;
// AboutBox properties // AboutBox properties
@ -720,7 +733,8 @@ function TLazAutoUpdate.AppIsActive(const ExeName: string): boolean;
begin begin
Result := AppIsRunning(ExeName); Result := AppIsRunning(ExeName);
end; end;
{
// Obselete. fileinfo functions used instead
function TLazAutoUpdate.VersionStringToNumber(AVersionString: string): integer; function TLazAutoUpdate.VersionStringToNumber(AVersionString: string): integer;
// Converts 'n.n.n.n' into an integer // Converts 'n.n.n.n' into an integer
var var
@ -742,7 +756,7 @@ begin
if TryStrToInt(s, i) then if TryStrToInt(s, i) then
Result := Result + i; Result := Result + i;
end; end;
}
procedure TLazAutoUpdate.ResetAppVersion; procedure TLazAutoUpdate.ResetAppVersion;
begin begin
fApplicationVersionString := GetFileVersion; fApplicationVersionString := GetFileVersion;
@ -869,6 +883,7 @@ begin
end; end;
function TLazAutoUpdate.SilentUpdate: boolean; function TLazAutoUpdate.SilentUpdate: boolean;
// Part of the tray update system
begin begin
// read the VMT once // read the VMT once
if Assigned(fOndebugEvent) then if Assigned(fOndebugEvent) then
@ -964,7 +979,6 @@ function TLazAutoUpdate.IsOnlineVersionNewer(const sznewINIPath: string): boolea
// to fApplicationVersionNumber // to fApplicationVersionNumber
var var
VersionINI: TIniFile; VersionINI: TIniFile;
iGUIVersion: integer;
{ {
C_INISection = 'versions'; C_INISection = 'versions';
C_GUIEntry ='GUI'; C_GUIEntry ='GUI';
@ -985,20 +999,13 @@ begin
VersionINI.Free; VersionINI.Free;
end; end;
if fFireDebugEvent then if fFireDebugEvent then
fOndebugEvent(Self, 'IsSourceForgeVersionNewer', fOndebugEvent(Self, 'IsOnlineVersionNewer',
Format('fGUIOnlineVersion=%s, fApplicationVersionString=%s, szTempXMLPath=%s', Format('fGUIOnlineVersion=%s, fApplicationVersionString=%s, szTempXMLPath=%s',
[fGUIOnlineVersion, fApplicationVersionString, sznewINIPath])); [fGUIOnlineVersion, fApplicationVersionString, sznewINIPath]));
// Fetch the 4 (or less) version elements and make into an Integer // Fetch the 4 (or less) version elements and make into an Integer
// so 1.10 > 1.9.9.9 // so 1.10 > 1.9.9.9
// iGUIVersion := VersionStringToNumber(fGUIOnlineVersion); // iGUIVersion := VersionStringToNumber(fGUIOnlineVersion);
{
if fFireDebugEvent then
fOndebugEvent(Self, 'IsSourceForgeVersionNewer',
Format('iGUIVersion=%d, fApplicationVersionNumber=%d',
[iGUIVersion, fApplicationVersionQuad]));
}
// Test: Is the online version newer? // Test: Is the online version newer?
if NewerVersion(fGUIQuad, fApplicationVersionQuad) then if NewerVersion(fGUIQuad, fApplicationVersionQuad) then
Result := True; Result := True;
@ -1032,12 +1039,13 @@ begin
if fShowDialogs then if fShowDialogs then
ShowMessage(C_PropIsEmpty); ShowMessage(C_PropIsEmpty);
if fFireDebugEvent then if fFireDebugEvent then
fOndebugEvent(Self, 'NewVersionAvailable', C_PropIsEmpty); fOndebugEvent(Self, 'NewVersionAvailable (auSourceForge)', C_PropIsEmpty);
Exit; Exit;
end; end;
szURL := Format(C_SOURCEFORGEURL, [fSourceForgeProjectName, szURL := Format(C_SOURCEFORGEURL, [fSourceForgeProjectName,
fUpdatesFolder, fVersionsININame]); fUpdatesFolder, fVersionsININame]);
end; end;
if fProjectType = auGitHubReleaseZip then if fProjectType = auGitHubReleaseZip then
begin begin
if ((fGitHubProjectName = '') or (fGitHubRepositoryName = '')) then if ((fGitHubProjectName = '') or (fGitHubRepositoryName = '')) then
@ -1045,15 +1053,18 @@ begin
if fShowDialogs then if fShowDialogs then
ShowMessage(C_PropIsEmpty); ShowMessage(C_PropIsEmpty);
if fFireDebugEvent then if fFireDebugEvent then
fOndebugEvent(Self, 'NewVersionAvailable', C_PropIsEmpty); fOndebugEvent(Self, 'NewVersionAvailable (auGitHubReleaseZip)', C_PropIsEmpty);
Exit; Exit;
end; end;
If ((fUpdatesFolder=C_NotApplicable) or (fUpdatesFolder='')) then if ((fUpdatesFolder = C_NotApplicable) or (fUpdatesFolder = '')) then
szURL := Format(C_GITHUBFILE_URL, [fGitHubProjectName,fGitHubRepositoryName,fGitHubBranch,fVersionsININame]) szURL := Format(C_GITHUBFILE_URL,
[fGitHubProjectName, fGitHubRepositoryName, fGitHubBranchOrTag, fVersionsININame])
else else
szURL := Format(C_GITHUBFILE_URL_UPDATES, [fGitHubProjectName,fGitHubRepositoryName,fGitHubBranch,fUpdatesFolder,fVersionsININame]); szURL := Format(C_GITHUBFILE_URL_UPDATES,
[fGitHubProjectName, fGitHubRepositoryName, fGitHubBranchOrTag,
fUpdatesFolder, fVersionsININame]);
end; end;
// ShowMessage(szURL);
if fProjectType = auOther then if fProjectType = auOther then
// fauOtherSourceURL ends with '/' // fauOtherSourceURL ends with '/'
begin begin
@ -1202,13 +1213,16 @@ begin
end; end;
szTargetPath := fZipfileName; szTargetPath := fZipfileName;
if fProjectType = auSourceForge then if fProjectType = auSourceForge then
szURL := Format(C_SOURCEFORGEURL, [fSourceForgeProjectName, fUpdatesFolder, szURL := Format(C_SOURCEFORGEURL, [fSourceForgeProjectName,
ExtractFileName(szTargetPath)]); fUpdatesFolder, ExtractFileName(szTargetPath)]);
if fProjectType = auGitHubReleaseZip then if fProjectType = auGitHubReleaseZip then
If ((fUpdatesFolder=C_NotApplicable) or (fUpdatesFolder='')) then if ((fUpdatesFolder = C_NotApplicable) or (fUpdatesFolder = '')) then
szURL := Format(C_GITHUBFILE_URL, [fGitHubProjectName,fGitHubRepositoryName,fGitHubBranch,fZipfileName]) szURL := Format(C_GITHUBFILE_URL,
[fGitHubProjectName, fGitHubRepositoryName, fGitHubBranchOrTag, fZipfileName])
else else
szURL := Format(C_GITHUBFILE_URL_UPDATES, [fGitHubProjectName,fGitHubRepositoryName,fGitHubBranch,fUpdatesFolder,fZipfileName]); szURL := Format(C_GITHUBFILE_URL_UPDATES,
[fGitHubProjectName, fGitHubRepositoryName, fGitHubBranchOrTag,
fUpdatesFolder, fZipfileName]);
if fProjectType = auOther then if fProjectType = auOther then
// fauOtherSourceURL ends with '/' // fauOtherSourceURL ends with '/'
begin begin
@ -1398,6 +1412,7 @@ begin
end; end;
function TLazAutoUpdate.CreateLocalLauImportFile: boolean; function TLazAutoUpdate.CreateLocalLauImportFile: boolean;
// Used in SysTray app
var var
LAUTRayINI: TIniFile; LAUTRayINI: TIniFile;
szSection: string; szSection: string;
@ -1528,8 +1543,8 @@ begin
begin begin
if fFireDebugEvent then if fFireDebugEvent then
fOndebugEvent(Self, 'RelocateLauImportFile', fOndebugEvent(Self, 'RelocateLauImportFile',
Format('Relocated %s from %s to %s', [C_LAUTRayINI, Format('Relocated %s from %s to %s',
szSourceLAUTrayPath, szDestLAUTrayPath])); [C_LAUTRayINI, szSourceLAUTrayPath, szDestLAUTrayPath]));
SysUtils.DeleteFile(szSourceLAUTrayPath); SysUtils.DeleteFile(szSourceLAUTrayPath);
end end
else else
@ -1541,6 +1556,7 @@ begin
end; end;
function TLazAutoUpdate.DoSilentUpdate: boolean; function TLazAutoUpdate.DoSilentUpdate: boolean;
// Used in Systray app
// Called from UpdateToNewVersion when the app is not running // Called from UpdateToNewVersion when the app is not running
// Updates the app, and also copies over and updates C_LAUTRayINI // Updates the app, and also copies over and updates C_LAUTRayINI
var var
@ -1718,8 +1734,8 @@ begin
end; end;
function TLazAutoUpdate.RemoteUpdateToNewVersion: boolean; function TLazAutoUpdate.RemoteUpdateToNewVersion: boolean;
// Used in Systray app
// Shells to 'lauupdate' console app in ProgramDirectory to remotely update an app // Shells to 'lauupdate' console app in ProgramDirectory to remotely update an app
{$IFDEF WINDOWS} {$IFDEF WINDOWS}
function RunAsAdmin(const Handle: THandle; const Path, Params: string): boolean; function RunAsAdmin(const Handle: THandle; const Path, Params: string): boolean;
var var
@ -1744,8 +1760,8 @@ var
begin begin
Result := False; Result := False;
{$IFDEF WINDOWS} {$IFDEF WINDOWS}
If fWindowsAdminCheck then if fWindowsAdminCheck then
If NOT IsWindowsAdmin then if not IsWindowsAdmin then
begin begin
ShowAdminCheckMessage; ShowAdminCheckMessage;
Exit; Exit;
@ -1871,7 +1887,8 @@ end;
function TLazAutoUpdate.UpdateToNewVersion: boolean; function TLazAutoUpdate.UpdateToNewVersion: boolean;
// Shells to updater console
// Requires admin user in Win 10
{$IFDEF WINDOWS} {$IFDEF WINDOWS}
function RunAsAdmin(const Handle: THandle; const Path, Params: string): boolean; function RunAsAdmin(const Handle: THandle; const Path, Params: string): boolean;
var var
@ -1896,8 +1913,8 @@ var
begin begin
Result := False; Result := False;
{$IFDEF WINDOWS} {$IFDEF WINDOWS}
If fWindowsAdminCheck then if fWindowsAdminCheck then
If NOT IsWindowsAdmin then if not IsWindowsAdmin then
begin begin
ShowAdminCheckMessage; ShowAdminCheckMessage;
Exit; Exit;
@ -1997,7 +2014,8 @@ begin
FUpdateHMProcess.Execute; FUpdateHMProcess.Execute;
except except
raise Exception.CreateFmt( raise Exception.CreateFmt(
'Error %d: Run this application in Administrator mode or turn off UAC', [GetLastOSError]); 'Error %d: Run this application in Administrator mode or turn off UAC',
[GetLastOSError]);
end; end;
// Check for C_WhatsNewFilename in the app directory in a LOOP // Check for C_WhatsNewFilename in the app directory in a LOOP
@ -2026,12 +2044,14 @@ end;
procedure TLazAutoUpdate.ClearUpdateList; procedure TLazAutoUpdate.ClearUpdateList;
// Unused
begin begin
Setlength(fUpdateList, 0); Setlength(fUpdateList, 0);
end; end;
function TLazAutoUpdate.AddToUpdateList(APrettyName, APath, AVersionString: string; function TLazAutoUpdate.AddToUpdateList(APrettyName, APath, AVersionString: string;
AVersionNumber: cardinal): integer; AVersionNumber: cardinal): integer;
// Unused
var var
iLast: integer; iLast: integer;
TheRec: UpdateListRecord; TheRec: UpdateListRecord;
@ -2077,6 +2097,7 @@ begin
end; end;
procedure TLazAutoUpdate.SetProjectType(AValue: TProjectType); procedure TLazAutoUpdate.SetProjectType(AValue: TProjectType);
// Set properties in a context-sensitive way
begin begin
if (AValue <> fProjectType) then if (AValue <> fProjectType) then
fProjectType := AValue; fProjectType := AValue;
@ -2086,7 +2107,7 @@ begin
fSourceForgeProjectName := C_NotApplicable; fSourceForgeProjectName := C_NotApplicable;
fGitHubRepositoryName := C_NotApplicable; fGitHubRepositoryName := C_NotApplicable;
fGitHubProjectName := C_NotApplicable; fGitHubProjectName := C_NotApplicable;
fGitHubBranch:=C_NotApplicable; fGitHubBranchOrTag := C_NotApplicable;
fauOtherSourceFilename := ''; fauOtherSourceFilename := '';
fauOtherSourceURL := ''; fauOtherSourceURL := '';
end; end;
@ -2098,7 +2119,7 @@ begin
fauOtherSourceURL := C_NotApplicable; fauOtherSourceURL := C_NotApplicable;
fGitHubRepositoryName := C_NotApplicable; fGitHubRepositoryName := C_NotApplicable;
fGitHubProjectName := C_NotApplicable; fGitHubProjectName := C_NotApplicable;
fGitHubBranch:=C_NotApplicable; fGitHubBranchOrTag := C_NotApplicable;
end; end;
if fProjectType = auGitHubReleaseZip then if fProjectType = auGitHubReleaseZip then
begin begin
@ -2107,21 +2128,22 @@ begin
fSourceForgeProjectName := C_NotApplicable; fSourceForgeProjectName := C_NotApplicable;
fauOtherSourceFilename := C_NotApplicable; fauOtherSourceFilename := C_NotApplicable;
fauOtherSourceURL := C_NotApplicable; fauOtherSourceURL := C_NotApplicable;
fGitHubBranch:= C_MASTER; fGitHubBranchOrTag := C_MASTER;
fGitHubRepositoryName := ''; fGitHubRepositoryName := '';
fGitHubProjectName := ''; fGitHubProjectName := '';
fUpdatesFolder := C_NotApplicable; fUpdatesFolder := C_NotApplicable;
end; end;
end; end;
procedure TLazAutoUpdate.SetSourceForgeProjectName(Avalue: string); procedure TLazAutoUpdate.SetSourceForgeProjectName(Avalue: string);
// Ensure lowercase
begin begin
fSourceForgeProjectName := LowerCase(AValue); fSourceForgeProjectName := LowerCase(AValue);
end; end;
procedure TLazAutoUpdate.SetAppFilename(Avalue: string); procedure TLazAutoUpdate.SetAppFilename(Avalue: string);
// Guess a default value
begin begin
fAppFilename := AValue; fAppFilename := AValue;
// Set a default value? // Set a default value?
@ -2212,7 +2234,7 @@ begin
end; end;
procedure TThreadedDownload.DownloadTerminiated(Sender: TObject); procedure TThreadedDownload.DownloadTerminiated(Sender: TObject);
// Unzips all files ready for updatehm to copy them over // Unzips all files ready for updatehmxxx to copy them over
var var
UnZipper: TUnZipper; UnZipper: TUnZipper;
begin begin
@ -2241,16 +2263,11 @@ end;
function DownloadHTTP(URL, TargetFile: string; var ReturnCode, DownloadSize: integer; function DownloadHTTP(URL, TargetFile: string; var ReturnCode, DownloadSize: integer;
bIsSourceForge, fDebugmode: boolean): boolean; bIsSourceForge, fDebugmode: boolean): boolean;
// Download file; retry if necessary. // Download file; retry if necessary.
// Deals with SourceForge download links // Deals with https download links
const
MaxRetries = 3;
var var
HTTPClient: TFPHTTPClient; HTTPClient: TFPHTTPClient;
HTTPGetResult: boolean;
RetryAttempt, i: integer;
begin begin
Result := False; Result := False;
RetryAttempt := 1;
HTTPClient := TFPHTTPClient.Create(nil); HTTPClient := TFPHTTPClient.Create(nil);
if bIsSourceForge then if bIsSourceForge then
begin begin
@ -2263,6 +2280,7 @@ begin
HTTPClient.Get(URL, TargetFile); HTTPClient.Get(URL, TargetFile);
ReturnCode := HTTPClient.ResponseStatusCode; ReturnCode := HTTPClient.ResponseStatusCode;
DownloadSize := Filesize(TargetFile); DownloadSize := Filesize(TargetFile);
Result:=True;
except except
// We don't care for the reason for this error; the download failed. // We don't care for the reason for this error; the download failed.
Result := False; Result := False;