1919
2020using Therena::LaunchBounce::Configuration;
2121
22- void Configuration::Initialize (int argc, wchar_t * argv[] )
22+ void Configuration::Initialize ()
2323{
24- if (0 == argc || argc % 2 == 0 )
25- {
26- return ;
27- }
24+ const auto commandLineString = GetCommandLine ();
25+ const auto commandLine = ParseCommandLine (commandLineString);
2826
29- for (auto i = 1 ; i < argc; i = i + 2 )
27+ for (const auto & param : commandLine )
3028 {
3129 auto type = ParameterType::Unknown;
32- const auto result = ConvertParameterType (argv[i] , type);
30+ const auto result = ConvertParameterType (param. first , type);
3331 if (result)
3432 {
35- m_Parameters[type] = argv[i + 1 ] ;
33+ m_Parameters[type] = param. second ;
3634 }
3735 }
3836}
3937
38+ std::vector<std::pair<std::wstring, std::wstring>> Configuration::ParseCommandLine (const std::wstring& commandLine)
39+ {
40+ std::vector<std::pair<std::wstring, std::wstring>> params;
41+ std::wistringstream iss (commandLine);
42+ std::wstring token;
43+ std::wstring key;
44+ std::wstring value;
45+
46+ bool isFirstToken = true ;
47+ bool isQuotedValue = false ;
48+ while (iss >> token)
49+ {
50+ if (isFirstToken)
51+ {
52+ isFirstToken = false ;
53+ continue ;
54+ }
55+
56+ if (isQuotedValue)
57+ {
58+ if (token.back () == L' "' )
59+ {
60+ value += L" " + token.substr (0 , token.length () - 1 );
61+ isQuotedValue = false ;
62+ params.push_back ({ key, value });
63+ value.clear ();
64+ }
65+ else
66+ {
67+ value += L" " + token;
68+ }
69+ }
70+ else if (token.front () == L' "' )
71+ {
72+ value = token.substr (1 );
73+ if (token.back () != L' "' )
74+ {
75+ isQuotedValue = true ;
76+ }
77+ else
78+ {
79+ value.pop_back ();
80+ params.push_back ({ key, value });
81+ value.clear ();
82+ }
83+ }
84+ else if (token.front () == L' -' && !isQuotedValue)
85+ {
86+ key = token;
87+ }
88+ else
89+ {
90+ params.push_back ({ key, token });
91+ }
92+ }
93+
94+ return params;
95+ }
96+
4097bool Configuration::GetParameter (ParameterType type, std::wstring& parameter)
4198{
4299 if (m_Parameters.end () == m_Parameters.find (type))
@@ -63,6 +120,13 @@ bool Configuration::ConvertParameterType(const std::wstring& parameter, Paramete
63120 return true ;
64121 }
65122
123+
124+ if (std::wstring::npos != parameter.find (L" Hide" ))
125+ {
126+ type = ParameterType::Hide;
127+ return true ;
128+ }
129+
66130 return false ;
67131}
68132
0 commit comments