| 58 | } |
| 59 | |
| 60 | int main(int argc, char *argv[]) |
| 61 | { |
| 62 | //return main2(); |
| 63 | int ret = 0; |
| 64 | const char *open_file = NULL; |
| 65 | int logLevel = -1; |
| 66 | bool bStoreLog = false; |
| 67 | |
| 68 | //----------------------rebuild command param |
| 69 | #ifdef _WIN32 |
| 70 | // Under Windows, we need to manually retrieve the command-line arguments and convert them from UTF-16 to UTF-8. |
| 71 | // This prevents data loss if there are any characters that wouldn't fit in the local ANSI code page. |
| 72 | int argcUTF16 = 0; |
| 73 | LPWSTR* argvUTF16 = CommandLineToArgvW(GetCommandLineW(), &argcUTF16); |
| 74 | |
| 75 | std::vector<QByteArray> argvUTF8Q; |
| 76 | std::for_each(argvUTF16, argvUTF16 + argcUTF16, [&argvUTF8Q](const LPWSTR& arg) { |
| 77 | argvUTF8Q.emplace_back(QString::fromUtf16(reinterpret_cast<const char16_t*>(arg), -1).toUtf8()); |
| 78 | }); |
| 79 | |
| 80 | LocalFree(argvUTF16); |
| 81 | |
| 82 | // Ms::runApplication() wants an argv-style array of raw pointers to the arguments, so let's create a vector of them. |
| 83 | std::vector<char*> argvUTF8; |
| 84 | for (auto& arg : argvUTF8Q){ |
| 85 | argvUTF8.push_back(arg.data()); |
| 86 | } |
| 87 | |
| 88 | // Don't use the arguments passed to main(), because they're in the local ANSI code page. |
| 89 | (void*)(argc); |
| 90 | (void*)(argv); |
| 91 | |
| 92 | int argcFinal = argcUTF16; |
| 93 | char** argvFinal = argvUTF8.data(); |
| 94 | #else |
| 95 | int argcFinal = argc; |
| 96 | char** argvFinal = argv; |
| 97 | #endif |
| 98 | |
| 99 | //----------------------command param parse |
| 100 | while (1) { |
| 101 | static const struct option long_options[] = { |
| 102 | {"loglevel", required_argument, 0, 'l'}, |
| 103 | {"version", no_argument, 0, 'v'}, |
| 104 | {"storelog", no_argument, 0, 's'}, |
| 105 | {"help", no_argument, 0, 'h'}, |
| 106 | {0, 0, 0, 0} |
| 107 | }; |
| 108 | |
| 109 | const char *shortopts = "l:Vvhs?"; |
| 110 | const int c = getopt_long(argcFinal, argvFinal, shortopts, long_options, NULL); |
| 111 | if (c == -1) |
| 112 | break; |
| 113 | |
| 114 | switch (c) |
| 115 | { |
| 116 | case 'l': // log level |
| 117 | logLevel = atoi(optarg); |
nothing calls this directly
no test coverage detected