From 1885f1a853d095c9d5957f3a8ad191b2bb89279e Mon Sep 17 00:00:00 2001 From: emerycp Date: Fri, 7 Jul 2023 18:24:55 -0400 Subject: [PATCH 1/3] Creating New Project doesn't add .project --- Editor/src/Windows/EditorInterface.cpp | 14 +++++++++----- Editor/src/Windows/WelcomeWindow.cpp | 15 +++++++++------ Nuake/src/Resource/Project.cpp | 6 ++++++ Nuake/src/Resource/Project.h | 1 + 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/Editor/src/Windows/EditorInterface.cpp b/Editor/src/Windows/EditorInterface.cpp index 871ceab8..ef0db267 100644 --- a/Editor/src/Windows/EditorInterface.cpp +++ b/Editor/src/Windows/EditorInterface.cpp @@ -1248,14 +1248,18 @@ namespace Nuake { void NewProject() { - if (Engine::GetProject()) + if (Engine::GetProject() && Engine::GetProject()->Exist()) Engine::GetProject()->Save(); - + std::string selectedProject = FileDialog::SaveFile("Project file\0*.project"); - if (selectedProject == "") // Hit cancel + + if(!String::EndsWith(selectedProject, ".project")) + selectedProject += ".project"; + + if (selectedProject.empty()) // Hit cancel return; - - Ref project = Project::New("Unnamed project", "no description", selectedProject + ".project"); + + Ref project = Project::New("Unnamed project", "no description", selectedProject); Engine::LoadProject(project); Engine::LoadScene(Scene::New()); } diff --git a/Editor/src/Windows/WelcomeWindow.cpp b/Editor/src/Windows/WelcomeWindow.cpp index bab529cd..58763ffe 100644 --- a/Editor/src/Windows/WelcomeWindow.cpp +++ b/Editor/src/Windows/WelcomeWindow.cpp @@ -166,28 +166,31 @@ namespace Nuake if (ImGui::Button("New Project", buttonSize)) { std::string selectedProject = FileDialog::SaveFile("Project file\0*.project"); - + if (!selectedProject.empty()) { + if(!String::EndsWith(selectedProject, ".project")) + selectedProject += ".project"; + auto backslashSplits = String::Split(selectedProject, '\\'); auto fileName = backslashSplits[backslashSplits.size() - 1]; - std::string finalPath = selectedProject; + std::string finalPath = String::Split(selectedProject, '.')[0]; if (String::EndsWith(fileName, ".project")) { // We need to create a folder - if (const auto& dirPath = selectedProject; - std::filesystem::create_directory(dirPath)) + if (const auto& dirPath = finalPath; + !std::filesystem::create_directory(dirPath)) { // Should we continue? Logger::Log("Failed creating project directory: " + dirPath); } - finalPath += "\\" + fileName + ".project"; + finalPath += "\\" + fileName; } - auto project = Project::New(fileName, "no description", finalPath); + auto project = Project::New(String::Split(fileName, '.')[0], "no description", finalPath); Engine::LoadProject(project); Engine::LoadScene(Scene::New()); project->Save(); diff --git a/Nuake/src/Resource/Project.cpp b/Nuake/src/Resource/Project.cpp index 8cefc2f8..79f5fd5d 100644 --- a/Nuake/src/Resource/Project.cpp +++ b/Nuake/src/Resource/Project.cpp @@ -53,6 +53,12 @@ namespace Nuake projectFile.close(); } + bool Project::Exist() + { + struct stat buffer{}; + return (stat (this->FullPath.c_str(), &buffer) == 0); + } + Ref Project::New(const std::string& Name, const std::string& Description, const std::string& FullPath) { return CreateRef(Name, Description, FullPath); diff --git a/Nuake/src/Resource/Project.h b/Nuake/src/Resource/Project.h index da025243..e35a568c 100644 --- a/Nuake/src/Resource/Project.h +++ b/Nuake/src/Resource/Project.h @@ -26,6 +26,7 @@ namespace Nuake void Save(); void SaveAs(const std::string& FullPath); + bool Exist(); static Ref New(const std::string& Name, const std::string& Description, const std::string& FullPath); static Ref New(); From 6b4d0c0f695e777136ff3036ac6237b5eed1934d Mon Sep 17 00:00:00 2001 From: emerycp Date: Fri, 7 Jul 2023 18:33:29 -0400 Subject: [PATCH 2/3] Renamed Exist method to FileExist --- Editor/src/Windows/EditorInterface.cpp | 2 +- Nuake/src/Resource/Project.cpp | 2 +- Nuake/src/Resource/Project.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Editor/src/Windows/EditorInterface.cpp b/Editor/src/Windows/EditorInterface.cpp index ef0db267..5379053c 100644 --- a/Editor/src/Windows/EditorInterface.cpp +++ b/Editor/src/Windows/EditorInterface.cpp @@ -1248,7 +1248,7 @@ namespace Nuake { void NewProject() { - if (Engine::GetProject() && Engine::GetProject()->Exist()) + if (Engine::GetProject() && Engine::GetProject()->FileExist()) Engine::GetProject()->Save(); std::string selectedProject = FileDialog::SaveFile("Project file\0*.project"); diff --git a/Nuake/src/Resource/Project.cpp b/Nuake/src/Resource/Project.cpp index 79f5fd5d..c1294a12 100644 --- a/Nuake/src/Resource/Project.cpp +++ b/Nuake/src/Resource/Project.cpp @@ -53,7 +53,7 @@ namespace Nuake projectFile.close(); } - bool Project::Exist() + bool Project::FileExist() { struct stat buffer{}; return (stat (this->FullPath.c_str(), &buffer) == 0); diff --git a/Nuake/src/Resource/Project.h b/Nuake/src/Resource/Project.h index e35a568c..ee3fb232 100644 --- a/Nuake/src/Resource/Project.h +++ b/Nuake/src/Resource/Project.h @@ -26,7 +26,7 @@ namespace Nuake void Save(); void SaveAs(const std::string& FullPath); - bool Exist(); + bool FileExist(); static Ref New(const std::string& Name, const std::string& Description, const std::string& FullPath); static Ref New(); From 97f931fa04135a062983ffc1570ed18610f1b404 Mon Sep 17 00:00:00 2001 From: emerycp Date: Fri, 7 Jul 2023 18:59:50 -0400 Subject: [PATCH 3/3] Changed file verification from stat to FileStream::exists --- Nuake/src/Resource/Project.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Nuake/src/Resource/Project.cpp b/Nuake/src/Resource/Project.cpp index c1294a12..78c0b8f3 100644 --- a/Nuake/src/Resource/Project.cpp +++ b/Nuake/src/Resource/Project.cpp @@ -55,8 +55,7 @@ namespace Nuake bool Project::FileExist() { - struct stat buffer{}; - return (stat (this->FullPath.c_str(), &buffer) == 0); + return std::filesystem::exists(this->FullPath.c_str()); } Ref Project::New(const std::string& Name, const std::string& Description, const std::string& FullPath)