To V0.3.5.0. Shortcut code working in Windows and Linux

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5721 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
gbamber
2017-01-28 11:30:16 +00:00
parent 0b3de90fc7
commit fc3d43a170
3 changed files with 196 additions and 132 deletions

View File

@ -4,11 +4,11 @@
<PathDelim Value="\"/> <PathDelim Value="\"/>
<Version Value="10"/> <Version Value="10"/>
<BuildModes Active="Linux64"/> <BuildModes Active="Linux64"/>
<Units Count="31"> <Units Count="34">
<Unit0> <Unit0>
<Filename Value="testapp.lpr"/> <Filename Value="testapp.lpr"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="8"/> <EditorIndex Value="11"/>
<CursorPos X="25" Y="28"/> <CursorPos X="25" Y="28"/>
<UsageCount Value="94"/> <UsageCount Value="94"/>
<Loaded Value="True"/> <Loaded Value="True"/>
@ -19,8 +19,8 @@
<ComponentName Value="mainform"/> <ComponentName Value="mainform"/>
<HasResources Value="True"/> <HasResources Value="True"/>
<ResourceBaseClass Value="Form"/> <ResourceBaseClass Value="Form"/>
<TopLine Value="208"/> <TopLine Value="177"/>
<CursorPos X="66" Y="220"/> <CursorPos X="36" Y="181"/>
<UsageCount Value="94"/> <UsageCount Value="94"/>
<Loaded Value="True"/> <Loaded Value="True"/>
<LoadedDesigner Value="True"/> <LoadedDesigner Value="True"/>
@ -42,15 +42,15 @@
</Unit3> </Unit3>
<Unit4> <Unit4>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<EditorIndex Value="1"/> <IsVisibleTab Value="True"/>
<TopLine Value="44"/> <WindowIndex Value="1"/>
<CursorPos X="63" Y="61"/> <TopLine Value="1707"/>
<CursorPos X="44" Y="1747"/>
<ExtraEditorCount Value="2"/> <ExtraEditorCount Value="2"/>
<ExtraEditor1> <ExtraEditor1>
<IsVisibleTab Value="True"/> <EditorIndex Value="1"/>
<WindowIndex Value="1"/> <TopLine Value="44"/>
<TopLine Value="1707"/> <CursorPos X="63" Y="61"/>
<CursorPos X="44" Y="1747"/>
</ExtraEditor1> </ExtraEditor1>
<ExtraEditor2> <ExtraEditor2>
<EditorIndex Value="-1"/> <EditorIndex Value="-1"/>
@ -186,9 +186,9 @@
<Unit22> <Unit22>
<Filename Value="..\ushortcut.pas"/> <Filename Value="..\ushortcut.pas"/>
<IsVisibleTab Value="True"/> <IsVisibleTab Value="True"/>
<EditorIndex Value="4"/> <EditorIndex Value="6"/>
<TopLine Value="219"/> <TopLine Value="179"/>
<CursorPos X="87" Y="240"/> <CursorPos X="9" Y="221"/>
<UsageCount Value="36"/> <UsageCount Value="36"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit22> </Unit22>
@ -201,7 +201,7 @@
</Unit23> </Unit23>
<Unit24> <Unit24>
<Filename Value="C:\laztrunk\fpc\packages\winunits-base\src\shlobj.pp"/> <Filename Value="C:\laztrunk\fpc\packages\winunits-base\src\shlobj.pp"/>
<EditorIndex Value="7"/> <EditorIndex Value="10"/>
<TopLine Value="2203"/> <TopLine Value="2203"/>
<CursorPos X="56" Y="2335"/> <CursorPos X="56" Y="2335"/>
<UsageCount Value="25"/> <UsageCount Value="25"/>
@ -210,8 +210,8 @@
<Unit25> <Unit25>
<Filename Value="C:\laztrunk\fpc\rtl\objpas\classes\classesh.inc"/> <Filename Value="C:\laztrunk\fpc\rtl\objpas\classes\classesh.inc"/>
<EditorIndex Value="3"/> <EditorIndex Value="3"/>
<TopLine Value="399"/> <TopLine Value="662"/>
<CursorPos X="30" Y="426"/> <CursorPos X="25" Y="697"/>
<UsageCount Value="24"/> <UsageCount Value="24"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit25> </Unit25>
@ -239,144 +239,168 @@
</Unit28> </Unit28>
<Unit29> <Unit29>
<Filename Value="C:\laztrunk\fpc\rtl\objpas\sysutils\finah.inc"/> <Filename Value="C:\laztrunk\fpc\rtl\objpas\sysutils\finah.inc"/>
<EditorIndex Value="6"/> <EditorIndex Value="9"/>
<CursorPos X="10" Y="33"/> <CursorPos X="38" Y="36"/>
<UsageCount Value="23"/> <UsageCount Value="23"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit29> </Unit29>
<Unit30> <Unit30>
<Filename Value="C:\laztrunk\lazarus\components\lazutils\lazfileutils.pas"/> <Filename Value="C:\laztrunk\lazarus\components\lazutils\lazfileutils.pas"/>
<UnitName Value="LazFileUtils"/> <UnitName Value="LazFileUtils"/>
<EditorIndex Value="5"/> <EditorIndex Value="8"/>
<TopLine Value="273"/> <TopLine Value="58"/>
<CursorPos X="3" Y="278"/> <CursorPos X="29" Y="87"/>
<UsageCount Value="23"/> <UsageCount Value="23"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit30> </Unit30>
<Unit31>
<Filename Value="C:\laztrunk\fpc\packages\rtl-objpas\src\inc\strutils.pp"/>
<EditorIndex Value="7"/>
<TopLine Value="1809"/>
<CursorPos X="3" Y="1812"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit31>
<Unit32>
<Filename Value="C:\laztrunk\fpc\rtl\objpas\classes\stringl.inc"/>
<EditorIndex Value="4"/>
<TopLine Value="1110"/>
<CursorPos X="10" Y="1116"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit32>
<Unit33>
<Filename Value="C:\laztrunk\fpc\rtl\objpas\sysutils\sysencodingh.inc"/>
<EditorIndex Value="5"/>
<TopLine Value="10"/>
<CursorPos X="24" Y="104"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit33>
</Units> </Units>
<OtherDefines Count="1"> <OtherDefines Count="1">
<Define0 Value="DEBUGMODE"/> <Define0 Value="DEBUGMODE"/>
</OtherDefines> </OtherDefines>
<JumpHistory Count="30" HistoryIndex="29"> <JumpHistory Count="30" HistoryIndex="29">
<Position1> <Position1>
<Filename Value="umainform.pas"/> <Filename Value="..\ushortcut.pas"/>
<Caret Line="176" Column="4" TopLine="157"/> <Caret Line="268" Column="79" TopLine="239"/>
</Position1> </Position1>
<Position2> <Position2>
<Filename Value="umainform.pas"/> <Filename Value="..\ushortcut.pas"/>
<Caret Line="170" Column="45" TopLine="159"/> <Caret Line="235" Column="60" TopLine="216"/>
</Position2> </Position2>
<Position3> <Position3>
<Filename Value="umainform.pas"/> <Filename Value="..\ushortcut.pas"/>
<Caret Line="194" TopLine="170"/> <Caret Line="272" Column="25" TopLine="245"/>
</Position3> </Position3>
<Position4> <Position4>
<Filename Value="umainform.pas"/> <Filename Value="..\ushortcut.pas"/>
<Caret Line="147" TopLine="145"/> <Caret Line="233" Column="47" TopLine="214"/>
</Position4> </Position4>
<Position5> <Position5>
<Filename Value="umainform.pas"/> <Filename Value="..\ushortcut.pas"/>
<Caret Line="146" TopLine="144"/> <Caret Line="239" Column="20" TopLine="229"/>
</Position5> </Position5>
<Position6> <Position6>
<Filename Value="umainform.pas"/> <Filename Value="..\ushortcut.pas"/>
<Caret Line="148" TopLine="146"/> <Caret Line="295" Column="31" TopLine="259"/>
</Position6> </Position6>
<Position7> <Position7>
<Filename Value="umainform.pas"/> <Filename Value="..\ushortcut.pas"/>
<Caret Line="125" TopLine="108"/> <Caret Line="289" Column="22" TopLine="268"/>
</Position7> </Position7>
<Position8> <Position8>
<Filename Value="umainform.pas"/> <Filename Value="..\ushortcut.pas"/>
<Caret Line="118" Column="30" TopLine="93"/> <Caret Line="278" Column="71" TopLine="268"/>
</Position8> </Position8>
<Position9> <Position9>
<Filename Value="umainform.pas"/> <Filename Value="..\ushortcut.pas"/>
<Caret Line="124" Column="45" TopLine="103"/> <Caret Line="306" Column="78" TopLine="269"/>
</Position9> </Position9>
<Position10> <Position10>
<Filename Value="umainform.pas"/> <Filename Value="..\ushortcut.pas"/>
<Caret Line="125" Column="45" TopLine="104"/> <Caret Line="289" Column="57" TopLine="261"/>
</Position10> </Position10>
<Position11> <Position11>
<Filename Value="umainform.pas"/> <Filename Value="..\ushortcut.pas"/>
<Caret Line="198" Column="3" TopLine="196"/> <Caret Line="255" Column="57" TopLine="229"/>
</Position11> </Position11>
<Position12> <Position12>
<Filename Value="umainform.pas"/> <Filename Value="..\ushortcut.pas"/>
<Caret Line="214" Column="56" TopLine="201"/> <Caret Line="308" Column="21" TopLine="277"/>
</Position12> </Position12>
<Position13> <Position13>
<Filename Value="umainform.pas"/> <Filename Value="..\ushortcut.pas"/>
<Caret Line="216" Column="56" TopLine="203"/> <Caret Line="149" Column="39" TopLine="121"/>
</Position13> </Position13>
<Position14> <Position14>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="1004" Column="101" TopLine="970"/> <Caret Line="999" Column="4" TopLine="970"/>
</Position14> </Position14>
<Position15> <Position15>
<Filename Value="..\ushortcut.pas"/> <Filename Value="..\ushortcut.pas"/>
<Caret Line="268" Column="79" TopLine="239"/> <Caret Line="186" Column="24" TopLine="160"/>
</Position15> </Position15>
<Position16> <Position16>
<Filename Value="..\ushortcut.pas"/> <Filename Value="..\ushortcut.pas"/>
<Caret Line="235" Column="60" TopLine="216"/> <Caret Line="245" Column="26" TopLine="218"/>
</Position16> </Position16>
<Position17> <Position17>
<Filename Value="..\ushortcut.pas"/> <Filename Value="..\ushortcut.pas"/>
<Caret Line="272" Column="25" TopLine="245"/> <Caret Line="246" Column="31" TopLine="222"/>
</Position17> </Position17>
<Position18> <Position18>
<Filename Value="..\ushortcut.pas"/> <Filename Value="..\ushortcut.pas"/>
<Caret Line="233" Column="47" TopLine="214"/> <Caret Line="248" Column="53" TopLine="222"/>
</Position18> </Position18>
<Position19> <Position19>
<Filename Value="..\ushortcut.pas"/> <Filename Value="..\ushortcut.pas"/>
<Caret Line="239" Column="20" TopLine="229"/> <Caret Line="212" Column="33" TopLine="184"/>
</Position19> </Position19>
<Position20> <Position20>
<Filename Value="..\ushortcut.pas"/> <Filename Value="C:\laztrunk\fpc\rtl\objpas\classes\stringl.inc"/>
<Caret Line="295" Column="31" TopLine="259"/> <Caret Line="1116" Column="75" TopLine="1116"/>
</Position20> </Position20>
<Position21> <Position21>
<Filename Value="..\ushortcut.pas"/> <Filename Value="..\ushortcut.pas"/>
<Caret Line="289" Column="22" TopLine="268"/> <Caret Line="287" TopLine="269"/>
</Position21> </Position21>
<Position22> <Position22>
<Filename Value="..\ushortcut.pas"/> <Filename Value="C:\laztrunk\fpc\rtl\objpas\sysutils\sysencodingh.inc"/>
<Caret Line="278" Column="71" TopLine="268"/> <Caret Line="104" Column="24" TopLine="66"/>
</Position22> </Position22>
<Position23> <Position23>
<Filename Value="..\ushortcut.pas"/> <Filename Value="..\ushortcut.pas"/>
<Caret Line="306" Column="78" TopLine="269"/> <Caret Line="283" Column="56" TopLine="256"/>
</Position23> </Position23>
<Position24> <Position24>
<Filename Value="..\ushortcut.pas"/> <Filename Value="..\ushortcut.pas"/>
<Caret Line="289" Column="57" TopLine="261"/> <Caret Line="312" Column="56" TopLine="285"/>
</Position24> </Position24>
<Position25> <Position25>
<Filename Value="..\ushortcut.pas"/> <Filename Value="C:\laztrunk\fpc\rtl\objpas\classes\stringl.inc"/>
<Caret Line="255" Column="57" TopLine="229"/> <Caret Line="1116" Column="10" TopLine="1110"/>
</Position25> </Position25>
<Position26> <Position26>
<Filename Value="..\ushortcut.pas"/> <Filename Value="..\ushortcut.pas"/>
<Caret Line="308" Column="21" TopLine="277"/> <Caret Line="283" Column="55" TopLine="256"/>
</Position26> </Position26>
<Position27> <Position27>
<Filename Value="..\ushortcut.pas"/> <Filename Value="..\ushortcut.pas"/>
<Caret Line="149" Column="39" TopLine="121"/> <Caret Line="212" Column="40" TopLine="185"/>
</Position27> </Position27>
<Position28> <Position28>
<Filename Value="..\ulazautoupdate.pas"/> <Filename Value="..\ushortcut.pas"/>
<Caret Line="999" Column="4" TopLine="970"/> <Caret Line="255" Column="75" TopLine="235"/>
</Position28> </Position28>
<Position29> <Position29>
<Filename Value="..\ushortcut.pas"/> <Filename Value="umainform.pas"/>
<Caret Line="186" Column="24" TopLine="160"/> <Caret Line="218" Column="29" TopLine="208"/>
</Position29> </Position29>
<Position30> <Position30>
<Filename Value="..\ushortcut.pas"/> <Filename Value="..\ushortcut.pas"/>
<Caret Line="245" Column="26" TopLine="218"/> <Caret Line="264" Column="13" TopLine="238"/>
</Position30> </Position30>
</JumpHistory> </JumpHistory>
</ProjectSession> </ProjectSession>

