int main (int argc, char *argv[]) { struct sigaction sig_callback; g_thread_init (NULL); gdk_threads_init (); gtk_init (&argc, &argv); bindtextdomain (GETTEXT_PACKAGE, SNES9XLOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); ZeroMemory (&Settings, sizeof (Settings)); /* Allow original config file for backend settings */ S9xLoadConfigFiles (argv, argc); /* Perform our config here */ gui_config = new Snes9xConfig (); S9xInitInputDevices (); gui_config->load_config_file (); char *rom_filename = S9xParseArgs (argv, argc); S9xReportControllers (); if (!Memory.Init () || !S9xInitAPU ()) exit (3); g_set_application_name ("Snes9x"); top_level = new Snes9xWindow (gui_config); /* If we're going to fullscreen, do it before showing window to avoid flicker. */ if ((gui_config->full_screen_on_open && rom_filename) || (gui_config->fullscreen)) gtk_window_fullscreen (top_level->get_window ()); top_level->show (); S9xInitDisplay (argc, argv); Memory.PostRomInitFunc = S9xPostRomInit; S9xPortSoundInit (); gui_config->reconfigure (); top_level->update_accels (); Settings.Paused = TRUE; syncing = 0; idle_func_id = g_idle_add_full (IDLE_FUNC_PRIORITY, S9xIdleFunc, NULL, NULL); g_timeout_add (10000, S9xScreenSaverCheckFunc, NULL); S9xNoROMLoaded (); if (rom_filename) { if (S9xOpenROM (rom_filename) && gui_config->full_screen_on_open) gtk_window_unfullscreen (top_level->get_window()); } memset (&sig_callback, 0, sizeof (struct sigaction)); sig_callback.sa_handler = S9xTerm; sigaction (15 /* SIGTERM */, &sig_callback, NULL); sigaction (3 /* SIGQUIT */, &sig_callback, NULL); sigaction (2 /* SIGINT */, &sig_callback, NULL); if (gui_config->fullscreen) { gui_config->fullscreen = 0; needs_fullscreening = 1; } #ifdef USE_JOYSTICK gui_config->flush_joysticks (); #endif gtk_window_present (top_level->get_window ()); gdk_threads_lock (); gtk_main (); return 0; }
const char* WinParseCommandLineAndLoadConfigFile (char *line) { // Break the command line up into an array of string pointers, each pointer // points at a separate word or character sequence enclosed in quotes. #define MAX_PARAMETERS 100 char *p = line; static char *parameters [MAX_PARAMETERS]; int count = 0; //parameters [count++] = "Snes9X"; while (count < MAX_PARAMETERS && *p) { p = SkipSpaces (p); if (*p == '"') { p++; parameters [count++] = p; while (*p && *p != '"') p++; *p++ = 0; } else if (*p == '\'') { p++; parameters [count++] = p; while (*p && *p != '\'') p++; *p++ = 0; } else { parameters [count++] = p; while (*p && !isspace (*p)) p++; if (!*p) break; *p++ = 0; } } configMutex = CreateMutex(NULL, FALSE, TEXT("Snes9xConfigMutex")); int times = 0; DWORD waitVal = WAIT_TIMEOUT; while(waitVal == WAIT_TIMEOUT && ++times <= 150) // wait at most 15 seconds waitVal = WaitForSingleObject(configMutex, 100); // ensure previous config file is not lost if we crashed while writing a new one { std::string ftemp; ftemp=S9xGetDirectory(DEFAULT_DIR); ftemp+=SLASH_STR "config_error"; FILE* tempfile = fopen(ftemp.c_str(), "rb"); if(tempfile) { fclose(tempfile); std::string fname; for(int i=0; i<2; i++) { fname=S9xGetDirectory(DEFAULT_DIR); if(i == 0) fname+=SLASH_STR "snes9x.conf"; else if(i == 1) fname+=SLASH_STR "snes9x.cfg"; tempfile = fopen((fname + ".autobak").c_str(), "rb"); if(tempfile) { fclose(tempfile); MoveFileExA((fname + ".autobak").c_str(), fname.c_str(), MOVEFILE_REPLACE_EXISTING|MOVEFILE_WRITE_THROUGH); } } remove(ftemp.c_str()); } } S9xLoadConfigFiles(parameters, count); ReleaseMutex(configMutex); CloseHandle(configMutex); const char* rf = S9xParseArgs (parameters, count); /*if(rf) strcpy(rom_filename, rf); else rom_filename[0] = '\0';*/ return rf; }