\doxysection{File\+Manager.\+h}
\hypertarget{_file_manager_8h_source}{}\label{_file_manager_8h_source}\index{Include/FileSystem/FileManager.h@{Include/FileSystem/FileManager.h}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{comment}{//\ =====================================================================================================================}}
\DoxyCodeLine{00002\ \textcolor{comment}{//\ \ OpenShaderDesigner,\ an\ open\ source\ software\ utility\ to\ create\ materials\ and\ shaders.}}
\DoxyCodeLine{00003\ \textcolor{comment}{//\ \ Copyright\ (C)\ 2024\ \ Medusa\ Slockbower}}
\DoxyCodeLine{00004\ \textcolor{comment}{//}}
\DoxyCodeLine{00005\ \textcolor{comment}{//\ \ This\ program\ is\ free\ software:\ you\ can\ redistribute\ it\ and/or\ modify}}
\DoxyCodeLine{00006\ \textcolor{comment}{//\ \ it\ under\ the\ terms\ of\ the\ GNU\ General\ Public\ License\ as\ published\ by}}
\DoxyCodeLine{00007\ \textcolor{comment}{//\ \ the\ Free\ Software\ Foundation,\ either\ version\ 3\ of\ the\ License,\ or}}
\DoxyCodeLine{00008\ \textcolor{comment}{//\ \ (at\ your\ option)\ any\ later\ version.}}
\DoxyCodeLine{00009\ \textcolor{comment}{//}}
\DoxyCodeLine{00010\ \textcolor{comment}{//\ \ This\ program\ is\ distributed\ in\ the\ hope\ that\ it\ will\ be\ useful,}}
\DoxyCodeLine{00011\ \textcolor{comment}{//\ \ but\ WITHOUT\ ANY\ WARRANTY;\ without\ even\ the\ implied\ warranty\ of}}
\DoxyCodeLine{00012\ \textcolor{comment}{//\ \ MERCHANTABILITY\ or\ FITNESS\ FOR\ A\ PARTICULAR\ PURPOSE.\ \ See\ the}}
\DoxyCodeLine{00013\ \textcolor{comment}{//\ \ GNU\ General\ Public\ License\ for\ more\ details.}}
\DoxyCodeLine{00014\ \textcolor{comment}{//}}
\DoxyCodeLine{00015\ \textcolor{comment}{//\ \ You\ should\ have\ received\ a\ copy\ of\ the\ GNU\ General\ Public\ License}}
\DoxyCodeLine{00016\ \textcolor{comment}{//\ \ along\ with\ this\ program.\ \ If\ not,\ see\ <https://www.gnu.org/licenses/>.}}
\DoxyCodeLine{00017\ \textcolor{comment}{//\ =====================================================================================================================}}
\DoxyCodeLine{00018\ }
\DoxyCodeLine{00019\ \textcolor{preprocessor}{\#ifndef\ FILESYSTEM\_H}}
\DoxyCodeLine{00020\ \textcolor{preprocessor}{\#define\ FILESYSTEM\_H}}
\DoxyCodeLine{00021\ }
\DoxyCodeLine{00022\ \textcolor{preprocessor}{\#include\ <Editor/EditorWindow.h>}}
\DoxyCodeLine{00023\ }
\DoxyCodeLine{00024\ \textcolor{preprocessor}{\#include\ <open-\/cpp-\/utils/filesystem.h>}}
\DoxyCodeLine{00025\ \textcolor{preprocessor}{\#include\ <open-\/cpp-\/utils/map.h>}}
\DoxyCodeLine{00026\ \textcolor{preprocessor}{\#include\ <open-\/cpp-\/utils/startup.h>}}
\DoxyCodeLine{00027\ }
\DoxyCodeLine{00028\ \textcolor{preprocessor}{\#define\ RegisterAsset(Name,\ Type,\ ...)\ \(\backslash\)}}
\DoxyCodeLine{00029\ \textcolor{preprocessor}{\ \ \ \ STARTUP(\_Register\#\#Type)\ \{\ FileManager::Register(Name,\ \{\ \_\_VA\_ARGS\_\_\ \},\ \#\#Type::Create,\ \#\#Type::Load,\ \#\#Type::Import);\ \}}}
\DoxyCodeLine{00030\ }
\DoxyCodeLine{00031\ \textcolor{keyword}{namespace\ }ocu\ =\ open\_cpp\_utils;}
\DoxyCodeLine{00032\ }
\DoxyCodeLine{00033\ \textcolor{keyword}{namespace\ }OpenShaderDesigner}
\DoxyCodeLine{00034\ \{}
\DoxyCodeLine{00035\ }
\DoxyCodeLine{00036\ \textcolor{keyword}{class\ }\mbox{\hyperlink{class_open_shader_designer_1_1_file_manager}{FileManager}}\ :\ \textcolor{keyword}{public}\ \mbox{\hyperlink{class_open_shader_designer_1_1_editor_window}{EditorWindow}}}
\DoxyCodeLine{00037\ \{}
\DoxyCodeLine{00038\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00039\ \ \ \ \ \textcolor{keyword}{class\ }\mbox{\hyperlink{class_open_shader_designer_1_1_file_manager_1_1_asset}{Asset}};}
\DoxyCodeLine{00040\ \ \ \ \ \textcolor{keyword}{using\ }FileSystem\ =\ ocu::filesystem<Asset,\ FileManager>;}
\DoxyCodeLine{00041\ \ \ \ \ \textcolor{keyword}{using\ }File\ \ \ \ \ \ \ =\ FileSystem::file;}
\DoxyCodeLine{00042\ \ \ \ \ \textcolor{keyword}{using\ }Path\ \ \ \ \ \ \ =\ std::filesystem::path;}
\DoxyCodeLine{00043\ \ \ \ \ \textcolor{keyword}{using\ }FileID\ \ \ \ \ =\ FileSystem::file\_id;}
\DoxyCodeLine{00044\ \ \ \ \ \textcolor{keyword}{using\ }CreateFunc\ =\ \mbox{\hyperlink{class_open_shader_designer_1_1_file_manager_1_1_asset}{Asset}}*\ (*)(\textcolor{keyword}{const}\ Path\&);}
\DoxyCodeLine{00045\ \ \ \ \ \textcolor{keyword}{using\ }LoadFunc\ \ \ =\ \mbox{\hyperlink{class_open_shader_designer_1_1_file_manager_1_1_asset}{Asset}}*\ (*)(\textcolor{keyword}{const}\ Path\&);}
\DoxyCodeLine{00046\ \ \ \ \ \textcolor{keyword}{using\ }ImportFunc\ =\ \mbox{\hyperlink{class_open_shader_designer_1_1_file_manager_1_1_asset}{Asset}}*\ (*)(\textcolor{keyword}{const}\ Path\&,\ \textcolor{keyword}{const}\ Path\&);}
\DoxyCodeLine{00047\ \ \ \ \ \textcolor{keyword}{friend}\ FileSystem;}
\DoxyCodeLine{00048\ }
\DoxyCodeLine{00049\ \textcolor{keyword}{private}:}
\DoxyCodeLine{00050\ \ \ \ \ \textcolor{keyword}{struct\ }AssetDetail}
\DoxyCodeLine{00051\ \ \ \ \ \{}
\DoxyCodeLine{00052\ \ \ \ \ \ \ \ \ std::string\ \ \ \ \ \ \ \ \ \ \ \ \ \ Name;}
\DoxyCodeLine{00053\ \ \ \ \ \ \ \ \ std::vector<std::string>\ Extensions;}
\DoxyCodeLine{00054\ \ \ \ \ \ \ \ \ CreateFunc\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Create;}
\DoxyCodeLine{00055\ \ \ \ \ \ \ \ \ LoadFunc\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Load;}
\DoxyCodeLine{00056\ \ \ \ \ \ \ \ \ ImportFunc\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Import;}
\DoxyCodeLine{00057\ }
\DoxyCodeLine{00058\ \ \ \ \ \ \ \ \ AssetDetail()\ :\ Create(\textcolor{keyword}{nullptr}),\ Load(\textcolor{keyword}{nullptr}),\ Import(\textcolor{keyword}{nullptr})\ \{\ \}}
\DoxyCodeLine{00059\ \ \ \ \ \ \ \ \ AssetDetail(\textcolor{keyword}{const}\ std::string\&\ name)\ :\ Name(name),\ Create(\textcolor{keyword}{nullptr}),\ Load(\textcolor{keyword}{nullptr}),\ Import(\textcolor{keyword}{nullptr})\ \{\}}
\DoxyCodeLine{00060\ }
\DoxyCodeLine{00061\ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00062\ \ \ \ \ \ \ \ \ AssetDetail(\textcolor{keyword}{const}\ std::string\&\ name,\ \textcolor{keyword}{const}\ std::vector<std::string>\&\ exts,}
\DoxyCodeLine{00063\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ CreateFunc\ create,\ \textcolor{keyword}{const}\ LoadFunc\ load,\ \textcolor{keyword}{const}\ ImportFunc\ \textcolor{keyword}{import})}
\DoxyCodeLine{00064\ \ \ \ \ \ \ \ \ :\ Name(name),\ Extensions(exts),\ Create(create),\ Load(load),\ Import(\textcolor{keyword}{import})\ \{\}}
\DoxyCodeLine{00065\ \ \ \ \ \};}
\DoxyCodeLine{00066\ }
\DoxyCodeLine{00067\ \ \ \ \ \textcolor{keyword}{using\ }AssetMenuHierarchy\ =\ ocu::directed\_tree<AssetDetail>;}
\DoxyCodeLine{00068\ \ \ \ \ \textcolor{keyword}{using\ }AssetType\ =\ AssetMenuHierarchy::node;}
\DoxyCodeLine{00069\ \ \ \ \ \textcolor{keyword}{using\ }ExtensionMapping\ =\ ocu::map<std::string,\ AssetType>;}
\DoxyCodeLine{00070\ \ \ \ \ }
\DoxyCodeLine{00071\ \ \ \ \ \textcolor{keyword}{static}\ AssetMenuHierarchy\&\ AssetMenu()\ \{\ \textcolor{keyword}{static}\ AssetMenuHierarchy\ Menu;\ \textcolor{keywordflow}{return}\ Menu;\ \}}
\DoxyCodeLine{00072\ \ \ \ \ \textcolor{keyword}{static}\ ExtensionMapping\&\ ExtensionMap()\ \{\ \textcolor{keyword}{static}\ ExtensionMapping\ Map;\ \textcolor{keywordflow}{return}\ Map;\ \}}
\DoxyCodeLine{00073\ \ \ \ \ }
\DoxyCodeLine{00074\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00075\ }
\DoxyCodeLine{00076\ \ \ \ \ \textcolor{keyword}{class\ }\mbox{\hyperlink{class_open_shader_designer_1_1_file_manager_1_1_asset}{Asset}}}
\DoxyCodeLine{00077\ \ \ \ \ \{}
\DoxyCodeLine{00078\ \ \ \ \ \textcolor{keyword}{public}:}
\DoxyCodeLine{00079\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{class_open_shader_designer_1_1_file_manager_1_1_asset}{Asset}}(\textcolor{keyword}{const}\ Path\&\ path)\ :\ Dirty\_(\textcolor{keyword}{false})\ \{\ \}}
\DoxyCodeLine{00080\ \ \ \ \ \ \ \ \ \textcolor{keyword}{virtual}\ \mbox{\hyperlink{class_open_shader_designer_1_1_file_manager_1_1_asset}{\string~Asset}}()\ =\ \textcolor{keywordflow}{default};}
\DoxyCodeLine{00081\ \ \ \ \ }
\DoxyCodeLine{00082\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{bool}\ Dirty()\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ Dirty\_;\ \}}
\DoxyCodeLine{00083\ }
\DoxyCodeLine{00084\ \ \ \ \ \ \ \ \ \textcolor{keyword}{virtual}\ \textcolor{keywordtype}{void}\ Open()\ \{\ \};}
\DoxyCodeLine{00085\ \ \ \ \ \ \ \ \ \textcolor{keyword}{virtual}\ \textcolor{keywordtype}{void}\ Save(\textcolor{keyword}{const}\ Path\&\ path)\ \{\ Dirty\_\ =\ \textcolor{keyword}{false};\ \}}
\DoxyCodeLine{00086\ }
\DoxyCodeLine{00087\ \ \ \ \ \ \ \ \ File\&\ GetFile()\ \{\ \textcolor{keywordflow}{return}\ Manager\_-\/>Get(File\_);\ \}}
\DoxyCodeLine{00088\ \ \ \ \ \ \ \ \ FileID\ GetID()\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ File\_;\ \}}
\DoxyCodeLine{00089\ }
\DoxyCodeLine{00090\ \ \ \ \ \textcolor{keyword}{protected}:}
\DoxyCodeLine{00091\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{void}\ MakeDirty()\ \{\ Dirty\_\ =\ \textcolor{keyword}{true};\ \}}
\DoxyCodeLine{00092\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{class_open_shader_designer_1_1_file_manager}{FileManager}}*\ Parent()\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ Manager\_;\ \}}
\DoxyCodeLine{00093\ }
\DoxyCodeLine{00094\ \ \ \ \ \textcolor{keyword}{private}:}
\DoxyCodeLine{00095\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{class_open_shader_designer_1_1_file_manager}{FileManager}}*\ Manager\_;}
\DoxyCodeLine{00096\ \ \ \ \ \ \ \ \ FileID\ File\_;}
\DoxyCodeLine{00097\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{bool}\ Dirty\_;}
\DoxyCodeLine{00098\ \ \ \ \ \ \ \ \ \textcolor{keyword}{friend}\ \mbox{\hyperlink{class_open_shader_designer_1_1_file_manager}{FileManager}};}
\DoxyCodeLine{00099\ \ \ \ \ \};}
\DoxyCodeLine{00100\ }
\DoxyCodeLine{00101\ \ \ \ \ \textcolor{keyword}{struct\ }\mbox{\hyperlink{struct_open_shader_designer_1_1_file_manager_1_1_folder}{Folder}}\ :\ \mbox{\hyperlink{class_open_shader_designer_1_1_file_manager_1_1_asset}{Asset}}}
\DoxyCodeLine{00102\ \ \ \ \ \{}
\DoxyCodeLine{00103\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{struct_open_shader_designer_1_1_file_manager_1_1_folder}{Folder}}(\textcolor{keyword}{const}\ std::filesystem::path\&\ p)\ :\ \mbox{\hyperlink{class_open_shader_designer_1_1_file_manager_1_1_asset}{Asset}}(p)\ \{\ \};}
\DoxyCodeLine{00104\ \ \ \ \ \ \ \ \ \textcolor{keyword}{virtual}\ \mbox{\hyperlink{struct_open_shader_designer_1_1_file_manager_1_1_folder}{\string~Folder}}()\ =\ \textcolor{keywordflow}{default};}
\DoxyCodeLine{00105\ }
\DoxyCodeLine{00106\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{void}\ Open()\textcolor{keyword}{\ override\ }\{\ Manager\_-\/>CurrentDirectory\_\ =\ GetID();\ \}}
\DoxyCodeLine{00107\ \ \ \ \ \};}
\DoxyCodeLine{00108\ \ \ \ \ }
\DoxyCodeLine{00109\ \textcolor{keyword}{private}:}
\DoxyCodeLine{00110\ \ \ \ \ \textcolor{keyword}{static}\ \mbox{\hyperlink{class_open_shader_designer_1_1_file_manager_1_1_asset}{Asset}}*\ load(\textcolor{keyword}{const}\ Path\&\ file,\ FileID\ \textcolor{keywordtype}{id});}
\DoxyCodeLine{00111\ \ \ \ \ \textcolor{keyword}{static}\ \mbox{\hyperlink{class_open_shader_designer_1_1_file_manager_1_1_asset}{Asset}}*\ \textcolor{keyword}{import}(\textcolor{keyword}{const}\ Path\&\ src,\ \textcolor{keyword}{const}\ Path\&\ dst,\ FileID\ id);}
\DoxyCodeLine{00112\ \ \ \ \ \textcolor{keyword}{static}\ \mbox{\hyperlink{class_open_shader_designer_1_1_file_manager_1_1_asset}{Asset}}*\ create(\textcolor{keyword}{const}\ Path\&\ file,\ FileID\ \textcolor{keywordtype}{id});}
\DoxyCodeLine{00113\ \ \ \ \ }
\DoxyCodeLine{00114\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00115\ \ \ \ \ \mbox{\hyperlink{class_open_shader_designer_1_1_file_manager}{FileManager}}();}
\DoxyCodeLine{00116\ \ \ \ \ \textcolor{keyword}{virtual}\ \mbox{\hyperlink{class_open_shader_designer_1_1_file_manager}{\string~FileManager}}()\ =\ \textcolor{keywordflow}{default};}
\DoxyCodeLine{00117\ }
\DoxyCodeLine{00118\ \ \ \ \ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{class_open_shader_designer_1_1_file_manager_a260bfcf96b5daf480aa30dc990ab796d}{DrawMenu}}()\ \textcolor{keyword}{override};}
\DoxyCodeLine{00119\ \ \ \ \ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{class_open_shader_designer_1_1_file_manager_a3093fe988eb2d678943945d1d383cb38}{DrawWindow}}()\ \textcolor{keyword}{override};}
\DoxyCodeLine{00120\ }
\DoxyCodeLine{00121\ \ \ \ \ FileID\ CurrentDirectory()\textcolor{keyword}{\ const\ \ \ \ }\{\ \textcolor{keywordflow}{return}\ CurrentDirectory\_;\ \}}
\DoxyCodeLine{00122\ \ \ \ \ \textcolor{keywordtype}{void}\ \ \ CurrentDirectory(FileID\ \textcolor{keywordtype}{id})\ \{\ CurrentDirectory\_\ =\ id;\ \}}
\DoxyCodeLine{00123\ }
\DoxyCodeLine{00124\ \ \ \ \ FileID\ Create(\textcolor{keyword}{const}\ std::string\&\ name)\ \{\ \textcolor{keywordflow}{return}\ Filesystem\_.create(name,\ CurrentDirectory\_);\ \}}
\DoxyCodeLine{00125\ \ \ \ \ FileID\ Import(\textcolor{keyword}{const}\ Path\&\ path)\ \ \ \ \ \ \ \ \{\ \textcolor{keywordflow}{return}\ Filesystem\_.import(path,\ CurrentDirectory\_);\ \}}
\DoxyCodeLine{00126\ \ \ \ \ FileID\ LoadDirectory(\textcolor{keyword}{const}\ Path\&\ path)\ \{\ \textcolor{keywordflow}{return}\ Filesystem\_.load\_directory(path);\ \}}
\DoxyCodeLine{00127\ \ \ \ \ \textcolor{keywordtype}{void}\ \ \ CloseDirectory(FileID\ dir)\ \ \ \ \ \ \{\ Filesystem\_.close\_directory(dir);\ \}}
\DoxyCodeLine{00128\ \ \ \ \ }
\DoxyCodeLine{00129\ \ \ \ \ FileID\ Get(\textcolor{keyword}{const}\ Path\&\ path)\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ Filesystem\_.find(path);\ \}}
\DoxyCodeLine{00130\ \ \ \ \ File\&\ \ Get(FileID\ \textcolor{keywordtype}{id})\ \ \ \ \ \ \ \ \ \ \ \ \ \ \{\ \textcolor{keywordflow}{return}\ Filesystem\_[id];\ \}}
\DoxyCodeLine{00131\ \ \ \ \ \textcolor{keyword}{const}\ File\&\ Get(FileID\ \textcolor{keywordtype}{id})\textcolor{keyword}{\ const\ \ \ }\{\ \textcolor{keywordflow}{return}\ Filesystem\_[id];\ \}}
\DoxyCodeLine{00132\ }
\DoxyCodeLine{00133\ \ \ \ \ FileID\ Parent(FileID\ \textcolor{keywordtype}{id})\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ Filesystem\_.parent(\textcolor{keywordtype}{id});\ \}}
\DoxyCodeLine{00134\ }
\DoxyCodeLine{00135\ \ \ \ \ \textcolor{keywordtype}{bool}\ AnyDirty();}
\DoxyCodeLine{00136\ \ \ \ \ \textcolor{keywordtype}{void}\ SaveAll();}
\DoxyCodeLine{00137\ }
\DoxyCodeLine{00138\ \ \ \ \ \textcolor{keyword}{static}\ Path\ GetHomeDirectory();}
\DoxyCodeLine{00139\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keywordtype}{void}\ Register(\textcolor{keyword}{const}\ std::filesystem::path\&\ path,}
\DoxyCodeLine{00140\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ std::vector<std::string>\&\ extension,}
\DoxyCodeLine{00141\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ CreateFunc\ create,\ LoadFunc\ load,\ ImportFunc\ \textcolor{keyword}{import});}
\DoxyCodeLine{00142\ \textcolor{keyword}{private}:}
\DoxyCodeLine{00143\ \ \ \ \ FileSystem\ \ Filesystem\_;}
\DoxyCodeLine{00144\ \ \ \ \ FileID\ \ \ \ \ \ CurrentDirectory\_,\ Selected\_;}
\DoxyCodeLine{00145\ \ \ \ \ \textcolor{keywordtype}{bool}\ \ \ \ \ \ \ \ Rename\_,\ FocusRename\_;}
\DoxyCodeLine{00146\ \ \ \ \ std::string\ RenameBuffer\_;}
\DoxyCodeLine{00147\ \};}
\DoxyCodeLine{00148\ }
\DoxyCodeLine{00149\ \}}
\DoxyCodeLine{00150\ }
\DoxyCodeLine{00151\ }
\DoxyCodeLine{00152\ \textcolor{preprocessor}{\#endif\ }\textcolor{comment}{//FILESYSTEM\_H}}

\end{DoxyCode}
