summaryrefslogtreecommitdiff
path: root/src/common/file_util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/file_util.cpp')
-rw-r--r--src/common/file_util.cpp62
1 files changed, 31 insertions, 31 deletions
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp
index 35da07306..b6dec838c 100644
--- a/src/common/file_util.cpp
+++ b/src/common/file_util.cpp
@@ -88,7 +88,7 @@ bool IsDirectory(const std::string &filename)
88#endif 88#endif
89 89
90 if (result < 0) { 90 if (result < 0) {
91 WARN_LOG(COMMON, "IsDirectory: stat failed on %s: %s", 91 WARN_LOG(COMMON, "IsDirectory: stat failed on %s: %s",
92 filename.c_str(), GetLastErrorMsg()); 92 filename.c_str(), GetLastErrorMsg());
93 return false; 93 return false;
94 } 94 }
@@ -102,7 +102,7 @@ bool Delete(const std::string &filename)
102{ 102{
103 INFO_LOG(COMMON, "Delete: file %s", filename.c_str()); 103 INFO_LOG(COMMON, "Delete: file %s", filename.c_str());
104 104
105 // Return true because we care about the file no 105 // Return true because we care about the file no
106 // being there, not the actual delete. 106 // being there, not the actual delete.
107 if (!Exists(filename)) 107 if (!Exists(filename))
108 { 108 {
@@ -120,13 +120,13 @@ bool Delete(const std::string &filename)
120#ifdef _WIN32 120#ifdef _WIN32
121 if (!DeleteFile(Common::UTF8ToTStr(filename).c_str())) 121 if (!DeleteFile(Common::UTF8ToTStr(filename).c_str()))
122 { 122 {
123 WARN_LOG(COMMON, "Delete: DeleteFile failed on %s: %s", 123 WARN_LOG(COMMON, "Delete: DeleteFile failed on %s: %s",
124 filename.c_str(), GetLastErrorMsg()); 124 filename.c_str(), GetLastErrorMsg());
125 return false; 125 return false;
126 } 126 }
127#else 127#else
128 if (unlink(filename.c_str()) == -1) { 128 if (unlink(filename.c_str()) == -1) {
129 WARN_LOG(COMMON, "Delete: unlink failed on %s: %s", 129 WARN_LOG(COMMON, "Delete: unlink failed on %s: %s",
130 filename.c_str(), GetLastErrorMsg()); 130 filename.c_str(), GetLastErrorMsg());
131 return false; 131 return false;
132 } 132 }
@@ -232,28 +232,28 @@ bool DeleteDir(const std::string &filename)
232 return false; 232 return false;
233} 233}
234 234
235// renames file srcFilename to destFilename, returns true on success 235// renames file srcFilename to destFilename, returns true on success
236bool Rename(const std::string &srcFilename, const std::string &destFilename) 236bool Rename(const std::string &srcFilename, const std::string &destFilename)
237{ 237{
238 INFO_LOG(COMMON, "Rename: %s --> %s", 238 INFO_LOG(COMMON, "Rename: %s --> %s",
239 srcFilename.c_str(), destFilename.c_str()); 239 srcFilename.c_str(), destFilename.c_str());
240 if (rename(srcFilename.c_str(), destFilename.c_str()) == 0) 240 if (rename(srcFilename.c_str(), destFilename.c_str()) == 0)
241 return true; 241 return true;
242 ERROR_LOG(COMMON, "Rename: failed %s --> %s: %s", 242 ERROR_LOG(COMMON, "Rename: failed %s --> %s: %s",
243 srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg()); 243 srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
244 return false; 244 return false;
245} 245}
246 246
247// copies file srcFilename to destFilename, returns true on success 247// copies file srcFilename to destFilename, returns true on success
248bool Copy(const std::string &srcFilename, const std::string &destFilename) 248bool Copy(const std::string &srcFilename, const std::string &destFilename)
249{ 249{
250 INFO_LOG(COMMON, "Copy: %s --> %s", 250 INFO_LOG(COMMON, "Copy: %s --> %s",
251 srcFilename.c_str(), destFilename.c_str()); 251 srcFilename.c_str(), destFilename.c_str());
252#ifdef _WIN32 252#ifdef _WIN32
253 if (CopyFile(Common::UTF8ToTStr(srcFilename).c_str(), Common::UTF8ToTStr(destFilename).c_str(), FALSE)) 253 if (CopyFile(Common::UTF8ToTStr(srcFilename).c_str(), Common::UTF8ToTStr(destFilename).c_str(), FALSE))
254 return true; 254 return true;
255 255
256 ERROR_LOG(COMMON, "Copy: failed %s --> %s: %s", 256 ERROR_LOG(COMMON, "Copy: failed %s --> %s: %s",
257 srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg()); 257 srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
258 return false; 258 return false;
259#else 259#else
@@ -267,7 +267,7 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename)
267 FILE *input = fopen(srcFilename.c_str(), "rb"); 267 FILE *input = fopen(srcFilename.c_str(), "rb");
268 if (!input) 268 if (!input)
269 { 269 {
270 ERROR_LOG(COMMON, "Copy: input failed %s --> %s: %s", 270 ERROR_LOG(COMMON, "Copy: input failed %s --> %s: %s",
271 srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg()); 271 srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
272 return false; 272 return false;
273 } 273 }
@@ -277,7 +277,7 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename)
277 if (!output) 277 if (!output)
278 { 278 {
279 fclose(input); 279 fclose(input);
280 ERROR_LOG(COMMON, "Copy: output failed %s --> %s: %s", 280 ERROR_LOG(COMMON, "Copy: output failed %s --> %s: %s",
281 srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg()); 281 srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
282 return false; 282 return false;
283 } 283 }
@@ -291,8 +291,8 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename)
291 { 291 {
292 if (ferror(input) != 0) 292 if (ferror(input) != 0)
293 { 293 {
294 ERROR_LOG(COMMON, 294 ERROR_LOG(COMMON,
295 "Copy: failed reading from source, %s --> %s: %s", 295 "Copy: failed reading from source, %s --> %s: %s",
296 srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg()); 296 srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
297 goto bail; 297 goto bail;
298 } 298 }
@@ -302,8 +302,8 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename)
302 int wnum = fwrite(buffer, sizeof(char), rnum, output); 302 int wnum = fwrite(buffer, sizeof(char), rnum, output);
303 if (wnum != rnum) 303 if (wnum != rnum)
304 { 304 {
305 ERROR_LOG(COMMON, 305 ERROR_LOG(COMMON,
306 "Copy: failed writing to output, %s --> %s: %s", 306 "Copy: failed writing to output, %s --> %s: %s",
307 srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg()); 307 srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
308 goto bail; 308 goto bail;
309 } 309 }
@@ -335,7 +335,7 @@ u64 GetSize(const std::string &filename)
335 WARN_LOG(COMMON, "GetSize: failed %s: is a directory", filename.c_str()); 335 WARN_LOG(COMMON, "GetSize: failed %s: is a directory", filename.c_str());
336 return 0; 336 return 0;
337 } 337 }
338 338
339 struct stat64 buf; 339 struct stat64 buf;
340#ifdef _WIN32 340#ifdef _WIN32
341 if (_tstat64(Common::UTF8ToTStr(filename).c_str(), &buf) == 0) 341 if (_tstat64(Common::UTF8ToTStr(filename).c_str(), &buf) == 0)
@@ -384,10 +384,10 @@ u64 GetSize(FILE *f)
384 return size; 384 return size;
385} 385}
386 386
387// creates an empty file filename, returns true on success 387// creates an empty file filename, returns true on success
388bool CreateEmptyFile(const std::string &filename) 388bool CreateEmptyFile(const std::string &filename)
389{ 389{
390 INFO_LOG(COMMON, "CreateEmptyFile: %s", filename.c_str()); 390 INFO_LOG(COMMON, "CreateEmptyFile: %s", filename.c_str());
391 391
392 if (!FileUtil::IOFile(filename, "wb")) 392 if (!FileUtil::IOFile(filename, "wb"))
393 { 393 {
@@ -437,7 +437,7 @@ u32 ScanDirectoryTree(const std::string &directory, FSTEntry& parentEntry)
437#endif 437#endif
438 // check for "." and ".." 438 // check for "." and ".."
439 if (((virtualName[0] == '.') && (virtualName[1] == '\0')) || 439 if (((virtualName[0] == '.') && (virtualName[1] == '\0')) ||
440 ((virtualName[0] == '.') && (virtualName[1] == '.') && 440 ((virtualName[0] == '.') && (virtualName[1] == '.') &&
441 (virtualName[2] == '\0'))) 441 (virtualName[2] == '\0')))
442 continue; 442 continue;
443 entry.virtualName = virtualName; 443 entry.virtualName = virtualName;
@@ -452,14 +452,14 @@ u32 ScanDirectoryTree(const std::string &directory, FSTEntry& parentEntry)
452 foundEntries += (u32)entry.size; 452 foundEntries += (u32)entry.size;
453 } 453 }
454 else 454 else
455 { // is a file 455 { // is a file
456 entry.isDirectory = false; 456 entry.isDirectory = false;
457 entry.size = GetSize(entry.physicalName.c_str()); 457 entry.size = GetSize(entry.physicalName.c_str());
458 } 458 }
459 ++foundEntries; 459 ++foundEntries;
460 // Push into the tree 460 // Push into the tree
461 parentEntry.children.push_back(entry); 461 parentEntry.children.push_back(entry);
462#ifdef _WIN32 462#ifdef _WIN32
463 } while (FindNextFile(hFind, &ffd) != 0); 463 } while (FindNextFile(hFind, &ffd) != 0);
464 FindClose(hFind); 464 FindClose(hFind);
465#else 465#else
@@ -504,7 +504,7 @@ bool DeleteDirRecursively(const std::string &directory)
504 504
505 // check for "." and ".." 505 // check for "." and ".."
506 if (((virtualName[0] == '.') && (virtualName[1] == '\0')) || 506 if (((virtualName[0] == '.') && (virtualName[1] == '\0')) ||
507 ((virtualName[0] == '.') && (virtualName[1] == '.') && 507 ((virtualName[0] == '.') && (virtualName[1] == '.') &&
508 (virtualName[2] == '\0'))) 508 (virtualName[2] == '\0')))
509 continue; 509 continue;
510 510
@@ -540,7 +540,7 @@ bool DeleteDirRecursively(const std::string &directory)
540 closedir(dirp); 540 closedir(dirp);
541#endif 541#endif
542 FileUtil::DeleteDir(directory); 542 FileUtil::DeleteDir(directory);
543 543
544 return true; 544 return true;
545} 545}
546 546
@@ -585,7 +585,7 @@ void CopyDir(const std::string &source_path, const std::string &dest_path)
585std::string GetCurrentDir() 585std::string GetCurrentDir()
586{ 586{
587 char *dir; 587 char *dir;
588 // Get the current working directory (getcwd uses malloc) 588 // Get the current working directory (getcwd uses malloc)
589 if (!(dir = __getcwd(NULL, 0))) { 589 if (!(dir = __getcwd(NULL, 0))) {
590 590
591 ERROR_LOG(COMMON, "GetCurrentDirectory failed: %s", 591 ERROR_LOG(COMMON, "GetCurrentDirectory failed: %s",
@@ -604,7 +604,7 @@ bool SetCurrentDir(const std::string &directory)
604} 604}
605 605
606#if defined(__APPLE__) 606#if defined(__APPLE__)
607std::string GetBundleDirectory() 607std::string GetBundleDirectory()
608{ 608{
609 CFURLRef BundleRef; 609 CFURLRef BundleRef;
610 char AppBundlePath[MAXPATHLEN]; 610 char AppBundlePath[MAXPATHLEN];
@@ -666,8 +666,8 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string &new
666 if (FileUtil::Exists(ROOT_DIR DIR_SEP USERDATA_DIR)) 666 if (FileUtil::Exists(ROOT_DIR DIR_SEP USERDATA_DIR))
667 paths[D_USER_IDX] = ROOT_DIR DIR_SEP USERDATA_DIR DIR_SEP; 667 paths[D_USER_IDX] = ROOT_DIR DIR_SEP USERDATA_DIR DIR_SEP;
668 else 668 else
669 paths[D_USER_IDX] = std::string(getenv("HOME") ? 669 paths[D_USER_IDX] = std::string(getenv("HOME") ?
670 getenv("HOME") : getenv("PWD") ? 670 getenv("HOME") : getenv("PWD") ?
671 getenv("PWD") : "") + DIR_SEP EMU_DATA_DIR DIR_SEP; 671 getenv("PWD") : "") + DIR_SEP EMU_DATA_DIR DIR_SEP;
672#endif 672#endif
673 673
@@ -749,7 +749,7 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string &new
749 paths[F_MAINLOG_IDX] = paths[D_LOGS_IDX] + MAIN_LOG; 749 paths[F_MAINLOG_IDX] = paths[D_LOGS_IDX] + MAIN_LOG;
750 } 750 }
751 } 751 }
752 752
753 return paths[DirIDX]; 753 return paths[DirIDX];
754} 754}
755 755
@@ -762,7 +762,7 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string &new
762// if (!FileUtil::Exists(dir)) 762// if (!FileUtil::Exists(dir))
763// dir = SHARED_USER_DIR THEMES_DIR "/" + theme_name + "/"; 763// dir = SHARED_USER_DIR THEMES_DIR "/" + theme_name + "/";
764//#endif 764//#endif
765// 765//
766// return dir; 766// return dir;
767//} 767//}
768 768