-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathoptions.cpp
More file actions
97 lines (82 loc) · 2.12 KB
/
Copy pathoptions.cpp
File metadata and controls
97 lines (82 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "stdafx.h"
#include "options.h"
#include "program_options.h"
#include "util.h"
namespace fs = std::filesystem;
using namespace std;
using namespace primo::program_options;
using namespace primo::codecs;
void setDefaultOptions(Options& opt)
{
opt.inputFile = getExeDir() + L"/../../assets/aud/equinox-48KHz.wav";
fs::path output(getExeDir() + L"/../../output/enc_mp3_push");
fs::create_directories(output);
wostringstream s;
s << output.c_str() << L"/equinox-48KHz.mp3";
opt.outputFile = s.str();
}
void help(OptionsConfig<wchar_t>& optcfg)
{
wcout << L"enc_mp3_push --input <wav file> --output <mp3 file>" << endl;
doHelp(wcout, optcfg);
}
bool validateOptions(Options& opt)
{
if(opt.inputFile.empty())
{
wcout << L"Input file needed" << endl;
return false;
}
else
{
wcout << L"Input file: " << opt.inputFile << endl;
}
if(opt.outputFile.empty())
{
wcout << L"Output file needed" << endl;
return false;
}
else
{
wcout << L"Output file: " << opt.outputFile << endl;
}
return true;
}
ErrorCodes prepareOptions(Options &opt, int argc, wchar_t* argv[])
{
if (argc < 2)
{
setDefaultOptions(opt);
wcout << L"Using defaults:\n";
wcout << L" --input " << opt.inputFile;
wcout << L" --output " << opt.outputFile;
wcout << endl;
return Parsed;
}
primo::program_options::OptionsConfig<wchar_t> optcfg;
optcfg.addOptions()
(L"help,h", opt.help, L"")
(L"input,i", opt.inputFile, wstring(), L"input WAV file")
(L"output,o", opt.outputFile, wstring(), L"output MP3 file");
try
{
primo::program_options::scanArgv(optcfg, argc, argv);
}
catch (primo::program_options::ParseFailure<wchar_t> &ex)
{
wcout << ex.message() << endl;
help(optcfg);
return Error;
}
if (opt.help)
{
help(optcfg);
return Command;
}
if (!validateOptions(opt))
{
help(optcfg);
return Error;
}
return Parsed;
}