V0.3.4.1 - wip

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5717 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
gbamber
2017-01-27 14:16:25 +00:00
parent 8df7405532
commit e9b6ce6f04
8 changed files with 183 additions and 97 deletions

View File

@ -66,7 +66,7 @@ More information in the Wiki Home Page http://wiki.freepascal.org/LazAutoUpdater
along with this library; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"/>
<Version Minor="3" Release="4"/>
<Version Minor="3" Release="4" Build="1"/>
<Files Count="7">
<Item1>
<Filename Value="ulazautoupdate.pas"/>

View File

@ -19,7 +19,9 @@
</General>
<VersionInfo>
<UseVersionInfo Value="True"/>
<RevisionNr Value="1"/>
<MinorVersionNr Value="1"/>
<RevisionNr Value="3"/>
<BuildNr Value="1"/>
<StringTable ProductVersion="0.0.0.0"/>
</VersionInfo>
<BuildModes Count="5">

View File

@ -3,14 +3,14 @@
<ProjectSession>
<PathDelim Value="\"/>
<Version Value="10"/>
<BuildModes Active="Win64"/>
<BuildModes Active="Linux64"/>
<Units Count="28">
<Unit0>
<Filename Value="testapp.lpr"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="6"/>
<CursorPos X="25" Y="28"/>
<UsageCount Value="65"/>
<UsageCount Value="67"/>
<Loaded Value="True"/>
</Unit0>
<Unit1>
@ -19,9 +19,9 @@
<ComponentName Value="mainform"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<TopLine Value="170"/>
<CursorPos Y="194"/>
<UsageCount Value="65"/>
<TopLine Value="208"/>
<CursorPos X="66" Y="220"/>
<UsageCount Value="67"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
</Unit1>
@ -32,7 +32,7 @@
<WindowIndex Value="1"/>
<TopLine Value="31"/>
<CursorPos X="48" Y="14"/>
<UsageCount Value="48"/>
<UsageCount Value="50"/>
</Unit2>
<Unit3>
<Filename Value="..\lazautoupdate_httpclient.pas"/>
@ -43,8 +43,8 @@
<Unit4>
<Filename Value="..\ulazautoupdate.pas"/>
<EditorIndex Value="1"/>
<TopLine Value="1721"/>
<CursorPos X="68" Y="1774"/>
<TopLine Value="992"/>
<CursorPos X="68" Y="1025"/>
<ExtraEditorCount Value="2"/>
<ExtraEditor1>
<IsVisibleTab Value="True"/>
@ -58,7 +58,7 @@
<TopLine Value="-1"/>
<CursorPos X="-1" Y="-1"/>
</ExtraEditor2>
<UsageCount Value="31"/>
<UsageCount Value="32"/>
<Loaded Value="True"/>
</Unit4>
<Unit5>
@ -145,7 +145,7 @@
<WindowIndex Value="1"/>
<TopLine Value="132"/>
<CursorPos X="6" Y="338"/>
<UsageCount Value="21"/>
<UsageCount Value="22"/>
<Loaded Value="True"/>
</Unit16>
<Unit17>
@ -187,9 +187,9 @@
<Filename Value="..\ushortcut.pas"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="4"/>
<TopLine Value="187"/>
<CursorPos X="57" Y="209"/>
<UsageCount Value="22"/>
<TopLine Value="222"/>
<CursorPos X="72" Y="237"/>
<UsageCount Value="23"/>
<Loaded Value="True"/>
</Unit22>
<Unit23>
@ -204,7 +204,7 @@
<EditorIndex Value="5"/>
<TopLine Value="2203"/>
<CursorPos X="56" Y="2335"/>
<UsageCount Value="11"/>
<UsageCount Value="12"/>
<Loaded Value="True"/>
</Unit24>
<Unit25>
@ -212,7 +212,7 @@
<EditorIndex Value="3"/>
<TopLine Value="399"/>
<CursorPos X="30" Y="426"/>
<UsageCount Value="10"/>
<UsageCount Value="11"/>
<Loaded Value="True"/>
</Unit25>
<Unit26>
@ -227,7 +227,7 @@
<EditorIndex Value="2"/>
<TopLine Value="65"/>
<CursorPos X="41" Y="86"/>
<UsageCount Value="10"/>
<UsageCount Value="11"/>
<Loaded Value="True"/>
</Unit27>
</Units>
@ -237,123 +237,123 @@
<JumpHistory Count="30" HistoryIndex="29">
<Position1>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="243" TopLine="223"/>
<Caret Line="570" Column="28" TopLine="542"/>
</Position1>
<Position2>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="241" Column="43" TopLine="214"/>
<Caret Line="621" Column="46" TopLine="582"/>
</Position2>
<Position3>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="251" Column="21" TopLine="223"/>
<Caret Line="629" Column="65" TopLine="593"/>
</Position3>
<Position4>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="679" Column="49" TopLine="658"/>
<Caret Line="637" Column="51" TopLine="615"/>
</Position4>
<Position5>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="701" Column="38" TopLine="687"/>
<Caret Line="639" Column="8" TopLine="615"/>
</Position5>
<Position6>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="457" Column="37" TopLine="444"/>
<Caret Line="637" Column="50" TopLine="616"/>
</Position6>
<Position7>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="466" Column="23" TopLine="452"/>
<Caret Line="971" Column="61" TopLine="944"/>
</Position7>
<Position8>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="470" Column="40" TopLine="460"/>
<Caret Line="480" Column="20" TopLine="448"/>
</Position8>
<Position9>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="583" Column="36" TopLine="552"/>
<Caret Line="785" TopLine="758"/>
</Position9>
<Position10>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="553" TopLine="529"/>
<Caret Line="784" Column="41" TopLine="757"/>
</Position10>
<Position11>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="545" Column="6" TopLine="523"/>
<Caret Line="474" TopLine="456"/>
</Position11>
<Position12>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="61" Column="74" TopLine="50"/>
<Caret Line="966" Column="70" TopLine="931"/>
</Position12>
<Position13>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="570" Column="28" TopLine="542"/>
<Filename Value="umainform.pas"/>
<Caret Line="15" Column="16" TopLine="8"/>
</Position13>
<Position14>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="621" Column="46" TopLine="582"/>
<Filename Value="umainform.pas"/>
<Caret Line="152" Column="37" TopLine="146"/>
</Position14>
<Position15>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="629" Column="65" TopLine="593"/>
<Filename Value="umainform.pas"/>
<Caret Line="154" Column="37" TopLine="148"/>
</Position15>
<Position16>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="637" Column="51" TopLine="615"/>
<Caret Line="1014" Column="57" TopLine="977"/>
</Position16>
<Position17>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="639" Column="8" TopLine="615"/>
<Filename Value="umainform.pas"/>
<Caret Line="176" Column="4" TopLine="157"/>
</Position17>
<Position18>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="637" Column="50" TopLine="616"/>
<Filename Value="umainform.pas"/>
<Caret Line="170" Column="45" TopLine="159"/>
</Position18>
<Position19>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="971" Column="61" TopLine="944"/>
<Filename Value="umainform.pas"/>
<Caret Line="194" TopLine="170"/>
</Position19>
<Position20>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="480" Column="20" TopLine="448"/>
<Filename Value="umainform.pas"/>
<Caret Line="147" TopLine="145"/>
</Position20>
<Position21>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="785" TopLine="758"/>
<Filename Value="umainform.pas"/>
<Caret Line="146" TopLine="144"/>
</Position21>
<Position22>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="784" Column="41" TopLine="757"/>
<Filename Value="umainform.pas"/>
<Caret Line="148" TopLine="146"/>
</Position22>
<Position23>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="474" TopLine="456"/>
<Filename Value="umainform.pas"/>
<Caret Line="125" TopLine="108"/>
</Position23>
<Position24>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="966" Column="70" TopLine="931"/>
<Filename Value="umainform.pas"/>
<Caret Line="118" Column="30" TopLine="93"/>
</Position24>
<Position25>
<Filename Value="umainform.pas"/>
<Caret Line="15" Column="16" TopLine="8"/>
<Caret Line="124" Column="45" TopLine="103"/>
</Position25>
<Position26>
<Filename Value="umainform.pas"/>
<Caret Line="152" Column="37" TopLine="146"/>
<Caret Line="125" Column="45" TopLine="104"/>
</Position26>
<Position27>
<Filename Value="umainform.pas"/>
<Caret Line="154" Column="37" TopLine="148"/>
<Caret Line="198" Column="3" TopLine="196"/>
</Position27>
<Position28>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="1014" Column="57" TopLine="977"/>
<Filename Value="umainform.pas"/>
<Caret Line="214" Column="56" TopLine="201"/>
</Position28>
<Position29>
<Filename Value="umainform.pas"/>
<Caret Line="176" Column="4" TopLine="157"/>
<Caret Line="216" Column="56" TopLine="203"/>
</Position29>
<Position30>
<Filename Value="umainform.pas"/>
<Caret Line="170" Column="45" TopLine="159"/>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="1004" Column="101" TopLine="970"/>
</Position30>
</JumpHistory>
</ProjectSession>

