mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-15 20:08:54 +03:00
Moved FileDialog into its own class
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
#include "Commands.h"
|
||||
|
||||
#include <Engine.h>
|
||||
|
||||
#include "src/FileSystem/FileSystem.h"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
namespace NuakeEditor
|
||||
{
|
||||
bool SaveSceneCommand::Execute()
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
#include "MaterialEditor.h"
|
||||
#include <imgui/imgui.h>
|
||||
#include <src/Resource/FontAwesome5.h>
|
||||
#include <src/Vendors/imgui/imgui_internal.h>
|
||||
#include "../Misc/InterfaceFonts.h"
|
||||
#include <src/Resource/FontAwesome5.h>
|
||||
#include <src/Resource/ResourceManager.h>
|
||||
#include <src/FileSystem/FileDialog.h>
|
||||
|
||||
#include <imgui/imgui.h>
|
||||
#include <src/Vendors/imgui/imgui_internal.h>
|
||||
|
||||
|
||||
void MaterialEditor::Draw(Ref<Nuake::Material> material)
|
||||
{
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
#include "NetScriptPanel.h"
|
||||
|
||||
#include "../Windows/FileSystemUI.h"
|
||||
#include <src/Scene/Components/NetScriptComponent.h>
|
||||
|
||||
#include <src/FileSystem/FileDialog.h>
|
||||
#include "src/FileSystem/FileSystem.h"
|
||||
#include <src/Scripting/ScriptingEngineNet.h>
|
||||
#include <src/Scene/Components/NetScriptComponent.h>
|
||||
#include <src/Scene/Entities/ImGuiHelper.h>
|
||||
|
||||
|
||||
void NetScriptPanel::Draw(Nuake::Entity entity)
|
||||
{
|
||||
if (!entity.HasComponent<Nuake::NetScriptComponent>())
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "ScriptPanel.h"
|
||||
#include "../Windows/FileSystemUI.h"
|
||||
#include <src/Scene/Components/WrenScriptComponent.h>
|
||||
#include "src/FileSystem/FileDialog.h"
|
||||
#include "src/FileSystem/FileSystem.h"
|
||||
|
||||
void ScriptPanel::Draw(Nuake::Entity entity)
|
||||
|
||||
@@ -53,6 +53,9 @@
|
||||
#include <src/Resource/ModelLoader.h>
|
||||
#include "../ScriptingContext/ScriptingContext.h"
|
||||
#include <src/Scene/Components/BSPBrushComponent.h>
|
||||
|
||||
#include <src/FileSystem/FileDialog.h>
|
||||
|
||||
#include <Tracy.hpp>
|
||||
|
||||
namespace Nuake {
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <src/Resource/ResourceLoader.h>
|
||||
#include <src/Resource/FontAwesome5.h>
|
||||
#include <src/Scripting/WrenScript.h>
|
||||
#include <src/FileSystem/FileDialog.h>
|
||||
|
||||
#include <Engine.h>
|
||||
#include <src/Resource/Prefab.h>
|
||||
|
||||
@@ -12,9 +12,10 @@
|
||||
|
||||
#include <src/Rendering/Textures/Material.h>
|
||||
#include "../Misc/PopupHelper.h"
|
||||
|
||||
#include <src/FileSystem/FileDialog.h>
|
||||
#include "src/Scene/Systems/WadConverter.h"
|
||||
#include "../Misc/ThumbnailManager.h"
|
||||
|
||||
#include <Tracy.hpp>
|
||||
|
||||
namespace Nuake
|
||||
|
||||
@@ -7,11 +7,16 @@
|
||||
#include <src/FileSystem/File.h>
|
||||
#include <src/Threading/JobSystem.h>
|
||||
#include <src/UI/ImUI.h>
|
||||
#include <src/FileSystem/FileDialog.h>
|
||||
|
||||
#include <imgui/imgui.h>
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <regex>
|
||||
|
||||
|
||||
void MapImporterWindow::Draw()
|
||||
{
|
||||
auto& io = ImGui::GetIO();
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <src/Rendering/Textures/TextureManager.h>
|
||||
#include <src/Rendering/Textures/Texture.h>
|
||||
#include <src/Scene/Entities/ImGuiHelper.h>
|
||||
#include <src/FileSystem/FileDialog.h>
|
||||
#include "src/FileSystem/FileSystem.h"
|
||||
#include <src/UI/ImUI.h>
|
||||
#include <src/Core/Logger.h>
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
#include "ProjectInterface.h"
|
||||
#include <src/Vendors/imgui/imgui.h>
|
||||
|
||||
#include "Engine.h"
|
||||
#include <src/FileSystem/FileDialog.h>
|
||||
#include "src/FileSystem/FileSystem.h"
|
||||
#include <src/Scripting/ScriptingEngineNet.h>
|
||||
#include <src/Scripting/ScriptingEngineNet.h>
|
||||
|
||||
#include <src/Vendors/imgui/imgui.h>
|
||||
//#include "ImGuiTextHelper.h"
|
||||
|
||||
namespace Nuake {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "ProjectSettingsWindow.h"
|
||||
#include <imgui/imgui.h>
|
||||
#include "../../Misc/InterfaceFonts.h"
|
||||
#include <src/FileSystem/FileDialog.h>
|
||||
#include "src/FileSystem/FileSystem.h"
|
||||
#include "../EditorInterface.h"
|
||||
#include "../../Commands/Commands/Commands.h"
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "../Misc/InterfaceFonts.h"
|
||||
|
||||
#include <Engine.h>
|
||||
#include <src/FileSystem/FileDialog.h>
|
||||
#include "src/FileSystem/FileSystem.h"
|
||||
#include <src/Resource/Project.h>
|
||||
#include <src/Core/Logger.h>
|
||||
|
||||
@@ -22,11 +22,12 @@
|
||||
|
||||
#include "GLFW/glfw3.h"
|
||||
#include "GLFW/glfw3native.h"
|
||||
#include "imgui/imgui.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <imgui/imgui.h>
|
||||
#include <Subprocess.hpp>
|
||||
#include <codecvt>
|
||||
#include <filesystem>
|
||||
#include <Subprocess.hpp>
|
||||
|
||||
namespace Nuake {
|
||||
|
||||
|
||||
189
Nuake/src/FileSystem/FileDialog.cpp
Normal file
189
Nuake/src/FileSystem/FileDialog.cpp
Normal file
@@ -0,0 +1,189 @@
|
||||
#include "FileDialog.h"
|
||||
|
||||
#include "Engine.h"
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
// Platform specific stuff
|
||||
// Windows
|
||||
#ifdef NK_WIN
|
||||
#define GLFW_EXPOSE_NATIVE_WIN32
|
||||
#include "GLFW/glfw3native.h"
|
||||
#include <commdlg.h>
|
||||
#include <ShlObj.h>
|
||||
#endif
|
||||
|
||||
// Linux
|
||||
#ifdef NK_LINUX
|
||||
#include "gtk/gtk.h"
|
||||
#endif
|
||||
|
||||
|
||||
using namespace Nuake;
|
||||
|
||||
std::string FileDialog::OpenFile(const std::string_view& filter)
|
||||
{
|
||||
std::string filePath;
|
||||
#ifdef NK_WIN
|
||||
OPENFILENAMEA ofn;
|
||||
CHAR szFile[260] = { 0 };
|
||||
ZeroMemory(&ofn, sizeof(OPENFILENAME));
|
||||
ofn.lStructSize = sizeof(OPENFILENAME);
|
||||
ofn.hwndOwner = glfwGetWin32Window(Engine::GetCurrentWindow()->GetHandle());
|
||||
ofn.lpstrFile = szFile;
|
||||
ofn.nMaxFile = sizeof(szFile);
|
||||
ofn.lpstrFilter = filter.data();
|
||||
ofn.nFilterIndex = 1;
|
||||
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
|
||||
if (GetOpenFileNameA(&ofn) == TRUE)
|
||||
{
|
||||
filePath = std::string(ofn.lpstrFile);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef NK_LINUX
|
||||
GtkWidget *dialog;
|
||||
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
|
||||
gint res;
|
||||
|
||||
dialog = gtk_file_chooser_dialog_new("Open File",
|
||||
NULL,
|
||||
action,
|
||||
"_Cancel",
|
||||
GTK_RESPONSE_CANCEL,
|
||||
"_Open",
|
||||
GTK_RESPONSE_ACCEPT,
|
||||
NULL);
|
||||
|
||||
gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);
|
||||
|
||||
if (filter) {
|
||||
GtkFileFilter *file_filter = gtk_file_filter_new();
|
||||
gtk_file_filter_set_name(file_filter, "Filter Name");
|
||||
gtk_file_filter_add_pattern(file_filter, filter);
|
||||
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), file_filter);
|
||||
}
|
||||
|
||||
res = gtk_dialog_run(GTK_DIALOG(dialog));
|
||||
|
||||
if (res == GTK_RESPONSE_ACCEPT) {
|
||||
char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
|
||||
filePath = filename;
|
||||
g_free(filename);
|
||||
}
|
||||
|
||||
gtk_widget_destroy(dialog);
|
||||
#endif
|
||||
return filePath;
|
||||
}
|
||||
|
||||
std::string FileDialog::SaveFile(const std::string_view& filter)
|
||||
{
|
||||
#ifdef NK_WIN
|
||||
OPENFILENAMEA ofn;
|
||||
CHAR szFile[260] = { 0 };
|
||||
ZeroMemory(&ofn, sizeof(OPENFILENAME));
|
||||
ofn.lStructSize = sizeof(OPENFILENAME);
|
||||
ofn.hwndOwner = glfwGetWin32Window(Engine::GetCurrentWindow()->GetHandle());
|
||||
ofn.lpstrFile = szFile;
|
||||
ofn.nMaxFile = sizeof(szFile);
|
||||
ofn.lpstrFilter = filter.data();
|
||||
ofn.nFilterIndex = 1;
|
||||
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_OVERWRITEPROMPT;
|
||||
if (GetSaveFileNameA(&ofn) == TRUE)
|
||||
{
|
||||
return ofn.lpstrFile;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef NK_LINUX
|
||||
GtkWidget *dialog;
|
||||
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SAVE;
|
||||
gint res;
|
||||
|
||||
gtk_init(NULL, NULL);
|
||||
|
||||
dialog = gtk_file_chooser_dialog_new("Save File",
|
||||
NULL,
|
||||
action,
|
||||
"_Cancel",
|
||||
GTK_RESPONSE_CANCEL,
|
||||
"_Save",
|
||||
GTK_RESPONSE_ACCEPT,
|
||||
NULL);
|
||||
|
||||
GtkFileFilter *file_filter = gtk_file_filter_new();
|
||||
gtk_file_filter_set_name(file_filter, filter);
|
||||
gtk_file_filter_add_pattern(file_filter, "*.*"); // You can customize this pattern
|
||||
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), file_filter);
|
||||
|
||||
res = gtk_dialog_run(GTK_DIALOG(dialog));
|
||||
if (res == GTK_RESPONSE_ACCEPT)
|
||||
{
|
||||
char *filename;
|
||||
GtkFileChooser *chooser = GTK_FILE_CHOOSER(dialog);
|
||||
filename = gtk_file_chooser_get_filename(chooser);
|
||||
std::string result(filename);
|
||||
g_free(filename);
|
||||
gtk_widget_destroy(dialog);
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_widget_destroy(dialog);
|
||||
return std::string();
|
||||
}
|
||||
#endif
|
||||
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::string FileDialog::OpenFolder()
|
||||
{
|
||||
std::string folderPath;
|
||||
|
||||
#ifdef NK_WIN
|
||||
BROWSEINFOA bi;
|
||||
CHAR szFolder[260] = { 0 };
|
||||
ZeroMemory(&bi, sizeof(BROWSEINFO));
|
||||
bi.lpszTitle = "Select a Folder";
|
||||
bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
|
||||
bi.hwndOwner = glfwGetWin32Window(Engine::GetCurrentWindow()->GetHandle());
|
||||
bi.pszDisplayName = szFolder;
|
||||
LPITEMIDLIST pidl = SHBrowseForFolderA(&bi);
|
||||
if (pidl != NULL)
|
||||
{
|
||||
SHGetPathFromIDListA(pidl, szFolder);
|
||||
folderPath = std::string(szFolder);
|
||||
CoTaskMemFree(pidl);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef NK_LINUX
|
||||
GtkWidget* dialog;
|
||||
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
|
||||
gint res;
|
||||
|
||||
dialog = gtk_file_chooser_dialog_new("Select Folder",
|
||||
NULL,
|
||||
action,
|
||||
"_Cancel",
|
||||
GTK_RESPONSE_CANCEL,
|
||||
"_Select",
|
||||
GTK_RESPONSE_ACCEPT,
|
||||
NULL);
|
||||
|
||||
res = gtk_dialog_run(GTK_DIALOG(dialog));
|
||||
|
||||
if (res == GTK_RESPONSE_ACCEPT) {
|
||||
char* foldername = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
|
||||
folderPath = foldername;
|
||||
g_free(foldername);
|
||||
}
|
||||
|
||||
gtk_widget_destroy(dialog);
|
||||
#endif
|
||||
|
||||
return folderPath;
|
||||
}
|
||||
14
Nuake/src/FileSystem/FileDialog.h
Normal file
14
Nuake/src/FileSystem/FileDialog.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
#include "src/Core/Core.h"
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
class FileDialog
|
||||
{
|
||||
public:
|
||||
static std::string OpenFile(const std::string_view& filter);
|
||||
static std::string SaveFile(const std::string_view& filter);
|
||||
|
||||
static std::string OpenFolder();
|
||||
};
|
||||
}
|
||||
@@ -3,437 +3,250 @@
|
||||
#include "Engine.h"
|
||||
#include "src/Core/OS.h"
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#ifdef NK_WIN
|
||||
#define GLFW_EXPOSE_NATIVE_WIN32
|
||||
|
||||
#include "GLFW/glfw3native.h"
|
||||
#include <commdlg.h>
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef NK_LINUX
|
||||
#include "gtk/gtk.h"
|
||||
#endif
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <ShlObj.h>
|
||||
#include "filewatch/FileWatch.hpp"
|
||||
|
||||
#include "Directory.h"
|
||||
#include "File.h"
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
namespace fs = std::filesystem;
|
||||
#include "filewatch/FileWatch.hpp"
|
||||
|
||||
std::string FileDialog::OpenFile(const char* filter)
|
||||
{
|
||||
std::string filePath;
|
||||
#ifdef NK_WIN
|
||||
OPENFILENAMEA ofn;
|
||||
CHAR szFile[260] = { 0 };
|
||||
ZeroMemory(&ofn, sizeof(OPENFILENAME));
|
||||
ofn.lStructSize = sizeof(OPENFILENAME);
|
||||
ofn.hwndOwner = glfwGetWin32Window(Engine::GetCurrentWindow()->GetHandle());
|
||||
ofn.lpstrFile = szFile;
|
||||
ofn.nMaxFile = sizeof(szFile);
|
||||
ofn.lpstrFilter = filter;
|
||||
ofn.nFilterIndex = 1;
|
||||
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
|
||||
if (GetOpenFileNameA(&ofn) == TRUE)
|
||||
{
|
||||
filePath = std::string(ofn.lpstrFile);
|
||||
}
|
||||
#include <filesystem>
|
||||
|
||||
#endif
|
||||
using namespace Nuake;
|
||||
|
||||
#ifdef NK_LINUX
|
||||
GtkWidget *dialog;
|
||||
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
|
||||
gint res;
|
||||
|
||||
dialog = gtk_file_chooser_dialog_new("Open File",
|
||||
NULL,
|
||||
action,
|
||||
"_Cancel",
|
||||
GTK_RESPONSE_CANCEL,
|
||||
"_Open",
|
||||
GTK_RESPONSE_ACCEPT,
|
||||
NULL);
|
||||
|
||||
gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);
|
||||
|
||||
if (filter) {
|
||||
GtkFileFilter *file_filter = gtk_file_filter_new();
|
||||
gtk_file_filter_set_name(file_filter, "Filter Name");
|
||||
gtk_file_filter_add_pattern(file_filter, filter);
|
||||
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), file_filter);
|
||||
}
|
||||
|
||||
res = gtk_dialog_run(GTK_DIALOG(dialog));
|
||||
|
||||
if (res == GTK_RESPONSE_ACCEPT) {
|
||||
char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
|
||||
filePath = filename;
|
||||
g_free(filename);
|
||||
}
|
||||
|
||||
gtk_widget_destroy(dialog);
|
||||
#endif
|
||||
return filePath;
|
||||
}
|
||||
|
||||
std::string FileDialog::SaveFile(const char* filter)
|
||||
{
|
||||
#ifdef NK_WIN
|
||||
OPENFILENAMEA ofn;
|
||||
CHAR szFile[260] = { 0 };
|
||||
ZeroMemory(&ofn, sizeof(OPENFILENAME));
|
||||
ofn.lStructSize = sizeof(OPENFILENAME);
|
||||
ofn.hwndOwner = glfwGetWin32Window(Engine::GetCurrentWindow()->GetHandle());
|
||||
ofn.lpstrFile = szFile;
|
||||
ofn.nMaxFile = sizeof(szFile);
|
||||
ofn.lpstrFilter = filter;
|
||||
ofn.nFilterIndex = 1;
|
||||
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_OVERWRITEPROMPT;
|
||||
if (GetSaveFileNameA(&ofn) == TRUE)
|
||||
{
|
||||
return ofn.lpstrFile;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef NK_LINUX
|
||||
GtkWidget *dialog;
|
||||
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SAVE;
|
||||
gint res;
|
||||
|
||||
gtk_init(NULL, NULL);
|
||||
|
||||
dialog = gtk_file_chooser_dialog_new("Save File",
|
||||
NULL,
|
||||
action,
|
||||
"_Cancel",
|
||||
GTK_RESPONSE_CANCEL,
|
||||
"_Save",
|
||||
GTK_RESPONSE_ACCEPT,
|
||||
NULL);
|
||||
|
||||
GtkFileFilter *file_filter = gtk_file_filter_new();
|
||||
gtk_file_filter_set_name(file_filter, filter);
|
||||
gtk_file_filter_add_pattern(file_filter, "*.*"); // You can customize this pattern
|
||||
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), file_filter);
|
||||
|
||||
res = gtk_dialog_run(GTK_DIALOG(dialog));
|
||||
if (res == GTK_RESPONSE_ACCEPT)
|
||||
{
|
||||
char *filename;
|
||||
GtkFileChooser *chooser = GTK_FILE_CHOOSER(dialog);
|
||||
filename = gtk_file_chooser_get_filename(chooser);
|
||||
std::string result(filename);
|
||||
g_free(filename);
|
||||
gtk_widget_destroy(dialog);
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_widget_destroy(dialog);
|
||||
return std::string();
|
||||
}
|
||||
#endif
|
||||
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::string FileDialog::OpenFolder()
|
||||
{
|
||||
std::string folderPath;
|
||||
|
||||
#ifdef NK_WIN
|
||||
BROWSEINFOA bi;
|
||||
CHAR szFolder[260] = { 0 };
|
||||
ZeroMemory(&bi, sizeof(BROWSEINFO));
|
||||
bi.lpszTitle = "Select a Folder";
|
||||
bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
|
||||
bi.hwndOwner = glfwGetWin32Window(Engine::GetCurrentWindow()->GetHandle());
|
||||
bi.pszDisplayName = szFolder;
|
||||
LPITEMIDLIST pidl = SHBrowseForFolderA(&bi);
|
||||
if (pidl != NULL)
|
||||
{
|
||||
SHGetPathFromIDListA(pidl, szFolder);
|
||||
folderPath = std::string(szFolder);
|
||||
CoTaskMemFree(pidl);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef NK_LINUX
|
||||
GtkWidget* dialog;
|
||||
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
|
||||
gint res;
|
||||
|
||||
dialog = gtk_file_chooser_dialog_new("Select Folder",
|
||||
NULL,
|
||||
action,
|
||||
"_Cancel",
|
||||
GTK_RESPONSE_CANCEL,
|
||||
"_Select",
|
||||
GTK_RESPONSE_ACCEPT,
|
||||
NULL);
|
||||
|
||||
res = gtk_dialog_run(GTK_DIALOG(dialog));
|
||||
|
||||
if (res == GTK_RESPONSE_ACCEPT) {
|
||||
char* foldername = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
|
||||
folderPath = foldername;
|
||||
g_free(foldername);
|
||||
}
|
||||
|
||||
gtk_widget_destroy(dialog);
|
||||
#endif
|
||||
|
||||
return folderPath;
|
||||
}
|
||||
|
||||
std::string FileSystem::Root = "";
|
||||
|
||||
Ref<Directory> FileSystem::RootDirectory;
|
||||
Ref<filewatch::FileWatch<std::string>> FileSystem::RootFileWatch;
|
||||
std::string FileSystem::Root = "";
|
||||
|
||||
Ref<Directory> FileSystem::RootDirectory;
|
||||
Ref<filewatch::FileWatch<std::string>> FileSystem::RootFileWatch;
|
||||
|
||||
|
||||
void FileSystem::ScanDirectory(Ref<Directory> directory)
|
||||
void FileSystem::ScanDirectory(Ref<Directory> directory)
|
||||
{
|
||||
for (const auto& entry : std::filesystem::directory_iterator(directory->FullPath))
|
||||
{
|
||||
for (const auto& entry : std::filesystem::directory_iterator(directory->FullPath))
|
||||
if (entry.is_directory())
|
||||
{
|
||||
if (entry.is_directory())
|
||||
{
|
||||
Ref<Directory> newDir = CreateRef<Directory>();
|
||||
newDir->FullPath = entry.path().string();
|
||||
newDir->Name = entry.path().filename().string();
|
||||
Ref<Directory> newDir = CreateRef<Directory>();
|
||||
newDir->FullPath = entry.path().string();
|
||||
newDir->Name = entry.path().filename().string();
|
||||
|
||||
newDir->Parent = directory;
|
||||
ScanDirectory(newDir);
|
||||
directory->Directories.push_back(newDir);
|
||||
}
|
||||
else if (entry.is_regular_file())
|
||||
{
|
||||
std::filesystem::path currentPath = entry.path();
|
||||
std::string absolutePath = currentPath.string();
|
||||
std::string name = currentPath.filename().string();
|
||||
std::string extension = currentPath.extension().string();
|
||||
Ref<File> newFile = CreateRef<File>(directory, absolutePath, name, extension);
|
||||
directory->Files.push_back(newFile);
|
||||
}
|
||||
newDir->Parent = directory;
|
||||
ScanDirectory(newDir);
|
||||
directory->Directories.push_back(newDir);
|
||||
}
|
||||
else if (entry.is_regular_file())
|
||||
{
|
||||
std::filesystem::path currentPath = entry.path();
|
||||
std::string absolutePath = currentPath.string();
|
||||
std::string name = currentPath.filename().string();
|
||||
std::string extension = currentPath.extension().string();
|
||||
Ref<File> newFile = CreateRef<File>(directory, absolutePath, name, extension);
|
||||
directory->Files.push_back(newFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool FileSystem::DirectoryExists(const std::string& path, bool absolute)
|
||||
{
|
||||
const std::string& finalPath = absolute ? path : Root + path;
|
||||
bool FileSystem::DirectoryExists(const std::string& path, bool absolute)
|
||||
{
|
||||
const std::string& finalPath = absolute ? path : Root + path;
|
||||
|
||||
return std::filesystem::exists(finalPath) && std::filesystem::is_directory(finalPath);
|
||||
}
|
||||
return std::filesystem::exists(finalPath) && std::filesystem::is_directory(finalPath);
|
||||
}
|
||||
|
||||
bool FileSystem::MakeDirectory(const std::string& path, bool absolute)
|
||||
{
|
||||
return std::filesystem::create_directories(absolute ? path : FileSystem::Root + path);
|
||||
}
|
||||
bool FileSystem::MakeDirectory(const std::string& path, bool absolute)
|
||||
{
|
||||
return std::filesystem::create_directories(absolute ? path : FileSystem::Root + path);
|
||||
}
|
||||
|
||||
bool FileSystem::FileExists(const std::string& path, bool absolute)
|
||||
{
|
||||
std::string fullPath = absolute ? path : FileSystem::Root + path;
|
||||
return std::filesystem::exists(fullPath) && std::filesystem::is_regular_file(fullPath);
|
||||
}
|
||||
bool FileSystem::FileExists(const std::string& path, bool absolute)
|
||||
{
|
||||
std::string fullPath = absolute ? path : FileSystem::Root + path;
|
||||
return std::filesystem::exists(fullPath) && std::filesystem::is_regular_file(fullPath);
|
||||
}
|
||||
|
||||
void FileSystem::SetRootDirectory(const std::string path)
|
||||
{
|
||||
Root = path;
|
||||
RootFileWatch = CreateRef<filewatch::FileWatch<std::string>>(
|
||||
path, [&](const std::string& path, const filewatch::Event& event)
|
||||
void FileSystem::SetRootDirectory(const std::string path)
|
||||
{
|
||||
Root = path;
|
||||
RootFileWatch = CreateRef<filewatch::FileWatch<std::string>>(
|
||||
path, [&](const std::string& path, const filewatch::Event& event)
|
||||
{
|
||||
std::string normalizedPath = String::ReplaceSlash(path);
|
||||
|
||||
// Detect if its a file and not a folder.
|
||||
if (!FileSystem::FileExists(normalizedPath))
|
||||
{
|
||||
std::string normalizedPath = String::ReplaceSlash(path);
|
||||
return;
|
||||
}
|
||||
|
||||
// Detect if its a file and not a folder.
|
||||
if (!FileSystem::FileExists(normalizedPath))
|
||||
if(Ref<File> file = GetFile(normalizedPath); file)
|
||||
{
|
||||
if (file->GetFileType() == FileType::Unkown)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(Ref<File> file = GetFile(normalizedPath); file)
|
||||
Logger::Log(normalizedPath + " event: " + filewatch::event_to_string(event), "filewatcher", VERBOSE);
|
||||
|
||||
if (event == filewatch::Event::modified)
|
||||
{
|
||||
if (file->GetFileType() == FileType::Unkown)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Logger::Log(normalizedPath + " event: " + filewatch::event_to_string(event), "filewatcher", VERBOSE);
|
||||
|
||||
if (event == filewatch::Event::modified)
|
||||
{
|
||||
file->SetHasBeenModified(true);
|
||||
}
|
||||
file->SetHasBeenModified(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
Scan();
|
||||
}
|
||||
}
|
||||
);
|
||||
Scan();
|
||||
}
|
||||
|
||||
void FileSystem::Scan()
|
||||
{
|
||||
RootDirectory = CreateRef<Directory>(Root);
|
||||
ScanDirectory(RootDirectory);
|
||||
}
|
||||
void FileSystem::Scan()
|
||||
{
|
||||
RootDirectory = CreateRef<Directory>(Root);
|
||||
ScanDirectory(RootDirectory);
|
||||
}
|
||||
|
||||
std::string FileSystem::AbsoluteToRelative(const std::string& path)
|
||||
{
|
||||
const fs::path rootPath(Root);
|
||||
const fs::path absolutePath(path);
|
||||
return fs::relative(absolutePath, rootPath).generic_string();
|
||||
}
|
||||
std::string FileSystem::AbsoluteToRelative(const std::string& path)
|
||||
{
|
||||
const std::filesystem::path rootPath(Root);
|
||||
const std::filesystem::path absolutePath(path);
|
||||
return std::filesystem::relative(absolutePath, rootPath).generic_string();
|
||||
}
|
||||
|
||||
std::string FileSystem::RelativeToAbsolute(const std::string& path)
|
||||
{
|
||||
return Root + path;
|
||||
}
|
||||
std::string FileSystem::RelativeToAbsolute(const std::string& path)
|
||||
{
|
||||
return Root + path;
|
||||
}
|
||||
|
||||
std::string FileSystem::GetParentPath(const std::string& fullPath)
|
||||
{
|
||||
std::filesystem::path pathObj(fullPath);
|
||||
auto returnvalue = pathObj.parent_path().string();
|
||||
return returnvalue + "/";
|
||||
}
|
||||
std::string FileSystem::GetParentPath(const std::string& fullPath)
|
||||
{
|
||||
std::filesystem::path pathObj(fullPath);
|
||||
auto returnvalue = pathObj.parent_path().string();
|
||||
return returnvalue + "/";
|
||||
}
|
||||
|
||||
std::string FileSystem::ReadFile(const std::string& path, bool absolute)
|
||||
{
|
||||
std::string finalPath = path;
|
||||
if (!absolute)
|
||||
finalPath = Root + path;
|
||||
std::string FileSystem::ReadFile(const std::string& path, bool absolute)
|
||||
{
|
||||
std::string finalPath = path;
|
||||
if (!absolute)
|
||||
finalPath = Root + path;
|
||||
|
||||
std::ifstream myReadFile(finalPath, std::ios::in | std::ios::binary);
|
||||
std::string fileContent = "";
|
||||
std::string allFile = "";
|
||||
std::ifstream myReadFile(finalPath, std::ios::in | std::ios::binary);
|
||||
std::string fileContent = "";
|
||||
std::string allFile = "";
|
||||
|
||||
char bom[3];
|
||||
myReadFile.read(bom, 3);
|
||||
char bom[3];
|
||||
myReadFile.read(bom, 3);
|
||||
|
||||
// Check for UTF-8 BOM (EF BB BF)
|
||||
if (bom[0] == 0xEF && bom[1] == 0xBB && bom[2] == 0xBF)
|
||||
// Check for UTF-8 BOM (EF BB BF)
|
||||
if (bom[0] == 0xEF && bom[1] == 0xBB && bom[2] == 0xBF)
|
||||
{
|
||||
myReadFile.seekg(3);
|
||||
}
|
||||
else
|
||||
{
|
||||
myReadFile.seekg(0);
|
||||
}
|
||||
|
||||
// Use a while loop together with the getline() function to read the file line by line
|
||||
while (getline(myReadFile, fileContent))
|
||||
{
|
||||
allFile.append(fileContent + "\n");
|
||||
}
|
||||
|
||||
// Close the file
|
||||
myReadFile.close();
|
||||
return allFile;
|
||||
}
|
||||
|
||||
std::ofstream FileSystem::fileWriter;
|
||||
bool FileSystem::BeginWriteFile(const std::string path, bool absolute)
|
||||
{
|
||||
fileWriter = std::ofstream();
|
||||
fileWriter.open(absolute ? path : FileSystem::Root + path);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FileSystem::WriteLine(const std::string line)
|
||||
{
|
||||
fileWriter << line.c_str();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void FileSystem::EndWriteFile()
|
||||
{
|
||||
fileWriter.close();
|
||||
}
|
||||
|
||||
uintmax_t FileSystem::DeleteFileFromPath(const std::string& path)
|
||||
{
|
||||
return std::remove(path.c_str());
|
||||
}
|
||||
|
||||
uintmax_t FileSystem::DeleteFolder(const std::string& path)
|
||||
{
|
||||
return std::filesystem::remove_all(path.c_str());
|
||||
}
|
||||
|
||||
std::string FileSystem::GetConfigFolderPath()
|
||||
{
|
||||
std::string subFolderPath = OS::GetConfigFolderPath().append("/Nuake/");
|
||||
if (!DirectoryExists(subFolderPath, true))
|
||||
{
|
||||
MakeDirectory(subFolderPath);
|
||||
}
|
||||
|
||||
return subFolderPath;
|
||||
}
|
||||
|
||||
Ref<Directory> FileSystem::GetFileTree()
|
||||
{
|
||||
return RootDirectory;
|
||||
}
|
||||
|
||||
Ref<File> FileSystem::GetFile(const std::string& path)
|
||||
{
|
||||
// Note, Might be broken on other platforms.
|
||||
auto splits = String::Split(path, '/');
|
||||
|
||||
int currentDepth = -1;
|
||||
std::string currentDirName = ".";
|
||||
Ref<Directory> currentDirComparator = RootDirectory;
|
||||
while (currentDirName == currentDirComparator->Name)
|
||||
{
|
||||
currentDepth++;
|
||||
currentDirName = splits[currentDepth];
|
||||
|
||||
// Find next directory
|
||||
for (auto& d : currentDirComparator->Directories)
|
||||
{
|
||||
myReadFile.seekg(3);
|
||||
}
|
||||
else
|
||||
{
|
||||
myReadFile.seekg(0);
|
||||
}
|
||||
|
||||
// Use a while loop together with the getline() function to read the file line by line
|
||||
while (getline(myReadFile, fileContent))
|
||||
{
|
||||
allFile.append(fileContent + "\n");
|
||||
}
|
||||
|
||||
// Close the file
|
||||
myReadFile.close();
|
||||
return allFile;
|
||||
}
|
||||
|
||||
std::ofstream FileSystem::fileWriter;
|
||||
bool FileSystem::BeginWriteFile(const std::string path, bool absolute)
|
||||
{
|
||||
fileWriter = std::ofstream();
|
||||
fileWriter.open(absolute ? path : FileSystem::Root + path);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FileSystem::WriteLine(const std::string line)
|
||||
{
|
||||
fileWriter << line.c_str();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void FileSystem::EndWriteFile()
|
||||
{
|
||||
fileWriter.close();
|
||||
}
|
||||
|
||||
uintmax_t FileSystem::DeleteFileFromPath(const std::string& path)
|
||||
{
|
||||
return std::remove(path.c_str());
|
||||
}
|
||||
|
||||
uintmax_t FileSystem::DeleteFolder(const std::string& path)
|
||||
{
|
||||
return std::filesystem::remove_all(path.c_str());
|
||||
}
|
||||
|
||||
std::string FileSystem::GetConfigFolderPath()
|
||||
{
|
||||
std::string subFolderPath = OS::GetConfigFolderPath().append("/Nuake/");
|
||||
if (!DirectoryExists(subFolderPath, true))
|
||||
{
|
||||
MakeDirectory(subFolderPath);
|
||||
}
|
||||
|
||||
return subFolderPath;
|
||||
}
|
||||
|
||||
Ref<Directory> FileSystem::GetFileTree()
|
||||
{
|
||||
return RootDirectory;
|
||||
}
|
||||
|
||||
Ref<File> FileSystem::GetFile(const std::string& path)
|
||||
{
|
||||
// Note, Might be broken on other platforms.
|
||||
auto splits = String::Split(path, '/');
|
||||
|
||||
int currentDepth = -1;
|
||||
std::string currentDirName = ".";
|
||||
Ref<Directory> currentDirComparator = RootDirectory;
|
||||
while (currentDirName == currentDirComparator->Name)
|
||||
{
|
||||
currentDepth++;
|
||||
currentDirName = splits[currentDepth];
|
||||
|
||||
// Find next directory
|
||||
for (auto& d : currentDirComparator->Directories)
|
||||
if (d->Name == currentDirName)
|
||||
{
|
||||
if (d->Name == currentDirName)
|
||||
{
|
||||
currentDirComparator = d;
|
||||
}
|
||||
}
|
||||
|
||||
// Find in files if can't find in directories.
|
||||
for (auto& f : currentDirComparator->Files)
|
||||
{
|
||||
if (f->GetName() == currentDirName)
|
||||
{
|
||||
return f;
|
||||
}
|
||||
currentDirComparator = d;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
// Find in files if can't find in directories.
|
||||
for (auto& f : currentDirComparator->Files)
|
||||
{
|
||||
if (f->GetName() == currentDirName)
|
||||
{
|
||||
return f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string FileSystem::GetFileNameFromPath(const std::string& path)
|
||||
{
|
||||
const auto& split = String::Split(path, '/');
|
||||
return String::Split(split[split.size() - 1], '.')[0];
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::string FileSystem::GetFileNameFromPath(const std::string& path)
|
||||
{
|
||||
const auto& split = String::Split(path, '/');
|
||||
return String::Split(split[split.size() - 1], '.')[0];
|
||||
}
|
||||
|
||||
|
||||
Directory::Directory(const std::string& path)
|
||||
{
|
||||
Files = std::vector<Ref<File>>();
|
||||
Directories = std::vector<Ref<Directory>>();
|
||||
Name = FileSystem::AbsoluteToRelative(path);
|
||||
FullPath = path;
|
||||
}
|
||||
}
|
||||
Directory::Directory(const std::string& path)
|
||||
{
|
||||
Files = std::vector<Ref<File>>();
|
||||
Directories = std::vector<Ref<Directory>>();
|
||||
Name = FileSystem::AbsoluteToRelative(path);
|
||||
FullPath = path;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
#pragma once
|
||||
#include "src/Core/Core.h"
|
||||
#include "String.h"
|
||||
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
namespace filewatch
|
||||
{
|
||||
@@ -15,14 +9,6 @@ namespace filewatch
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
class FileDialog
|
||||
{
|
||||
public:
|
||||
static std::string OpenFile(const char* filter);
|
||||
static std::string SaveFile(const char* filter);
|
||||
static std::string OpenFolder();
|
||||
};
|
||||
|
||||
class Directory;
|
||||
class File;
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <json/json.hpp>
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <streambuf>
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "Engine.h"
|
||||
#include "src/Core/Maths.h"
|
||||
#include "src/FileSystem/FileSystem.h"
|
||||
#include "src/FileSystem/FileDialog.h"
|
||||
|
||||
#include "src/Scene/Components.h"
|
||||
#include "src/Scene/Components/BoxCollider.h"
|
||||
@@ -31,12 +32,12 @@
|
||||
#include "src/Scene/Components/SkinnedModelComponent.h"
|
||||
#include "src/Scene/Components/BoneComponent.h"
|
||||
|
||||
#include <Tracy.hpp>
|
||||
|
||||
#include <fstream>
|
||||
#include <future>
|
||||
#include <streambuf>
|
||||
#include <chrono>
|
||||
#include <Tracy.hpp>
|
||||
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
|
||||
@@ -11,10 +11,12 @@
|
||||
#include "NetModules/InputNetAPI.h"
|
||||
#include "NetModules/SceneNetAPI.h"
|
||||
|
||||
#include <src/Scene/Components/BSPBrushComponent.h>
|
||||
|
||||
#include <filesystem>
|
||||
#include <sstream>
|
||||
#include <random>
|
||||
#include <regex>
|
||||
#include <src/Scene/Components/BSPBrushComponent.h>
|
||||
|
||||
|
||||
void ExceptionCallback(std::string_view InMessage)
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace Coral
|
||||
class Type;
|
||||
}
|
||||
|
||||
#include <filesystem>
|
||||
#include <Coral/HostInstance.hpp>
|
||||
#include <Coral/GC.hpp>
|
||||
#include <Coral/Array.hpp>
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
#include <src/Vendors/wren/src/include/wren.h>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
WrenScript::WrenScript(Ref<File> file, bool isEntityScript)
|
||||
|
||||
Reference in New Issue
Block a user