mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-15 20:08:54 +03:00
Creating New Project doesn't add .project
This commit is contained in:
@@ -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 = Project::New("Unnamed project", "no description", selectedProject + ".project");
|
||||
|
||||
Ref<Project> project = Project::New("Unnamed project", "no description", selectedProject);
|
||||
Engine::LoadProject(project);
|
||||
Engine::LoadScene(Scene::New());
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -53,6 +53,12 @@ namespace Nuake
|
||||
projectFile.close();
|
||||
}
|
||||
|
||||
bool Project::Exist()
|
||||
{
|
||||
struct stat buffer{};
|
||||
return (stat (this->FullPath.c_str(), &buffer) == 0);
|
||||
}
|
||||
|
||||
Ref<Project> Project::New(const std::string& Name, const std::string& Description, const std::string& FullPath)
|
||||
{
|
||||
return CreateRef<Project>(Name, Description, FullPath);
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace Nuake
|
||||
|
||||
void Save();
|
||||
void SaveAs(const std::string& FullPath);
|
||||
bool Exist();
|
||||
|
||||
static Ref<Project> New(const std::string& Name, const std::string& Description, const std::string& FullPath);
|
||||
static Ref<Project> New();
|
||||
|
||||
Reference in New Issue
Block a user