V0.2.0.0: Working copy

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5641 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
gbamber
2017-01-14 07:43:26 +00:00
parent 770575537e
commit 7568085be6
8 changed files with 204 additions and 131 deletions

View File

@ -10,7 +10,7 @@
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="4"/> <EditorIndex Value="4"/>
<CursorPos X="33" Y="27"/> <CursorPos X="33" Y="27"/>
<UsageCount Value="28"/> <UsageCount Value="29"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit0> </Unit0>
<Unit1> <Unit1>
@ -19,9 +19,9 @@
<ComponentName Value="mainform"/> <ComponentName Value="mainform"/>
<HasResources Value="True"/> <HasResources Value="True"/>
<ResourceBaseClass Value="Form"/> <ResourceBaseClass Value="Form"/>
<TopLine Value="53"/> <TopLine Value="88"/>
<CursorPos X="29" Y="72"/> <CursorPos X="43" Y="108"/>
<UsageCount Value="28"/> <UsageCount Value="29"/>
<Loaded Value="True"/> <Loaded Value="True"/>
<LoadedDesigner Value="True"/> <LoadedDesigner Value="True"/>
</Unit1> </Unit1>
@ -37,14 +37,14 @@
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<IsVisibleTab Value="True"/> <IsVisibleTab Value="True"/>
<EditorIndex Value="3"/> <EditorIndex Value="3"/>
<TopLine Value="130"/> <TopLine Value="334"/>
<CursorPos X="58" Y="134"/> <CursorPos X="34" Y="358"/>
<ExtraEditorCount Value="1"/> <ExtraEditorCount Value="1"/>
<ExtraEditor1> <ExtraEditor1>
<EditorIndex Value="-1"/> <IsVisibleTab Value="True"/>
<WindowIndex Value="-1"/> <WindowIndex Value="1"/>
<TopLine Value="-1"/> <TopLine Value="1743"/>
<CursorPos X="-1" Y="-1"/> <CursorPos X="63" Y="1782"/>
</ExtraEditor1> </ExtraEditor1>
<UsageCount Value="14"/> <UsageCount Value="14"/>
<Loaded Value="True"/> <Loaded Value="True"/>
@ -103,123 +103,123 @@
<JumpHistory Count="30" HistoryIndex="29"> <JumpHistory Count="30" HistoryIndex="29">
<Position1> <Position1>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="1703" Column="86" TopLine="1678"/> <Caret Line="47" Column="34" TopLine="21"/>
</Position1> </Position1>
<Position2> <Position2>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="1702" Column="93" TopLine="1682"/> <Caret Line="1722" Column="21" TopLine="1702"/>
</Position2> </Position2>
<Position3> <Position3>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="1736" Column="47" TopLine="1709"/> <Caret Line="1763" Column="53" TopLine="1733"/>
</Position3> </Position3>
<Position4> <Position4>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="1723" Column="17" TopLine="1716"/> <Caret Line="1651" Column="39" TopLine="1637"/>
</Position4> </Position4>
<Position5> <Position5>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="1721" Column="21" TopLine="1683"/> <Caret Line="1652" Column="42" TopLine="1626"/>
</Position5> </Position5>
<Position6> <Position6>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="47" Column="34" TopLine="21"/> <Caret Line="1663" Column="16" TopLine="1638"/>
</Position6> </Position6>
<Position7> <Position7>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="1722" Column="21" TopLine="1702"/> <Caret Line="1730" Column="5" TopLine="1698"/>
</Position7> </Position7>
<Position8> <Position8>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="1763" Column="53" TopLine="1733"/> <Caret Line="47" Column="27"/>
</Position8> </Position8>
<Position9> <Position9>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="1651" Column="39" TopLine="1637"/> <Caret Line="1355" Column="25" TopLine="1330"/>
</Position9> </Position9>
<Position10> <Position10>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="1652" Column="42" TopLine="1626"/> <Caret Line="1361" Column="14" TopLine="1319"/>
</Position10> </Position10>
<Position11> <Position11>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="1663" Column="16" TopLine="1638"/> <Caret Line="1360" Column="49" TopLine="1337"/>
</Position11> </Position11>
<Position12> <Position12>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="1730" Column="5" TopLine="1698"/> <Caret Line="1354" Column="15" TopLine="1330"/>
</Position12> </Position12>
<Position13> <Position13>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="47" Column="27"/> <Caret Line="1670" Column="5" TopLine="1646"/>
</Position13> </Position13>
<Position14> <Position14>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="1355" Column="25" TopLine="1330"/> <Caret Line="1354" Column="16" TopLine="1330"/>
</Position14> </Position14>
<Position15> <Position15>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="1361" Column="14" TopLine="1319"/> <Caret Line="1361" Column="15" TopLine="1337"/>
</Position15> </Position15>
<Position16> <Position16>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="1360" Column="49" TopLine="1337"/> <Caret Line="1354" Column="17" TopLine="1330"/>
</Position16> </Position16>
<Position17> <Position17>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="umainform.pas"/>
<Caret Line="1354" Column="15" TopLine="1330"/> <Caret Line="9" Column="11"/>
</Position17> </Position17>
<Position18> <Position18>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="umainform.pas"/>
<Caret Line="1670" Column="5" TopLine="1646"/> <Caret Line="117" Column="65" TopLine="93"/>
</Position18> </Position18>
<Position19> <Position19>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="umainform.pas"/>
<Caret Line="1354" Column="16" TopLine="1330"/> <Caret Line="114" TopLine="91"/>
</Position19> </Position19>
<Position20> <Position20>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="umainform.pas"/>
<Caret Line="1361" Column="15" TopLine="1337"/> <Caret Line="113" TopLine="90"/>
</Position20> </Position20>
<Position21> <Position21>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="umainform.pas"/>
<Caret Line="1354" Column="17" TopLine="1330"/> <Caret Line="88" TopLine="86"/>
</Position21> </Position21>
<Position22> <Position22>
<Filename Value="umainform.pas"/> <Filename Value="umainform.pas"/>
<Caret Line="9" Column="11"/> <Caret Line="87" TopLine="85"/>
</Position22> </Position22>
<Position23> <Position23>
<Filename Value="umainform.pas"/> <Filename Value="umainform.pas"/>
<Caret Line="117" Column="65" TopLine="93"/> <Caret Line="45" TopLine="30"/>
</Position23> </Position23>
<Position24> <Position24>
<Filename Value="umainform.pas"/> <Filename Value="umainform.pas"/>
<Caret Line="114" TopLine="91"/> <Caret Line="78" Column="29" TopLine="58"/>
</Position24> </Position24>
<Position25> <Position25>
<Filename Value="umainform.pas"/> <Filename Value="umainform.pas"/>
<Caret Line="113" TopLine="90"/> <Caret Line="77" Column="6" TopLine="53"/>
</Position25> </Position25>
<Position26> <Position26>
<Filename Value="umainform.pas"/> <Filename Value="umainform.pas"/>
<Caret Line="88" TopLine="86"/> <Caret Line="73" Column="48" TopLine="53"/>
</Position26> </Position26>
<Position27> <Position27>
<Filename Value="umainform.pas"/> <Filename Value="umainform.pas"/>
<Caret Line="87" TopLine="85"/> <Caret Line="75" Column="48" TopLine="55"/>
</Position27> </Position27>
<Position28> <Position28>
<Filename Value="umainform.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="45" TopLine="30"/> <Caret Line="7" Column="17"/>
</Position28> </Position28>
<Position29> <Position29>
<Filename Value="umainform.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="78" Column="29" TopLine="58"/> <Caret Line="359" Column="29" TopLine="341"/>
</Position29> </Position29>
<Position30> <Position30>
<Filename Value="umainform.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="77" Column="6" TopLine="53"/> <Caret Line="357" Column="58" TopLine="352"/>
</Position30> </Position30>
</JumpHistory> </JumpHistory>
</ProjectSession> </ProjectSession>