View File

@ -176,9 +176,10 @@ end;
procedure Tmainform.cmd_MakeDesktopShortcutClick(Sender: TObject); procedure Tmainform.cmd_MakeDesktopShortcutClick(Sender: TObject);
begin begin
LazAutoUpdate1.ShortCut.ShortCutName:='Test Application'; LazAutoUpdate1.ShortCut.ShortCutName:=Application.Title;
LazAutoUpdate1.ShortCut.Target:=Application.EXEName; LazAutoUpdate1.ShortCut.Target:=Application.EXEName;
LazAutoUpdate1.ShortCut.IconFilename:=ChangeFileExt(Application.EXEName,'.ico'); LazAutoUpdate1.ShortCut.IconFilename:=ChangeFileExt(Application.EXEName,'.ico');
LazAutoUpdate1.ShortCut.Category:=scUtility;
If LazAutoUpdate1.MakeShortCut then If LazAutoUpdate1.MakeShortCut then
ShowMessage('Success! New shortcut is now on your desktop') ShowMessage('Success! New shortcut is now on your desktop')
else else

View File

@ -85,7 +85,7 @@ interface
uses uses
Classes, SysUtils, LazUTF8, FileUtil, LazFileUtils Classes, SysUtils, LazUTF8, FileUtil, LazFileUtils
{$IFDEF LINUX},process,strutils{$ENDIF} {$IFDEF LINUX}, process, strutils, LazUTF8Classes{$ENDIF}
{$IFDEF WINDOWS}, Windows, shlobj {for special folders}, ActiveX, {$IFDEF WINDOWS}, Windows, shlobj {for special folders}, ActiveX,
ComObj, ShellAPI{$ENDIF} ; ComObj, ShellAPI{$ENDIF} ;
@ -107,12 +107,12 @@ begin
Result := sDebugString; Result := sDebugString;
end; end;
// Builds up a string with linebreaks // Builds up a string with linebreaks
procedure AddToDebugString(Astring:String); procedure AddToDebugString(Astring: string);
begin begin
if (sDebugString = '') then if (sDebugString = '') then
sDebugString:=LineEnding + '* ' + Astring sDebugString := LineEnding + '* ' + Astring
else else
sDebugString:=sDebugString + LineEnding + '* ' + Astring; sDebugString := sDebugString + LineEnding + '* ' + Astring;
end; end;
{$IFDEF UNIX} {$IFDEF UNIX}
@ -158,34 +158,34 @@ begin
sDebugString := ''; sDebugString := '';
// Simple failure check // Simple failure check
if not FileExistsUTF8(Target) then if not FileExistsUTF8(Target) then
begin begin
AddToDebugString('Filename ' + Target + ' does not exist'); AddToDebugString('Filename ' + Target + ' does not exist');
Result := False; Result := False;
Exit; Exit;
end; end;
try try
{ Creates an instance of IShellLink } { Creates an instance of IShellLink }
IObject := CreateComObject(CLSID_ShellLink); IObject := CreateComObject(CLSID_ShellLink);
ISLink := IObject as IShellLink; ISLink := IObject as IShellLink;
IPFile := IObject as IPersistFile; IPFile := IObject as IPersistFile;
TRY try
ISLink.SetPath(PChar(Target)); ISLink.SetPath(PChar(Target));
ISLink.SetArguments(PChar(TargetArguments)); ISLink.SetArguments(PChar(TargetArguments));
ISLink.SetWorkingDirectory(PChar(ExtractFilePath(Target))); ISLink.SetWorkingDirectory(PChar(ExtractFilePath(Target)));
// ISLink.SetIconLocation(Pchar(ExtractFilePath(Target) + IconFileName)); // ISLink.SetIconLocation(Pchar(ExtractFilePath(Target) + IconFileName));
{ Get the desktop location } { Get the desktop location }
SHGetSpecialFolderLocation(0, CSIDL_DESKTOPDIRECTORY, PIDL); SHGetSpecialFolderLocation(0, CSIDL_DESKTOPDIRECTORY, PIDL);
SHGetPathFromIDList(PIDL, InFolder); SHGetPathFromIDList(PIDL, InFolder);
LinkName := IncludeTrailingPathDelimiter(InFolder) + ShortcutName + '.lnk'; LinkName := IncludeTrailingPathDelimiter(InFolder) + ShortcutName + '.lnk';
{ Get rid of any existing shortcut first } { Get rid of any existing shortcut first }
If Not SysUtils.DeleteFile(LinkName) then if not SysUtils.DeleteFile(LinkName) then
AddToDebugString('Could not delete existing link ' + LinkName); AddToDebugString('Could not delete existing link ' + LinkName);
{ Create the link } { Create the link }
IPFile.Save(PWChar(LinkName), False); IPFile.Save(PWChar(LinkName), False);
finally finally
FreeAndNil(IPFile); FreeAndNil(IPFile);
end; end;
except except
Result := False; Result := False;
@ -197,6 +197,9 @@ end;
function CreateDesktopShortCut(Target, TargetArguments, ShortcutName, function CreateDesktopShortCut(Target, TargetArguments, ShortcutName,
IconFileName, Category: string): boolean; IconFileName, Category: string): boolean;
{ {
* Comprehensive debugging messages in this routine.
* So many flavours of Linux.. - if no desktop icon is created then
* call GetShortCutDebugString and log the result to a file.
IN: IN:
Target: Filename with full path Target: Filename with full path
TargetArguments: String of arguments TargetArguments: String of arguments
@ -209,13 +212,13 @@ OUT:
Use function GetShortCutDebugString to get errors as a string Use function GetShortCutDebugString to get errors as a string
} }
var var
XdgDesktopStringList: TStrings; XdgDesktopStringList: TStringListUTF8;
XdgDesktopFile: string; XdgDesktopFile: string;
Aprocess: TProcess; Aprocess: TProcess;
sPathToShare: string; sPathToShare: string;
sDesktopFilename:String; sDesktopFilename: string;
begin begin
// Suceed by default: // Succeed by default:
Result := True; Result := True;
sDebugString := ''; sDebugString := '';
// Simple failure checks // Simple failure checks
@ -242,23 +245,38 @@ begin
AddToDebugString('Category is blank. Using "Utility"'); AddToDebugString('Category is blank. Using "Utility"');
Category := 'Utility'; Category := 'Utility';
end; end;
// Make up a compliant filename // Make up an 8-character filename
sDesktopFilename:=Copy2Space(shortcutname); sDesktopFilename := DelSpace(shortcutname);
sDesktopFilename:=LeftStr(sDesktopFilename,8); sDesktopFilename := LeftStr(sDesktopFilename, 8);
sDesktopFilename := LowerCase(sDesktopFilename);
AddToDebugString('Desktop filename = ' + sDesktopFilename); AddToDebugString('Desktop filename = ' + sDesktopFilename);
// Standard path to DeskTop files // Standard path to DeskTop files
sPathToShare := IncludeTrailingPathDelimiter(ExpandFileNameUTF8('~')) + // IncludeTrailingPathDelimiter(ExpandFileNameUTF8('~')) resolves to '/root/'
'usr/share/applications' + DirectorySeparator + sPathToShare := '/usr/share/applications' + DirectorySeparator +
sDesktopFilename + '.desktop'; sDesktopFilename + '.desktop';
// Directory check
if not DirectoryExistsUTF8('/usr/share/applications') then
begin
AddToDebugString('Failure: Invalid directory - ' + '/usr/share/applications');
Result := False;
Exit;
end;
// Temp directory path // Temp directory path
XdgDesktopFile := IncludeTrailingPathDelimiter(GetTempDir(False)) + XdgDesktopFile := IncludeTrailingPathDelimiter(GetTempDir(False)) +
sDesktopFilename + '.desktop'; sDesktopFilename + '.desktop';
// Directory check
AddToDebugString('XdgDesktopFile = ' + XdgDesktopFile); if not DirectoryExistsUTF8(GetTempDir(False)) then
AddToDebugString('sPathToShare = ' + sPathToShare); begin
AddToDebugString('Failure: Invalid directory - ' + GetTempDir(False));
Result := False;
Exit;
end;
AddToDebugString('Success: XdgDesktopFile = ' + XdgDesktopFile);
AddToDebugString('Success: sPathToShare = ' + sPathToShare);
// Make up the desktop file // Make up the desktop file
XdgDesktopStringList := TStringList.Create; XdgDesktopStringList := TStringListUTF8.Create;
try try
XdgDesktopStringList.Add('[Desktop Entry]'); XdgDesktopStringList.Add('[Desktop Entry]');
XdgDesktopStringList.Add('Encoding=UTF-8'); XdgDesktopStringList.Add('Encoding=UTF-8');
@ -276,11 +294,15 @@ begin
AProcess := TProcess.Create(nil); AProcess := TProcess.Create(nil);
try try
try try
if FileExistsUTF8(XdgDesktopFile) then DeleteFile(XdgDesktopFile); if FileExistsUTF8(XdgDesktopFile) then
DeleteFile(XdgDesktopFile);
Sleep(100); Sleep(100);
XdgDesktopStringList.SaveToFile(XdgDesktopFile); try
if Not FileExistsUTF8(XdgDesktopFile) then XdgDesktopStringList.SaveToFile(XdgDesktopFile);
AddToDebugString('XdgDesktopFile wasn''t saved'); except
if not FileExistsUTF8(XdgDesktopFile) then
AddToDebugString('Failure: XdgDesktopFile wasn''t saved');
end;
if FileExistsUTF8(XdgDesktopFile) then if FileExistsUTF8(XdgDesktopFile) then
begin begin
Aprocess.Executable := 'xdg-desktop-icon install'; Aprocess.Executable := 'xdg-desktop-icon install';
@ -289,26 +311,30 @@ begin
AProcess.Parameters.Add(XdgDesktopFile); AProcess.Parameters.Add(XdgDesktopFile);
Aprocess.Execute; Aprocess.Execute;
Sleep(100); Sleep(100);
AddToDebugString('xdg-desktop-icon install succeeded');
end; end;
except except
// xdg-desktop-icon install failed. // xdg-desktop-icon install failed.
Result := False; Result := False;
AddToDebugString('Exception running "xdg-desktop-icon install"'); AddToDebugString('Failure: Exception running "xdg-desktop-icon install"');
// OK. Try usr/share/applications // OK. Try usr/share/applications
if FileExistsUTF8(sPathToShare) then if FileExistsUTF8(sPathToShare) then
begin begin
If SysUtils.DeleteFile(sPathToShare) then if SysUtils.DeleteFile(sPathToShare) then
AddToDebugString('Successfully deleted existing ' + sPathToShare) AddToDebugString('Successfully deleted existing ' + sPathToShare)
else else
AddToDebugString('Unable to delete existing ' + sPathToShare); AddToDebugString('Failure: Unable to delete existing ' + sPathToShare);
end; end;
// Save the stringlist directly to usr/share/applications // Save the stringlist directly to usr/share/applications
XdgDesktopStringList.SaveToFile(sPathToShare); try
If Not FileExistsUTF8(sPathToShare) then XdgDesktopStringList.SaveToFile(sPathToShare);
begin except
Result:=FALSE; if not FileExistsUTF8(sPathToShare) then
AddToDebugString('SaveToFile(' + sPathToShare + ') failed'); begin
Result := False;
AddToDebugString('Failure: SaveToFile(' + sPathToShare + ') failed');
end;
end; end;
end; end;
finally finally
@ -316,18 +342,31 @@ begin
end; end;
if Result = False then if Result = False then
try try
If (FileExistsUTF8(XdgDesktopFile)) AND (NOT FileExistsUTF8(sPathToShare)) then if Not (FileExistsUTF8(XdgDesktopFile)) then
BEGIN AddToDebugString('Unable to locate temporary ' + XdgDesktopFile);
// Last try to copy file to usr/share/applications if (FileExistsUTF8(XdgDesktopFile)) and (not FileExistsUTF8(sPathToShare)) then
if CopyFile(XdgDesktopFile, sPathToShare) then begin
Result := True // Last try to copy file to usr/share/applications
else if CopyFile(XdgDesktopFile, sPathToShare) then
AddToDebugString(Format('Unable to copy %s file to %s', [XdgDesktopFile, sPathToShare])); begin
// Temp file is no longer needed.... AddToDebugString(Format('Successfully copied %s file to %s',
if not SysUtils.DeleteFile(XdgDesktopFile) then [XdgDesktopFile, sPathToShare]));
AddToDebugString('Unable to delete temporary ' + XdgDesktopFile); Result := True;
end end
else AddToDebugString('Unable to locate temporary ' + XdgDesktopFile); else
AddToDebugString(Format('Unable to copy %s file to %s',
[XdgDesktopFile, sPathToShare]));
// Temp file is no longer needed....
if not SysUtils.DeleteFile(XdgDesktopFile) then
begin
AddToDebugString('Failure: Unable to delete temporary ' + XdgDesktopFile);
end;
end;
if (FileExistsUTF8(sPathToShare)) then
begin
Result:=true;
AddToDebugString('Success: Desktop file - ' + sPathToShare);
end;
finally finally
// Swallow, let filesystem maintenance clear it up // Swallow, let filesystem maintenance clear it up
end; end;