Process_StartUpdater -> Updater_Start

This commit is contained in:
UnknownShadow200 2019-09-04 07:24:28 +10:00
parent c5b1b019d7
commit 41bfc6b1ae
3 changed files with 43 additions and 34 deletions

View File

@ -642,7 +642,7 @@ static void Launcher_ApplyUpdate(void) {
res = File_MarkExecutable(&scriptPath);
if (res) Logger_Warn(res, "making update script executable");
res = Process_StartUpdater();
res = Updater_Start();
if (res) { Logger_Warn(res, "running updater"); return; }
}

View File

@ -1119,14 +1119,6 @@ ReturnCode Process_StartOpen(const String* args) {
return instance > 32 ? 0 : (ReturnCode)instance;
}
ReturnCode Process_StartUpdater(void) {
static const String args = String_FromConst("cmd.exe /C start cmd /C " UPDATE_FILENAME);
TCHAR str[NATIVE_STR_LEN];
/* args must be modifiable, otherwise access violation */
Platform_ConvertString(str, &args);
return Process_RawStart(NULL, str);
}
ReturnCode Process_GetExePath(String* path) {
TCHAR raw[NATIVE_STR_LEN];
int len;
@ -1147,7 +1139,6 @@ ReturnCode Process_StartOpen(const String* args) {
return 0;
}
ReturnCode Process_StartUpdater(void) { return ERR_NOT_SUPPORTED; }
ReturnCode Process_GetExePath(String* path) { return ERR_NOT_SUPPORTED; }
#elif defined CC_BUILD_ANDROID
static char gameArgsBuffer[512];
@ -1164,7 +1155,6 @@ ReturnCode Process_StartOpen(const String* args) {
return 0; /* TODO: Is there a clean way of handling an error */
}
ReturnCode Process_StartUpdater(void) { return ERR_NOT_SUPPORTED; }
ReturnCode Process_GetExePath(String* path) { return ERR_NOT_SUPPORTED; }
#elif defined CC_BUILD_POSIX
static ReturnCode Process_RawStart(const char* path, const char** argv) {
@ -1233,32 +1223,11 @@ ReturnCode Process_GetExePath(String* path) {
ReturnCode Process_StartOpen(const String* args) {
return Process_RawStartOpen("/usr/bin/open", args);
}
ReturnCode Process_StartUpdater(void) {
static const char* args[5] = { "/usr/bin/open", "-a", "Terminal", "./update.sh", NULL };
return Process_RawStart("/usr/bin/open", args);
}
#elif defined CC_BUILD_UNIX
ReturnCode Process_StartOpen(const String* args) {
/* TODO: Can this be used on original Solaris, or is it just an OpenIndiana thing */
return Process_RawStartOpen("xdg-open", args);
}
ReturnCode Process_StartUpdater(void) {
char path[NATIVE_STR_LEN];
int len = 0;
char* argv[2];
ReturnCode res = Process_RawGetExePath(path, &len);
if (res) return res;
path[len] = '\0';
/* Because the process is only referenced by inocde, we can */
/* just unlink current filename and rename updated file to it */
if (unlink(path) == -1) return errno;
if (rename(UPDATE_FILE, path) == -1) return errno;
argv[0] = path; argv[1] = NULL;
return Process_RawStart(path, argv);
}
#endif
/* Retrieving exe path is completely OS dependant */
#if defined CC_BUILD_OSX
@ -1328,6 +1297,45 @@ static ReturnCode Process_RawGetExePath(char* path, int* len) {
#endif
/*########################################################################################################################*
*--------------------------------------------------------Updater----------------------------------------------------------*
*#########################################################################################################################*/
#if defined CC_BUILD_WIN
ReturnCode Updater_Start(void) {
static const String args = String_FromConst("cmd.exe /C start cmd /C " UPDATE_FILENAME);
TCHAR str[NATIVE_STR_LEN];
/* args must be modifiable, otherwise access violation */
Platform_ConvertString(str, &args);
return Process_RawStart(NULL, str);
}
#elif defined CC_BUILD_WEB || defined CC_BUILD_ANDROID
ReturnCode Updater_Start(void) { return ERR_NOT_SUPPORTED; }
#elif defined CC_BUILD_OSX
ReturnCode Updater_Start(void) {
static const char* args[5] = { "/usr/bin/open", "-a", "Terminal", "./update.sh", NULL };
return Process_RawStart("/usr/bin/open", args);
}
#elif defined CC_BUILD_UNIX
ReturnCode Updater_Start(void) {
char path[NATIVE_STR_LEN];
int len = 0;
char* argv[2];
ReturnCode res = Process_RawGetExePath(path, &len);
if (res) return res;
path[len] = '\0';
/* Because the process is only referenced by inocde, we can */
/* just unlink current filename and rename updated file to it */
if (unlink(path) == -1) return errno;
if (rename(UPDATE_FILE, path) == -1) return errno;
argv[0] = path; argv[1] = NULL;
return Process_RawStart(path, argv);
}
#endif
/*########################################################################################################################*
*-------------------------------------------------------Dynamic lib-------------------------------------------------------*
*#########################################################################################################################*/

View File

@ -65,11 +65,12 @@ CC_API void Process_Exit(ReturnCode code);
/* Starts the platform-specific program to open the given url or filename. */
/* For example, provide a http:// url to open a website in the user's web browser. */
CC_API ReturnCode Process_StartOpen(const String* args);
/* Starts the platform-specific method to update then start the game using the UPDATE_FILE file. */
CC_API ReturnCode Process_StartUpdater(void);
/* Returns the full path of the application's executable. */
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);
/* Attempts to load a native dynamic library from the given path. */
CC_API ReturnCode DynamicLib_Load(const String* path, void** lib);
/* Attempts to get the address of the symbol in the given dynamic library. */