View File

@ -7,10 +7,10 @@ object mainform: Tmainform
Caption = 'mainform'
ClientHeight = 237
ClientWidth = 345
Font.Height = -12
OnActivate = FormActivate
OnCreate = FormCreate
OnDestroy = FormDestroy
ParentFont = True
Position = poDesktopCenter
LCLVersion = '1.7'
Visible = True
@ -83,17 +83,6 @@ object mainform: Tmainform
ParentColor = False
ParentFont = False
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 cmd_MakeDesktopShortcut: TButton
Left = 24
Height = 25
@ -101,7 +90,7 @@ object mainform: Tmainform
Width = 147
Caption = 'Make Desktop Shortcut'
OnClick = cmd_MakeDesktopShortcutClick
TabOrder = 7
TabOrder = 6
end
object cmd_DeleteDesktopShortcut: TButton
Left = 184
@ -110,8 +99,35 @@ object mainform: Tmainform
Width = 139
Caption = 'Delete Desktop Shortcut'
OnClick = cmd_DeleteDesktopShortcutClick
TabOrder = 7
end
object chk_DebugMode: TCheckBox
Left = 184
Height = 19
Top = 54
Width = 109
Caption = 'Write Debug Log'
OnChange = chk_DebugModeChange
TabOrder = 8
end
object chk_ShowDialogs: TCheckBox
Left = 184
Height = 19
Top = 80
Width = 91
Caption = 'Show Dialogs'
OnChange = chk_ShowDialogsChange
TabOrder = 9
end
object chk_ShowProgress: TCheckBox
Left = 184
Height = 19
Top = 104
Width = 97
Caption = 'Show Progress'
OnChange = chk_ShowProgressChange
TabOrder = 10
end
object LazAutoUpdate1: TLazAutoUpdate
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'
@ -146,7 +162,7 @@ object mainform: Tmainform
GitHubBranchOrTag = 'updates'
ShortCut.ShortcutName = 'AnotherName'
ShortCut.Category = scAudioVideo
Left = 200
Top = 24
Left = 8
Top = 8
end
end

