Trap errors if Keyman Desktop is not installed when trying to install a keyboard

This commit is contained in:
Marc Durdin 2018-05-03 15:11:07 +07:00
parent c65501edaa
commit f0ef356b8f
2 changed files with 30 additions and 7 deletions

View file

@ -340,7 +340,12 @@ end;
function IsKeymanDesktopInstalled: Boolean;
begin
Result := FileExists(TKeymanPaths.KeymanDesktopInstallPath(TKeymanPaths.S_KMShell));
try
Result := FileExists(TKeymanPaths.KeymanDesktopInstallPath(TKeymanPaths.S_KMShell));
except
on E:EKeymanPath do
Result := False;
end;
end;
procedure InstallPackage(const nm: string; FCanInstallUnreg: Boolean);
@ -356,7 +361,16 @@ begin
Exit;
end;
kmshell := TKeymanPaths.KeymanDesktopInstallPath(TKeymanPaths.S_KMShell);
try
kmshell := TKeymanPaths.KeymanDesktopInstallPath(TKeymanPaths.S_KMShell);
except
on E:EKeymanPath do
begin
ShowMessage('Keyman Desktop is not installed. You must install Keyman Desktop to install this keyboard.');
Exit;
end;
end;
if TUtilExecute.WaitForProcess('"'+kmshell+'" -i "'+nm+'"', ExtractFilePath(nm)) = False then // I3475
ShowMessage('Failed to install package: '+errmsg);
@ -615,7 +629,12 @@ end;
function GetKMShellPath(var ps: string): Boolean; // I3655
begin
ps := TKeymanPaths.KeymanDesktopInstallPath(TKeymanPaths.S_KMShell);
try
ps := TKeymanPaths.KeymanDesktopInstallPath(TKeymanPaths.S_KMShell);
except
on E:EKeymanPath do
Exit(False);
end;
Result := FileExists(ps);
end;

View file

@ -2,7 +2,12 @@ unit KeymanPaths;
interface
uses
System.SysUtils;
type
EKeymanPath = class(Exception);
TKeymanPaths = class
public
const S_KMShell = 'kmshell.exe';
@ -28,7 +33,6 @@ uses
Winapi.Windows,
Winapi.ActiveX,
Winapi.ShlObj,
System.SysUtils,
System.Win.Registry,
DebugPaths,
@ -90,7 +94,7 @@ begin
Result := GetDebugPath('KeymanDesktop', Result);
if Result = '' then
raise Exception.Create('Unable to find the Keyman Desktop directory. You should reinstall the product.');
raise EKeymanPath.Create('Unable to find the Keyman Desktop directory. You should reinstall the product.');
Result := IncludeTrailingPathDelimiter(Result) + filename;
end;
@ -114,7 +118,7 @@ begin
Result := GetDebugPath('KeymanEngine', Result);
if Result = '' then
raise Exception.Create('Unable to find the Keyman Engine directory. You should reinstall the product.');
raise EKeymanPath.Create('Unable to find the Keyman Engine directory. You should reinstall the product.');
Result := IncludeTrailingPathDelimiter(Result) + filename;
end;
@ -147,7 +151,7 @@ begin
Result := GetDebugPath('Keyboards', Result, True);
if Result = '' then
raise Exception.Create('Unable to find the Keyboards directory. You should reinstall the product.');
raise EKeymanPath.Create('Unable to find the Keyboards directory. You should reinstall the product.');
Result := Result + Filename;
end;