Changeset 1328 for cpp/common
- Timestamp:
- 12/26/24 01:40:08 (37 hours ago)
- Location:
- cpp/common/virtfile
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/common/virtfile/stdiofile.cpp
r820 r1328 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 18Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2024 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 11 11 #include <common/dirs.h> 12 12 #include <common/platform/android/AndroidAPK_DIR.h> 13 #endif 14 #include <sys/stat.h> 15 #include <unistd.h> 16 #ifdef _WIN32 17 #include <sys/utime.h> 18 #else 19 #include <utime.h> 13 20 #endif 14 21 … … 74 81 } 75 82 83 bool StdioFileSystem::Vdelete(const char* path) 84 { 85 return removeFile(path); 86 } 76 87 88 bool StdioFileSystem::Vstat(const char* path, Stat* out) 89 { 90 #ifdef _WIN32 91 //under windows, there are a few choices of _statXX structures: 32bit, 64bit, ansi, widechar (and their corresponding _statXX() functions). For the future: ensure utf8 filenames work. 92 using stat = struct _stat64i32; //"struct" because there is also a function with the same name 93 //struct _stat64i32 info; //an alternative, simple way if one does not want to use "using" above 94 #else 95 struct //if there was "using" earlier, then we cannot use "struct" in type name 96 #endif 97 stat info; 98 if (_stat(path, &info) != 0) return false; 99 out->is_file = S_ISREG(info.st_mode); 100 #if defined IPHONE && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)) 101 out->modification_time = info.st_mtimespec.tv_sec; 102 #else 103 out->modification_time = info.st_mtime; 104 #endif 105 return true; 106 } 77 107 78 79 108 bool StdioFileSystem::Vsettime(const char* path, double timestamp) 109 { 110 #ifdef _WIN32 111 //under windows, there are a few choices of _statXX structures: 32bit, 64bit, ansi, widechar (and their corresponding _statXX() functions). For the future: ensure utf8 filenames work. 112 using stat = struct _stat64i32; //"struct" because there is also a function with the same name 113 //struct _stat64i32 info; //an alternative, simple way if one does not want to use "using" above 114 #else 115 struct //if there was "using" earlier, then we cannot use "struct" in type name 116 #endif 117 stat info; 118 if (_stat(path, &info) != 0) return false; 119 struct utimbuf times; 120 #if defined IPHONE && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)) 121 times.actime = info.st_atimespec.tv_sec; 122 #else 123 times.actime = info.st_atime; 124 #endif 125 times.modtime = (time_t)timestamp; 126 return utime(path, ×) == 0; 127 } 80 128 81 129 #ifndef NO_STD_IN_OUT_ERR -
cpp/common/virtfile/stdiofile.h
r820 r1328 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 18Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2024 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 18 18 bool Vmkdir(const char* path) { return makeDirectory(path); } 19 19 bool Vdirexists(const char* path, bool is_writable); 20 bool Vdelete(const char* path); 21 bool Vstat(const char* path, Stat* stat); 22 bool Vsettime(const char* path, double timestamp); 20 23 }; 21 24 -
cpp/common/virtfile/virtfile.cpp
r888 r1328 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 15Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2024 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 50 50 } 51 51 52 bool Vdelete(const char* path) 53 { 54 return VirtFILE::vfs ? VirtFILE::vfs->Vdelete(path) : false; 55 } 56 57 bool Vstat(const char* path, struct VirtFileSystem::Stat *stat) 58 { 59 return VirtFILE::vfs ? VirtFILE::vfs->Vstat(path, stat) : false; 60 } 61 62 bool Vsettime(const char* path, double timestamp) 63 { 64 return VirtFILE::vfs ? VirtFILE::vfs->Vsettime(path, timestamp) : false; 65 } 52 66 VirtFILE::~VirtFILE() 53 67 {} … … 99 113 bool VirtFileSystem::Vmkdir(const char* path) { return false; } 100 114 bool VirtFileSystem::Vdirexists(const char* path, bool is_writable) { return false; } 115 bool VirtFileSystem::Vdelete(const char* path) { return false; } 116 bool VirtFileSystem::Vstat(const char* path, Stat* stat) { return false; } 117 bool VirtFileSystem::Vsettime(const char* path, double timestamp) { return false; } 101 118 102 119 ////////////////////////////////////////////////////////////////////////// … … 206 223 { 207 224 return (chain != NULL) ? chain->Vdirexists(path, is_writable) : false; 225 } 226 227 bool ChainFileSystem::Vdelete(const char* path) 228 { 229 return (chain != NULL) ? chain->Vdelete(path) : false; 230 } 231 232 bool ChainFileSystem::Vstat(const char* path, Stat* stat) 233 { 234 return (chain != NULL) ? chain->Vstat(path, stat) : false; 235 } 236 237 bool ChainFileSystem::Vsettime(const char* path, double timestamp) 238 { 239 return (chain != NULL) ? chain->Vsettime(path, timestamp) : false; 208 240 } 209 241 -
cpp/common/virtfile/virtfile.h
r891 r1328 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 19Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2024 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 98 98 virtual bool Vmkdirs(const char* path); 99 99 virtual bool Vdirexists(const char* path, bool is_writable); 100 virtual bool Vdelete(const char* path); 101 struct Stat { bool is_file; time_t modification_time; }; 102 virtual bool Vstat(const char* path, Stat* stat); 103 virtual bool Vsettime(const char* path, double timestamp); 100 104 }; 101 105 … … 113 117 bool Vmkdirs(const char* path); 114 118 bool Vdirexists(const char* path, bool is_writable); 119 bool Vdelete(const char* path); 120 bool Vstat(const char* path, Stat* stat); 121 bool Vsettime(const char* path, double timestamp); 115 122 116 123 class Dir : public VirtDIR … … 135 142 DLLEXP bool Vmkdirs(const char* path); 136 143 DLLEXP bool Vdirexists(const char* path, bool is_writable); 144 DLLEXP bool Vdelete(const char* path); 145 DLLEXP bool Vstat(const char* path, struct VirtFileSystem::Stat *stat); 146 DLLEXP bool Vsettime(const char* path, double timestamp); 137 147 138 148 #ifdef VIRTFILE_OVERLOADING
Note: See TracChangeset
for help on using the changeset viewer.