From 7b282ce50f8d51d5a7886468d4f16882e7fcae2b Mon Sep 17 00:00:00 2001 From: Daniel Wolf Date: Wed, 25 Nov 2015 22:04:48 +0100 Subject: [PATCH] Using std::string instead of std::wstring for command-line args Turns out that even if I manage to get Unicode command line args, there still is no portable way of opening a file from a Unicode path. --- src/main.cpp | 6 ++---- src/platform_tools.h | 2 -- src/platform_tools_win.cpp | 22 ---------------------- 3 files changed, 2 insertions(+), 28 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index f1fbd2a..4f67038 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,7 +9,6 @@ using std::exception; using std::string; -using std::wstring; using std::unique_ptr; using std::map; using std::chrono::duration; @@ -70,11 +69,10 @@ ptree createXmlTree(const path& filePath, const map& phones int main(int argc, char *argv[]) { try { // Get sound file name - std::vector commandLineArgs = getCommandLineArgs(argc, argv); - if (commandLineArgs.size() != 2) { + if (argc != 2) { throw std::runtime_error("Invalid command line arguments. Call with sound file name as sole argument."); } - wstring soundFileName = commandLineArgs[1]; + string soundFileName = argv[1]; // Create audio streams unique_ptr audioStream = createAudioStream(soundFileName); diff --git a/src/platform_tools.h b/src/platform_tools.h index 30e925f..55d27ea 100644 --- a/src/platform_tools.h +++ b/src/platform_tools.h @@ -3,8 +3,6 @@ #include -std::vector getCommandLineArgs(int argc, char *argv[]); - boost::filesystem::path getBinDirectory(); #endif //LIPSYNC_PLATFORM_TOOLS_H diff --git a/src/platform_tools_win.cpp b/src/platform_tools_win.cpp index 07cd813..1dda5cf 100644 --- a/src/platform_tools_win.cpp +++ b/src/platform_tools_win.cpp @@ -2,28 +2,6 @@ #include "tools.h" #include "platform_tools.h" -std::vector getCommandLineArgs(int argc, char **argv) { - UNUSED(argv); - - // Get command line as single Unicode string - LPWSTR commandLine = GetCommandLineW(); - - // Split into individual args - int argumentCount; - LPWSTR* arguments = CommandLineToArgvW(commandLine, &argumentCount); - if (!arguments) throw std::runtime_error("Could not determine command line arguments."); - auto _ = finally([&arguments](){ LocalFree(arguments); }); - assert(argumentCount == argc); - - // Convert to vector - std::vector result; - for (int i = 0; i < argumentCount; i++) { - result.push_back(arguments[i]); - } - - return result; -} - boost::filesystem::path getBinDirectory() { std::vector executablePath(MAX_PATH);