View File

@ -45,9 +45,11 @@ type
{ Tmainform }
Tmainform = class(TForm)
chk_DebugMode: TCheckBox;
chk_ShowDialogs: TCheckBox;
chk_ShowProgress: TCheckBox;
cmd_DeleteDesktopShortcut: TButton;
cmd_MakeDesktopShortcut: TButton;
cmd_SilentUpdate: TButton;
cmd_AutoUpdate: TButton;
cmd_updateToNewVersion: TButton;
cmd_DownloadNewVersion: TButton;
@ -56,6 +58,9 @@ type
lbl_Version: TLabel;
LazAutoUpdate1: TLazAutoUpdate;
StatusBar1: TStatusBar;
procedure chk_DebugModeChange(Sender: TObject);
procedure chk_ShowDialogsChange(Sender: TObject);
procedure chk_ShowProgressChange(Sender: TObject);
procedure cmd_AutoUpdateClick(Sender: TObject);
procedure cmd_DeleteDesktopShortcutClick(Sender: TObject);
procedure cmd_DownloadNewVersionClick(Sender: TObject);
@ -92,7 +97,7 @@ procedure Tmainform.CloseLog;
begin
If Assigned(Logger) then
begin
Logger.Info('End of Log');
If Logger.Active then Logger.Info('End of Log');
Logger.Active:=False;
end;
end;
@ -120,12 +125,15 @@ begin
Logger.LogType := ltFile;
Logger.FileName := C_LogFileName;
Logger.Active := True;
Logger.Info('Start of Log');
Logger.Info('Testing Logging functionality');
Except
Raise Exception.Create('Trouble with the logger. Click OK to quit');
If Assigned(Logger) then FreeAndNil(Logger);
Application.Terminate;
end;
Logger.Active := False;
if FileExistsUTF8(C_LogFileName) then
DeleteFile(C_LogFileName);
// FORCE AN UPDATE EVERY TIME HERE?
// LazAutoUpdate1.AppVersion:='0.0.0.0';
lbl_Version.Caption:='Version: ' + LazAutoUpdate1.AppVersion;
@ -144,7 +152,6 @@ end;
procedure Tmainform.cmd_SilentUpdateClick(Sender: TObject);
begin
LazAutoUpdate1.SilentUpdate;
end;
procedure Tmainform.cmd_updateToNewVersionClick(Sender: TObject);
@ -188,6 +195,32 @@ begin
{$ENDIF}
end;
procedure Tmainform.chk_DebugModeChange(Sender: TObject);
begin
If chk_DebugMode.Checked then
begin
Logger.Active := True;
Logger.Info('Logging started');
LazAutoUpdate1.DebugMode:=True;
end
else
begin
LazAutoUpdate1.DebugMode:=False;
Logger.Info('Logging ended');
Logger.Active := False;
end;
end;
procedure Tmainform.chk_ShowDialogsChange(Sender: TObject);
begin
LazAutoUpdate1.ShowDialogs:=chk_ShowDialogs.Checked;
end;
procedure Tmainform.chk_ShowProgressChange(Sender: TObject);
begin
LazAutoUpdate1.ShowUpdateInCaption:=chk_ShowProgress.Checked;
end;
procedure Tmainform.cmd_DeleteDesktopShortcutClick(Sender: TObject);
begin
LazAutoUpdate1.ShortCut.ShortCutName:='Test Application';

