mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-25 23:55:38 +00:00
Added a FileSystemUtil function to create an empty file
This commit is contained in:
parent
0267a9db00
commit
66555101bf
|
@ -733,6 +733,40 @@ namespace Utils
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool createEmptyFile(const std::string& path)
|
||||||
|
{
|
||||||
|
if (exists(path)) {
|
||||||
|
#if defined(_WIN64)
|
||||||
|
LOG(LogError) << "Couldn't create target file \""
|
||||||
|
<< Utils::String::replace(path, "/", "\\")
|
||||||
|
<< "\" as it already exists";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ofstream targetFile {Utils::String::stringToWideString(path).c_str(),
|
||||||
|
std::ios::binary};
|
||||||
|
if (targetFile.fail()) {
|
||||||
|
LOG(LogError) << "Couldn't create target file \""
|
||||||
|
<< Utils::String::replace(path, "/", "\\")
|
||||||
|
#else
|
||||||
|
LOG(LogError) << "Couldn't create target file \"" << path
|
||||||
|
<< "\" as it already exists";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ofstream targetFile {path, std::ios::binary};
|
||||||
|
if (targetFile.fail()) {
|
||||||
|
LOG(LogError) << "Couldn't create target file \"" << path
|
||||||
|
#endif
|
||||||
|
<< "\", permission problems?";
|
||||||
|
targetFile.close();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
targetFile.close();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool removeFile(const std::string& path)
|
bool removeFile(const std::string& path)
|
||||||
{
|
{
|
||||||
const std::string& genericPath {getGenericPath(path)};
|
const std::string& genericPath {getGenericPath(path)};
|
||||||
|
|
|
@ -58,6 +58,7 @@ namespace Utils
|
||||||
bool renameFile(const std::string& sourcePath,
|
bool renameFile(const std::string& sourcePath,
|
||||||
const std::string& destinationPath,
|
const std::string& destinationPath,
|
||||||
bool overwrite);
|
bool overwrite);
|
||||||
|
bool createEmptyFile(const std::string& path);
|
||||||
bool removeFile(const std::string& path);
|
bool removeFile(const std::string& path);
|
||||||
bool removeDirectory(const std::string& path);
|
bool removeDirectory(const std::string& path);
|
||||||
bool createDirectory(const std::string& path);
|
bool createDirectory(const std::string& path);
|
||||||
|
|
Loading…
Reference in a new issue