LkEngine 0.1.2
 
Loading...
Searching...
No Matches
FileSystem.h
1#pragma once
2
5#include "LkEngine/Core/Log/Log.h"
6
7#include <bitset>
8#include <filesystem>
9
10/* Remove microsoft's filesystem macros. */
11#if defined(LK_PLATFORM_WINDOWS) && defined(CreateDirectory)
12# undef CreateDirectory
13# undef MoveFile
14# undef CopyFile
15# undef DeleteFile
16# undef GetEnvironmentVariable
17# undef SetEnvironmentVariable
18#endif
19
20
21namespace LkEngine {
22
24 {
25 public:
26 static bool Exists(const std::filesystem::path& Filepath);
27 static bool DeleteFile(const std::filesystem::path& Filepath);
28
29 static bool Move(const std::filesystem::path& OldFilepath, const std::filesystem::path& NewFilepath);
30 static bool Copy(const std::filesystem::path& OldFilepath, const std::filesystem::path& NewFilepath);
31 static bool Rename(const std::filesystem::path& OldFilepath, const std::filesystem::path& NewFilepath);
32 static bool RenameFilename(const std::filesystem::path& OldFilepath, const std::string& NewName);
33
34 static bool CreateDirectory(const std::filesystem::path& Directory);
35 static bool IsDirectory(const std::filesystem::path& Path);
36 static bool IsNewer(const std::filesystem::path& EntryA, const std::filesystem::path& EntryB);
37
38 static bool ShowFileInExplorer(const std::filesystem::path& Path);
39 static bool OpenDirectoryInExplorer(const std::filesystem::path& DirectoryPath);
40
41 static bool FindSimilarFiles(const std::string& FilePattern,
42 const std::filesystem::path& Directory,
43 std::vector<std::filesystem::path>& Found);
44
45 static bool MoveFile(const std::filesystem::path& Filepath, const std::filesystem::path& Destination)
46 {
47 return Move(Filepath, Destination / Filepath.filename());
48 }
49
55 static void ConvertToPlatformPath(std::string& Path);
56 static void ConvertToUnixPath(std::string& WindowsPath);
57 static void ConvertToWindowsPath(std::string& UnixPath);
58
64 [[nodiscard]] static std::string ConvertToPlatformPath(const std::filesystem::path& Path);
65 [[nodiscard]] static std::string ConvertToUnixPath(const std::filesystem::path& WindowsPath);
66 [[nodiscard]] static std::string ConvertToWindowsPath(const std::filesystem::path& UnixPath);
67
68 static std::string RemoveFileExtension(const std::string& File)
69 {
70 const std::size_t DotPosition = File.find_last_of('.');
71 if (DotPosition == std::string::npos)
72 {
73 return File;
74 }
75
76 return File.substr(0, DotPosition);
77 }
78
79 static std::string RemoveFileExtension(const std::filesystem::path& File)
80 {
81 std::string FileName = File.string();
82 const std::size_t DotPosition = FileName.find_last_of('.');
83 if (DotPosition == std::string::npos)
84 {
85 return FileName;
86 }
87
88 return FileName.substr(0, DotPosition);
89 }
90
91 static void RemoveFileExtension(std::string& File)
92 {
93 const std::size_t DotPosition = File.find_last_of('.');
94 if (DotPosition == std::string::npos)
95 {
96 return;
97 }
98
99 File = File.substr(0, DotPosition);
100 }
101
103 {
104 const char* Name;
105 const char* Spec;
106 };
107
108 static std::filesystem::path OpenFileDialog(const std::initializer_list<FFileDialogFilterItem> InFilters = {});
109 static std::filesystem::path SaveFileDialog(const std::initializer_list<FFileDialogFilterItem> InFilters = {});
110 static std::filesystem::path OpenFolderDialog(const char* InitialFolder = "");
111
112 FORCEINLINE static std::filesystem::path GetWorkingDir() { return WorkingDir; }
113 FORCEINLINE static std::filesystem::path GetBinaryDir() { return BinaryDir; }
114 FORCEINLINE static std::filesystem::path GetEngineDir() { return EngineDir; }
115 FORCEINLINE static std::filesystem::path GetEditorDir() { return EditorDir; }
116 FORCEINLINE static std::filesystem::path GetRuntimeDir() { return RuntimeDir; }
117 FORCEINLINE static std::filesystem::path GetConfigDir() { return ConfigDir; }
118 FORCEINLINE static std::filesystem::path GetResourcesDir() { return ResourcesDir; }
119 FORCEINLINE static std::filesystem::path GetAssetsDir() { return AssetsDir; }
120
121 FORCEINLINE static std::filesystem::path GetEngineConfig() { return EngineConfig; }
122 FORCEINLINE static std::filesystem::path GetEditorConfig() { return EditorConfig; }
123
124 private:
125 static std::filesystem::path WorkingDir;
126 static std::filesystem::path BinaryDir;
127 static std::filesystem::path EngineDir;
128 static std::filesystem::path EditorDir;
129 static std::filesystem::path RuntimeDir;
130 static std::filesystem::path ConfigDir;
131 static std::filesystem::path ResourcesDir;
132 static std::filesystem::path AssetsDir;
133 static std::filesystem::path ProjectsDir;
134
135 static std::filesystem::path EngineConfig;
136 static std::filesystem::path EditorConfig;
137
138 friend struct Global;
139 };
140
141}
Core macros used by the entire engine.
Core types.
Definition FileSystem.h:24
static void ConvertToPlatformPath(std::string &Path)
Definition FileSystem.cpp:189
Definition Asset.h:11