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.
This commit is contained in:
Daniel Wolf 2015-11-25 22:04:48 +01:00
parent 27ba3ef357
commit 7b282ce50f
3 changed files with 2 additions and 28 deletions

View File

@ -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<centiseconds, Phone>& phones
int main(int argc, char *argv[]) {
try {
// Get sound file name
std::vector<wstring> 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> audioStream = createAudioStream(soundFileName);

View File

@ -3,8 +3,6 @@
#include <boost/filesystem.hpp>
std::vector<std::wstring> getCommandLineArgs(int argc, char *argv[]);
boost::filesystem::path getBinDirectory();
#endif //LIPSYNC_PLATFORM_TOOLS_H

View File

@ -2,28 +2,6 @@
#include "tools.h"
#include "platform_tools.h"
std::vector<std::wstring> 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<std::wstring> result;
for (int i = 0; i < argumentCount; i++) {
result.push_back(arguments[i]);
}
return result;
}
boost::filesystem::path getBinDirectory() {
std::vector<WCHAR> executablePath(MAX_PATH);