From 9d2e08a8c7c94d08fa059644ff2fecfcca14762c Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sat, 12 Mar 2011 02:28:00 +0000 Subject: [PATCH] - g3d viewer now auto registers g3d files with itself in windows so users may double click a g3d file to launch it within the viewer from explorer. Windows G3d is now a console application so we can see commandline options and console output --- mk/windoze/g3d_viewer.vcproj | 4 +-- source/g3d_viewer/main.cpp | 55 +++++++++++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/mk/windoze/g3d_viewer.vcproj b/mk/windoze/g3d_viewer.vcproj index 3befc670b..4f1afac5a 100755 --- a/mk/windoze/g3d_viewer.vcproj +++ b/mk/windoze/g3d_viewer.vcproj @@ -69,7 +69,7 @@ LinkIncremental="2" AdditionalLibraryDirectories="../../source/win32_deps/lib;"../../build/$(ConfigurationName)/libglest";../../source/shared_lib/sources/streflop/libstreflop" GenerateDebugInformation="true" - SubSystem="2" + SubSystem="1" TargetMachine="1" /> #include "config.h" #include "game_constants.h" +#include +//#include #ifndef WIN32 #define stricmp strcasecmp @@ -108,7 +110,7 @@ bool hasCommandArgument(int argc, wxChar** argv,const string argName, if(foundIndex != NULL) { *foundIndex = -1; } - int compareLen = strlen(argName.c_str()); + size_t compareLen = strlen(argName.c_str()); for(int idx = startLookupIndex; idx < argc; idx++) { const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(argv[idx]); @@ -389,6 +391,35 @@ MainWindow::MainWindow( std::pair > unitToLoad, timer = new wxTimer(this); timer->Start(100); + + // For windows register g3d file extension to launch this app +#ifdef WIN32 + // example from: http://stackoverflow.com/questions/1387769/create-registry-entry-to-associate-file-extension-with-application-in-c + //[HKEY_CURRENT_USER\Software\Classes\blergcorp.blergapp.v1\shell\open\command] + //@="c:\path\to\app.exe \"%1\"" + //[HKEY_CURRENT_USER\Software\Classes\.blerg] + //@="blergcorp.blergapp.v1" + + //Open the registry key. + string subKey = "Software\\Classes\\megaglest.g3d\\shell\\open\\command"; + HKEY keyHandle; + DWORD dwDisposition; + RegCreateKeyEx(HKEY_CURRENT_USER,subKey.c_str(),0, NULL, 0, KEY_ALL_ACCESS, NULL, &keyHandle, &dwDisposition); + //Set the value. + string launchApp = appPath + " \"%1\""; + DWORD len = launchApp.length() + 1; + RegSetValueEx(keyHandle, NULL, 0, REG_SZ, (PBYTE)launchApp.c_str(), len); + RegCloseKey(keyHandle); + + subKey = "Software\\Classes\\.g3d"; + RegCreateKeyEx(HKEY_CURRENT_USER,subKey.c_str(),0, NULL, 0, KEY_ALL_ACCESS, NULL, &keyHandle, &dwDisposition); + //Set the value. + launchApp = "megaglest.g3d"; + len = launchApp.length() + 1; + RegSetValueEx(keyHandle, NULL, 0, REG_SZ, (PBYTE)launchApp.c_str(), len); + RegCloseKey(keyHandle); + +#endif } MainWindow::~MainWindow(){ @@ -2024,13 +2055,29 @@ bool App::OnInit(){ } string appPath = ""; + +//#if defined(__MINGW32__) +// const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(argv[0])); +// appPath = tmp_buf; +//#else +// appPath = wxFNCONV(argv[0]); +//#endif +// printf("appPath [%s]\n",argv[0]); + + wxString exe_path = wxStandardPaths::Get().GetExecutablePath(); + //wxString path_separator = wxFileName::GetPathSeparator(); + //exe_path = exe_path.BeforeLast(path_separator[0]); + //exe_path += path_separator; + #if defined(__MINGW32__) - const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(argv[0])); + const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(exe_path)); appPath = tmp_buf; #else - appPath = wxFNCONV(argv[0]); + appPath = wxFNCONV(exe_path); #endif +// printf("#2 appPath [%s]\n",appPath.c_str()); + mainWindow= new MainWindow( unitToLoad, modelPath, particlePath, @@ -2068,4 +2115,4 @@ int App::OnExit(){ }}//end namespace -IMPLEMENT_APP(Shared::G3dViewer::App) +IMPLEMENT_APP_CONSOLE(Shared::G3dViewer::App)