mirror of
https://github.com/Lime3DS/Lime3DS
synced 2024-12-27 01:22:37 -06:00
Common: Rename the File namespace to FileUtil, to match the filename and prevent collisions.
This commit is contained in:
parent
edaf59a759
commit
6b7b36a874
8 changed files with 31 additions and 31 deletions
|
@ -671,7 +671,7 @@ public:
|
||||||
_failureReason->clear();
|
_failureReason->clear();
|
||||||
_failureReason->append("LoadStateWrongVersion");
|
_failureReason->append("LoadStateWrongVersion");
|
||||||
|
|
||||||
if (!File::Exists(_rFilename)) {
|
if (!FileUtil::Exists(_rFilename)) {
|
||||||
_failureReason->clear();
|
_failureReason->clear();
|
||||||
_failureReason->append("LoadStateDoesntExist");
|
_failureReason->append("LoadStateDoesntExist");
|
||||||
ERROR_LOG(COMMON, "ChunkReader: File doesn't exist");
|
ERROR_LOG(COMMON, "ChunkReader: File doesn't exist");
|
||||||
|
@ -679,7 +679,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check file size
|
// Check file size
|
||||||
const u64 fileSize = File::GetSize(_rFilename);
|
const u64 fileSize = FileUtil::GetSize(_rFilename);
|
||||||
static const u64 headerSize = sizeof(SChunkHeader);
|
static const u64 headerSize = sizeof(SChunkHeader);
|
||||||
if (fileSize < headerSize)
|
if (fileSize < headerSize)
|
||||||
{
|
{
|
||||||
|
@ -687,7 +687,7 @@ public:
|
||||||
return ERROR_BAD_FILE;
|
return ERROR_BAD_FILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
File::IOFile pFile(_rFilename, "rb");
|
FileUtil::IOFile pFile(_rFilename, "rb");
|
||||||
if (!pFile)
|
if (!pFile)
|
||||||
{
|
{
|
||||||
ERROR_LOG(COMMON,"ChunkReader: Can't open file for reading");
|
ERROR_LOG(COMMON,"ChunkReader: Can't open file for reading");
|
||||||
|
@ -765,7 +765,7 @@ public:
|
||||||
{
|
{
|
||||||
INFO_LOG(COMMON, "ChunkReader: Writing %s" , _rFilename.c_str());
|
INFO_LOG(COMMON, "ChunkReader: Writing %s" , _rFilename.c_str());
|
||||||
|
|
||||||
File::IOFile pFile(_rFilename, "wb");
|
FileUtil::IOFile pFile(_rFilename, "wb");
|
||||||
if (!pFile)
|
if (!pFile)
|
||||||
{
|
{
|
||||||
ERROR_LOG(COMMON,"ChunkReader: Error opening file for write");
|
ERROR_LOG(COMMON,"ChunkReader: Error opening file for write");
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
// This namespace has various generic functions related to files and paths.
|
// This namespace has various generic functions related to files and paths.
|
||||||
// The code still needs a ton of cleanup.
|
// The code still needs a ton of cleanup.
|
||||||
// REMEMBER: strdup considered harmful!
|
// REMEMBER: strdup considered harmful!
|
||||||
namespace File
|
namespace FileUtil
|
||||||
{
|
{
|
||||||
|
|
||||||
// Remove any ending forward slashes from directory paths
|
// Remove any ending forward slashes from directory paths
|
||||||
|
@ -172,7 +172,7 @@ bool CreateFullPath(const std::string &fullPath)
|
||||||
int panicCounter = 100;
|
int panicCounter = 100;
|
||||||
INFO_LOG(COMMON, "CreateFullPath: path %s", fullPath.c_str());
|
INFO_LOG(COMMON, "CreateFullPath: path %s", fullPath.c_str());
|
||||||
|
|
||||||
if (File::Exists(fullPath))
|
if (FileUtil::Exists(fullPath))
|
||||||
{
|
{
|
||||||
INFO_LOG(COMMON, "CreateFullPath: path exists %s", fullPath.c_str());
|
INFO_LOG(COMMON, "CreateFullPath: path exists %s", fullPath.c_str());
|
||||||
return true;
|
return true;
|
||||||
|
@ -190,8 +190,8 @@ bool CreateFullPath(const std::string &fullPath)
|
||||||
|
|
||||||
// Include the '/' so the first call is CreateDir("/") rather than CreateDir("")
|
// Include the '/' so the first call is CreateDir("/") rather than CreateDir("")
|
||||||
std::string const subPath(fullPath.substr(0, position + 1));
|
std::string const subPath(fullPath.substr(0, position + 1));
|
||||||
if (!File::IsDirectory(subPath))
|
if (!FileUtil::IsDirectory(subPath))
|
||||||
File::CreateDir(subPath);
|
FileUtil::CreateDir(subPath);
|
||||||
|
|
||||||
// A safety check
|
// A safety check
|
||||||
panicCounter--;
|
panicCounter--;
|
||||||
|
@ -211,7 +211,7 @@ bool DeleteDir(const std::string &filename)
|
||||||
INFO_LOG(COMMON, "DeleteDir: directory %s", filename.c_str());
|
INFO_LOG(COMMON, "DeleteDir: directory %s", filename.c_str());
|
||||||
|
|
||||||
// check if a directory
|
// check if a directory
|
||||||
if (!File::IsDirectory(filename))
|
if (!FileUtil::IsDirectory(filename))
|
||||||
{
|
{
|
||||||
ERROR_LOG(COMMON, "DeleteDir: Not a directory %s", filename.c_str());
|
ERROR_LOG(COMMON, "DeleteDir: Not a directory %s", filename.c_str());
|
||||||
return false;
|
return false;
|
||||||
|
@ -386,7 +386,7 @@ bool CreateEmptyFile(const std::string &filename)
|
||||||
{
|
{
|
||||||
INFO_LOG(COMMON, "CreateEmptyFile: %s", filename.c_str());
|
INFO_LOG(COMMON, "CreateEmptyFile: %s", filename.c_str());
|
||||||
|
|
||||||
if (!File::IOFile(filename, "wb"))
|
if (!FileUtil::IOFile(filename, "wb"))
|
||||||
{
|
{
|
||||||
ERROR_LOG(COMMON, "CreateEmptyFile: failed %s: %s",
|
ERROR_LOG(COMMON, "CreateEmptyFile: failed %s: %s",
|
||||||
filename.c_str(), GetLastErrorMsg());
|
filename.c_str(), GetLastErrorMsg());
|
||||||
|
@ -519,7 +519,7 @@ bool DeleteDirRecursively(const std::string &directory)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!File::Delete(newPath))
|
if (!FileUtil::Delete(newPath))
|
||||||
{
|
{
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
closedir(dirp);
|
closedir(dirp);
|
||||||
|
@ -536,7 +536,7 @@ bool DeleteDirRecursively(const std::string &directory)
|
||||||
}
|
}
|
||||||
closedir(dirp);
|
closedir(dirp);
|
||||||
#endif
|
#endif
|
||||||
File::DeleteDir(directory);
|
FileUtil::DeleteDir(directory);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -546,8 +546,8 @@ void CopyDir(const std::string &source_path, const std::string &dest_path)
|
||||||
{
|
{
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
if (source_path == dest_path) return;
|
if (source_path == dest_path) return;
|
||||||
if (!File::Exists(source_path)) return;
|
if (!FileUtil::Exists(source_path)) return;
|
||||||
if (!File::Exists(dest_path)) File::CreateFullPath(dest_path);
|
if (!FileUtil::Exists(dest_path)) FileUtil::CreateFullPath(dest_path);
|
||||||
|
|
||||||
struct dirent dirent, *result = NULL;
|
struct dirent dirent, *result = NULL;
|
||||||
DIR *dirp = opendir(source_path.c_str());
|
DIR *dirp = opendir(source_path.c_str());
|
||||||
|
@ -569,10 +569,10 @@ void CopyDir(const std::string &source_path, const std::string &dest_path)
|
||||||
{
|
{
|
||||||
source += '/';
|
source += '/';
|
||||||
dest += '/';
|
dest += '/';
|
||||||
if (!File::Exists(dest)) File::CreateFullPath(dest);
|
if (!FileUtil::Exists(dest)) FileUtil::CreateFullPath(dest);
|
||||||
CopyDir(source, dest);
|
CopyDir(source, dest);
|
||||||
}
|
}
|
||||||
else if (!File::Exists(dest)) File::Copy(source, dest);
|
else if (!FileUtil::Exists(dest)) FileUtil::Copy(source, dest);
|
||||||
}
|
}
|
||||||
closedir(dirp);
|
closedir(dirp);
|
||||||
#endif
|
#endif
|
||||||
|
@ -660,7 +660,7 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string &new
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
paths[D_USER_IDX] = GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP;
|
paths[D_USER_IDX] = GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP;
|
||||||
#else
|
#else
|
||||||
if (File::Exists(ROOT_DIR DIR_SEP USERDATA_DIR))
|
if (FileUtil::Exists(ROOT_DIR DIR_SEP USERDATA_DIR))
|
||||||
paths[D_USER_IDX] = ROOT_DIR DIR_SEP USERDATA_DIR DIR_SEP;
|
paths[D_USER_IDX] = ROOT_DIR DIR_SEP USERDATA_DIR DIR_SEP;
|
||||||
else
|
else
|
||||||
paths[D_USER_IDX] = std::string(getenv("HOME") ?
|
paths[D_USER_IDX] = std::string(getenv("HOME") ?
|
||||||
|
@ -688,7 +688,7 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string &new
|
||||||
|
|
||||||
if (!newPath.empty())
|
if (!newPath.empty())
|
||||||
{
|
{
|
||||||
if (!File::IsDirectory(newPath))
|
if (!FileUtil::IsDirectory(newPath))
|
||||||
{
|
{
|
||||||
WARN_LOG(COMMON, "Invalid path specified %s", newPath.c_str());
|
WARN_LOG(COMMON, "Invalid path specified %s", newPath.c_str());
|
||||||
return paths[DirIDX];
|
return paths[DirIDX];
|
||||||
|
@ -750,11 +750,11 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string &new
|
||||||
|
|
||||||
//std::string GetThemeDir(const std::string& theme_name)
|
//std::string GetThemeDir(const std::string& theme_name)
|
||||||
//{
|
//{
|
||||||
// std::string dir = File::GetUserPath(D_THEMES_IDX) + theme_name + "/";
|
// std::string dir = FileUtil::GetUserPath(D_THEMES_IDX) + theme_name + "/";
|
||||||
//
|
//
|
||||||
//#if !defined(_WIN32)
|
//#if !defined(_WIN32)
|
||||||
// // If theme does not exist in user's dir load from shared directory
|
// // If theme does not exist in user's dir load from shared directory
|
||||||
// if (!File::Exists(dir))
|
// if (!FileUtil::Exists(dir))
|
||||||
// dir = SHARED_USER_DIR THEMES_DIR "/" + theme_name + "/";
|
// dir = SHARED_USER_DIR THEMES_DIR "/" + theme_name + "/";
|
||||||
//#endif
|
//#endif
|
||||||
//
|
//
|
||||||
|
@ -763,12 +763,12 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string &new
|
||||||
|
|
||||||
bool WriteStringToFile(bool text_file, const std::string &str, const char *filename)
|
bool WriteStringToFile(bool text_file, const std::string &str, const char *filename)
|
||||||
{
|
{
|
||||||
return File::IOFile(filename, text_file ? "w" : "wb").WriteBytes(str.data(), str.size());
|
return FileUtil::IOFile(filename, text_file ? "w" : "wb").WriteBytes(str.data(), str.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ReadFileToString(bool text_file, const char *filename, std::string &str)
|
bool ReadFileToString(bool text_file, const char *filename, std::string &str)
|
||||||
{
|
{
|
||||||
File::IOFile file(filename, text_file ? "r" : "rb");
|
FileUtil::IOFile file(filename, text_file ? "r" : "rb");
|
||||||
auto const f = file.GetHandle();
|
auto const f = file.GetHandle();
|
||||||
|
|
||||||
if (!f)
|
if (!f)
|
||||||
|
@ -854,7 +854,7 @@ void IOFile::SetHandle(std::FILE* file)
|
||||||
u64 IOFile::GetSize()
|
u64 IOFile::GetSize()
|
||||||
{
|
{
|
||||||
if (IsOpen())
|
if (IsOpen())
|
||||||
return File::GetSize(m_file);
|
return FileUtil::GetSize(m_file);
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ enum {
|
||||||
NUM_PATH_INDICES
|
NUM_PATH_INDICES
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace File
|
namespace FileUtil
|
||||||
{
|
{
|
||||||
|
|
||||||
// FileSystem tree node/
|
// FileSystem tree node/
|
||||||
|
|
|
@ -75,7 +75,7 @@ LogManager::LogManager()
|
||||||
m_Log[LogTypes::MEMCARD_MANAGER] = new LogContainer("MemCard Manager", "MemCard Manager");
|
m_Log[LogTypes::MEMCARD_MANAGER] = new LogContainer("MemCard Manager", "MemCard Manager");
|
||||||
m_Log[LogTypes::NETPLAY] = new LogContainer("NETPLAY", "Netplay");
|
m_Log[LogTypes::NETPLAY] = new LogContainer("NETPLAY", "Netplay");
|
||||||
|
|
||||||
m_fileLog = new FileLogListener(File::GetUserPath(F_MAINLOG_IDX).c_str());
|
m_fileLog = new FileLogListener(FileUtil::GetUserPath(F_MAINLOG_IDX).c_str());
|
||||||
m_consoleLog = new ConsoleListener();
|
m_consoleLog = new ConsoleListener();
|
||||||
m_debuggerLog = new DebuggerLogListener();
|
m_debuggerLog = new DebuggerLogListener();
|
||||||
|
|
||||||
|
|
|
@ -351,7 +351,7 @@ ResultStatus AppLoader_ELF::Load() {
|
||||||
if (is_loaded)
|
if (is_loaded)
|
||||||
return ResultStatus::ErrorAlreadyLoaded;
|
return ResultStatus::ErrorAlreadyLoaded;
|
||||||
|
|
||||||
File::IOFile file(filename, "rb");
|
FileUtil::IOFile file(filename, "rb");
|
||||||
|
|
||||||
if (file.IsOpen()) {
|
if (file.IsOpen()) {
|
||||||
u32 size = (u32)file.GetSize();
|
u32 size = (u32)file.GetSize();
|
||||||
|
|
|
@ -78,7 +78,7 @@ ResultStatus LoadFile(const std::string& filename) {
|
||||||
{
|
{
|
||||||
INFO_LOG(LOADER, "Loading BIN file %s...", filename.c_str());
|
INFO_LOG(LOADER, "Loading BIN file %s...", filename.c_str());
|
||||||
|
|
||||||
File::IOFile file(filename, "rb");
|
FileUtil::IOFile file(filename, "rb");
|
||||||
|
|
||||||
if (file.IsOpen()) {
|
if (file.IsOpen()) {
|
||||||
file.ReadBytes(Memory::GetPointer(Memory::EXEFS_CODE_VADDR), (size_t)file.GetSize());
|
file.ReadBytes(Memory::GetPointer(Memory::EXEFS_CODE_VADDR), (size_t)file.GetSize());
|
||||||
|
|
|
@ -138,7 +138,7 @@ ResultStatus AppLoader_NCCH::LoadExec() const {
|
||||||
*/
|
*/
|
||||||
ResultStatus AppLoader_NCCH::LoadSectionExeFS(const char* name, std::vector<u8>& buffer) const {
|
ResultStatus AppLoader_NCCH::LoadSectionExeFS(const char* name, std::vector<u8>& buffer) const {
|
||||||
// Iterate through the ExeFs archive until we find the .code file...
|
// Iterate through the ExeFs archive until we find the .code file...
|
||||||
File::IOFile file(filename, "rb");
|
FileUtil::IOFile file(filename, "rb");
|
||||||
if (file.IsOpen()) {
|
if (file.IsOpen()) {
|
||||||
for (int i = 0; i < kMaxSections; i++) {
|
for (int i = 0; i < kMaxSections; i++) {
|
||||||
// Load the specified section...
|
// Load the specified section...
|
||||||
|
@ -199,7 +199,7 @@ ResultStatus AppLoader_NCCH::Load() {
|
||||||
if (is_loaded)
|
if (is_loaded)
|
||||||
return ResultStatus::ErrorAlreadyLoaded;
|
return ResultStatus::ErrorAlreadyLoaded;
|
||||||
|
|
||||||
File::IOFile file(filename, "rb");
|
FileUtil::IOFile file(filename, "rb");
|
||||||
if (file.IsOpen()) {
|
if (file.IsOpen()) {
|
||||||
file.ReadBytes(&ncch_header, sizeof(NCCH_Header));
|
file.ReadBytes(&ncch_header, sizeof(NCCH_Header));
|
||||||
|
|
||||||
|
@ -290,7 +290,7 @@ ResultStatus AppLoader_NCCH::ReadLogo(std::vector<u8>& buffer) const {
|
||||||
* @return ResultStatus result of function
|
* @return ResultStatus result of function
|
||||||
*/
|
*/
|
||||||
ResultStatus AppLoader_NCCH::ReadRomFS(std::vector<u8>& buffer) const {
|
ResultStatus AppLoader_NCCH::ReadRomFS(std::vector<u8>& buffer) const {
|
||||||
File::IOFile file(filename, "rb");
|
FileUtil::IOFile file(filename, "rb");
|
||||||
if (file.IsOpen()) {
|
if (file.IsOpen()) {
|
||||||
// Check if the NCCH has a RomFS...
|
// Check if the NCCH has a RomFS...
|
||||||
if (ncch_header.romfs_offset != 0 && ncch_header.romfs_size != 0) {
|
if (ncch_header.romfs_offset != 0 && ncch_header.romfs_size != 0) {
|
||||||
|
|
|
@ -336,7 +336,7 @@ void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data) {
|
||||||
png_infop info_ptr = nullptr;
|
png_infop info_ptr = nullptr;
|
||||||
|
|
||||||
// Open file for writing (binary mode)
|
// Open file for writing (binary mode)
|
||||||
File::IOFile fp(filename, "wb");
|
FileUtil::IOFile fp(filename, "wb");
|
||||||
|
|
||||||
// Initialize write structure
|
// Initialize write structure
|
||||||
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
|
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
|
||||||
|
|
Loading…
Reference in a new issue