Work-in-progress

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5719 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
gbamber
2017-01-27 16:24:27 +00:00
parent 55b0f8fb67
commit 4fa832acde
2 changed files with 156 additions and 102 deletions

View File

@ -4,11 +4,11 @@
<PathDelim Value="\"/>
<Version Value="10"/>
<BuildModes Active="Linux64"/>
<Units Count="28">
<Units Count="31">
<Unit0>
<Filename Value="testapp.lpr"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="6"/>
<EditorIndex Value="8"/>
<CursorPos X="25" Y="28"/>
<UsageCount Value="67"/>
<Loaded Value="True"/>
@ -49,7 +49,7 @@
<ExtraEditorCount Value="2"/>
<ExtraEditor1>
<EditorIndex Value="1"/>
<TopLine Value="992"/>
<TopLine Value="1058"/>
<CursorPos X="68" Y="1025"/>
</ExtraEditor1>
<ExtraEditor2>
@ -187,8 +187,8 @@
<Filename Value="..\ushortcut.pas"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="4"/>
<TopLine Value="7"/>
<CursorPos X="56" Y="39"/>
<TopLine Value="251"/>
<CursorPos X="69" Y="278"/>
<UsageCount Value="23"/>
<Loaded Value="True"/>
</Unit22>
@ -201,7 +201,7 @@
</Unit23>
<Unit24>
<Filename Value="C:\laztrunk\fpc\packages\winunits-base\src\shlobj.pp"/>
<EditorIndex Value="5"/>
<EditorIndex Value="7"/>
<TopLine Value="2203"/>
<CursorPos X="56" Y="2335"/>
<UsageCount Value="12"/>
@ -230,6 +230,29 @@
<UsageCount Value="11"/>
<Loaded Value="True"/>
</Unit27>
<Unit28>
<Filename Value="C:\laztrunk\fpc\rtl\objpas\sysutils\osutilsh.inc"/>
<EditorIndex Value="-1"/>
<TopLine Value="10"/>
<CursorPos X="25" Y="40"/>
<UsageCount Value="10"/>
</Unit28>
<Unit29>
<Filename Value="C:\laztrunk\fpc\rtl\objpas\sysutils\finah.inc"/>
<EditorIndex Value="6"/>
<CursorPos X="10" Y="33"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit29>
<Unit30>
<Filename Value="C:\laztrunk\lazarus\components\lazutils\lazfileutils.pas"/>
<UnitName Value="LazFileUtils"/>
<EditorIndex Value="5"/>
<TopLine Value="273"/>
<CursorPos X="3" Y="278"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit30>
</Units>
<OtherDefines Count="1">
<Define0 Value="DEBUGMODE"/>
@ -237,123 +260,123 @@
<JumpHistory Count="30" HistoryIndex="29">
<Position1>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="570" Column="28" TopLine="542"/>
<Caret Line="785" TopLine="758"/>
</Position1>
<Position2>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="621" Column="46" TopLine="582"/>
<Caret Line="784" Column="41" TopLine="757"/>
</Position2>
<Position3>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="629" Column="65" TopLine="593"/>
<Caret Line="474" TopLine="456"/>
</Position3>
<Position4>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="637" Column="51" TopLine="615"/>
<Caret Line="966" Column="70" TopLine="931"/>
</Position4>
<Position5>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="639" Column="8" TopLine="615"/>
<Filename Value="umainform.pas"/>
<Caret Line="15" Column="16" TopLine="8"/>
</Position5>
<Position6>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="637" Column="50" TopLine="616"/>
<Filename Value="umainform.pas"/>
<Caret Line="152" Column="37" TopLine="146"/>
</Position6>
<Position7>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="971" Column="61" TopLine="944"/>
<Filename Value="umainform.pas"/>
<Caret Line="154" Column="37" TopLine="148"/>
</Position7>
<Position8>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="480" Column="20" TopLine="448"/>
<Caret Line="1014" Column="57" TopLine="977"/>
</Position8>
<Position9>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="785" TopLine="758"/>
<Filename Value="umainform.pas"/>
<Caret Line="176" Column="4" TopLine="157"/>
</Position9>
<Position10>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="784" Column="41" TopLine="757"/>
<Filename Value="umainform.pas"/>
<Caret Line="170" Column="45" TopLine="159"/>
</Position10>
<Position11>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="474" TopLine="456"/>
<Filename Value="umainform.pas"/>
<Caret Line="194" TopLine="170"/>
</Position11>
<Position12>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="966" Column="70" TopLine="931"/>
<Filename Value="umainform.pas"/>
<Caret Line="147" TopLine="145"/>
</Position12>
<Position13>
<Filename Value="umainform.pas"/>
<Caret Line="15" Column="16" TopLine="8"/>
<Caret Line="146" TopLine="144"/>
</Position13>
<Position14>
<Filename Value="umainform.pas"/>
<Caret Line="152" Column="37" TopLine="146"/>
<Caret Line="148" TopLine="146"/>
</Position14>
<Position15>
<Filename Value="umainform.pas"/>
<Caret Line="154" Column="37" TopLine="148"/>
<Caret Line="125" TopLine="108"/>
</Position15>
<Position16>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="1014" Column="57" TopLine="977"/>
<Filename Value="umainform.pas"/>
<Caret Line="118" Column="30" TopLine="93"/>
</Position16>
<Position17>
<Filename Value="umainform.pas"/>
<Caret Line="176" Column="4" TopLine="157"/>
<Caret Line="124" Column="45" TopLine="103"/>
</Position17>
<Position18>
<Filename Value="umainform.pas"/>
<Caret Line="170" Column="45" TopLine="159"/>
<Caret Line="125" Column="45" TopLine="104"/>
</Position18>
<Position19>
<Filename Value="umainform.pas"/>
<Caret Line="194" TopLine="170"/>
<Caret Line="198" Column="3" TopLine="196"/>
</Position19>
<Position20>
<Filename Value="umainform.pas"/>
<Caret Line="147" TopLine="145"/>
<Caret Line="214" Column="56" TopLine="201"/>
</Position20>
<Position21>
<Filename Value="umainform.pas"/>
<Caret Line="146" TopLine="144"/>
<Caret Line="216" Column="56" TopLine="203"/>
</Position21>
<Position22>
<Filename Value="umainform.pas"/>
<Caret Line="148" TopLine="146"/>
</Position22>
<Position23>
<Filename Value="umainform.pas"/>
<Caret Line="125" TopLine="108"/>
</Position23>
<Position24>
<Filename Value="umainform.pas"/>
<Caret Line="118" Column="30" TopLine="93"/>
</Position24>
<Position25>
<Filename Value="umainform.pas"/>
<Caret Line="124" Column="45" TopLine="103"/>
</Position25>
<Position26>
<Filename Value="umainform.pas"/>
<Caret Line="125" Column="45" TopLine="104"/>
</Position26>
<Position27>
<Filename Value="umainform.pas"/>
<Caret Line="198" Column="3" TopLine="196"/>
</Position27>
<Position28>
<Filename Value="umainform.pas"/>
<Caret Line="214" Column="56" TopLine="201"/>
</Position28>
<Position29>
<Filename Value="umainform.pas"/>
<Caret Line="216" Column="56" TopLine="203"/>
</Position29>
<Position30>
<Filename Value="..\ulazautoupdate.pas"/>
<Caret Line="1004" Column="101" TopLine="970"/>
</Position22>
<Position23>
<Filename Value="..\ushortcut.pas"/>
<Caret Line="268" Column="79" TopLine="239"/>
</Position23>
<Position24>
<Filename Value="..\ushortcut.pas"/>
<Caret Line="235" Column="60" TopLine="216"/>
</Position24>
<Position25>
<Filename Value="..\ushortcut.pas"/>
<Caret Line="272" Column="25" TopLine="245"/>
</Position25>
<Position26>
<Filename Value="..\ushortcut.pas"/>
<Caret Line="233" Column="47" TopLine="214"/>
</Position26>
<Position27>
<Filename Value="..\ushortcut.pas"/>
<Caret Line="239" Column="20" TopLine="229"/>
</Position27>
<Position28>
<Filename Value="..\ushortcut.pas"/>
<Caret Line="295" Column="31" TopLine="259"/>
</Position28>
<Position29>
<Filename Value="..\ushortcut.pas"/>
<Caret Line="289" Column="22" TopLine="268"/>
</Position29>
<Position30>
<Filename Value="..\ushortcut.pas"/>
<Caret Line="278" Column="71" TopLine="268"/>
</Position30>
</JumpHistory>
</ProjectSession>

