2 Skelton for retropc emulator
4 Author : Takeda.Toshiya
16 #pragma comment(lib, "shlwapi.lib")
23 #if !defined(SUPPORT_SECURE_FUNCTIONS) || defined(Q_OS_WIN)
24 errno_t _tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource)
26 _tcscpy(strDestination, strSource);
30 _TCHAR *_tcstok_s(_TCHAR *strToken, const char *strDelimit, _TCHAR **context)
32 return _tcstok(strToken, strDelimit);
35 int _stprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...)
39 int result = _vstprintf(buffer, format, ap);
44 int _vstprintf_s(_TCHAR *buffer, size_t numberOfElements, const _TCHAR *format, va_list argptr)
46 return _vstprintf(buffer, format, argptr);
50 bool check_file_extension(const _TCHAR* file_path, const _TCHAR* ext)
52 #if defined(_USE_AGAR)
53 int nam_len = strlen(file_path);
54 int ext_len = strlen(ext);
56 return (nam_len >= ext_len && strncmp(&file_path[nam_len - ext_len], ext, ext_len) == 0);
57 #elif defined(_USE_QT)
58 QString s_fpath = file_path;
61 s_fpath = s_fpath.toUpper();
62 s_ext = s_ext.toUpper();
63 if(s_fpath.length() < s_ext.length()) return false;
64 s_fpath = s_fpath.right(s_ext.length());
65 if(s_fpath == s_ext) return true;
68 int nam_len = _tcslen(file_path);
69 int ext_len = _tcslen(ext);
71 return (nam_len >= ext_len && _tcsncicmp(&file_path[nam_len - ext_len], ext, ext_len) == 0);
75 _TCHAR *get_file_path_without_extensiton(const _TCHAR* file_path)
77 static _TCHAR path[_MAX_PATH];
79 #if defined(_USE_AGAR) || defined(_USE_QT)
81 static _TCHAR p3[_MAX_PATH];
82 strcpy(path, file_path);
83 p1 = (_TCHAR *)strrchr(path, '/');
84 p2 = (_TCHAR *)strrchr(path, '.');
88 } else if(p1 == NULL) {
89 strncpy(p3, path, p2 - path);
94 strncpy(p3, path, p2 - path);
101 _tcscpy_s(path, _MAX_PATH, file_path);
102 PathRemoveExtension(path);
107 uint32 getcrc32(uint8 data[], int size)
109 static bool initialized = false;
110 static uint32 table[256];
113 for(int i = 0; i < 256; i++) {
115 for(int j = 0; j < 8; j++) {
117 c = (c >> 1) ^ 0xedb88320;
128 for(int i = 0; i < size; i++) {
129 c = table[(c ^ data[i]) & 0xff] ^ (c >> 8);
134 void cur_time_t::increment()
142 // days in this month
145 days = LEAP_YEAR(year) ? 29 : 28;
146 } else if(month == 4 || month == 6 || month == 9 || month == 11) {
156 if(++day_of_week >= 7) {
164 void cur_time_t::update_year()
169 } else if(year < 100) {
174 void cur_time_t::update_day_of_week()
176 static const int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
177 int y = year - (month < 3);
178 day_of_week = (y + y / 4 - y / 100 + y / 400 + t[month - 1] + day) % 7;
181 #define STATE_VERSION 1
183 void cur_time_t::save_state(void *f)
185 FILEIO *state_fio = (FILEIO *)f;
187 state_fio->FputUint32(STATE_VERSION);
189 state_fio->FputInt32(year);
190 state_fio->FputInt32(month);
191 state_fio->FputInt32(day);
192 state_fio->FputInt32(day_of_week);
193 state_fio->FputInt32(hour);
194 state_fio->FputInt32(minute);
195 state_fio->FputInt32(second);
196 state_fio->FputBool(initialized);
199 bool cur_time_t::load_state(void *f)
201 FILEIO *state_fio = (FILEIO *)f;
203 if(state_fio->FgetUint32() != STATE_VERSION) {
206 year = state_fio->FgetInt32();
207 month = state_fio->FgetInt32();
208 day = state_fio->FgetInt32();
209 day_of_week = state_fio->FgetInt32();
210 hour = state_fio->FgetInt32();
211 minute = state_fio->FgetInt32();
212 second = state_fio->FgetInt32();
213 initialized = state_fio->FgetBool();