mirror of https://github.com/OpenRCT2/OpenRCT2.git
Make File/Path calls more robust
This commit is contained in:
parent
3752a5ab05
commit
46abcda068
|
@ -27,7 +27,9 @@ namespace File
|
||||||
{
|
{
|
||||||
fs::path file = u8path(path);
|
fs::path file = u8path(path);
|
||||||
log_verbose("Checking if file exists: %s", std::string(path).c_str());
|
log_verbose("Checking if file exists: %s", std::string(path).c_str());
|
||||||
return fs::exists(file);
|
std::error_code ec;
|
||||||
|
const auto result = fs::exists(file, ec);
|
||||||
|
return result && ec.value() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Copy(std::string_view srcPath, std::string_view dstPath, bool overwrite)
|
bool Copy(std::string_view srcPath, std::string_view dstPath, bool overwrite)
|
||||||
|
@ -38,25 +40,23 @@ namespace File
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fs::copy_file(u8path(srcPath), u8path(dstPath));
|
std::error_code ec;
|
||||||
|
const auto result = fs::copy_file(u8path(srcPath), u8path(dstPath), ec);
|
||||||
|
return result && ec.value() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Delete(std::string_view path)
|
bool Delete(std::string_view path)
|
||||||
{
|
{
|
||||||
return fs::remove(u8path(path));
|
std::error_code ec;
|
||||||
|
const auto result = fs::remove(u8path(path), ec);
|
||||||
|
return result && ec.value() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Move(std::string_view srcPath, std::string_view dstPath)
|
bool Move(std::string_view srcPath, std::string_view dstPath)
|
||||||
{
|
{
|
||||||
try
|
std::error_code ec;
|
||||||
{
|
fs::rename(u8path(srcPath), u8path(dstPath), ec);
|
||||||
fs::rename(u8path(srcPath), u8path(dstPath));
|
return ec.value() == 0;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (const fs::filesystem_error&)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<uint8_t> ReadAllBytes(std::string_view path)
|
std::vector<uint8_t> ReadAllBytes(std::string_view path)
|
||||||
|
|
|
@ -66,7 +66,9 @@ namespace Path
|
||||||
|
|
||||||
bool DirectoryExists(std::string_view path)
|
bool DirectoryExists(std::string_view path)
|
||||||
{
|
{
|
||||||
return fs::is_directory(u8path(path));
|
std::error_code ec;
|
||||||
|
const auto result = fs::is_directory(u8path(path), ec);
|
||||||
|
return result && ec.value() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetFileName(std::string_view path)
|
std::string GetFileName(std::string_view path)
|
||||||
|
@ -107,6 +109,8 @@ namespace Path
|
||||||
|
|
||||||
bool DeleteDirectory(std::string_view path)
|
bool DeleteDirectory(std::string_view path)
|
||||||
{
|
{
|
||||||
return fs::remove_all(u8path(path)) > 0;
|
std::error_code ec;
|
||||||
|
const auto result = fs::remove_all(u8path(path), ec);
|
||||||
|
return (result > 0) && ec.value() == 0;
|
||||||
}
|
}
|
||||||
} // namespace Path
|
} // namespace Path
|
||||||
|
|
Loading…
Reference in New Issue