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

View File

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