| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#pragma once |
| 5 |
|
| 6 |
#include <filesystem> |
| 7 |
#include <string> |
| 8 |
#include <string_view> |
| 9 |
#include <vector> |
| 10 |
|
| 11 |
#include <sys/stat.h> |
| 12 |
|
| 13 |
#include "Common/CommonTypes.h" |
| 14 |
|
| 15 |
#ifdef _WIN32 |
| 16 |
#include "Common/StringUtil.h" |
| 17 |
#endif |
| 18 |
|
| 19 |
#ifdef ANDROID |
| 20 |
#include "Common/StringUtil.h" |
| 21 |
#include "jni/AndroidCommon/AndroidCommon.h" |
| 22 |
#endif |
| 23 |
|
| 24 |
|
| 25 |
enum |
| 26 |
{ |
| 27 |
D_USER_IDX, |
| 28 |
D_GCUSER_IDX, |
| 29 |
D_WIIROOT_IDX, |
| 30 |
D_TRIUSER_IDX, |
| 31 |
D_SESSION_WIIROOT_IDX, |
| 32 |
D_CONFIG_IDX, |
| 33 |
D_GAMESETTINGS_IDX, |
| 34 |
|
| 35 |
D_SKYLANDERS_IDX, |
| 36 |
|
| 37 |
D_MAPS_IDX, |
| 38 |
D_CACHE_IDX, |
| 39 |
D_COVERCACHE_IDX, |
| 40 |
D_REDUMPCACHE_IDX, |
| 41 |
D_SHADERCACHE_IDX, |
| 42 |
D_RETROACHIEVEMENTSCACHE_IDX, |
| 43 |
D_SHADERS_IDX, |
| 44 |
D_STATESAVES_IDX, |
| 45 |
D_SCREENSHOTS_IDX, |
| 46 |
D_HIRESTEXTURES_IDX, |
| 47 |
D_RIIVOLUTION_IDX, |
| 48 |
D_DUMP_IDX, |
| 49 |
D_DUMPFRAMES_IDX, |
| 50 |
D_DUMPOBJECTS_IDX, |
| 51 |
D_DUMPAUDIO_IDX, |
| 52 |
D_DUMPTEXTURES_IDX, |
| 53 |
D_DUMPDSP_IDX, |
| 54 |
D_DUMPSSL_IDX, |
| 55 |
D_DUMPDEBUG_IDX, |
| 56 |
D_DUMPDEBUG_BRANCHWATCH_IDX, |
| 57 |
D_DUMPDEBUG_JITBLOCKS_IDX, |
| 58 |
D_LOAD_IDX, |
| 59 |
D_LOGS_IDX, |
| 60 |
D_THEMES_IDX, |
| 61 |
D_STYLES_IDX, |
| 62 |
D_PIPES_IDX, |
| 63 |
D_MEMORYWATCHER_IDX, |
| 64 |
D_WFSROOT_IDX, |
| 65 |
D_BACKUP_IDX, |
| 66 |
D_RESOURCEPACK_IDX, |
| 67 |
D_DYNAMICINPUT_IDX, |
| 68 |
D_GRAPHICSMOD_IDX, |
| 69 |
D_FIRMWARE_IDX, |
| 70 |
D_GBAUSER_IDX, |
| 71 |
D_GBASAVES_IDX, |
| 72 |
D_WIISDCARDSYNCFOLDER_IDX, |
| 73 |
D_WIISYSCONF_IDX, |
| 74 |
D_GPU_DRIVERS_EXTRACTED, |
| 75 |
D_GPU_DRIVERS_TMP, |
| 76 |
D_GPU_DRIVERS_HOOKS, |
| 77 |
D_GPU_DRIVERS_FILE_REDIRECT, |
| 78 |
D_ASM_ROOT_IDX, |
| 79 |
D_BANNERS_WIIROOT_IDX, |
| 80 |
FIRST_FILE_USER_PATH_IDX, |
| 81 |
F_DOLPHINCONFIG_IDX = FIRST_FILE_USER_PATH_IDX, |
| 82 |
F_GCPADCONFIG_IDX, |
| 83 |
F_WIIPADCONFIG_IDX, |
| 84 |
F_GCKEYBOARDCONFIG_IDX, |
| 85 |
F_GFXCONFIG_IDX, |
| 86 |
F_LOGGERCONFIG_IDX, |
| 87 |
F_MAINLOG_IDX, |
| 88 |
F_MEM1DUMP_IDX, |
| 89 |
F_MEM2DUMP_IDX, |
| 90 |
F_ARAMDUMP_IDX, |
| 91 |
F_FAKEVMEMDUMP_IDX, |
| 92 |
F_GCSRAM_IDX, |
| 93 |
F_MEMORYWATCHERLOCATIONS_IDX, |
| 94 |
F_MEMORYWATCHERSOCKET_IDX, |
| 95 |
F_WIISDCARDIMAGE_IDX, |
| 96 |
F_WIISYSCONF_IDX, |
| 97 |
F_DUALSHOCKUDPCLIENTCONFIG_IDX, |
| 98 |
F_FREELOOKCONFIG_IDX, |
| 99 |
F_GBABIOS_IDX, |
| 100 |
F_RETROACHIEVEMENTSCONFIG_IDX, |
| 101 |
NUM_PATH_INDICES |
| 102 |
}; |
| 103 |
|
| 104 |
namespace File |
| 105 |
{ |
| 106 |
|
| 107 |
struct FSTEntry |
| 108 |
{ |
| 109 |
bool isDirectory = false; |
| 110 |
u64 size = 0; |
| 111 |
std::string physicalName; |
| 112 |
std::string virtualName; |
| 113 |
std::vector<FSTEntry> children; |
| 114 |
}; |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
class FileInfo final |
| 121 |
{ |
| 122 |
public: |
| 123 |
explicit FileInfo(const std::string& path); |
| 124 |
explicit FileInfo(const char* path); |
| 125 |
|
| 126 |
|
| 127 |
bool Exists() const; |
| 128 |
|
| 129 |
bool IsDirectory() const; |
| 130 |
|
| 131 |
bool IsFile() const; |
| 132 |
|
| 133 |
u64 GetSize() const; |
| 134 |
|
| 135 |
private: |
| 136 |
std::filesystem::file_status m_status; |
| 137 |
std::uintmax_t m_size; |
| 138 |
bool m_exists; |
| 139 |
}; |
| 140 |
|
| 141 |
|
| 142 |
bool Exists(const std::string& path); |
| 143 |
|
| 144 |
|
| 145 |
bool IsDirectory(const std::string& path); |
| 146 |
|
| 147 |
|
| 148 |
bool IsFile(const std::string& path); |
| 149 |
|
| 150 |
|
| 151 |
u64 GetSize(const std::string& path); |
| 152 |
|
| 153 |
|
| 154 |
u64 GetSize(FILE* f); |
| 155 |
|
| 156 |
|
| 157 |
bool CreateDir(const std::string& filename); |
| 158 |
|
| 159 |
|
| 160 |
bool CreateDirs(std::string_view filename); |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
bool CreateFullPath(std::string_view fullPath); |
| 166 |
|
| 167 |
enum class IfAbsentBehavior |
| 168 |
{ |
| 169 |
ConsoleWarning, |
| 170 |
NoConsoleWarning |
| 171 |
}; |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
bool Delete(const std::string& filename, |
| 176 |
IfAbsentBehavior behavior = IfAbsentBehavior::ConsoleWarning); |
| 177 |
|
| 178 |
|
| 179 |
bool DeleteDir(const std::string& filename, |
| 180 |
IfAbsentBehavior behavior = IfAbsentBehavior::ConsoleWarning); |
| 181 |
|
| 182 |
|
| 183 |
bool Rename(const std::string& srcFilename, const std::string& destFilename); |
| 184 |
|
| 185 |
|
| 186 |
bool RenameSync(const std::string& srcFilename, const std::string& destFilename); |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
bool CopyRegularFile(std::string_view source_path, std::string_view destination_path); |
| 191 |
|
| 192 |
|
| 193 |
bool CreateEmptyFile(const std::string& filename); |
| 194 |
|
| 195 |
|
| 196 |
FSTEntry ScanDirectoryTree(const std::string& directory, bool recursive); |
| 197 |
|
| 198 |
|
| 199 |
bool DeleteDirRecursively(const std::string& directory); |
| 200 |
|
| 201 |
|
| 202 |
std::string GetCurrentDir(); |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
bool Copy(std::string_view source_path, std::string_view dest_path, |
| 207 |
bool overwrite_existing = false); |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
bool MoveWithOverwrite(std::string_view source_path, std::string_view dest_path); |
| 215 |
|
| 216 |
|
| 217 |
bool SetCurrentDir(const std::string& directory); |
| 218 |
|
| 219 |
|
| 220 |
std::string CreateTempDir(); |
| 221 |
|
| 222 |
|
| 223 |
std::string GetTempFilenameForAtomicWrite(std::string path); |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
const std::string& GetUserPath(unsigned int dir_index); |
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
void SetUserPath(unsigned int dir_index, std::string path); |
| 232 |
|
| 233 |
|
| 234 |
std::string GetThemeDir(const std::string& theme_name); |
| 235 |
|
| 236 |
|
| 237 |
const std::string& GetSysDirectory(); |
| 238 |
|
| 239 |
#ifdef ANDROID |
| 240 |
void SetSysDirectory(const std::string& path); |
| 241 |
void SetGpuDriverDirectories(const std::string& path, const std::string& lib_path); |
| 242 |
const std::string GetGpuDriverDirectory(unsigned int dir_index); |
| 243 |
#endif |
| 244 |
|
| 245 |
#ifdef __APPLE__ |
| 246 |
std::string GetBundleDirectory(); |
| 247 |
#endif |
| 248 |
|
| 249 |
std::string GetExePath(); |
| 250 |
std::string GetExeDirectory(); |
| 251 |
|
| 252 |
bool WriteStringToFile(const std::string& filename, std::string_view str); |
| 253 |
bool ReadFileToString(const std::string& filename, std::string& str); |
| 254 |
|
| 255 |
|
| 256 |
template <typename T> |
| 257 |
void OpenFStream(T& fstream, const std::string& filename, std::ios_base::openmode openmode) |
| 258 |
{ |
| 259 |
#ifdef _WIN32 |
| 260 |
fstream.open(UTF8ToTStr(filename).c_str(), openmode); |
| 261 |
#else |
| 262 |
#ifdef ANDROID |
| 263 |
|
| 264 |
if (IsPathAndroidContent(filename)) |
| 265 |
fstream.__open(OpenAndroidContent(filename, OpenModeToAndroid(openmode)), openmode); |
| 266 |
else |
| 267 |
#endif |
| 268 |
fstream.open(filename.c_str(), openmode); |
| 269 |
#endif |
| 270 |
} |
| 271 |
|
| 272 |
} |