Skip to content

Commit

Permalink
fix windows file link problem with drive letter
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbannon committed Apr 19, 2024
1 parent d888d76 commit 7f7abbe
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 36 deletions.
29 changes: 21 additions & 8 deletions source/editbox.pas
Original file line number Diff line number Diff line change
Expand Up @@ -2733,7 +2733,11 @@ function TEditBoxForm.BuildFileLink(ItsFile : Boolean; CharNo: integer = 0): boo
result := True;
if CharNo = 0 then
CharNo := Kmemo1.RealSelStart;
{$ifdef WINDOWS} // ToDo : make this a property from settings, we call it from all over the place
HomeDir := GetEnvironmentVariableUTF8('HOME');
{$else}
HomeDir := GetEnvironmentVariableUTF8('HOMEPATH');
{$endif}
if ItsFile then begin // its either File or Directory
OpenDialogFileLink.InitialDir := HomeDir;
if not OpenDialogFileLink.Execute then
Expand Down Expand Up @@ -2804,7 +2808,7 @@ function TEditBoxForm.OpenFileLink(LinkText : string) : boolean;
LinkText := LinkText.Remove(0, 1); // Lazarus code will re-wrap the text later in process
i := LinkText.IndexOf('"', 0); // Must have a second "
if i = -1 then begin
showmessage('Badly formed link : ' + LinkText);
showmessage('Badly formed link : '#10 + LinkText);
exit;
end;
LinkText := LinkText.Remove(i, 99); // remove second " and anything after it too
Expand All @@ -2813,25 +2817,34 @@ function TEditBoxForm.OpenFileLink(LinkText : string) : boolean;
showmessage('Empty Link');
exit;
end;
if not (LinkText[1] in ['\', '/']) then // Relative path if first char after token is not a slash
if not (LinkText[1] in ['\', '/']) then begin // Relative path if first char after token is not a slash
{$ifdef WINDOWS} // it might still be an absolute path, starts with eg c:\ ?
if (length(LinkText) < 4) // too short
or (LinkText[2] <> ':') then // not a drive specifier, not much of a test but its windows !
LinkText := appendPathDelim(GetEnvironmentVariableUTF8('HOMEPATH')) + LinkText;
{$else}
LinkText := appendPathDelim(GetEnvironmentVariableUTF8('HOME')) + LinkText;
{$endif}
end;
if not (FileExists(LinkText) or DirectoryExists(LinkText)) then begin
showmessage('File does not exist : ' + LinkText);
end else begin
showmessage('File does not exist : '#10 + LinkText);
exit;
end;

{$ifdef WINDOWS}
// 'Executable on Windows is a dogs breakfast. https://forum.lazarus.freepascal.org/index.php/topic,24615.0.html
// 'Executable' on Windows is a dogs breakfast. https://forum.lazarus.freepascal.org/index.php/topic,24615.0.html
if WindowsFileIsExecutable() then begin
{$else}
if FileIsExecutable(LinkText) then begin
{$endif}
{$endif}
Msg := 'Link is an executable file.';
if IDYES <> Application.MessageBox('Open an executable ?'
,pchar(Msg) , MB_ICONQUESTION + MB_YESNO) then
exit;
end;
if not OpenDocument(LinkText) then
showmessage('Sorry, cannot open ' + LinkText);
end;
showmessage('Sorry, cannot open '#10 + LinkText);

end;

// ToDo : look at issues below, #2 particulary important, no error if OS cannot open link
Expand Down
4 changes: 2 additions & 2 deletions source/savenote.pas
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
vastly better xml.
2021/11/04 SaveNewTemplate now gets a current date stamp.
2024/01/23 Added support for Indent
2024/04/14 Stop underline appearing with text from a hyperlink block, evualate !
2024/04/14 Stop underline appearing with text from a hyperlink block
}

{$mode objfpc}{$H+}
Expand Down Expand Up @@ -576,7 +576,7 @@ procedure TBSaveNote.ReadKMemo(FileName : ANSIString; Title : string; KM1 : TKMe
BlockNo : integer = 0;
Block : TKMemoBlock;
NextBlock : integer;
ExistingUnderline : boolean = false;
//ExistingUnderline : boolean = false;
begin
KM := KM1;
FSize := Sett.FontNormal;
Expand Down
26 changes: 0 additions & 26 deletions source/settings.pas
Original file line number Diff line number Diff line change
Expand Up @@ -926,32 +926,6 @@ function TSett.CheckDirectory(DirPath : string) : boolean;
DebugLn('Settings cannot write into [' + DirPath + ']');
end;

(* // This has been moved to TB_Utils
function TSett.GetDefaultConfigDir : string;
begin
Result := '';
if Application.HasOption('config-dir') then
Result := Application.GetOptionValue('config-dir');
if Result = '' then begin
{$ifdef DARWIN}
// First we try the right place, if there use it, else try unix place, if
// its not there, go back to right place.
Result := GetEnvironmentVariable('HOME') + '/Library/Application Support/Tomboy-ng/Config';
if not DirectoryExistsUTF8(Result) then begin
Result := GetAppConfigDirUTF8(False);
if not DirectoryExistsUTF8(Result) then // must be new install, put in right place
Result := GetEnvironmentVariable('HOME') + '/Library/Application Support/Tomboy-ng/Config';
end;
{$else}
Result := GetAppConfigDirUTF8(False);
{$endif}
end;
Result := AppendPathDelim(Result);
{$ifndef DARWIN}
// MainForm.SetAltHelpPath(Result); // English help notes in read only space
{$endif}
end; *)

function TSett.GetFixedFont() : string;
var T : string;
FontNames : array[1..9] of string
Expand Down

0 comments on commit 7f7abbe

Please sign in to comment.