doukutsu-rs/src/main.rs

52 lines
1.5 KiB
Rust
Raw Permalink Normal View History

#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
2021-01-27 18:20:47 +00:00
use std::process::exit;
fn main() {
2021-10-14 04:54:11 +00:00
let args = std::env::args();
2022-11-19 17:20:03 +00:00
let mut options = doukutsu_rs::game::LaunchOptions { server_mode: false, editor: false };
2021-10-14 04:54:11 +00:00
for arg in args {
if arg == "--server-mode" {
options.server_mode = true;
}
2022-01-06 01:11:17 +00:00
if arg == "--editor" {
options.editor = true;
}
}
if options.server_mode && options.editor {
eprintln!("Cannot run in server mode and editor mode at the same time.");
exit(1);
2021-10-14 04:54:11 +00:00
}
2022-11-19 17:20:03 +00:00
let result = doukutsu_rs::game::init(options);
2021-01-27 18:20:47 +00:00
#[cfg(target_os = "windows")]
unsafe {
2022-11-19 17:20:03 +00:00
use std::ffi::OsStr;
use std::os::windows::prelude::*;
2021-01-27 18:20:47 +00:00
use winapi::_core::ptr::null_mut;
2022-11-19 17:20:03 +00:00
use winapi::shared::ntdef::LPCWSTR;
2021-01-27 18:20:47 +00:00
use winapi::um::winuser::MessageBoxW;
use winapi::um::winuser::MB_OK;
if let Err(e) = result {
2022-11-19 17:20:03 +00:00
let title: LPCWSTR = OsStr::new("Error!").encode_wide().chain(Some(0)).collect::<Vec<u16>>().as_ptr();
2021-04-03 20:15:17 +00:00
let message: LPCWSTR = OsStr::new(format!("Whoops, doukutsu-rs crashed: {}", e).as_str())
2022-11-19 17:20:03 +00:00
.encode_wide()
.chain(Some(0))
.collect::<Vec<u16>>()
.as_ptr();
MessageBoxW(null_mut(), message, title, MB_OK);
2021-01-27 18:20:47 +00:00
exit(1);
}
}
if let Err(e) = result {
2021-10-14 04:54:11 +00:00
eprintln!("Initialization error: {}", e);
2021-01-27 18:20:47 +00:00
exit(1);
}
2020-08-18 16:46:07 +00:00
}