summaryrefslogtreecommitdiff
path: root/src/common/file_util.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2014-09-18 22:27:06 -0400
committerGravatar bunnei2014-09-18 22:27:06 -0400
commita9630a9d2b432bea7bdfef4aa462035b98b34517 (patch)
tree258010943e989fc61a2a439ff15ead7ed3d11a6f /src/common/file_util.cpp
parentMerge pull request #107 from lioncash/sprintf (diff)
parentKernel: Implement the Close command for Archive, File and Directory. (diff)
downloadyuzu-a9630a9d2b432bea7bdfef4aa462035b98b34517.tar.gz
yuzu-a9630a9d2b432bea7bdfef4aa462035b98b34517.tar.xz
yuzu-a9630a9d2b432bea7bdfef4aa462035b98b34517.zip
Merge pull request #70 from linkmauve/master
Implement filesystem services, and the required kernel objects.
Diffstat (limited to 'src/common/file_util.cpp')
-rw-r--r--src/common/file_util.cpp38
1 files changed, 19 insertions, 19 deletions
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp
index 970041007..ecfccbd66 100644
--- a/src/common/file_util.cpp
+++ b/src/common/file_util.cpp
@@ -39,7 +39,7 @@
39// This namespace has various generic functions related to files and paths. 39// This namespace has various generic functions related to files and paths.
40// The code still needs a ton of cleanup. 40// The code still needs a ton of cleanup.
41// REMEMBER: strdup considered harmful! 41// REMEMBER: strdup considered harmful!
42namespace File 42namespace FileUtil
43{ 43{
44 44
45// Remove any ending forward slashes from directory paths 45// Remove any ending forward slashes from directory paths
@@ -172,7 +172,7 @@ bool CreateFullPath(const std::string &fullPath)
172 int panicCounter = 100; 172 int panicCounter = 100;
173 INFO_LOG(COMMON, "CreateFullPath: path %s", fullPath.c_str()); 173 INFO_LOG(COMMON, "CreateFullPath: path %s", fullPath.c_str());
174 174
175 if (File::Exists(fullPath)) 175 if (FileUtil::Exists(fullPath))
176 { 176 {
177 INFO_LOG(COMMON, "CreateFullPath: path exists %s", fullPath.c_str()); 177 INFO_LOG(COMMON, "CreateFullPath: path exists %s", fullPath.c_str());
178 return true; 178 return true;
@@ -190,8 +190,8 @@ bool CreateFullPath(const std::string &fullPath)
190 190
191 // Include the '/' so the first call is CreateDir("/") rather than CreateDir("") 191 // Include the '/' so the first call is CreateDir("/") rather than CreateDir("")
192 std::string const subPath(fullPath.substr(0, position + 1)); 192 std::string const subPath(fullPath.substr(0, position + 1));
193 if (!File::IsDirectory(subPath)) 193 if (!FileUtil::IsDirectory(subPath))
194 File::CreateDir(subPath); 194 FileUtil::CreateDir(subPath);
195 195
196 // A safety check 196 // A safety check
197 panicCounter--; 197 panicCounter--;
@@ -211,7 +211,7 @@ bool DeleteDir(const std::string &filename)
211 INFO_LOG(COMMON, "DeleteDir: directory %s", filename.c_str()); 211 INFO_LOG(COMMON, "DeleteDir: directory %s", filename.c_str());
212 212
213 // check if a directory 213 // check if a directory
214 if (!File::IsDirectory(filename)) 214 if (!FileUtil::IsDirectory(filename))
215 { 215 {
216 ERROR_LOG(COMMON, "DeleteDir: Not a directory %s", filename.c_str()); 216 ERROR_LOG(COMMON, "DeleteDir: Not a directory %s", filename.c_str());
217 return false; 217 return false;
@@ -386,7 +386,7 @@ bool CreateEmptyFile(const std::string &filename)
386{ 386{
387 INFO_LOG(COMMON, "CreateEmptyFile: %s", filename.c_str()); 387 INFO_LOG(COMMON, "CreateEmptyFile: %s", filename.c_str());
388 388
389 if (!File::IOFile(filename, "wb")) 389 if (!FileUtil::IOFile(filename, "wb"))
390 { 390 {
391 ERROR_LOG(COMMON, "CreateEmptyFile: failed %s: %s", 391 ERROR_LOG(COMMON, "CreateEmptyFile: failed %s: %s",
392 filename.c_str(), GetLastErrorMsg()); 392 filename.c_str(), GetLastErrorMsg());
@@ -519,7 +519,7 @@ bool DeleteDirRecursively(const std::string &directory)
519 } 519 }
520 else 520 else
521 { 521 {
522 if (!File::Delete(newPath)) 522 if (!FileUtil::Delete(newPath))
523 { 523 {
524 #ifndef _WIN32 524 #ifndef _WIN32
525 closedir(dirp); 525 closedir(dirp);
@@ -536,7 +536,7 @@ bool DeleteDirRecursively(const std::string &directory)
536 } 536 }
537 closedir(dirp); 537 closedir(dirp);
538#endif 538#endif
539 File::DeleteDir(directory); 539 FileUtil::DeleteDir(directory);
540 540
541 return true; 541 return true;
542} 542}
@@ -546,8 +546,8 @@ void CopyDir(const std::string &source_path, const std::string &dest_path)
546{ 546{
547#ifndef _WIN32 547#ifndef _WIN32
548 if (source_path == dest_path) return; 548 if (source_path == dest_path) return;
549 if (!File::Exists(source_path)) return; 549 if (!FileUtil::Exists(source_path)) return;
550 if (!File::Exists(dest_path)) File::CreateFullPath(dest_path); 550 if (!FileUtil::Exists(dest_path)) FileUtil::CreateFullPath(dest_path);
551 551
552 struct dirent dirent, *result = NULL; 552 struct dirent dirent, *result = NULL;
553 DIR *dirp = opendir(source_path.c_str()); 553 DIR *dirp = opendir(source_path.c_str());
@@ -569,10 +569,10 @@ void CopyDir(const std::string &source_path, const std::string &dest_path)
569 { 569 {
570 source += '/'; 570 source += '/';
571 dest += '/'; 571 dest += '/';
572 if (!File::Exists(dest)) File::CreateFullPath(dest); 572 if (!FileUtil::Exists(dest)) FileUtil::CreateFullPath(dest);
573 CopyDir(source, dest); 573 CopyDir(source, dest);
574 } 574 }
575 else if (!File::Exists(dest)) File::Copy(source, dest); 575 else if (!FileUtil::Exists(dest)) FileUtil::Copy(source, dest);
576 } 576 }
577 closedir(dirp); 577 closedir(dirp);
578#endif 578#endif
@@ -660,7 +660,7 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string &new
660#ifdef _WIN32 660#ifdef _WIN32
661 paths[D_USER_IDX] = GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP; 661 paths[D_USER_IDX] = GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP;
662#else 662#else
663 if (File::Exists(ROOT_DIR DIR_SEP USERDATA_DIR)) 663 if (FileUtil::Exists(ROOT_DIR DIR_SEP USERDATA_DIR))
664 paths[D_USER_IDX] = ROOT_DIR DIR_SEP USERDATA_DIR DIR_SEP; 664 paths[D_USER_IDX] = ROOT_DIR DIR_SEP USERDATA_DIR DIR_SEP;
665 else 665 else
666 paths[D_USER_IDX] = std::string(getenv("HOME") ? 666 paths[D_USER_IDX] = std::string(getenv("HOME") ?
@@ -688,7 +688,7 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string &new
688 688
689 if (!newPath.empty()) 689 if (!newPath.empty())
690 { 690 {
691 if (!File::IsDirectory(newPath)) 691 if (!FileUtil::IsDirectory(newPath))
692 { 692 {
693 WARN_LOG(COMMON, "Invalid path specified %s", newPath.c_str()); 693 WARN_LOG(COMMON, "Invalid path specified %s", newPath.c_str());
694 return paths[DirIDX]; 694 return paths[DirIDX];
@@ -750,11 +750,11 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string &new
750 750
751//std::string GetThemeDir(const std::string& theme_name) 751//std::string GetThemeDir(const std::string& theme_name)
752//{ 752//{
753// std::string dir = File::GetUserPath(D_THEMES_IDX) + theme_name + "/"; 753// std::string dir = FileUtil::GetUserPath(D_THEMES_IDX) + theme_name + "/";
754// 754//
755//#if !defined(_WIN32) 755//#if !defined(_WIN32)
756// // If theme does not exist in user's dir load from shared directory 756// // If theme does not exist in user's dir load from shared directory
757// if (!File::Exists(dir)) 757// if (!FileUtil::Exists(dir))
758// dir = SHARED_USER_DIR THEMES_DIR "/" + theme_name + "/"; 758// dir = SHARED_USER_DIR THEMES_DIR "/" + theme_name + "/";
759//#endif 759//#endif
760// 760//
@@ -763,12 +763,12 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string &new
763 763
764bool WriteStringToFile(bool text_file, const std::string &str, const char *filename) 764bool WriteStringToFile(bool text_file, const std::string &str, const char *filename)
765{ 765{
766 return File::IOFile(filename, text_file ? "w" : "wb").WriteBytes(str.data(), str.size()); 766 return FileUtil::IOFile(filename, text_file ? "w" : "wb").WriteBytes(str.data(), str.size());
767} 767}
768 768
769bool ReadFileToString(bool text_file, const char *filename, std::string &str) 769bool ReadFileToString(bool text_file, const char *filename, std::string &str)
770{ 770{
771 File::IOFile file(filename, text_file ? "r" : "rb"); 771 FileUtil::IOFile file(filename, text_file ? "r" : "rb");
772 auto const f = file.GetHandle(); 772 auto const f = file.GetHandle();
773 773
774 if (!f) 774 if (!f)
@@ -854,7 +854,7 @@ void IOFile::SetHandle(std::FILE* file)
854u64 IOFile::GetSize() 854u64 IOFile::GetSize()
855{ 855{
856 if (IsOpen()) 856 if (IsOpen())
857 return File::GetSize(m_file); 857 return FileUtil::GetSize(m_file);
858 else 858 else
859 return 0; 859 return 0;
860} 860}