X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fgui%2Fapp.cpp;h=9414dd4c6674ded2126adbacff1df1ef948e966c;hb=d207b11e613703aff7d00191c4595b7359f29700;hp=3961d31aaef3c92b7aba18b2790623fa79e7c11f;hpb=5c28b6dbf7aa20441c8a51f484f4f64b1966f7e3;p=virtualjaguar diff --git a/src/gui/app.cpp b/src/gui/app.cpp index 3961d31..9414dd4 100644 --- a/src/gui/app.cpp +++ b/src/gui/app.cpp @@ -7,11 +7,12 @@ // JLH = James Hammons // // Who When What -// --- ---------- ------------------------------------------------------------- +// --- ---------- ----------------------------------------------------------- // JLH 12/23/2009 Created this file // JLH 01/21/2011 Added SDL initialization // JLH 06/26/2011 Added fix to keep SDL from hijacking main() on win32 // JLH 05/24/2012 Added option switches +// JLH 03/05/2013 Fixed console redireciton on win32 platform :-P // #include "app.h" @@ -21,14 +22,15 @@ #include "gamepad.h" #include "log.h" #include "mainwin.h" +#include "profile.h" #include "settings.h" -#include "types.h" #include "version.h" // Apparently on win32, SDL is hijacking main from Qt. So let's do this: #ifdef __GCCWIN32__ #undef main +#include // Ick, but needed for console redirection on win32 :-O #endif // Function prototypes... @@ -38,23 +40,36 @@ static void ParseOptions(int argc, char * argv[]); //hm. :-/ // This is stuff we pass into the mainWindow... +// Also, these are defaults. :-) bool noUntunedTankPlease = false; bool loadAndGo = false; -bool useLogfile = true; +bool useLogfile = false; QString filename; // Here's the main application loop--short and simple... int main(int argc, char * argv[]) { - // Win32 console redirection, because MS and their band of super geniuses decided - // that nobody would ever launch an app from the command line. :-P - // And, of course, this doesn't work, but causes weird problems. Yay Microsoft. :-/ + // Win32 console redirection, because MS and their band of super geniuses + // decided that nobody would ever launch an app from the command line. :-P + // [Unfortunately, this doesn't seem to work on Vista/7. :-(] #ifdef __GCCWIN32__ -#if 0 - FILE * ctt = fopen("CON", "w"); - freopen("CON", "w", stdout); - freopen("CON", "w", stderr); -#endif + BOOL (WINAPI * AttachConsole)(DWORD dwProcessId); + + AttachConsole = (BOOL (WINAPI *)(DWORD)) + GetProcAddress(LoadLibraryA("kernel32.dll"), "AttachConsole"); + + if (AttachConsole != NULL && AttachConsole(((DWORD)-1))) + { + if (_fileno(stdout) == -1) + freopen("CONOUT$", "wb", stdout); + if (_fileno(stderr) == -1) + freopen("CONOUT$", "wb", stderr); + if (_fileno(stdin) == -1) + freopen("CONIN$", "rb", stdin); + + // Fix C++ + std::ios::sync_with_stdio(); + } #endif // Normally, this would be read in from the settings module... :-P @@ -65,11 +80,6 @@ int main(int argc, char * argv[]) // Check for options that must be in place be constructing the App object if (!ParseCommandLine(argc, argv)) { -#ifdef __GCCWIN32__ -#if 0 - fclose(ctt); -#endif -#endif return 0; } @@ -99,6 +109,7 @@ int main(int argc, char * argv[]) WriteLog("VJ: SDL (joystick, audio) successfully initialized.\n"); App app(argc, argv); // Declare an instance of the application Gamepad::AllocateJoysticks(); + AutoConnectProfiles(); retVal = app.exec(); // And run it! Gamepad::DeallocateJoysticks(); @@ -112,7 +123,8 @@ int main(int argc, char * argv[]) fclose(ctt); #endif #endif - LogDone(); // Close logfile + // Close logfile + LogDone(); return retVal; } @@ -125,12 +137,18 @@ App::App(int & argc, char * argv[]): QApplication(argc, argv) mainWindow = new MainWin(loadAndGo); mainWindow->plzDontKillMyComputer = noUntunedTankPlease; - ParseOptions(argc, argv); // Override defaults with command line (if any) + // Override defaults with command line (if any) + ParseOptions(argc, argv); mainWindow->SyncUI(); if (loadAndGo) + { mainWindow->LoadFile(filename); + if (!mainWindow->cartridgeLoaded) + printf("Could not load file \"%s\"!\n", filename.toUtf8().data()); + } + mainWindow->show(); } @@ -174,9 +192,11 @@ bool ParseCommandLine(int argc, char * argv[]) " --log -l Create and use log file\n" " --no-log Do not use log file\n" " --help -h Show this message\n" + " --please-dont-kill-my-computer\n" + " -z Run Virtual Jaguar without \"snow\"\n" "\n" "Invoking Virtual Jagaur with no filename will cause it to boot up\n" - "with the VJ GUI.\n" + "with the VJ GUI. Using Alpine mode will enable log file.\n" "\n"); return false; } @@ -193,6 +213,8 @@ bool ParseCommandLine(int argc, char * argv[]) { printf("Alpine Mode enabled.\n"); vjs.hardwareTypeAlpine = true; + // We also enable logging as well :-) + useLogfile = true; } if ((strcmp(argv[i], "--please-dont-kill-my-computer") == 0) || (strcmp(argv[i], "-z") == 0)) @@ -322,3 +344,4 @@ void ParseOptions(int argc, char * argv[]) char alpineROMPath[MAX_PATH]; char absROMPath[MAX_PATH]; #endif +