1212 */
1313
1414#include " ../src/CommandLineParser.hpp"
15+ #include < QCommandLineOption>
1516#include < QDebug>
1617
17- CommandLineParser::CommandLineParser (const QString& type) {
18+ CommandLineParser::CommandLineParser (const QString& type) : m_processStatus( 0 ) {
1819 if (type == " APP" ) {
1920 m_parser.setApplicationDescription (" Tomb Raider Linux Launcher" );
2021 m_parser.addHelpOption ();
2122
22- m_parser.addOption (QCommandLineOption (
23- QStringList{" so" , " showOriginal" }, " Show old Core Design list" ));
24-
25- m_parser.addOption (QCommandLineOption (
26- QStringList{" si" , " showInstalled" }, " Show only installed list" ));
27-
28- // Class
29- const QString classDesc =
30- " Filter levels by class. Allowed values:\n "
31- + m_class_options.join (" , " );
32-
33- m_parser.addOption (QCommandLineOption (
34- QStringList{" fc" , " filterByClass" }, classDesc, " class" ));
35-
36-
37- // Type
38- const QString typeDesc =
39- " Filter levels by TR game type. Allowed values: "
40- + m_type_options.join (" , " );
41-
42- m_parser.addOption (QCommandLineOption (
43- QStringList{" ft" , " filterByType" }, typeDesc, " type" ));
44-
45-
46- // Difficulty
47- const QString difficultyDesc =
48- " Filter levels by difficulty. Allowed values: "
49- + m_type_options.join (" , " );
50-
51- m_parser.addOption (QCommandLineOption (
52- QStringList{" fd" , " filterByDifficulty" }, difficultyDesc, " difficulty" ));
53-
54-
55- // Duration
56- const QString durationDesc =
57- " Filter levels by duration. Allowed values: "
58- + m_type_options.join (" , " );
59-
60- m_parser.addOption (QCommandLineOption (
61- QStringList{" fr" , " filterByDuration" }, durationDesc, " duration" ));
62-
23+ // Original ------------
24+ QStringList showOriginalName;
25+ showOriginalName << " so" << " showOriginal" ;
26+ QCommandLineOption showOriginalOption (showOriginalName);
27+ showOriginalOption.setDescription (" Show old Core Design list" );
28+ m_parser.addOption (showOriginalOption);
29+
30+ // Installed -----------
31+ QStringList showInstalledName;
32+ showInstalledName << " si" << " showInstalled" ;
33+ QCommandLineOption showInstalledOption (showInstalledName);
34+ showInstalledOption.setDescription (" Show only installed list" );
35+ m_parser.addOption (showInstalledOption);
36+
37+ // Class ---------------
38+ QStringList filterByClassName;
39+ filterByClassName << " fc" << " filterByClass" ;
40+ QCommandLineOption filterByClassOption (filterByClassName);
41+ const QString filterByClassDesc =
42+ " \n Filter levels by class. Allowed values:\n "
43+ + m_class_options.join (" , " ) + " \n " ;
44+ filterByClassOption.setDescription (filterByClassDesc);
45+ filterByClassOption.setValueName (" class" );
46+ m_parser.addOption (filterByClassOption);
47+
48+ // Type ----------------
49+ QStringList filterByTypeName;
50+ filterByTypeName << " ft" << " filterByType" ;
51+ QCommandLineOption filterByTypeOption (filterByTypeName);
52+ const QString filterByTypeDesc =
53+ " Filter levels by TR game type. Allowed values:\n "
54+ + m_type_options.join (" , " ) + " \n " ;
55+ filterByTypeOption.setDescription (filterByTypeDesc);
56+ filterByTypeOption.setValueName (" type" );
57+ m_parser.addOption (filterByTypeOption);
58+
59+ // Difficulty ----------
60+ QStringList filterByDifficultyName;
61+ filterByDifficultyName << " fd" << " filterByDifficulty" ;
62+ QCommandLineOption filterByDifficultyOption (filterByDifficultyName);
63+ const QString filterByDifficultyDesc =
64+ " Filter levels by difficulty. Allowed values:\n "
65+ + m_type_options.join (" , " ) + " \n " ;
66+ filterByDifficultyOption.setDescription (filterByDifficultyDesc);
67+ filterByDifficultyOption.setValueName (" difficulty" );
68+ m_parser.addOption (filterByDifficultyOption);
69+
70+ // Duration -----------
71+ QStringList filterByDurationName;
72+ filterByDurationName << " fr" << " filterByDuration" ;
73+ QCommandLineOption filterByDurationOption (filterByDurationName);
74+
75+ const QString filterByDurationDesc =
76+ " Filter levels by duration. Allowed values:\n "
77+ + m_type_options.join (" , " ) + " \n " ;
78+ filterByDurationOption.setDescription (filterByDurationDesc);
79+ filterByDurationOption.setValueName (" duration" );
80+ m_parser.addOption (filterByDurationOption);
6381
6482 // Sort
65- m_parser.addOption (QCommandLineOption (
66- QStringList{" sortByTitle" }, " Sort the list by title" ));
83+ QCommandLineOption sortByTitleOption (" sortByTitle" );
84+ sortByTitleOption.setDescription (" Sort the list by title" );
85+ m_parser.addOption (sortByTitleOption);
6786
68- m_parser.addOption (QCommandLineOption (
69- QStringList{" sortByDifficulty" }, " Sort the list by difficulty" ));
87+ QCommandLineOption sortByDifficultyOption (" sortByDifficulty" );
88+ sortByDifficultyOption.setDescription (" Sort the list by difficulty" );
89+ m_parser.addOption (sortByDifficultyOption);
7090
71- m_parser.addOption (QCommandLineOption (
72- QStringList{" sortByDuration" }, " Sort the list by duration" ));
91+ QCommandLineOption sortByDurationOption (" sortByDuration" );
92+ sortByDurationOption.setDescription (" Sort the list by duration" );
93+ m_parser.addOption (sortByDurationOption);
7394
74- m_parser.addOption (QCommandLineOption (
75- QStringList{" sortByClass" }, " Sort the list by class" ));
95+ QCommandLineOption sortByClassOption (" sortByClass" );
96+ sortByClassOption.setDescription (" Sort the list by class" );
97+ m_parser.addOption (sortByClassOption);
7698
77- m_parser.addOption (QCommandLineOption (
78- QStringList{" sortByType" }, " Sort the list by type" ));
99+ QCommandLineOption sortByTypeOption (" sortByType" );
100+ sortByTypeOption.setDescription (" Sort the list by type" );
101+ m_parser.addOption (sortByTypeOption);
79102
80- m_parser.addOption (QCommandLineOption (
81- QStringList{" sortByReleaseDate" }, " Sort the list by release date" ));
103+ QCommandLineOption sortByReleaseDateOption (" sortByReleaseDate" );
104+ sortByReleaseDateOption.setDescription (" Sort the list by release date" );
105+ m_parser.addOption (sortByReleaseDateOption);
82106
83107 } else if (type == " TEST" ) {
84108 m_parser.setApplicationDescription (" Tomb Raider Linux Launcher Test Suite" );
85109 m_parser.addHelpOption ();
86110
87- m_parser.addOption (QCommandLineOption (
88- QStringList {" w" , " widescreen" },
89- " Set widescreen bit on original games, probably not useful for TRLE" ,
90- " PATH" ));
111+ QStringList widescreenName;
112+ widescreenName << " w" << " widescreen" ;
113+ QCommandLineOption widescreenOption (widescreenName);
114+ const QString widescreenDesc = " Set widescreen bit on original games,"
115+ + QString (" probably not useful for TRLE" );
116+ widescreenOption.setDescription (widescreenDesc);
117+ widescreenOption.setDefaultValue (" PATH" );
118+ m_parser.addOption (widescreenOption);
119+
120+ QStringList binaryName;
121+ binaryName << " b" << " binary" ;
122+ QCommandLineOption binaryOption (binaryName);
123+ const QString binaryDesc = " Print PE Header Information,"
124+ + QString (" to record Tomb Raider and TRLE binaries" );
125+ binaryOption.setDescription (binaryDesc);
126+ binaryOption.setDefaultValue (" PATH" );
127+ m_parser.addOption (binaryOption);
91128
92- m_parser.addOption (QCommandLineOption (
93- QStringList {" b" , " binary" },
94- " Print PE Header Information, to record Tomb Raider and TRLE binaries" ,
95- " PATH" ));
96129 } else {
97130 qDebug () << " CommandLineParser: Internal object error" ;
98131 }
@@ -103,63 +136,63 @@ StartupSetting CommandLineParser::process(const QStringList& arguments) {
103136
104137 StartupSetting settings;
105138
106- if (m_parser.isSet (" showInstalled" )) {
139+ if (m_parser.isSet (" showInstalled" ) == true ) {
107140 settings.installed = true ;
108141 }
109142
110- if (m_parser.isSet (" showOriginal" )) {
143+ if (m_parser.isSet (" showOriginal" ) == true ) {
111144 settings.original = true ;
112145 }
113146
114147 // --- Class ---
115- if (m_parser.isSet (" filterByClass" )) {
148+ if (m_parser.isSet (" filterByClass" ) == true ) {
116149 QString value = m_parser.value (" filterByClass" );
117150 int idx = m_class_options.indexOf (value, Qt::CaseInsensitive);
118151 if (idx != -1 ) {
119152 settings.class_id = static_cast <quint8>(idx+1 );
120153 } else {
121154 qCritical ().noquote () << " Invalid class value:" << value
122155 << " \n Allowed:" << m_class_options.join (" , " );
123- ::exit ( 1 ) ;
156+ m_processStatus = 1 ;
124157 }
125158 }
126159
127160 // --- Type ---
128- if (m_parser.isSet (" filterByType" )) {
161+ if (m_parser.isSet (" filterByType" ) == true ) {
129162 QString value = m_parser.value (" filterByType" );
130163 int idx = m_type_options.indexOf (value, Qt::CaseInsensitive);
131164 if (idx != -1 ) {
132165 settings.type_id = static_cast <quint8>(idx);
133166 } else {
134167 qCritical ().noquote () << " Invalid type value:" << value
135168 << " \n Allowed:" << m_type_options.join (" , " );
136- ::exit ( 1 ) ;
169+ m_processStatus = 1 ;
137170 }
138171 }
139172
140173 // --- Difficulty ---
141- if (m_parser.isSet (" filterByDifficulty" )) {
174+ if (m_parser.isSet (" filterByDifficulty" ) == true ) {
142175 QString value = m_parser.value (" filterByDifficulty" );
143176 int idx = m_difficulty_options.indexOf (value, Qt::CaseInsensitive);
144177 if (idx != -1 ) {
145178 settings.difficulty_id = static_cast <quint8>(idx);
146179 } else {
147180 qCritical ().noquote () << " Invalid difficulty value:" << value
148181 << " \n Allowed:" << m_difficulty_options.join (" , " );
149- ::exit ( 1 ) ;
182+ m_processStatus = 1 ;
150183 }
151184 }
152185
153186 // --- Duration ---
154- if (m_parser.isSet (" filterByDuration" )) {
187+ if (m_parser.isSet (" filterByDuration" ) == true ) {
155188 QString value = m_parser.value (" filterByDuration" );
156189 int idx = m_duration_options.indexOf (value, Qt::CaseInsensitive);
157190 if (idx != -1 ) {
158191 settings.duration_id = static_cast <quint8>(idx);
159192 } else {
160193 qCritical ().noquote () << " Invalid duration value:" << value
161194 << " \n Allowed:" << m_duration_options.join (" , " );
162- ::exit ( 1 ) ;
195+ m_processStatus = 1 ;
163196 }
164197 }
165198
@@ -184,7 +217,7 @@ StartupSetting CommandLineParser::process(const QStringList& arguments) {
184217 qCritical ().noquote ()
185218 << " Only one sort option may be specified at a time.\n "
186219 << " You provided:" << setSorts.join (" , " );
187- ::exit ( 1 ) ;
220+ m_processStatus = 1 ;
188221 }
189222
190223 if (setSorts.size () == 1 ) {
@@ -196,3 +229,7 @@ StartupSetting CommandLineParser::process(const QStringList& arguments) {
196229
197230 return settings;
198231}
232+
233+ quint64 CommandLineParser::getProcessStatus () {
234+ return m_processStatus;
235+ }
0 commit comments