Changeset View
Changeset View
Standalone View
Standalone View
source/lib/file/file_system.cpp
/* Copyright (C) 2021 Wildfire Games. | /* Copyright (C) 2021 Wildfire Games. | ||||
Lint: Inaccurate Copyright Year: Inaccurate Copyright Year | |||||
* | * | ||||
* Permission is hereby granted, free of charge, to any person obtaining | * Permission is hereby granted, free of charge, to any person obtaining | ||||
* a copy of this software and associated documentation files (the | * a copy of this software and associated documentation files (the | ||||
* "Software"), to deal in the Software without restriction, including | * "Software"), to deal in the Software without restriction, including | ||||
* without limitation the rights to use, copy, modify, merge, publish, | * without limitation the rights to use, copy, modify, merge, publish, | ||||
* distribute, sublicense, and/or sell copies of the Software, and to | * distribute, sublicense, and/or sell copies of the Software, and to | ||||
* permit persons to whom the Software is furnished to do so, subject to | * permit persons to whom the Software is furnished to do so, subject to | ||||
* the following conditions: | * the following conditions: | ||||
▲ Show 20 Lines • Show All 185 Lines • ▼ Show 20 Lines | |||||
Status RenameFile(const OsPath& path, const OsPath& newPath) | Status RenameFile(const OsPath& path, const OsPath& newPath) | ||||
{ | { | ||||
if (path.empty()) | if (path.empty()) | ||||
return INFO::OK; | return INFO::OK; | ||||
try | try | ||||
{ | { | ||||
fs::rename(path.string8(), newPath.string8()); | fs::rename(fs::path(path.string()), fs::path(newPath.string())); | ||||
} | } | ||||
catch (fs::filesystem_error& err) | catch (fs::filesystem_error& err) | ||||
{ | { | ||||
debug_printf("RenameFile: failed to rename %s to %s.\n%s\n", path.string8().c_str(), path.string8().c_str(), err.what()); | debug_printf("RenameFile: failed to rename %s to %s.\n%s\n", path.string8().c_str(), path.string8().c_str(), err.what()); | ||||
return ERR::EXCEPTION; | return ERR::EXCEPTION; | ||||
} | } | ||||
return INFO::OK; | return INFO::OK; | ||||
} | } | ||||
Status CopyFile(const OsPath& path, const OsPath& newPath, bool override_if_exists/* = false*/) | Status CopyFile(const OsPath& path, const OsPath& newPath, bool override_if_exists/* = false*/) | ||||
{ | { | ||||
if(path.empty()) | if(path.empty()) | ||||
return INFO::OK; | return INFO::OK; | ||||
try | try | ||||
{ | { | ||||
if(override_if_exists) | if(override_if_exists) | ||||
fs::copy_file(path.string8(), newPath.string8(), boost::filesystem::copy_option::overwrite_if_exists); | fs::copy_file(fs::path(path.string()), fs::path(newPath.string()), boost::filesystem::copy_option::overwrite_if_exists); | ||||
else | else | ||||
fs::copy_file(path.string8(), newPath.string8()); | fs::copy_file(fs::path(path.string()), fs::path(newPath.string())); | ||||
} | } | ||||
catch(fs::filesystem_error& err) | catch(fs::filesystem_error& err) | ||||
{ | { | ||||
debug_printf("CopyFile: failed to copy %s to %s.\n%s\n", path.string8().c_str(), path.string8().c_str(), err.what()); | debug_printf("CopyFile: failed to copy %s to %s.\n%s\n", path.string8().c_str(), path.string8().c_str(), err.what()); | ||||
return ERR::EXCEPTION; | return ERR::EXCEPTION; | ||||
} | } | ||||
return INFO::OK; | return INFO::OK; | ||||
} | } |
Wildfire Games · Phabricator
Inaccurate Copyright Year