Skip to content

Commit 8f2f7c2

Browse files
authored
476 creating a new project throws a permission denied error (#477)
This fixes #476. There were several places where the user could select a folder when Yafc was expecting a file, and the two are not interchangeable.
2 parents 6cf625d + 035064f commit 8f2f7c2

File tree

6 files changed

+24
-4
lines changed

6 files changed

+24
-4
lines changed

Yafc.UI/ImGui/ImGuiUtils.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ public static ButtonEvent BuildContextMenuButton(this ImGui gui, string text, st
147147
}
148148

149149
// null-forgiving: OnlyOnFaulted guarantees that Exception is non-null.
150-
public static void CaptureException(this Task task) => _ = task.ContinueWith(t => throw t.Exception!, TaskContinuationOptions.OnlyOnFaulted);
150+
public static void CaptureException(this Task task) =>
151+
_ = task.ContinueWith(t => Ui.DispatchInMainThread(_ => throw t.Exception!, null), TaskContinuationOptions.OnlyOnFaulted);
151152

152153
public static bool BuildMouseOverIcon(this ImGui gui, Icon icon, SchemeColor color = SchemeColor.BackgroundText) {
153154
if (gui.isBuilding && gui.IsMouseOver(gui.lastRect)) {

Yafc/Data/locale/en/yafc.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ override-font=Override font
439439
override-font-long=Override the font that YAFC uses
440440
load-project-name=Load '__1__'
441441
welcome-alert-missing-directory=Project directory does not exist
442+
welcome-alert-path-is-directory=Project location is a directory
442443
welcome-create-project-name=Create '__1__'
443444
welcome-create-unnamed-project=Create new project
444445
welcome-browse-button=...

Yafc/Windows/FilesystemScreen.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ protected override void BuildContents(ImGui gui) {
7070

7171
private void BuildSelectButton(ImGui gui) {
7272
if (gui.BuildButton(button, active: resultValid)) {
73+
OkClicked();
74+
}
75+
}
76+
77+
private void OkClicked() {
78+
if (mode is Mode.SelectFile or Mode.SelectOrCreateFile && Directory.Exists(selectedResult)) {
79+
SetLocation(selectedResult);
80+
}
81+
else {
7382
CloseWithResult(selectedResult);
7483
}
7584
}
@@ -177,7 +186,7 @@ private void BuildElement(ImGui gui, (EntryType type, string location) element,
177186

178187
public bool KeyDown(SDL.SDL_Keysym key) {
179188
if (key.sym is SDL.SDL_Keycode.SDLK_KP_ENTER or SDL.SDL_Keycode.SDLK_RETURN or SDL.SDL_Keycode.SDLK_RETURN2) {
180-
CloseWithResult(selectedResult);
189+
OkClicked();
181190
return true;
182191
}
183192
else if (key.sym == SDL.SDL_Keycode.SDLK_ESCAPE) {

Yafc/Windows/MainScreen.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -652,8 +652,11 @@ private async Task<bool> SaveProjectAs() {
652652

653653
private Task<bool> SaveProject() {
654654
if (!string.IsNullOrEmpty(project.attachedFileName)) {
655-
project.Save(project.attachedFileName);
656-
return Task.FromResult(true);
655+
try {
656+
project.Save(project.attachedFileName);
657+
return Task.FromResult(true);
658+
}
659+
catch (Exception) { /* Error saving. Fall back to save as */ }
657660
}
658661

659662
return SaveProjectAs();

Yafc/Windows/WelcomeScreen.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,11 @@ private void ValidateSelection() {
416416
canCreate = false;
417417
return;
418418
}
419+
else if (Directory.Exists(path)) {
420+
createText = LSs.WelcomeAlertPathIsDirectory;
421+
canCreate = false;
422+
return;
423+
}
419424
createText = LSs.WelcomeCreateProjectName.L(Path.GetFileNameWithoutExtension(path));
420425
}
421426
else {

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Date:
3030
- Improved precision for building count calculation.
3131
- Remove automatic catalyst amount calculations when loading Factorio 2.0 data.
3232
- Update documentation for changing the selected Factorio-object language.
33+
- Make it much harder for the user to select a folder when YAFC is expecting a file.
3334
----------------------------------------------------------------------------------------------------------------------
3435
Version: 2.11.1
3536
Date: April 5th 2025

0 commit comments

Comments
 (0)