diff --git a/Source/Editor/Editor.cpp b/Source/Editor/Editor.cpp index 58739917e..c08648505 100644 --- a/Source/Editor/Editor.cpp +++ b/Source/Editor/Editor.cpp @@ -526,6 +526,23 @@ 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); + if (!FileSystem::DirectoryExists(lastProjectPath)) + lastProjectPath = String::Empty; + + // Try to open the last project when requested + if (projectPath.IsEmpty() && CommandLine::Options.LastProject.IsTrue() && !lastProjectPath.IsEmpty()) + projectPath = lastProjectPath; + // Missing project case if (projectPath.IsEmpty()) { @@ -541,7 +558,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 +642,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; } 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) /// 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"); 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;