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:
parent
27ba3ef357
commit
7b282ce50f
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue