]> Shamusworld >> Repos - virtualjaguar/blobdiff - src/gui/app.cpp
QString no longer supports toAscii, use toUtf8 instead
[virtualjaguar] / src / gui / app.cpp
index 10df86c646bd811afacaad00532b4afcac63c7d5..e0b942be432bcf05c4120d7a2e7cb4f7c915f5b4 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,14 +40,38 @@ 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
+       // [Unfortunately, this doesn't seem to work on Vista/7. :-(]
+#ifdef __GCCWIN32__
+       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
        vjs.hardwareTypeAlpine = false;
        // This is stuff we pass into the mainWindow...
        // Normally, this would be read in from the settings module... :-P
        vjs.hardwareTypeAlpine = false;
        // This is stuff we pass into the mainWindow...
@@ -52,7 +79,9 @@ 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))
+       {
                return 0;
                return 0;
+       }
 
        Q_INIT_RESOURCE(virtualjaguar); // This must the same name as the exe filename
 //or is it the .qrc filename???
 
        Q_INIT_RESOURCE(virtualjaguar); // This must the same name as the exe filename
 //or is it the .qrc filename???
@@ -79,32 +108,47 @@ 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);
                SDL_Quit();
        }
 
 
                // Free SDL components last...!
                SDL_QuitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_AUDIO);
                SDL_Quit();
        }
 
-       LogDone();                                                                      // Close logfile
+#ifdef __GCCWIN32__
+#if 0
+       fclose(ctt);
+#endif
+#endif
+       // Close logfile
+       LogDone();
        return retVal;
 }
 
 //
 // Main app constructor--we stick globally accessible stuff here... (?)
 //
        return retVal;
 }
 
 //
 // 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();
 
        mainWindow = new MainWin(loadAndGo);
        mainWindow->plzDontKillMyComputer = noUntunedTankPlease;
 {
        bool loadAndGo = !filename.isEmpty();
 
        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->SyncUI();
 
        if (loadAndGo)
+       {
                mainWindow->LoadFile(filename);
 
                mainWindow->LoadFile(filename);
 
+               if (!mainWindow->cartridgeLoaded)
+                       printf("Could not load file \"%s\"!\n", filename.toUtf8().data());
+       }
+
        mainWindow->show();
 }
 
        mainWindow->show();
 }
 
@@ -123,8 +167,8 @@ bool ParseCommandLine(int argc, char * argv[])
                        printf(
                                "Virtual Jaguar " VJ_RELEASE_VERSION " (" VJ_RELEASE_SUBVERSION ")\n"
                                "Based upon Virtual Jaguar core v1.0.0 by David Raingeard.\n"
                        printf(
                                "Virtual Jaguar " VJ_RELEASE_VERSION " (" VJ_RELEASE_SUBVERSION ")\n"
                                "Based upon Virtual Jaguar core v1.0.0 by David Raingeard.\n"
-                               "Written by Niels Wagenaar (Linux/WIN32), Carwin Jones (BeOS),\n"
-                               "James Hammons (Linux/WIN32) and Adam Green (MacOS)\n"
+                               "Written by James Hammons (Linux/WIN32), Niels Wagenaar (Linux/WIN32),\n"
+                               "Carwin Jones (BeOS), and Adam Green (MacOS)\n"
                                "Contact: http://sdlemu.ngemu.com/ | sdlemu@ngemu.com\n"
                                "\n"
                                "Usage:\n"
                                "Contact: http://sdlemu.ngemu.com/ | sdlemu@ngemu.com\n"
                                "\n"
                                "Usage:\n"
@@ -148,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"
                                "   --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"
                                "\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;
                }
                                "\n");
                        return false;
                }
@@ -167,9 +213,11 @@ bool ParseCommandLine(int argc, char * argv[])
                {
                        printf("Alpine Mode enabled.\n");
                        vjs.hardwareTypeAlpine = true;
                {
                        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)
+               if ((strcmp(argv[i], "--please-dont-kill-my-computer") == 0) || (strcmp(argv[i], "-z") == 0))
                {
                        noUntunedTankPlease = true;
                }
                {
                        noUntunedTankPlease = true;
                }
@@ -199,6 +247,8 @@ bool ParseCommandLine(int argc, char * argv[])
 //
 // This is to override settings loaded from the config file.
 // Note that settings set here will become the new defaults!
 //
 // This is to override settings loaded from the config file.
 // Note that settings set here will become the new defaults!
+// (Not any more: Settings are only saved if the config dialog was OKed, or
+// the toolbar buttons were pressed.)
 //
 void ParseOptions(int argc, char * argv[])
 {
 //
 void ParseOptions(int argc, char * argv[])
 {
@@ -294,3 +344,4 @@ void ParseOptions(int argc, char * argv[])
        char alpineROMPath[MAX_PATH];
        char absROMPath[MAX_PATH];
 #endif
        char alpineROMPath[MAX_PATH];
        char absROMPath[MAX_PATH];
 #endif
+