View File

@ -94,15 +94,19 @@ function CreateDesktopShortCut(Target, TargetArguments, ShortcutName,
function DeleteDesktopShortcut(ShortcutName: string): boolean;
Function GetShortCutErrorString:String;
function GetShortCutErrorString: string;
implementation
Var sErrorString:String;
var
sErrorString: string;
Function GetShortCutErrorString:String;
Begin
If (sErrorString='') then Result:='OK'
else Result:=sErrorString;
function GetShortCutErrorString: string;
begin
if (sErrorString = '') then
Result := 'OK'
else
Result := sErrorString;
end;
{$IFDEF UNIX}
@ -145,7 +149,7 @@ var
LinkName: WideString;
begin
Result := True;
sErrorString:='OK';
sErrorString := 'OK';
// Simple failure check
if not FileExistsUTF8(Target) then
Result := False;
@ -186,7 +190,7 @@ IN:
Target: Filename with full path
TargetArguments: String of arguments
ShortCutName: Simple string
IconFileName: Filename with full path
IconFileName: Filename with full path. If not specifies Executable will be used
Category: Simple string (see header of this unit)
OUT:
True = Success
@ -197,48 +201,55 @@ var
XdgDesktopContent: TStringList;
XdgDesktopFile: string;
Aprocess: TProcess;
sPathToShare: string;
begin
// Suceed by default:
Result := True;
sErrorString:='OK';
sErrorString := 'OK';
// Simple failure checks
if not FileExistsUTF8(Target) then
begin
sErrorString:='File "' + Target + '" cannot be located.';
sErrorString := 'File "' + Target + '" cannot be located.';
Result := False;
Exit;
end;
if not FileExistsUTF8(IconFileName) then
begin
sErrorString:='File "' + IconFileName + '" cannot be located.';
Result := False;
Exit;
sErrorString := 'File "' + IconFileName + '" cannot be located.';
IconFileName := Target;
end;
if ShortCutName = '' then
begin
sErrorString:='ShortcutName is blank.';
sErrorString := 'ShortcutName is blank.';
Result := False;
Exit;
end;
if Category = '' then
begin
sErrorString:='Category is blank. Using "Utility"';
Category := 'Utility';
end;
begin
sErrorString := 'Category is blank. Using "Utility"';
Category := 'Utility';
end;
sPathToShare := IncludeTrailingPathDelimiter(ExpandFileNameUTF8('~')) +
'usr/share/applications' + DirectorySeparator + 'test.desktop';
{
XdgDesktopFile := IncludeTrailingPathDelimiter(GetTempDir(False)) +
shortcutname + '.desktop';
}
// ExtractFileNameOnly(GetTempDir(False));
XdgDesktopFile := IncludeTrailingPathDelimiter(GetTempDir(False)) +
'test.desktop';
XdgDesktopContent := TStringList.Create;
try
XdgDesktopContent.Add('[Desktop Entry]');
XdgDesktopContent.Add('Encoding=UTF-8');
XdgDesktopContent.Add('Type=Application');
//XdgDesktopContent.Add('Nodisplay=True');
XdgDesktopContent.Add('Icon=' + IconFileName);
If TargetArguments <> '' then
XdgDesktopContent.Add('Exec=' + Target + ' ' + TargetArguments)
if TargetArguments <> '' then
XdgDesktopContent.Add('Exec=' + Target + ' ' + TargetArguments)
else
XdgDesktopContent.Add('Exec=' + Target);
XdgDesktopContent.Add('Exec=' + Target);
XdgDesktopContent.Add('Name=' + ShortcutName);
XdgDesktopContent.Add('Category=' + Category);
// We're going to try and call xdg-desktop-icon
@ -246,17 +257,29 @@ begin
AProcess := TProcess.Create(nil);
try
try
if FileExistsUTF8(XdgDesktopFile) then DeleteFile(XdgDesktopFile);
XdgDesktopContent.SaveToFile(XdgDesktopFile);
Sleep(100);
Aprocess.Executable := 'xdg-desktop-icon install';
AProcess.CurrentDirectory := ProgramDirectory;
AProcess.Parameters.Clear;
AProcess.Parameters.Add(XdgDesktopFile);
Aprocess.Execute;
Sleep(100);
if FileExistsUTF8(XdgDesktopFile) then
begin
Sleep(100);
Aprocess.Executable := 'xdg-desktop-icon install';
AProcess.CurrentDirectory := ProgramDirectory;
AProcess.Parameters.Clear;
AProcess.Parameters.Add(XdgDesktopFile);
Aprocess.Execute;
Sleep(100);
end
else
if FileExistsUTF8(sPathToShare) then DeleteFile(sPathToShare);
XdgDesktopContent.SaveToFile(sPathToShare);
If Not FileExistsUTF8(sPathToShare) then
begin
Result:=FALSE;
sErrorString := 'SaveToFile(' + sPathToShare + ') failed';
end;
except
Result := False;
sErrorString:='Exception running "xdg-desktop-icon install"';
sErrorString := 'Exception running "xdg-desktop-icon install"';
end;
finally
AProcess.Free;
@ -264,8 +287,16 @@ begin
if Result = False then
// Temp file is no longer needed....
try
If Not DeleteFile(XdgDesktopFile) then
sErrorString:='Unable to delete temporary ' + XdgDesktopFile;
If FileExistsUTF8(XdgDesktopFile) then
BEGIN
if CopyFile(XdgDesktopFile, sPathToShare) then
Result := True
else
sErrorString := Format('Unable to copy %s file to %s', [XdgDesktopFile, sPathToShare]);
if not DeleteFile(XdgDesktopFile) then
sErrorString := 'Unable to delete temporary ' + XdgDesktopFile;
end
else sErrorString := 'Unable to locate temporary ' + XdgDesktopFile;
finally
// Swallow, let filesystem maintenance clear it up
end;
@ -283,7 +314,7 @@ var
LinkName: WideString;
begin
Result := False;
sErrorString:='OK';
sErrorString := 'OK';
try
{ Get the desktop location }
SHGetSpecialFolderLocation(0, CSIDL_DESKTOPDIRECTORY, PIDL);
@ -292,7 +323,7 @@ begin
if SysUtils.DeleteFile(LinkName) then
Result := True;
except
sErrorString:='Exception deleting ' + LinkName;
sErrorString := 'Exception deleting ' + LinkName;
// Eat the exception
end;
end;
@ -300,7 +331,7 @@ end;
{$ELSE}
function DeleteDesktopShortcut(ShortcutName: string): boolean;
begin
sErrorString:='OK';
sErrorString := 'OK';
Result := False;
end;