mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-14 18:15:28 -04:00
Fix 'getting build time' erroring when used from a path with unicode characters
This commit is contained in:
parent
4be290d9d4
commit
1f93dff0f6
@ -1481,7 +1481,6 @@ static void UpdatesScreen_DevD3D9(void* w, int x, int y) { UpdatesScreen_Get(f
|
||||
static void UpdatesScreen_DevOpenGL(void* w, int x, int y) { UpdatesScreen_Get(false, false); }
|
||||
|
||||
static void UpdatesScreen_Update(struct UpdatesScreen* s) {
|
||||
String path; char pathBuffer[FILENAME_SIZE];
|
||||
TimeMS buildTime;
|
||||
ReturnCode res;
|
||||
|
||||
@ -1491,13 +1490,8 @@ static void UpdatesScreen_Update(struct UpdatesScreen* s) {
|
||||
}
|
||||
CheckUpdateTask_Run();
|
||||
|
||||
String_InitArray(path, pathBuffer);
|
||||
res = Process_GetExePath(&path);
|
||||
if (res) { Logger_Warn(res, "getting .exe path"); return; }
|
||||
|
||||
res = File_GetModifiedTime(&path, &buildTime);
|
||||
res = Updater_GetBuildTime(&buildTime);
|
||||
if (res) { Logger_Warn(res, "getting build time"); return; }
|
||||
|
||||
UpdatesScreen_Format(&s->lblYour, "Your build: ", buildTime);
|
||||
}
|
||||
|
||||
|
@ -415,24 +415,6 @@ ReturnCode Directory_Enum(const String* dirPath, void* obj, Directory_EnumCallba
|
||||
return res == ERROR_NO_MORE_FILES ? 0 : GetLastError();
|
||||
}
|
||||
|
||||
ReturnCode File_GetModifiedTime(const String* path, TimeMS* time) {
|
||||
FileHandle file;
|
||||
FILETIME ft;
|
||||
cc_uint64 raw;
|
||||
ReturnCode res = File_Open(&file, path);
|
||||
if (res) return res;
|
||||
|
||||
if (GetFileTime(file, NULL, NULL, &ft)) {
|
||||
raw = ft.dwLowDateTime | ((cc_uint64)ft.dwHighDateTime << 32);
|
||||
*time = FileTime_TotalMS(raw);
|
||||
} else {
|
||||
res = GetLastError();
|
||||
}
|
||||
|
||||
File_Close(file);
|
||||
return res;
|
||||
}
|
||||
|
||||
ReturnCode File_SetModifiedTime(const String* path, TimeMS time) {
|
||||
FileHandle file;
|
||||
FILETIME ft;
|
||||
@ -567,16 +549,6 @@ ReturnCode Directory_Enum(const String* dirPath, void* obj, Directory_EnumCallba
|
||||
return res;
|
||||
}
|
||||
|
||||
ReturnCode File_GetModifiedTime(const String* path, TimeMS* time) {
|
||||
char str[NATIVE_STR_LEN];
|
||||
struct stat sb;
|
||||
Platform_ConvertString(str, path);
|
||||
if (stat(str, &sb) == -1) return errno;
|
||||
|
||||
*time = (cc_uint64)sb.st_mtime * 1000 + UNIX_EPOCH;
|
||||
return 0;
|
||||
}
|
||||
|
||||
ReturnCode File_SetModifiedTime(const String* path, TimeMS time) {
|
||||
char str[NATIVE_STR_LEN];
|
||||
struct utimbuf times = { 0 };
|
||||
@ -1308,13 +1280,38 @@ ReturnCode Updater_Start(void) {
|
||||
Platform_ConvertString(str, &args);
|
||||
return Process_RawStart(NULL, str);
|
||||
}
|
||||
ReturnCode Updater_GetBuildTime(TimeMS* time) {
|
||||
TCHAR path[NATIVE_STR_LEN + 1];
|
||||
FileHandle file;
|
||||
FILETIME ft;
|
||||
cc_uint64 raw;
|
||||
int len = 0;
|
||||
|
||||
ReturnCode res = Process_RawGetExePath(path, &len);
|
||||
if (res) return res;
|
||||
path[len] = '\0';
|
||||
|
||||
file = CreateFile(path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
|
||||
if (file == INVALID_HANDLE_VALUE) return GetLastError();
|
||||
|
||||
if (GetFileTime(file, NULL, NULL, &ft)) {
|
||||
raw = ft.dwLowDateTime | ((cc_uint64)ft.dwHighDateTime << 32);
|
||||
*time = FileTime_TotalMS(raw);
|
||||
} else {
|
||||
res = GetLastError();
|
||||
}
|
||||
|
||||
File_Close(file);
|
||||
return res;
|
||||
}
|
||||
#elif defined CC_BUILD_WEB || defined CC_BUILD_ANDROID
|
||||
ReturnCode Updater_Start(void) { return ERR_NOT_SUPPORTED; }
|
||||
ReturnCode Updater_Start(void) { return ERR_NOT_SUPPORTED; }
|
||||
ReturnCode Updater_GetBuildTime(TimeMS* time) { return ERR_NOT_SUPPORTED; }
|
||||
#elif defined CC_BUILD_POSIX
|
||||
ReturnCode Updater_Start(void) {
|
||||
char path[NATIVE_STR_LEN];
|
||||
int len = 0;
|
||||
char path[NATIVE_STR_LEN + 1];
|
||||
char* argv[2];
|
||||
int len = 0;
|
||||
|
||||
ReturnCode res = Process_RawGetExePath(path, &len);
|
||||
if (res) return res;
|
||||
@ -1328,6 +1325,20 @@ ReturnCode Updater_Start(void) {
|
||||
argv[0] = path; argv[1] = NULL;
|
||||
return Process_RawStart(path, argv);
|
||||
}
|
||||
|
||||
ReturnCode Updater_GetBuildTime(TimeMS* ms) {
|
||||
char path[NATIVE_STR_LEN + 1];
|
||||
struct stat sb;
|
||||
int len = 0;
|
||||
|
||||
ReturnCode res = Process_RawGetExePath(path, &len);
|
||||
if (res) return res;
|
||||
path[len] = '\0';
|
||||
|
||||
if (stat(path, &sb) == -1) return errno;
|
||||
*time = (cc_uint64)sb.st_mtime * 1000 + UNIX_EPOCH;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -70,6 +70,8 @@ CC_API ReturnCode Process_GetExePath(String* path);
|
||||
|
||||
/* Starts the platform-specific method to update then start the game using the UPDATE_FILE file. */
|
||||
CC_API ReturnCode Updater_Start(void);
|
||||
/* Returns the last time the application was modified, as number of milliseconds since 1/1/0001 */
|
||||
CC_API ReturnCode Updater_GetBuildTime(TimeMS* ms);
|
||||
|
||||
/* Attempts to load a native dynamic library from the given path. */
|
||||
CC_API ReturnCode DynamicLib_Load(const String* path, void** lib);
|
||||
@ -133,8 +135,6 @@ CC_API ReturnCode Directory_Enum(const String* path, void* obj, Directory_EnumCa
|
||||
|
||||
/* Returns whether the given file exists. */
|
||||
CC_API bool File_Exists(const String* path);
|
||||
/* Returns the last time the file was modified, as number of milliseconds since 1/1/0001 */
|
||||
CC_API ReturnCode File_GetModifiedTime(const String* path, TimeMS* ms);
|
||||
/* Sets the last time the file was modified, as number of milliseconds since 1/1/0001 */
|
||||
CC_API ReturnCode File_SetModifiedTime(const String* path, TimeMS ms);
|
||||
/* Marks a file as being executable. */
|
||||
|
@ -107,8 +107,8 @@ static int Program_Run(int argc, char** argv) {
|
||||
#ifdef _MSC_VER
|
||||
/* NOTE: Make sure to comment this out before pushing a commit */
|
||||
//String rawArgs = String_FromConst("UnknownShadow200 fffff 127.0.0.1 25565");
|
||||
String rawArgs = String_FromConst("UnknownShadow200");
|
||||
argsCount = String_UNSAFE_Split(&rawArgs, ' ', args, 4);
|
||||
//String rawArgs = String_FromConst("UnknownShadow200");
|
||||
//argsCount = String_UNSAFE_Split(&rawArgs, ' ', args, 4);
|
||||
#endif
|
||||
|
||||
if (argsCount == 0) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user