mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-11 13:17:00 -04:00
'main' function is now app::OnRun, this allows us to not enter the main loop.
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@664 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
+19
-14
@@ -30,8 +30,13 @@
|
|||||||
*/
|
*/
|
||||||
class MSE : public wxApp {
|
class MSE : public wxApp {
|
||||||
public:
|
public:
|
||||||
|
/// Do nothing. The command line parsing, etc. is done in OnRun
|
||||||
|
bool OnInit() { return true; }
|
||||||
/// Main startup function of the program
|
/// Main startup function of the program
|
||||||
bool OnInit();
|
/** Use OnRun instead of OnInit, so we can determine whether or not we need a main loop
|
||||||
|
* Also, OnExit is always run.
|
||||||
|
*/
|
||||||
|
int OnRun();
|
||||||
/// On exit: write the settings to the config file
|
/// On exit: write the settings to the config file
|
||||||
int OnExit();
|
int OnExit();
|
||||||
/// On exception: display error message
|
/// On exception: display error message
|
||||||
@@ -60,7 +65,7 @@ void write_stdout(const String& str) {
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------------- : Initialization
|
// ----------------------------------------------------------------------------- : Initialization
|
||||||
|
|
||||||
bool MSE::OnInit() {
|
int MSE::OnRun() {
|
||||||
try {
|
try {
|
||||||
#ifdef __WXMSW__
|
#ifdef __WXMSW__
|
||||||
SetAppName(_("Magic Set Editor"));
|
SetAppName(_("Magic Set Editor"));
|
||||||
@@ -86,12 +91,12 @@ bool MSE::OnInit() {
|
|||||||
// Show the symbol editor
|
// Show the symbol editor
|
||||||
Window* wnd = new SymbolWindow(nullptr, argv[1]);
|
Window* wnd = new SymbolWindow(nullptr, argv[1]);
|
||||||
wnd->Show();
|
wnd->Show();
|
||||||
return true;
|
return wxApp::OnRun();
|
||||||
} else if (f.GetExt() == _("mse-set") || f.GetExt() == _("mse") || f.GetExt() == _("set")) {
|
} else if (f.GetExt() == _("mse-set") || f.GetExt() == _("mse") || f.GetExt() == _("set")) {
|
||||||
// Show the set window
|
// Show the set window
|
||||||
Window* wnd = new SetWindow(nullptr, import_set(argv[1]));
|
Window* wnd = new SetWindow(nullptr, import_set(argv[1]));
|
||||||
wnd->Show();
|
wnd->Show();
|
||||||
return true;
|
return wxApp::OnRun();
|
||||||
} else if (f.GetExt() == _("mse-installer")) {
|
} else if (f.GetExt() == _("mse-installer")) {
|
||||||
// Installer; install it
|
// Installer; install it
|
||||||
bool local = false;
|
bool local = false;
|
||||||
@@ -100,11 +105,11 @@ bool MSE::OnInit() {
|
|||||||
local = arg2 == _("--local");
|
local = arg2 == _("--local");
|
||||||
}
|
}
|
||||||
Installer::installFrom(argv[1], true, local);
|
Installer::installFrom(argv[1], true, local);
|
||||||
return true;
|
return EXIT_SUCCESS;
|
||||||
} else if (arg == _("--symbol-editor")) {
|
} else if (arg == _("--symbol-editor")) {
|
||||||
Window* wnd = new SymbolWindow(nullptr);
|
Window* wnd = new SymbolWindow(nullptr);
|
||||||
wnd->Show();
|
wnd->Show();
|
||||||
return true;
|
return wxApp::OnRun();
|
||||||
} else if (arg == _("--create-installer")) {
|
} else if (arg == _("--create-installer")) {
|
||||||
// create an installer
|
// create an installer
|
||||||
Installer inst;
|
Installer inst;
|
||||||
@@ -116,7 +121,7 @@ bool MSE::OnInit() {
|
|||||||
} else {
|
} else {
|
||||||
inst.saveAs(inst.prefered_filename, false);
|
inst.saveAs(inst.prefered_filename, false);
|
||||||
}
|
}
|
||||||
return true;
|
return EXIT_SUCCESS;
|
||||||
} else if (arg == _("--help") || arg == _("-?")) {
|
} else if (arg == _("--help") || arg == _("-?")) {
|
||||||
// command line help
|
// command line help
|
||||||
write_stdout( String(_("Magic Set Editor\n\n"))
|
write_stdout( String(_("Magic Set Editor\n\n"))
|
||||||
@@ -127,28 +132,29 @@ bool MSE::OnInit() {
|
|||||||
+ _(" FILE.mse \tLoad the set file in the MSE user interface.\n")
|
+ _(" FILE.mse \tLoad the set file in the MSE user interface.\n")
|
||||||
+ _(" FILE.mse-symbol \tLoad the symbol into the MSE symbol editor.\n")
|
+ _(" FILE.mse-symbol \tLoad the symbol into the MSE symbol editor.\n")
|
||||||
+ _(" FILE.mse-installer\tInstall the packages from the installer.\n")
|
+ _(" FILE.mse-installer\tInstall the packages from the installer.\n")
|
||||||
|
+ _(" --local \tInstall packages for this user only.\n")
|
||||||
+ _(" -? --help \tShows this help screen.\n")
|
+ _(" -? --help \tShows this help screen.\n")
|
||||||
+ _(" -v --version \tShow version information.\n")
|
+ _(" -v --version \tShow version information.\n")
|
||||||
|
+ _(" --symbol-editor \tShow the symbol editor instead of the welcome window.\n")
|
||||||
+ _(" --create-installer\n")
|
+ _(" --create-installer\n")
|
||||||
+ _(" FILE [FILE]...\tCreate an instaler named FILE, containing the listed packges.\n") );
|
+ _(" FILE [FILE]...\tCreate an instaler named FILE, containing the listed packges.\n") );
|
||||||
return true;
|
return EXIT_SUCCESS;
|
||||||
} else if (arg == _("--version") || arg == _("-v")) {
|
} else if (arg == _("--version") || arg == _("-v")) {
|
||||||
// dump version
|
// dump version
|
||||||
write_stdout( _("Magic Set Editor\nVersion ") + app_version.toString() + version_suffix );
|
write_stdout( _("Magic Set Editor\nVersion ") + app_version.toString() + version_suffix );
|
||||||
return true;
|
return EXIT_SUCCESS;
|
||||||
} else {
|
} else {
|
||||||
handle_error(_("Invalid command line argument:\n") + String(argv[1]));
|
handle_error(_("Invalid command line argument:\n") + String(argv[1]));
|
||||||
}
|
}
|
||||||
} catch (const Error& e) {
|
} catch (const Error& e) {
|
||||||
handle_error(e);
|
handle_error(e);
|
||||||
OnExit();
|
return EXIT_FAILURE;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// no command line arguments, or error, show welcome window
|
// no command line arguments, or error, show welcome window
|
||||||
(new WelcomeWindow())->Show();
|
(new WelcomeWindow())->Show();
|
||||||
return true;
|
return wxApp::OnRun();
|
||||||
|
|
||||||
} catch (const Error& e) {
|
} catch (const Error& e) {
|
||||||
handle_error(e, false);
|
handle_error(e, false);
|
||||||
@@ -158,8 +164,7 @@ bool MSE::OnInit() {
|
|||||||
} catch (...) {
|
} catch (...) {
|
||||||
handle_error(InternalError(_("An unexpected exception occurred!")), false);
|
handle_error(InternalError(_("An unexpected exception occurred!")), false);
|
||||||
}
|
}
|
||||||
OnExit();
|
return EXIT_FAILURE;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : Exit
|
// ----------------------------------------------------------------------------- : Exit
|
||||||
|
|||||||
Reference in New Issue
Block a user