]> Shamusworld >> Repos - virtualjaguar/blobdiff - src/gui/app.cpp
Special patch by ggn. :-)
[virtualjaguar] / src / gui / app.cpp
index 220275a2cee506c98e0b1ac45afe309f901f0a0e..bbe1333a04cb15af8fdd4624f2f5ce25e30fb8fd 100644 (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  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"
 
 #include <SDL.h>
 #include <QApplication>
 //
 
 #include "app.h"
 
 #include <SDL.h>
 #include <QApplication>
+#include "gamepad.h"
 #include "log.h"
 #include "mainwin.h"
 #include "log.h"
 #include "mainwin.h"
+#include "profile.h"
 #include "settings.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 "version.h"
 
 
 // Apparently on win32, SDL is hijacking main from Qt. So let's do this:
 #ifdef __GCCWIN32__
 #undef main
+#include <windows.h>   // Ick, but needed for console redirection on win32 :-O
 #endif
 
 // Function prototypes...
 #endif
 
 // Function prototypes...
@@ -37,23 +40,36 @@ static void ParseOptions(int argc, char * argv[]);
 
 //hm. :-/
 // This is stuff we pass into the mainWindow...
 
 //hm. :-/
 // This is stuff we pass into the mainWindow...
+// Also, these are defaults. :-)
 bool noUntunedTankPlease = false;
 bool loadAndGo = false;
 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[])
 {
 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__
 #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
 #endif
 
        // Normally, this would be read in from the settings module... :-P
@@ -64,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))
        {
        // 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;
        }
 
                return 0;
        }
 
@@ -97,7 +108,10 @@ int main(int argc, char * argv[])
        {
                WriteLog("VJ: SDL (joystick, audio) successfully initialized.\n");
                App app(argc, argv);                                    // Declare an instance of the application
        {
                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!
                retVal = app.exec();                                    // And run it!
+               Gamepad::DeallocateJoysticks();
 
                // Free SDL components last...!
                SDL_QuitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_AUDIO);
 
                // Free SDL components last...!
                SDL_QuitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_AUDIO);
@@ -116,7 +130,7 @@ int main(int argc, char * argv[])
 //
 // Main app constructor--we stick globally accessible stuff here... (?)
 //
 //
 // Main app constructor--we stick globally accessible stuff here... (?)
 //
-App::App(int argc, char * argv[]): QApplication(argc, argv)
+App::App(int argc, char * argv[]): QApplication(argc, argv)
 {
        bool loadAndGo = !filename.isEmpty();
 
 {
        bool loadAndGo = !filename.isEmpty();
 
@@ -171,6 +185,8 @@ 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"
                                "   --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"
                                "\n"
                                "Invoking Virtual Jagaur with no filename will cause it to boot up\n"
                                "with the VJ GUI.\n"