Game installer launches game with data directory for Windows (AppData)
This commit is contained in:
parent
23dcec9d07
commit
f535f8dce4
@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
#define LOCAL_LUA_DIR "Lua"
|
#define LOCAL_LUA_DIR "Lua"
|
||||||
|
|
||||||
|
#define APPDATA_SUBDIR "\\HardWIRED"
|
||||||
|
|
||||||
#define THUMB_CACHE_SIZE 256
|
#define THUMB_CACHE_SIZE 256
|
||||||
|
|
||||||
#ifndef M_PI
|
#ifndef M_PI
|
||||||
|
80
src/misc.c
80
src/misc.c
@ -12,6 +12,8 @@
|
|||||||
#include <icondoc.h>
|
#include <icondoc.h>
|
||||||
#include <update.h>
|
#include <update.h>
|
||||||
#if defined WIN32
|
#if defined WIN32
|
||||||
|
#include <Shlobj.h>
|
||||||
|
#include <Shlwapi.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#else
|
#else
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -467,80 +469,132 @@ char * clipboard_pull_text()
|
|||||||
int register_extension()
|
int register_extension()
|
||||||
{
|
{
|
||||||
#if defined WIN32
|
#if defined WIN32
|
||||||
|
int returnval;
|
||||||
LONG rresult;
|
LONG rresult;
|
||||||
HKEY newkey;
|
HKEY newkey;
|
||||||
char *currentfilename = exe_name();
|
char *currentfilename = exe_name();
|
||||||
char *iconname = NULL;
|
char *iconname = NULL;
|
||||||
char *opencommand = NULL;
|
char *opencommand = NULL;
|
||||||
|
char AppDataPath[MAX_PATH];
|
||||||
iconname = malloc(strlen(currentfilename)+6);
|
iconname = malloc(strlen(currentfilename)+6);
|
||||||
opencommand = malloc(strlen(currentfilename)+13);
|
|
||||||
sprintf(iconname, "%s,-102", currentfilename);
|
sprintf(iconname, "%s,-102", currentfilename);
|
||||||
sprintf(opencommand, "\"%s\" open \"%%1\"", currentfilename);
|
|
||||||
|
//Create Roaming application data folder
|
||||||
|
if(!SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA|CSIDL_FLAG_CREATE, NULL, 0, AppDataPath)))
|
||||||
|
{
|
||||||
|
returnval = 0;
|
||||||
|
goto finalise;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Move Game executable into application data folder
|
||||||
|
//TODO: Implement
|
||||||
|
|
||||||
|
opencommand = malloc(strlen(currentfilename)+53+strlen(AppDataPath));
|
||||||
|
if((strlen(AppDataPath)+strlen(APPDATA_SUBDIR "\\Powder Toy"))<MAX_PATH)
|
||||||
|
{
|
||||||
|
strappend(AppDataPath, APPDATA_SUBDIR);
|
||||||
|
#ifdef WIN32
|
||||||
|
if(_mkdir(AppDataPath))
|
||||||
|
#else
|
||||||
|
if(mkdir(AppDataPath, 0755))
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
returnval = 0;
|
||||||
|
goto finalise;
|
||||||
|
}
|
||||||
|
strappend(AppDataPath, "\\Powder Toy");
|
||||||
|
#ifdef WIN32
|
||||||
|
if(_mkdir(AppDataPath))
|
||||||
|
#else
|
||||||
|
if(mkdir(AppDataPath, 0755))
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
returnval = 0;
|
||||||
|
goto finalise;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
returnval = 0;
|
||||||
|
goto finalise;
|
||||||
|
}
|
||||||
|
sprintf(opencommand, "\"%s\" open \"%%1\" ddir \"%s\"", currentfilename, AppDataPath);
|
||||||
|
|
||||||
//Create extension entry
|
//Create extension entry
|
||||||
rresult = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Classes\\.cps", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &newkey, NULL);
|
rresult = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Classes\\.cps", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &newkey, NULL);
|
||||||
if (rresult != ERROR_SUCCESS) {
|
if (rresult != ERROR_SUCCESS) {
|
||||||
return 0;
|
returnval = 0;
|
||||||
|
goto finalise;
|
||||||
}
|
}
|
||||||
rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)"PowderToySave", strlen("PowderToySave")+1);
|
rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)"PowderToySave", strlen("PowderToySave")+1);
|
||||||
if (rresult != ERROR_SUCCESS) {
|
if (rresult != ERROR_SUCCESS) {
|
||||||
RegCloseKey(newkey);
|
RegCloseKey(newkey);
|
||||||
return 0;
|
returnval = 0;
|
||||||
|
goto finalise;
|
||||||
}
|
}
|
||||||
RegCloseKey(newkey);
|
RegCloseKey(newkey);
|
||||||
|
|
||||||
rresult = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Classes\\.stm", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &newkey, NULL);
|
rresult = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Classes\\.stm", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &newkey, NULL);
|
||||||
if (rresult != ERROR_SUCCESS) {
|
if (rresult != ERROR_SUCCESS) {
|
||||||
return 0;
|
returnval = 0;
|
||||||
|
goto finalise;
|
||||||
}
|
}
|
||||||
rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)"PowderToySave", strlen("PowderToySave")+1);
|
rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)"PowderToySave", strlen("PowderToySave")+1);
|
||||||
if (rresult != ERROR_SUCCESS) {
|
if (rresult != ERROR_SUCCESS) {
|
||||||
RegCloseKey(newkey);
|
RegCloseKey(newkey);
|
||||||
return 0;
|
returnval = 0;
|
||||||
|
goto finalise;
|
||||||
}
|
}
|
||||||
RegCloseKey(newkey);
|
RegCloseKey(newkey);
|
||||||
|
|
||||||
//Create program entry
|
//Create program entry
|
||||||
rresult = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Classes\\PowderToySave", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &newkey, NULL);
|
rresult = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Classes\\PowderToySave", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &newkey, NULL);
|
||||||
if (rresult != ERROR_SUCCESS) {
|
if (rresult != ERROR_SUCCESS) {
|
||||||
return 0;
|
returnval = 0;
|
||||||
|
goto finalise;
|
||||||
}
|
}
|
||||||
rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)"Powder Toy Save", strlen("Powder Toy Save")+1);
|
rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)"Powder Toy Save", strlen("Powder Toy Save")+1);
|
||||||
if (rresult != ERROR_SUCCESS) {
|
if (rresult != ERROR_SUCCESS) {
|
||||||
RegCloseKey(newkey);
|
RegCloseKey(newkey);
|
||||||
return 0;
|
returnval = 0;
|
||||||
|
goto finalise;
|
||||||
}
|
}
|
||||||
RegCloseKey(newkey);
|
RegCloseKey(newkey);
|
||||||
|
|
||||||
//Set DefaultIcon
|
//Set DefaultIcon
|
||||||
rresult = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Classes\\PowderToySave\\DefaultIcon", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &newkey, NULL);
|
rresult = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Classes\\PowderToySave\\DefaultIcon", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &newkey, NULL);
|
||||||
if (rresult != ERROR_SUCCESS) {
|
if (rresult != ERROR_SUCCESS) {
|
||||||
return 0;
|
returnval = 0;
|
||||||
|
goto finalise;
|
||||||
}
|
}
|
||||||
rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)iconname, strlen(iconname)+1);
|
rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)iconname, strlen(iconname)+1);
|
||||||
if (rresult != ERROR_SUCCESS) {
|
if (rresult != ERROR_SUCCESS) {
|
||||||
RegCloseKey(newkey);
|
RegCloseKey(newkey);
|
||||||
return 0;
|
returnval = 0;
|
||||||
|
goto finalise;
|
||||||
}
|
}
|
||||||
RegCloseKey(newkey);
|
RegCloseKey(newkey);
|
||||||
|
|
||||||
//Set Launch command
|
//Set Launch command
|
||||||
rresult = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Classes\\PowderToySave\\shell\\open\\command", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &newkey, NULL);
|
rresult = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Classes\\PowderToySave\\shell\\open\\command", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &newkey, NULL);
|
||||||
if (rresult != ERROR_SUCCESS) {
|
if (rresult != ERROR_SUCCESS) {
|
||||||
return 0;
|
returnval = 0;
|
||||||
|
goto finalise;
|
||||||
}
|
}
|
||||||
rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)opencommand, strlen(opencommand)+1);
|
rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)opencommand, strlen(opencommand)+1);
|
||||||
if (rresult != ERROR_SUCCESS) {
|
if (rresult != ERROR_SUCCESS) {
|
||||||
RegCloseKey(newkey);
|
RegCloseKey(newkey);
|
||||||
return 0;
|
returnval = 0;
|
||||||
|
goto finalise;
|
||||||
}
|
}
|
||||||
RegCloseKey(newkey);
|
RegCloseKey(newkey);
|
||||||
|
|
||||||
|
returnval = 1;
|
||||||
|
finalise:
|
||||||
|
|
||||||
if(iconname) free(iconname);
|
if(iconname) free(iconname);
|
||||||
if(opencommand) free(opencommand);
|
if(opencommand) free(opencommand);
|
||||||
if(currentfilename) free(currentfilename);
|
if(currentfilename) free(currentfilename);
|
||||||
|
|
||||||
return 1;
|
return returnval;
|
||||||
#elif defined(LIN32) || defined(LIN64)
|
#elif defined(LIN32) || defined(LIN64)
|
||||||
char *currentfilename = exe_name();
|
char *currentfilename = exe_name();
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
Reference in New Issue
Block a user