20
20
#ifndef UNICODE
21
21
#error Win32 build requires a unicode build
22
22
#endif
23
+ #else
24
+ #define _POSIX_SOURCE
25
+ #define _LARGE_TIME_API
23
26
#endif
24
27
25
28
#include " ppsspp_config.h"
37
40
#include < ctime>
38
41
#include < memory>
39
42
43
+ #include < sys/types.h>
44
+
40
45
#include " Common/Log.h"
41
46
#include " Common/LogReporting.h"
42
47
#include " Common/File/AndroidContentURI.h"
46
51
47
52
#ifdef _WIN32
48
53
#include " Common/CommonWindows.h"
54
+ #include < sys/utime.h>
49
55
#include < Windows.h>
50
56
#include < shlobj.h> // for SHGetFolderPath
51
57
#include < shellapi.h>
63
69
#include < errno.h>
64
70
#include < stdlib.h>
65
71
#include < unistd.h>
72
+ #include < utime.h>
66
73
#endif
67
74
68
75
#if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
@@ -167,7 +174,7 @@ FILE *OpenCFile(const Path &path, const char *mode) {
167
174
168
175
#if defined(_WIN32) && defined(UNICODE)
169
176
#if PPSSPP_PLATFORM(UWP) && !defined(__LIBRETRO__)
170
- // We shouldn't use _wfopen here,
177
+ // We shouldn't use _wfopen here,
171
178
// this function is not allowed to read outside Local and Installation folders
172
179
// FileSystem (broadFileSystemAccess) doesn't apply on _wfopen
173
180
// if we have custom memory stick location _wfopen will return null
@@ -471,7 +478,7 @@ bool Delete(const Path &filename) {
471
478
472
479
INFO_LOG (Log::Common, " Delete: file %s" , filename.c_str ());
473
480
474
- // Return true because we care about the file no
481
+ // Return true because we care about the file no
475
482
// being there, not the actual delete.
476
483
if (!Exists (filename)) {
477
484
WARN_LOG (Log::Common, " Delete: '%s' already does not exist" , filename.c_str ());
@@ -498,7 +505,7 @@ bool Delete(const Path &filename) {
498
505
#endif
499
506
#else
500
507
if (unlink (filename.c_str ()) == -1 ) {
501
- WARN_LOG (Log::Common, " Delete: unlink failed on %s: %s" ,
508
+ WARN_LOG (Log::Common, " Delete: unlink failed on %s: %s" ,
502
509
filename.c_str (), GetLastErrorMsg ().c_str ());
503
510
return false ;
504
511
}
@@ -547,7 +554,7 @@ bool CreateDir(const Path &path) {
547
554
if (::CreateDirectory (path.ToWString ().c_str (), NULL ))
548
555
return true ;
549
556
#endif
550
-
557
+
551
558
DWORD error = GetLastError ();
552
559
if (error == ERROR_ALREADY_EXISTS) {
553
560
WARN_LOG (Log::Common, " CreateDir: CreateDirectory failed on %s: already exists" , path.c_str ());
@@ -616,7 +623,7 @@ bool CreateFullPath(const Path &path) {
616
623
return true ;
617
624
}
618
625
619
- // renames file srcFilename to destFilename, returns true on success
626
+ // renames file srcFilename to destFilename, returns true on success
620
627
bool Rename (const Path &srcFilename, const Path &destFilename) {
621
628
if (srcFilename.Type () != destFilename.Type ()) {
622
629
// Impossible. You're gonna need to make a copy, and delete the original. Not the responsibility
@@ -659,12 +666,12 @@ bool Rename(const Path &srcFilename, const Path &destFilename) {
659
666
return true ;
660
667
#endif
661
668
662
- ERROR_LOG (Log::Common, " Rename: failed %s --> %s: %s" ,
669
+ ERROR_LOG (Log::Common, " Rename: failed %s --> %s: %s" ,
663
670
srcFilename.c_str (), destFilename.c_str (), GetLastErrorMsg ().c_str ());
664
671
return false ;
665
672
}
666
673
667
- // copies file srcFilename to destFilename, returns true on success
674
+ // copies file srcFilename to destFilename, returns true on success
668
675
bool Copy (const Path &srcFilename, const Path &destFilename) {
669
676
switch (srcFilename.Type ()) {
670
677
case PathType::NATIVE:
@@ -692,7 +699,7 @@ bool Copy(const Path &srcFilename, const Path &destFilename) {
692
699
if (CopyFile (srcFilename.ToWString ().c_str (), destFilename.ToWString ().c_str (), FALSE ))
693
700
return true ;
694
701
#endif
695
- ERROR_LOG (Log::Common, " Copy: failed %s --> %s: %s" ,
702
+ ERROR_LOG (Log::Common, " Copy: failed %s --> %s: %s" ,
696
703
srcFilename.c_str (), destFilename.c_str (), GetLastErrorMsg ().c_str ());
697
704
return false ;
698
705
#else
@@ -705,7 +712,7 @@ bool Copy(const Path &srcFilename, const Path &destFilename) {
705
712
// Open input file
706
713
FILE *input = OpenCFile (srcFilename, " rb" );
707
714
if (!input) {
708
- ERROR_LOG (Log::Common, " Copy: input failed %s --> %s: %s" ,
715
+ ERROR_LOG (Log::Common, " Copy: input failed %s --> %s: %s" ,
709
716
srcFilename.c_str (), destFilename.c_str (), GetLastErrorMsg ().c_str ());
710
717
return false ;
711
718
}
@@ -714,7 +721,7 @@ bool Copy(const Path &srcFilename, const Path &destFilename) {
714
721
FILE *output = OpenCFile (destFilename, " wb" );
715
722
if (!output) {
716
723
fclose (input);
717
- ERROR_LOG (Log::Common, " Copy: output failed %s --> %s: %s" ,
724
+ ERROR_LOG (Log::Common, " Copy: output failed %s --> %s: %s" ,
718
725
srcFilename.c_str (), destFilename.c_str (), GetLastErrorMsg ().c_str ());
719
726
return false ;
720
727
}
@@ -725,23 +732,23 @@ bool Copy(const Path &srcFilename, const Path &destFilename) {
725
732
int rnum = fread (buffer, sizeof (char ), BSIZE, input);
726
733
if (rnum != BSIZE) {
727
734
if (ferror (input) != 0 ) {
728
- ERROR_LOG (Log::Common,
729
- " Copy: failed reading from source, %s --> %s: %s" ,
735
+ ERROR_LOG (Log::Common,
736
+ " Copy: failed reading from source, %s --> %s: %s" ,
730
737
srcFilename.c_str (), destFilename.c_str (), GetLastErrorMsg ().c_str ());
731
738
fclose (input);
732
- fclose (output);
739
+ fclose (output);
733
740
return false ;
734
741
}
735
742
}
736
743
737
744
// write output
738
745
int wnum = fwrite (buffer, sizeof (char ), rnum, output);
739
746
if (wnum != rnum) {
740
- ERROR_LOG (Log::Common,
741
- " Copy: failed writing to output, %s --> %s: %s" ,
747
+ ERROR_LOG (Log::Common,
748
+ " Copy: failed writing to output, %s --> %s: %s" ,
742
749
srcFilename.c_str (), destFilename.c_str (), GetLastErrorMsg ().c_str ());
743
750
fclose (input);
744
- fclose (output);
751
+ fclose (output);
745
752
return false ;
746
753
}
747
754
}
@@ -883,9 +890,9 @@ uint64_t GetFileSize(FILE *f) {
883
890
#endif
884
891
}
885
892
886
- // creates an empty file filename, returns true on success
893
+ // creates an empty file filename, returns true on success
887
894
bool CreateEmptyFile (const Path &filename) {
888
- INFO_LOG (Log::Common, " CreateEmptyFile: %s" , filename.c_str ());
895
+ INFO_LOG (Log::Common, " CreateEmptyFile: %s" , filename.c_str ());
889
896
FILE *pFile = OpenCFile (filename, " wb" );
890
897
if (!pFile) {
891
898
ERROR_LOG (Log::Common, " CreateEmptyFile: failed to create '%s': %s" , filename.c_str (), GetLastErrorMsg ().c_str ());
@@ -1118,7 +1125,7 @@ bool IOFile::Seek(int64_t off, int origin)
1118
1125
}
1119
1126
1120
1127
uint64_t IOFile::Tell ()
1121
- {
1128
+ {
1122
1129
if (IsOpen ())
1123
1130
return ftello (m_file);
1124
1131
else
@@ -1240,4 +1247,23 @@ bool WriteDataToFile(bool text_file, const void* data, size_t size, const Path &
1240
1247
return true ;
1241
1248
}
1242
1249
1250
+ void ChangeMTime (const Path &path, time_t mtime) {
1251
+ if (path.Type () == PathType::CONTENT_URI) {
1252
+ // No clue what to do here.
1253
+ return ;
1254
+ }
1255
+
1256
+ #ifdef _WIN32
1257
+ _utimbuf buf{};
1258
+ buf.actime = mtime;
1259
+ buf.modtime = mtime;
1260
+ _utime (path.c_str (), &buf);
1261
+ #else
1262
+ utimbuf buf{};
1263
+ buf.actime = mtime;
1264
+ buf.modtime = mtime;
1265
+ utime (path.c_str (), &buf);
1266
+ #endif
1267
+ }
1268
+
1243
1269
} // namespace File
0 commit comments