View File

@ -11,6 +11,7 @@ object mainform: Tmainform
OnCreate = FormCreate OnCreate = FormCreate
Position = poDesktopCenter Position = poDesktopCenter
LCLVersion = '1.7' LCLVersion = '1.7'
Visible = True
object StatusBar1: TStatusBar object StatusBar1: TStatusBar
Left = 0 Left = 0
Height = 23 Height = 23
@ -80,6 +81,17 @@ object mainform: Tmainform
ParentColor = False ParentColor = False
ParentFont = False ParentFont = False
end end
object cmd_SilentUpdate: TButton
Left = 184
Height = 25
Top = 80
Width = 96
AutoSize = True
Caption = 'Silent Update'
OnClick = cmd_SilentUpdateClick
TabOrder = 6
Visible = False
end
object LazAutoUpdate1: TLazAutoUpdate object LazAutoUpdate1: TLazAutoUpdate
About.Description.Strings = ( About.Description.Strings = (
'A component for updating your application'#13#10'Designed for projects hosted by SourceForge'#13#10#13#10'Main methods:'#13#10'Procedure AutoUpdate'#13#10'Function NewVersionAvailable: Boolean'#13#10'Function DownloadNewVersion: Boolean'#13#10'Function UpdateToNewVersion: Boolean'#13#10'Procedure ShowWhatsNewIfAvailable'#13#10'For troubleshooting, set DebugMode=TRUE' 'A component for updating your application'#13#10'Designed for projects hosted by SourceForge'#13#10#13#10'Main methods:'#13#10'Procedure AutoUpdate'#13#10'Function NewVersionAvailable: Boolean'#13#10'Function DownloadNewVersion: Boolean'#13#10'Function UpdateToNewVersion: Boolean'#13#10'Procedure ShowWhatsNewIfAvailable'#13#10'For troubleshooting, set DebugMode=TRUE'

View File

@ -34,6 +34,7 @@ type
{ Tmainform } { Tmainform }
Tmainform = class(TForm) Tmainform = class(TForm)
cmd_SilentUpdate: TButton;
cmd_AutoUpdate: TButton; cmd_AutoUpdate: TButton;
cmd_updateToNewVersion: TButton; cmd_updateToNewVersion: TButton;
cmd_DownloadNewVersion: TButton; cmd_DownloadNewVersion: TButton;
@ -45,6 +46,7 @@ type
procedure cmd_AutoUpdateClick(Sender: TObject); procedure cmd_AutoUpdateClick(Sender: TObject);
procedure cmd_DownloadNewVersionClick(Sender: TObject); procedure cmd_DownloadNewVersionClick(Sender: TObject);
procedure cmd_NewVersionAvailableClick(Sender: TObject); procedure cmd_NewVersionAvailableClick(Sender: TObject);
procedure cmd_SilentUpdateClick(Sender: TObject);
procedure cmd_updateToNewVersionClick(Sender: TObject); procedure cmd_updateToNewVersionClick(Sender: TObject);
procedure FormActivate(Sender: TObject); procedure FormActivate(Sender: TObject);
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
@ -83,6 +85,11 @@ begin
LazAutoUpdate1.NewVersionAvailable; LazAutoUpdate1.NewVersionAvailable;
end; end;
procedure Tmainform.cmd_SilentUpdateClick(Sender: TObject);
begin
LazAutoUpdate1.SilentUpdate;
end;
procedure Tmainform.cmd_updateToNewVersionClick(Sender: TObject); procedure Tmainform.cmd_updateToNewVersionClick(Sender: TObject);
begin begin
LazAutoUpdate1.UpdateToNewVersion; LazAutoUpdate1.UpdateToNewVersion;

View File

@ -42,7 +42,7 @@ uses
fileinfo, winpeimagereader {need this for reading exe info} fileinfo, winpeimagereader {need this for reading exe info}
, elfreader {needed for reading ELF executables} , elfreader {needed for reading ELF executables}
, machoreader {needed for reading MACH-O executables} , machoreader {needed for reading MACH-O executables}
{$IFDEF WINDOWS},Windows,ShellAPI{$ENDIF}; // Thanks to Windows 10 and 704 error {$IFDEF WINDOWS}, Windows, ShellAPI{$ENDIF}; // Thanks to Windows 10 and 704 error
const const
C_OnlineAppPath = C_OnlineAppPath =
@ -114,14 +114,16 @@ const
C_GUIEntry = 'GUI'; C_GUIEntry = 'GUI';
C_ModuleEntry = 'Module'; C_ModuleEntry = 'Module';
{$IFDEF WINDOWS} {$IFDEF WINDOWS}
{$IFDEF CPU32}C_Updater = 'updatehmwin32.exe';{$ENDIF} {$IFDEF CPU32}C_UPDATER = 'updatehmwin32.exe';
{$IFDEF CPU64}C_Updater = 'updatehmwin64.exe';{$ENDIF} C_LOCALUPDATER = 'lauupdatewin32.exe';{$ENDIF}
C_LOCALUPDATER = 'lauupdate.exe'; {$IFDEF CPU64}C_UPDATER = 'updatehmwin64.exe';
C_LOCALUPDATER = 'lauupdatewin64.exe';{$ENDIF}
{$ENDIF} {$ENDIF}
{$IFDEF LINUX} {$IFDEF LINUX}
{$IFDEF CPU32}C_Updater = 'updatehmlinux32';{$ENDIF} {$IFDEF CPU32}C_UPDATER = 'updatehmlinux32';
{$IFDEF CPU64}C_Updater = 'updatehmlinux64';{$ENDIF} C_LOCALUPDATER = 'lauupdatelinux32';{$ENDIF}
C_LOCALUPDATER = 'lauupdate'; {$IFDEF CPU64}C_UPDATER = 'updatehmlinux64';
C_LOCALUPDATER = 'lauupdatelinux64';{$ENDIF}
{$ENDIF} {$ENDIF}
resourcestring resourcestring
@ -229,6 +231,7 @@ type
fQuad: TVersionQuad; fQuad: TVersionQuad;
fProgVersion: TProgramVersion; fProgVersion: TProgramVersion;
objFileVerInfo: TFileVersionInfo; objFileVerInfo: TFileVersionInfo;
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);
@ -353,7 +356,8 @@ type
write fDownloadCountLimit; write fDownloadCountLimit;
// Default is application filename.zip // Default is application filename.zip
property ZipfileName: string read fZipfileName write fZipfileName; property ZipfileName: string read fZipfileName write fZipfileName;
property UpdateExe:String read fUpdateExe;
property UpdateExeSilent:String read fUpdateSilentExe;
end; end;
{TThreadedDownload } {TThreadedDownload }
@ -526,6 +530,10 @@ begin
fZipfileName := ''; // assign later fZipfileName := ''; // assign later
fUpdateExe:=C_UPDATER;
fUpdateSilentExe:=C_LOCALUPDATER;
// Assorted versioninfo properties // Assorted versioninfo properties
fLCLVersion := GetLCLVersion; fLCLVersion := GetLCLVersion;
fWidgetSet := GetWidgetSet; fWidgetSet := GetWidgetSet;
@ -560,11 +568,13 @@ begin
AboutBoxAuthorEmail := 'minesadorada@charcodelvalle.com'; AboutBoxAuthorEmail := 'minesadorada@charcodelvalle.com';
AboutBoxLicenseType := 'MODIFIEDGPL'; AboutBoxLicenseType := 'MODIFIEDGPL';
end; end;
destructor TLazAutoUpdate.Destroy; destructor TLazAutoUpdate.Destroy;
begin begin
FreeAndNil(fThreadDownload); FreeAndNil(fThreadDownload);
inherited destroy; inherited Destroy;
end; end;
function TLazAutoUpdate.AppIsActive(const ExeName: string): boolean; function TLazAutoUpdate.AppIsActive(const ExeName: string): boolean;
begin begin
Result := AppIsRunning(ExeName); Result := AppIsRunning(ExeName);
@ -1345,13 +1355,13 @@ begin
if not FileExistsUTF8(szDestLAUTrayPath + C_LAUTRayINI) then if not FileExistsUTF8(szDestLAUTrayPath + C_LAUTRayINI) then
begin begin
// Move C_LAUTRayINI from app folder to local <AppData> folder // Move C_LAUTRayINI from app folder to local <AppData> folder
if FileUtil.CopyFile(szSourceLAUTrayPath, szDestLAUTrayPath + C_LAUTRayINI, if FileUtil.CopyFile(szSourceLAUTrayPath, szDestLAUTrayPath +
[cffOverwriteFile]) then C_LAUTRayINI, [cffOverwriteFile]) then
begin begin
if fFireDebugEvent then if fFireDebugEvent then
fOndebugEvent(Self, 'RelocateLauImportFile', fOndebugEvent(Self, 'RelocateLauImportFile',
Format('Relocated %s from %s to %s', Format('Relocated %s from %s to %s', [C_LAUTRayINI,
[C_LAUTRayINI, szSourceLAUTrayPath, szDestLAUTrayPath])); szSourceLAUTrayPath, szDestLAUTrayPath]));
SysUtils.DeleteFile(szSourceLAUTrayPath); SysUtils.DeleteFile(szSourceLAUTrayPath);
end end
else else
@ -1541,9 +1551,28 @@ end;
function TLazAutoUpdate.RemoteUpdateToNewVersion: boolean; function TLazAutoUpdate.RemoteUpdateToNewVersion: boolean;
// 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}
function RunAsAdmin(const Handle: THandle; const Path, Params: string): boolean;
var
sei: TShellExecuteInfoA;
begin
FillChar(sei, SizeOf(sei), 0);
sei.cbSize := SizeOf(sei);
sei.Wnd := Handle;
sei.fMask := SEE_MASK_FLAG_DDEWAIT or SEE_MASK_FLAG_NO_UI;
sei.lpVerb := 'runas';
sei.lpFile := PAnsiChar(Path);
sei.lpParameters := PAnsiChar(Params);
sei.nShow := SW_SHOWNORMAL;
Result := ShellExecuteExA(@sei);
end;
{$ENDIF}
var var
cCount: cardinal; cCount: cardinal;
szAppDir: string; szAppDir, szParams: string;
begin begin
Result := False; Result := False;
szAppDir := AppendPathDelim(ExtractFilePath(fAppFilename)); szAppDir := AppendPathDelim(ExtractFilePath(fAppFilename));
@ -1583,26 +1612,51 @@ begin
end; end;
{$IFDEF WINDOWS}
szParams := ExtractFileName(fAppFilename);
szParams := szParams + ' ' + fUpdatesFolder;
szParams := szParams + ' ' + C_WhatsNewFilename;
szParams := szParams + ' ' + fParentApplication.Title;
if (fCopyTree = True) then
szParams := szParams + ' copytree';
if fFireDebugEvent then
fOndebugEvent(Self, 'RemoteUpdateToNewVersion',
Format('Executing %s', [ProgramDirectory + C_LOCALUPDATER]));
RunAsAdmin(fParentForm.Handle, ProgramDirectory + C_LOCALUPDATER, szParams);
// Check for C_WhatsNewFilename in the app directory in a LOOP
if fFireDebugEvent then
fOndebugEvent(Self, 'RemoteUpdateToNewVersion',
Format('Waiting for %s', [szAppDir + C_WhatsNewFilename]));
while not FileExistsUTF8(szAppDir + C_WhatsNewFilename) do
begin
fParentApplication.ProcessMessages;
Inc(CCount);
if cCount > 10000000 then
Break; // Get out of jail in case updatehm.exe fails to copy file
end;
{$ELSE}
// Update and re-start the app // Update and re-start the app
FUpdateHMProcess := TAsyncProcess.Create(nil); FUpdateHMProcess := TAsyncProcess.Create(nil);
FUpdateHMProcess.Executable := ProgramDirectory + C_LOCALUPDATER;
FUpdateHMProcess.CurrentDirectory := ProgramDirectory;
if not fSilentMode then
FUpdateHMProcess.ConsoleTitle :=
Format(C_ConsoleTitle, [fParentApplication.Title]);
FUpdateHMProcess.Parameters.Clear;
FUpdateHMProcess.Parameters.Add(fAppFilename); //Param 1 = EXEname
FUpdateHMProcess.Parameters.Add(fUpdatesFolder); // Param 2 = updates
FUpdateHMProcess.Parameters.Add(C_WhatsNewFilename); // Param 3 = whatsnew.txt
FUpdateHMProcess.Parameters.Add(fParentApplication.Title); // Param 4 = Prettyname
if (fCopyTree = True) then
FUpdateHMProcess.Parameters.Add('copytree');
// Param 5 = Copy the whole of /updates to the App Folder
if fFireDebugEvent then
fOndebugEvent(Self, 'RemoteUpdateToNewVersion',
Format('Executing %s', [ProgramDirectory + C_LOCALUPDATER]));
try try
FUpdateHMProcess.Executable := ProgramDirectory + C_LOCALUPDATER;
FUpdateHMProcess.CurrentDirectory := ProgramDirectory;
if not fSilentMode then
FUpdateHMProcess.ConsoleTitle :=
Format(C_ConsoleTitle, [fParentApplication.Title]);
FUpdateHMProcess.Parameters.Clear;
FUpdateHMProcess.Parameters.Add(fAppFilename); //Param 1 = EXEname
FUpdateHMProcess.Parameters.Add(fUpdatesFolder); // Param 2 = updates
FUpdateHMProcess.Parameters.Add(C_WhatsNewFilename); // Param 3 = whatsnew.txt
FUpdateHMProcess.Parameters.Add(fParentApplication.Title); // Param 4 = Prettyname
if (fCopyTree = True) then
FUpdateHMProcess.Parameters.Add('copytree');
// Param 5 = Copy the whole of /updates to the App Folder
if fFireDebugEvent then
fOndebugEvent(Self, 'RemoteUpdateToNewVersion',
Format('Executing %s', [ProgramDirectory + C_LOCALUPDATER]));
FUpdateHMProcess.Execute; FUpdateHMProcess.Execute;
// Check for C_WhatsNewFilename in the app directory in a LOOP // Check for C_WhatsNewFilename in the app directory in a LOOP
@ -1616,22 +1670,22 @@ begin
if cCount > 10000000 then if cCount > 10000000 then
Break; // Get out of jail in case updatehm.exe fails to copy file Break; // Get out of jail in case updatehm.exe fails to copy file
end; end;
// remotely shut down the app?
if fSilentMode then
begin
if AppIsRunning(ExtractFileName(fAppFilename)) then
KillApp(ExtractFileName(fAppFilename));
if fFireDebugEvent then
fOndebugEvent(Self, 'RemoteUpdateToNewVersion',
Format('Killing %s ready for update', [fAppFilename]));
end;
finally finally
FUpdateHMProcess.Free; FUpdateHMProcess.Free;
if not fSilentMode then
fParentForm.Close;
end; end;
{$ENDIF}
// remotely shut down the app?
if fSilentMode then
begin
if AppIsRunning(ExtractFileName(fAppFilename)) then
KillApp(ExtractFileName(fAppFilename));
if fFireDebugEvent then
fOndebugEvent(Self, 'RemoteUpdateToNewVersion',
Format('Killing %s ready for update', [fAppFilename]));
end;
if not fSilentMode then
fParentForm.Close;
if fFireDebugEvent then if fFireDebugEvent then
fOndebugEvent(Self, 'RemoteUpdateToNewVersion', fOndebugEvent(Self, 'RemoteUpdateToNewVersion',
'Success'); 'Success');
@ -1642,26 +1696,26 @@ end;
function TLazAutoUpdate.UpdateToNewVersion: boolean; function TLazAutoUpdate.UpdateToNewVersion: boolean;
{$IFDEF WINDOWS} {$IFDEF WINDOWS}
// function RunAsAdmin(const Handle: Hwnd; const Path, Params: string): Boolean; function RunAsAdmin(const Handle: THandle; const Path, Params: string): boolean;
function RunAsAdmin(const Handle: THandle; const Path, Params: string): Boolean; var
var sei: TShellExecuteInfoA;
sei: TShellExecuteInfoA; begin
begin FillChar(sei, SizeOf(sei), 0);
FillChar(sei, SizeOf(sei), 0); sei.cbSize := SizeOf(sei);
sei.cbSize := SizeOf(sei); sei.Wnd := Handle;
sei.Wnd := Handle; sei.fMask := SEE_MASK_FLAG_DDEWAIT or SEE_MASK_FLAG_NO_UI;
sei.fMask := SEE_MASK_FLAG_DDEWAIT or SEE_MASK_FLAG_NO_UI; sei.lpVerb := 'runas';
sei.lpVerb := 'runas'; sei.lpFile := PAnsiChar(Path);
sei.lpFile := PAnsiChar(Path); sei.lpParameters := PAnsiChar(Params);
sei.lpParameters := PAnsiChar(Params); sei.nShow := SW_SHOWNORMAL;
sei.nShow := SW_SHOWNORMAL; Result := ShellExecuteExA(@sei);
Result := ShellExecuteExA(@sei); end;
end;
{$ENDIF} {$ENDIF}
var var
cCount: cardinal; cCount: cardinal;
szAppDir: string; szAppDir: string;
szParams:String; szParams: string;
begin begin
Result := False; Result := False;
szAppDir := AppendPathDelim(ExtractFilePath(fAppFilename)); szAppDir := AppendPathDelim(ExtractFilePath(fAppFilename));
@ -1679,13 +1733,13 @@ begin
else else
begin begin
cCount := 0; cCount := 0;
if not FileExistsUTF8(szAppDir + C_Updater) then if not FileExistsUTF8(szAppDir + C_UPDATER) then
begin begin
if fShowDialogs then if fShowDialogs then
ShowMessageFmt(C_UpdaterMissing, [szAppDir + C_Updater]); ShowMessageFmt(C_UpdaterMissing, [szAppDir + C_UPDATER]);
if fFireDebugEvent then if fFireDebugEvent then
fOndebugEvent(Self, 'UpdateToNewVersion', fOndebugEvent(Self, 'UpdateToNewVersion',
Format(C_UpdaterMissing, [szAppDir + C_Updater])); Format(C_UpdaterMissing, [szAppDir + C_UPDATER]));
Exit; Exit;
end; end;
@ -1710,16 +1764,16 @@ begin
Format('Killing %s ready for update', [fAppFilename])); Format('Killing %s ready for update', [fAppFilename]));
end; end;
{$IFDEF WINDOWS} {$IFDEF WINDOWS}
szParams:=ExtractFileName(fAppFilename); szParams := ExtractFileName(fAppFilename);
szParams:=szParams + ' ' + fUpdatesFolder; szParams := szParams + ' ' + fUpdatesFolder;
szParams:=szParams + ' ' + C_WhatsNewFilename; szParams := szParams + ' ' + C_WhatsNewFilename;
szParams:=szParams + ' ' + fParentApplication.Title; szParams := szParams + ' ' + fParentApplication.Title;
if (fCopyTree = True) then if (fCopyTree = True) then
szParams:=szParams + ' copytree'; szParams := szParams + ' copytree';
if fFireDebugEvent then if fFireDebugEvent then
fOndebugEvent(Self, 'UpdateToNewVersion', fOndebugEvent(Self, 'UpdateToNewVersion',
Format('Executing %s', [szAppDir + C_UPDATER])); Format('Executing %s', [szAppDir + C_UPDATER]));
RunAsAdmin(fParentForm.Handle,szAppDir + C_UPDATER, szParams); RunAsAdmin(fParentForm.Handle, szAppDir + C_UPDATER, szParams);
// Check for C_WhatsNewFilename in the app directory in a LOOP // Check for C_WhatsNewFilename in the app directory in a LOOP
if fFireDebugEvent then if fFireDebugEvent then
@ -1736,9 +1790,9 @@ begin
// Update and re-start the app // Update and re-start the app
FUpdateHMProcess := TAsyncProcess.Create(nil); FUpdateHMProcess := TAsyncProcess.Create(nil);
try try
// FUpdateHMProcess.Executable := AppendPathDelim(GetAppConfigDir(false)) + C_Updater; // FUpdateHMProcess.Executable := AppendPathDelim(GetAppConfigDir(false)) + C_Updater;
FUpdateHMProcess.Executable := szAppDir + C_UPDATER; FUpdateHMProcess.Executable := szAppDir + C_UPDATER;
// FUpdateHMProcess.CurrentDirectory := AppendPathDelim(GetAppConfigDir(false)); // FUpdateHMProcess.CurrentDirectory := AppendPathDelim(GetAppConfigDir(false));
FUpdateHMProcess.CurrentDirectory := szAppDir; FUpdateHMProcess.CurrentDirectory := szAppDir;
if not fSilentMode then if not fSilentMode then
FUpdateHMProcess.ConsoleTitle := FUpdateHMProcess.ConsoleTitle :=
@ -1754,11 +1808,12 @@ begin
if fFireDebugEvent then if fFireDebugEvent then
fOndebugEvent(Self, 'UpdateToNewVersion', fOndebugEvent(Self, 'UpdateToNewVersion',
Format('Executing %s', [szAppDir + C_UPDATER])); Format('Executing %s', [szAppDir + C_UPDATER]));
TRY try
FUpdateHMProcess.Execute; FUpdateHMProcess.Execute;
EXCEPT except
raise Exception.CreateFmt('Error %d: Run this application in Administrator mode or turn off UAC',[GetLastOSError]); raise Exception.CreateFmt(
END; '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 // Check for C_WhatsNewFilename in the app directory in a LOOP
if fFireDebugEvent then if fFireDebugEvent then
@ -1771,15 +1826,15 @@ END;
if cCount > 10000000 then if cCount > 10000000 then
Break; // Get out of jail in case updatehm.exe fails to copy file Break; // Get out of jail in case updatehm.exe fails to copy file
end; end;
finally finally
FUpdateHMProcess.Free; FUpdateHMProcess.Free;
end; end;
{$ENDIF} {$ENDIF}
if fFireDebugEvent then if fFireDebugEvent then
fOndebugEvent(Self, 'UpdateToNewVersion', fOndebugEvent(Self, 'UpdateToNewVersion',
'Success'); 'Success');
if not fSilentMode then if not fSilentMode then
fParentForm.Close; fParentForm.Close;
Result := True; Result := True;
end; end;
end; end;
@ -1975,8 +2030,8 @@ begin
end; end;
{ End of class members} { End of class members}
function DownloadHTTP(URL, TargetFile: string; function DownloadHTTP(URL, TargetFile: string; var ReturnCode, DownloadSize: integer;
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 SourceForge download links
const const
@ -1991,9 +2046,8 @@ begin
HTTPClient := TFPHTTPClient.Create(nil); HTTPClient := TFPHTTPClient.Create(nil);
if bIsSourceForge then if bIsSourceForge then
begin begin
HTTPClient.AllowRedirect:=True; HTTPClient.AllowRedirect := True;
end; end;
// ReturnCode may not be useful, but it's provided here // ReturnCode may not be useful, but it's provided here
try try
try try