From 3a8e8f8e8a351d179018ecd8cdcf87fef6214007 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 1 Nov 2013 00:16:35 +0900 Subject: [PATCH] mingw32: Use CommandLineToArgvW() and GetCommandLineW() to read cmd-line args This change enables aria2 to read unicode characters in command-line. --- src/main.cc | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/main.cc b/src/main.cc index f2be6c59..c0aeb4af 100644 --- a/src/main.cc +++ b/src/main.cc @@ -36,6 +36,10 @@ #include +#ifdef __MINGW32__ +#include +#endif // __MINGW32__ + #include #include "Context.h" #include "MultiUrlRequestInfo.h" @@ -43,12 +47,32 @@ #include "Platform.h" #include "Exception.h" #include "console.h" +#include "LogFactory.h" namespace aria2 { error_code::Value main(int argc, char** argv) { +#ifdef __MINGW32__ + int winArgc; + auto winArgv = CommandLineToArgvW(GetCommandLineW(), &winArgc); + if(winArgv == nullptr) { + A2_LOG_ERROR("Reading command-line failed"); + return error_code::UNKNOWN_ERROR; + } + std::vector> winArgStrs; + winArgStrs.reserve(winArgc); + auto pargv = make_unique(winArgc); + for(int i = 0; i < winArgc; ++i) { + winArgStrs.emplace_back(strdup(wCharToUtf8(winArgv[i]).c_str())); + pargv[i] = winArgStrs.back().get(); + } + + Context context(true, winArgc, pargv.get(), KeyVals()); +#else // !__MINGW32__ Context context(true, argc, argv, KeyVals()); +#endif // !__MINGW32__ + error_code::Value exitStatus = error_code::FINISHED; if(context.reqinfo) { exitStatus = context.reqinfo->execute();