From 3afd3ce2d5cf6bbfaef36447d0746cce6e6b5ed9 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Wed, 17 Dec 2025 02:52:29 +0200 Subject: [PATCH 1/5] Use XDG user directories on Linux special paths --- .../Engine/Platform/Linux/LinuxFileSystem.cpp | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/Source/Engine/Platform/Linux/LinuxFileSystem.cpp b/Source/Engine/Platform/Linux/LinuxFileSystem.cpp index 9b31dc28f..4293985fa 100644 --- a/Source/Engine/Platform/Linux/LinuxFileSystem.cpp +++ b/Source/Engine/Platform/Linux/LinuxFileSystem.cpp @@ -338,17 +338,35 @@ void LinuxFileSystem::GetSpecialFolderPath(const SpecialFolder type, String& res switch (type) { case SpecialFolder::Desktop: - result = home / TEXT("Desktop"); + { + String desktopDir; + if (!Platform::GetEnvironmentVariable(TEXT("XDG_DESKTOP_DIR"), desktopDir)) + result = desktopDir; + else + result = home / TEXT("Desktop"); break; + } case SpecialFolder::Documents: result = String::Empty; break; case SpecialFolder::Pictures: - result = home / TEXT("Pictures"); + { + String picturesDir; + if (!Platform::GetEnvironmentVariable(TEXT("XDG_PICTURES_DIR"), picturesDir)) + result = picturesDir; + else + result = home / TEXT("Pictures"); break; + } case SpecialFolder::AppData: - result = TEXT("/usr/share"); + { + String configHome; + if (!Platform::GetEnvironmentVariable(TEXT("XDG_CONFIG_HOME"), configHome)) + result = configHome; + else + result = home / TEXT(".config"); break; + } case SpecialFolder::LocalAppData: { String dataHome; From 5d368e59a098d0ee5854426a97f5ee8514521edb Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Wed, 17 Dec 2025 03:19:58 +0200 Subject: [PATCH 2/5] Fix `SpecialFolder::AppData` on Apple systems --- Source/Engine/Platform/Apple/AppleFileSystem.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Source/Engine/Platform/Apple/AppleFileSystem.cpp b/Source/Engine/Platform/Apple/AppleFileSystem.cpp index 450507009..a38269d69 100644 --- a/Source/Engine/Platform/Apple/AppleFileSystem.cpp +++ b/Source/Engine/Platform/Apple/AppleFileSystem.cpp @@ -83,17 +83,19 @@ void AppleFileSystem::GetSpecialFolderPath(const SpecialFolder type, String& res switch (type) { case SpecialFolder::Desktop: - result = home / TEXT("/Desktop"); + result = home / TEXT("/Desktop"); // TODO: should be NSDesktopDirectory break; case SpecialFolder::Documents: - result = home / TEXT("/Documents"); + result = home / TEXT("/Documents"); // TODO: should be NSDocumentDirectory break; case SpecialFolder::Pictures: - result = home / TEXT("/Pictures"); + result = home / TEXT("/Pictures"); // TODO: should be NSPicturesDirectory break; case SpecialFolder::AppData: + result = home / TEXT("/Library/Application Support"); // TODO: should be NSApplicationSupportDirectory + break; case SpecialFolder::LocalAppData: - result = home / TEXT("/Library/Caches"); + result = home / TEXT("/Library/Caches"); // TODO: should be NSApplicationSupportDirectory break; case SpecialFolder::ProgramData: result = home / TEXT("/Library/Application Support"); From b3ea47b9896896ec998142407115444660d20b3d Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Wed, 17 Dec 2025 03:03:41 +0200 Subject: [PATCH 3/5] Use last opened project as initial directory in project file dialog --- Source/Editor/Editor.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Source/Editor/Editor.cpp b/Source/Editor/Editor.cpp index 58739917e..92c15f591 100644 --- a/Source/Editor/Editor.cpp +++ b/Source/Editor/Editor.cpp @@ -526,6 +526,17 @@ int32 Editor::LoadProduct() return 12; } + // Get the last opened project path + String localCachePath; + FileSystem::GetSpecialFolderPath(SpecialFolder::AppData, localCachePath); + String editorConfigPath = localCachePath / TEXT("Flax"); + String lastProjectSettingPath = editorConfigPath / TEXT("LastProject.txt"); + if (!FileSystem::DirectoryExists(editorConfigPath)) + FileSystem::CreateDirectory(editorConfigPath); + String lastProjectPath; + if (FileSystem::FileExists(lastProjectSettingPath)) + File::ReadAllText(lastProjectSettingPath, lastProjectPath); + // Missing project case if (projectPath.IsEmpty()) { @@ -541,7 +552,7 @@ int32 Editor::LoadProduct() Array files; if (FileSystem::ShowOpenFileDialog( nullptr, - StringView::Empty, + lastProjectPath, TEXT("Project files (*.flaxproj)\0*.flaxproj\0All files (*.*)\0*.*\0"), false, TEXT("Select project to open in Editor"), @@ -625,6 +636,10 @@ int32 Editor::LoadProduct() } } + // Update the last opened project path + if (lastProjectPath.Compare(Project->ProjectFolderPath) != 0) + File::WriteAllText(lastProjectSettingPath, Project->ProjectFolderPath, Encoding::UTF8); + return 0; } From 604bfb5fe6230d6b2c67787329e5020726237535 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Wed, 17 Dec 2025 03:29:43 +0200 Subject: [PATCH 4/5] Add `-lastproject` editor command-line option to open the last project --- Source/Editor/Editor.cpp | 7 +++++++ Source/Engine/Engine/CommandLine.cpp | 1 + Source/Engine/Engine/CommandLine.h | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/Source/Editor/Editor.cpp b/Source/Editor/Editor.cpp index 92c15f591..e82be1128 100644 --- a/Source/Editor/Editor.cpp +++ b/Source/Editor/Editor.cpp @@ -537,6 +537,13 @@ int32 Editor::LoadProduct() if (FileSystem::FileExists(lastProjectSettingPath)) File::ReadAllText(lastProjectSettingPath, lastProjectPath); + // Try to open the last project when requested + if (projectPath.IsEmpty() && CommandLine::Options.LastProject.IsTrue()) + { + if (!lastProjectPath.IsEmpty() && FileSystem::DirectoryExists(lastProjectPath)) + projectPath = lastProjectPath; + } + // Missing project case if (projectPath.IsEmpty()) { diff --git a/Source/Engine/Engine/CommandLine.cpp b/Source/Engine/Engine/CommandLine.cpp index e0f9441eb..ad2c9c903 100644 --- a/Source/Engine/Engine/CommandLine.cpp +++ b/Source/Engine/Engine/CommandLine.cpp @@ -149,6 +149,7 @@ bool CommandLine::Parse(const Char* cmdLine) PARSE_BOOL_SWITCH("-clearcache ", ClearCache); PARSE_BOOL_SWITCH("-clearcooker ", ClearCookerCache); PARSE_ARG_SWITCH("-project ", Project); + PARSE_BOOL_SWITCH("-lastproject ", LastProject); PARSE_BOOL_SWITCH("-new ", NewProject); PARSE_BOOL_SWITCH("-genprojectfiles ", GenProjectFiles); PARSE_ARG_SWITCH("-build ", Build); diff --git a/Source/Engine/Engine/CommandLine.h b/Source/Engine/Engine/CommandLine.h index ad49bee04..0464a478f 100644 --- a/Source/Engine/Engine/CommandLine.h +++ b/Source/Engine/Engine/CommandLine.h @@ -133,6 +133,11 @@ public: /// String Project; + /// + /// -lastproject (Opens the last project) + /// + Nullable LastProject; + /// /// -new (generates the project files inside the specified project folder or uses current workspace folder) /// From f6e9cf644ace20e13bc62d0df7bc7fe057c4822d Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Wed, 17 Dec 2025 03:45:08 +0200 Subject: [PATCH 5/5] Verify the last project path before using it --- Source/Editor/Editor.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Source/Editor/Editor.cpp b/Source/Editor/Editor.cpp index e82be1128..c08648505 100644 --- a/Source/Editor/Editor.cpp +++ b/Source/Editor/Editor.cpp @@ -536,13 +536,12 @@ int32 Editor::LoadProduct() String lastProjectPath; if (FileSystem::FileExists(lastProjectSettingPath)) File::ReadAllText(lastProjectSettingPath, lastProjectPath); + if (!FileSystem::DirectoryExists(lastProjectPath)) + lastProjectPath = String::Empty; // Try to open the last project when requested - if (projectPath.IsEmpty() && CommandLine::Options.LastProject.IsTrue()) - { - if (!lastProjectPath.IsEmpty() && FileSystem::DirectoryExists(lastProjectPath)) - projectPath = lastProjectPath; - } + if (projectPath.IsEmpty() && CommandLine::Options.LastProject.IsTrue() && !lastProjectPath.IsEmpty()) + projectPath = lastProjectPath; // Missing project case if (projectPath.IsEmpty())