| 3287 | int main(int argc, const char **argv) { |
| 3288 | #else |
| 3289 | int wmain(int argc, wchar_t **wargv) { |
| 3290 | vector<string> utf8_args; |
| 3291 | utf8_args.resize(argc); |
| 3292 | vector<const char *> utf8_args_ptrs; |
| 3293 | utf8_args_ptrs.resize(argc); |
| 3294 | const char **argv = utf8_args_ptrs.data(); |
| 3295 | for (int i = 0; i < argc; i++) { |
| 3296 | utf8_args[i] = ShellState::Win32UnicodeToUtf8(wargv[i]); |
| 3297 | utf8_args_ptrs[i] = utf8_args[i].c_str(); |
| 3298 | } |
| 3299 | #endif |
| 3300 | |
| 3301 | auto &shell_state = ShellState::GetReference(); |
| 3302 | int rc = 0; |
| 3303 | try { |
| 3304 | rc = RunShell(argc, argv); |
| 3305 | } catch (std::exception &ex) { |
| 3306 | rc = 1; |
| 3307 | ErrorData error(ex); |
| 3308 | fprintf(stderr, "Exited due to error: %s", error.Message().c_str()); |
| 3309 | } |
| 3310 | try { |
| 3311 | // destroy shell state prior to program clean-up |
| 3312 | if (shell_state) { |
| 3313 | delete shell_state; |
| 3314 | } |
| 3315 | shell_state = nullptr; |
| 3316 | } catch (std::exception &ex) { |
| 3317 | rc = 1; |
| 3318 | ErrorData error(ex); |
| 3319 | fprintf(stderr, "Error during clean-up due to error: %s", error.Message().c_str()); |
| 3320 | } |
| 3321 | return rc; |
| 3322 | } |