Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(developer): handle invalid default project path in options 🍒 🏠 #11556

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion developer/src/tike/main/KeymanDeveloperOptions.pas
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ TKeymanDeveloperOptions = class
procedure optWriteBool(const nm: string; value: Boolean);
procedure optWriteInt(const nm: string; value: Integer);
procedure WriteServerConfigurationJson;
class function Default_DefaultProjectPath: string; static;
public
procedure Read;
procedure Write;
Expand Down Expand Up @@ -365,7 +366,12 @@ procedure TKeymanDeveloperOptions.Read;

FFix183_LadderLength := optReadInt(SRegValue_IDEOpt_WebLadderLength, CRegValue_IDEOpt_WebLadderLength_Default);

FDefaultProjectPath := IncludeTrailingPathDelimiter(optReadString(SRegValue_IDEOpt_DefaultProjectPath, GetFolderPath(CSIDL_PERSONAL) + CDefaultProjectPath));
FDefaultProjectPath := IncludeTrailingPathDelimiter(optReadString(SRegValue_IDEOpt_DefaultProjectPath, Default_DefaultProjectPath));
if (FDefaultProjectPath = '\') or IsRelativePath(FDefaultProjectPath) then
begin
// #11554
FDefaultProjectPath := Default_DefaultProjectPath;
end;

// for consistency with Keyman.System.KeymanSentryClient, we need to use
// reg.ReadInteger, as regReadInt, which in the dim dark past started
Expand Down Expand Up @@ -613,6 +619,11 @@ class function TKeymanDeveloperOptions.IsDefaultEditorTheme(s: string): Boolean;
Result := DefaultEditorThemeItemIndex(s) >= 0;
end;

class function TKeymanDeveloperOptions.Default_DefaultProjectPath: string;
begin
Result := GetFolderPath(CSIDL_PERSONAL) + CDefaultProjectPath;
end;

function LoadKeymanDeveloperSentryFlags: TKeymanSentryClientFlags;
begin
Result := [kscfCaptureExceptions, kscfShowUI, kscfTerminate];
Expand Down
21 changes: 16 additions & 5 deletions developer/src/tike/main/UfrmMain.pas
Original file line number Diff line number Diff line change
Expand Up @@ -552,11 +552,22 @@ procedure TfrmKeymanDeveloper.FormCreate(Sender: TObject);

FFilesToOpen := TStringList.Create;

if not ForceDirectories(FKeymanDeveloperOptions.DefaultProjectPath) then
begin
// Fall back to Documents folder if we cannot create the default project path
// Documents folder should always exist
FKeymanDeveloperOptions.DefaultProjectPath := GetFolderPath(CSIDL_PERSONAL);
try
if not ForceDirectories(FKeymanDeveloperOptions.DefaultProjectPath) then
begin
// Fall back to Documents folder if we cannot create the default project path
// Documents folder should always exist
FKeymanDeveloperOptions.DefaultProjectPath := GetFolderPath(CSIDL_PERSONAL);
end;
except
on E:EInOutError do
begin
// If the DefaultProjectPath is a relative, invalid path, then it may
// cause EInOutError (#11554). Note that this exception should no longer
// be possible because the path is sanitized when loaded in
// KeymanDeveloperOptions.pas, but keeping this fallback just in case.
FKeymanDeveloperOptions.DefaultProjectPath := GetFolderPath(CSIDL_PERSONAL);
end;
end;

FFirstShow := True;
Expand Down
Loading