From e9b6ce6f044439ba0e54f5cf2dc8694ef6250fc7 Mon Sep 17 00:00:00 2001 From: gbamber Date: Fri, 27 Jan 2017 14:16:25 +0000 Subject: [PATCH] V0.3.4.1 - wip git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5717 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../lazautoupdate/latest_stable/lazupdate.lpk | 2 +- .../latest_stable/testapp/testapp.lpi | 4 +- .../latest_stable/testapp/testapp.lps | 118 +++++++++--------- .../latest_stable/testapp/testapp.res | Bin 139584 -> 139584 bytes .../latest_stable/testapp/umainform.lfm | 46 ++++--- .../latest_stable/testapp/umainform.pas | 41 +++++- .../latest_stable/ulazautoupdate.pas | 8 +- .../lazautoupdate/latest_stable/ushortcut.pas | 61 +++++++-- 8 files changed, 183 insertions(+), 97 deletions(-) diff --git a/components/lazautoupdate/latest_stable/lazupdate.lpk b/components/lazautoupdate/latest_stable/lazupdate.lpk index a81aac19d..33f669008 100644 --- a/components/lazautoupdate/latest_stable/lazupdate.lpk +++ b/components/lazautoupdate/latest_stable/lazupdate.lpk @@ -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. "/> - + diff --git a/components/lazautoupdate/latest_stable/testapp/testapp.lpi b/components/lazautoupdate/latest_stable/testapp/testapp.lpi index e68e169eb..6965821fc 100644 --- a/components/lazautoupdate/latest_stable/testapp/testapp.lpi +++ b/components/lazautoupdate/latest_stable/testapp/testapp.lpi @@ -19,7 +19,9 @@ - + + + diff --git a/components/lazautoupdate/latest_stable/testapp/testapp.lps b/components/lazautoupdate/latest_stable/testapp/testapp.lps index 85c54bee6..236542fbb 100644 --- a/components/lazautoupdate/latest_stable/testapp/testapp.lps +++ b/components/lazautoupdate/latest_stable/testapp/testapp.lps @@ -3,14 +3,14 @@ - + - + @@ -19,9 +19,9 @@ - - - + + + @@ -32,7 +32,7 @@ - + @@ -43,8 +43,8 @@ - - + + @@ -58,7 +58,7 @@ - + @@ -145,7 +145,7 @@ - + @@ -187,9 +187,9 @@ - - - + + + @@ -204,7 +204,7 @@ - + @@ -212,7 +212,7 @@ - + @@ -227,7 +227,7 @@ - + @@ -237,123 +237,123 @@ - + - + - + - + - + - + - + - + - + - + - + - + - - + + - - + + - - + + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - + - + - - + + - + - - + + diff --git a/components/lazautoupdate/latest_stable/testapp/testapp.res b/components/lazautoupdate/latest_stable/testapp/testapp.res index 2feb20d57a5c3091f2e52171eb6749f3d47dde80..193ea8aa1815cc6c54959f54310f9ce1a1eb1f6b 100644 GIT binary patch delta 45 zcmX?bh~vN^jtxiH*cllZ7#JCtH=kxxW#lwu&|@$LV#DU2?Cn3<8MpsrXL6SW04Tl; AV*mgE delta 45 wcmX?bh~vN^jtxiH*crfpar0?5RYpz&20aEtAU0_J$=?2xopJk5b|!a804MqkTL1t6 diff --git a/components/lazautoupdate/latest_stable/testapp/umainform.lfm b/components/lazautoupdate/latest_stable/testapp/umainform.lfm index d3ece9ab1..f36b977a4 100644 --- a/components/lazautoupdate/latest_stable/testapp/umainform.lfm +++ b/components/lazautoupdate/latest_stable/testapp/umainform.lfm @@ -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 diff --git a/components/lazautoupdate/latest_stable/testapp/umainform.pas b/components/lazautoupdate/latest_stable/testapp/umainform.pas index d9b851b3d..b41eebf7b 100644 --- a/components/lazautoupdate/latest_stable/testapp/umainform.pas +++ b/components/lazautoupdate/latest_stable/testapp/umainform.pas @@ -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'; diff --git a/components/lazautoupdate/latest_stable/ulazautoupdate.pas b/components/lazautoupdate/latest_stable/ulazautoupdate.pas index 09ff8cd57..c07560197 100644 --- a/components/lazautoupdate/latest_stable/ulazautoupdate.pas +++ b/components/lazautoupdate/latest_stable/ulazautoupdate.pas @@ -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; diff --git a/components/lazautoupdate/latest_stable/ushortcut.pas b/components/lazautoupdate/latest_stable/ushortcut.pas index 977774a51..1c24adca9 100644 --- a/components/lazautoupdate/latest_stable/ushortcut.pas +++ b/components/lazautoupdate/latest_stable/ushortcut.pas @@ -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;