28 #define BUFFER_SIZE 1024 36 #define UNINST_KEY "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Panda3D Game Engine" 38 int main (
int argc,
char* argv[]) {
40 char buffer[BUFFER_SIZE];
45 PROCESS_INFORMATION pi;
50 DWORD dwType = REG_SZ;
51 DWORD dwBufSize =
sizeof(buf);
52 size = GetModuleFileName(NULL, buffer, BUFFER_SIZE);
56 p3dfile = (
char*) _alloca(size + 1);
57 memcpy(p3dfile, buffer, size);
59 memcpy(p3dfile + size - 3,
"p3d", 3);
64 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, UNINST_KEY, 0, KEY_QUERY_VALUE | KEY_WOW64_64KEY, &hKey) == ERROR_SUCCESS) {
65 if (RegQueryValueEx(hKey,
"DisplayIcon", 0, &dwType, (BYTE*) buf, &dwBufSize) == ERROR_SUCCESS) {
66 char *slash = strrchr(buf,
'\\');
68 strcpy(slash,
"\\panda3d.exe");
77 if (runtime == NULL) {
78 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, UNINST_KEY, 0, KEY_QUERY_VALUE | KEY_WOW64_32KEY, &hKey) == ERROR_SUCCESS) {
79 if (RegQueryValueEx(hKey,
"DisplayIcon", 0, &dwType, (BYTE*) buf, &dwBufSize) == ERROR_SUCCESS) {
80 char *slash = strrchr(buf,
'\\');
82 strcpy(slash,
"\\panda3d.exe");
93 if (runtime == NULL) {
94 if (RegOpenKey(HKEY_CLASSES_ROOT,
"Panda3D applet\\DefaultIcon", &hKey) == ERROR_SUCCESS) {
95 if (RegQueryValueEx(hKey, 0, 0, &dwType, (BYTE*) buf, &dwBufSize) == ERROR_SUCCESS) {
96 char *slash = strrchr(buf,
'\\');
98 strcpy(slash,
"\\panda3d.exe");
102 fprintf(stderr,
"Failed to read registry key. Try reinstalling the Panda3D Runtime.\n");
107 fprintf(stderr,
"The Panda3D Runtime does not appear to be installed!\n");
112 if (runtime == NULL) {
113 fprintf(stderr,
"Failed to find panda3d.exe in registry. Try reinstalling the Panda3D Runtime.\n");
118 cmd = GetCommandLine();
119 newcmd = (
char*) _alloca(strlen(runtime) + strlen(p3dfile) + strlen(cmd) - strlen (argv[0]) + 7);
120 sprintf(newcmd,
"\"%s\" \"%s\" %s", runtime, p3dfile, cmd + strlen(argv[0]));
121 memset(&si, 0,
sizeof(si));
122 si.cb =
sizeof(STARTUPINFO);
123 if (CreateProcess(runtime, newcmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) {
124 WaitForSingleObject(pi.hProcess, INFINITE);