View File

@ -999,9 +999,9 @@ begin
if fFireDebugEvent then
if Result = True then
fOndebugEvent(Self, 'MakeShortCut', 'MakeShortCut succeded')
fOndebugEvent(Self, 'MakeShortCut', 'MakeShortCut succeded.')
else
fOndebugEvent(Self, 'MakeShortCut', 'MakeShortCut failed');
fOndebugEvent(Self, 'MakeShortCut', 'MakeShortCut failed. Error: ' + GetShortCutErrorString);
end;
function TLazAutoUpdate.DeleteShortCut: boolean;
@ -1023,9 +1023,9 @@ begin
if fFireDebugEvent then
if Result = True then
fOndebugEvent(Self, 'MakeShortCut', 'DeleteShortCut succeded')
fOndebugEvent(Self, 'MakeShortCut', 'DeleteShortCut succeded.')
else
fOndebugEvent(Self, 'MakeShortCut', 'DeleteShortCut failed');
fOndebugEvent(Self, 'MakeShortCut', 'DeleteShortCut failed. Error: ' + GetShortCutErrorString);
end;

View File

@ -87,8 +87,17 @@ function CreateDesktopShortCut(Target, TargetArguments, ShortcutName,
function DeleteDesktopShortcut(ShortcutName: string): boolean;
Function GetShortCutErrorString:String;
implementation
Var sErrorString:String;
Function GetShortCutErrorString:String;
Begin
If (sErrorString='') then Result:='OK'
else Result:=sErrorString;
end;
{$IFDEF UNIX}
//Adapted from sysutils; Unix/Linux only
function XdgConfigHome: string;
@ -117,6 +126,7 @@ var
LinkName: WideString;
begin
Result := True;
sErrorString:='OK';
// Simple failure check
if not FileExistsUTF8(Target) then
Result := False;
@ -159,42 +169,63 @@ var
begin
// Suceed by default:
Result := True;
sErrorString:='OK';
// Simple failure checks
if not FileExistsUTF8(Target) then
begin
sErrorString:='File "' + Target + '" cannot be located.';
Result := False;
if not FileExistsUTF8(ExtractFilePath(Target) + IconFileName) then
Result := False;
if ShortCutName = '' then
Result := False;
if Result = False then
Exit;
end;
if not FileExistsUTF8(ExtractFilePath(Target) + IconFileName) then
begin
sErrorString:='File "' + ExtractFilePath(Target) + IconFileName + '" cannot be located.';
Result := False;
Exit;
end;
if ShortCutName = '' then
begin
sErrorString:='ShortcutName is blank.';
Result := False;
Exit;
end;
if Category = '' then
Category := 'Utility';
begin
sErrorString:='Category is blank. Using "Utility"';
Category := 'Utility';
end;
XdgDesktopFile := IncludeTrailingPathDelimiter(GetTempDir(False)) +
'fpcup-' + shortcutname + '.desktop';
shortcutname + '.desktop';
XdgDesktopContent := TStringList.Create;
try
XdgDesktopContent.Add('[Desktop Entry]');
XdgDesktopContent.Add('Encoding=UTF-8');
XdgDesktopContent.Add('Type=Application');
XdgDesktopContent.Add('Icon=' + ExtractFilePath(Target) + IconFileName);
XdgDesktopContent.Add('Exec=' + Target + ' ' + TargetArguments);
If TargetArguments <> '' then
XdgDesktopContent.Add('Exec=' + Target + ' ' + TargetArguments)
else
XdgDesktopContent.Add('Exec=' + Target);
XdgDesktopContent.Add('Name=' + ShortcutName);
XdgDesktopContent.Add('Category=' + Category + ';');
XdgDesktopContent.Add('Category=' + Category);
// We're going to try and call xdg-desktop-icon
// this may fail if shortcut exists already
AProcess := TProcess.Create(nil);
try
try
XdgDesktopContent.SaveToFile(XdgDesktopFile);
AProcess.Parameters.Add(XdgDesktopFile);
Sleep(100);
Aprocess.Executable := 'xdg-desktop-icon install';
Aprocess.WaitOnExit(2000);
AProcess.CurrentDirectory := ProgramDirectory;
AProcess.Parameters.Clear;
AProcess.Parameters.Add(XdgDesktopFile);
Aprocess.Execute;
//OperationSucceeded:=(ExecuteCommand('xdg-desktop-icon install ' + XdgDesktopFile,false)=0);
Sleep(100);
except
Result := False;
sErrorString:='Exception running "xdg-desktop-icon install"';
end;
finally
AProcess.Free;
@ -202,7 +233,8 @@ begin
if Result = False then
// Temp file is no longer needed....
try
DeleteFile(XdgDesktopFile);
If Not DeleteFile(XdgDesktopFile) then
sErrorString:='Unable to delete temporary ' + XdgDesktopFile;
finally
// Swallow, let filesystem maintenance clear it up
end;
@ -220,6 +252,7 @@ var
LinkName: WideString;
begin
Result := False;
sErrorString:='OK';
try
{ Get the desktop location }
SHGetSpecialFolderLocation(0, CSIDL_DESKTOPDIRECTORY, PIDL);
@ -228,6 +261,7 @@ begin
if SysUtils.DeleteFile(LinkName) then
Result := True;
except
sErrorString:='Exception deleting ' + LinkName;
// Eat the exception
end;
end;
@ -235,6 +269,7 @@ end;
{$ELSE}
function DeleteDesktopShortcut(ShortcutName: string): boolean;
begin
sErrorString:='OK';
Result := False;
end;