Skip to content

Commit eac6fd8

Browse files
committed
WIP
1 parent a260049 commit eac6fd8

File tree

7 files changed

+82
-174
lines changed

7 files changed

+82
-174
lines changed

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ set(CLIFP_QX_COMPONENTS
6565
Io
6666
Network
6767
Widgets
68+
Sql
6869
)
6970

7071
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
@@ -77,14 +78,14 @@ endif()
7778

7879
include(OB/FetchQx)
7980
ob_fetch_qx(
80-
REF "v0.6.2"
81+
REF "35191e7f6d4be5b50cd225366bc7350666722157"
8182
COMPONENTS
8283
${CLIFP_QX_COMPONENTS}
8384
)
8485

8586
# Fetch libfp (build and import from source)
8687
include(OB/Fetchlibfp)
87-
ob_fetch_libfp("v0.5.6")
88+
ob_fetch_libfp("4a8824b6f385631fbdb19af901772e5cdd0c4c67")
8889

8990
# Fetch QI-QMP (build and import from source)
9091
include(OB/FetchQI-QMP)

lib/backend/src/command/c-link.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// Unit Include
22
#include "c-link.h"
33

4+
// Qx Includes
5+
#include <qx/utility/qx-helpers.h>
6+
47
// libfp Includes
58
#include <fp/fp-install.h>
69

@@ -70,25 +73,22 @@ Qx::Error CLink::perform()
7073
return dbError;
7174
}
7275

73-
if(std::holds_alternative<Fp::Game>(entry_v))
76+
if(entry_v.holdsGame())
7477
{
75-
Fp::Game game = std::get<Fp::Game>(entry_v);
78+
const auto& game = entry_v.getGame();
7679
shortcutName = game.title();
7780
}
78-
else if(std::holds_alternative<Fp::AddApp>(entry_v))
81+
else if(entry_v.holdsAddApp())
7982
{
80-
Fp::AddApp addApp = std::get<Fp::AddApp>(entry_v);
83+
const auto& addApp = entry_v.getAddApp();;
8184

8285
// Get parent info
83-
dbError = database->getEntry(entry_v, addApp.parentId());
84-
if(dbError.isValid())
86+
Fp::Game parent;
87+
if(dbError = database->getGame(parent, addApp.parentGameId()); dbError.isValid())
8588
{
8689
postDirective<DError>(dbError);
8790
return dbError;
8891
}
89-
Q_ASSERT(std::holds_alternative<Fp::Game>(entry_v));
90-
91-
Fp::Game parent = std::get<Fp::Game>(entry_v);
9292
shortcutName = parent.title() + u" ("_s + addApp.name() + u")"_s;
9393
}
9494
else

lib/backend/src/command/c-play.cpp

Lines changed: 22 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -49,30 +49,6 @@ QString CPlayError::deriveSecondary() const { return mSpecific; }
4949
//Public:
5050
CPlay::CPlay(Core& coreRef, const QStringList& commandLine) : TitleCommand(coreRef, commandLine) {}
5151

52-
//-Class Functions---------------------------------------------------------------
53-
//Private:
54-
Fp::AddApp CPlay::buildAdditionalApp(const Fp::Db::QueryBuffer& addAppResult)
55-
{
56-
// Ensure query result is additional app
57-
assert(addAppResult.source == Fp::Db::Table_Add_App::NAME);
58-
59-
/* Form additional app from record
60-
*
61-
* Most of the descriptive fields here are not required for this app, but include them anyway in case it's later
62-
* desired to use them for something like logging.
63-
*/
64-
Fp::AddApp::Builder fpAab;
65-
fpAab.wId(addAppResult.result.value(Fp::Db::Table_Add_App::COL_ID).toString());
66-
fpAab.wAppPath(addAppResult.result.value(Fp::Db::Table_Add_App::COL_APP_PATH).toString());
67-
fpAab.wAutorunBefore(addAppResult.result.value(Fp::Db::Table_Add_App::COL_AUTORUN).toString());
68-
fpAab.wLaunchCommand(addAppResult.result.value(Fp::Db::Table_Add_App::COL_LAUNCH_COMMAND).toString());
69-
fpAab.wName(addAppResult.result.value(Fp::Db::Table_Add_App::COL_NAME).toString().remove(Qx::RegularExpression::LINE_BREAKS));
70-
fpAab.wWaitExit(addAppResult.result.value(Fp::Db::Table_Add_App::COL_WAIT_EXIT).toString());
71-
fpAab.wParentId(addAppResult.result.value(Fp::Db::Table_Add_App::COL_PARENT_ID).toString());
72-
73-
return fpAab.build();
74-
}
75-
7652
//-Instance Functions-------------------------------------------------------------
7753
//Private:
7854
void CPlay::addExtraExecParameters(TExec* execTask, Task::Stage taskStage)
@@ -122,7 +98,7 @@ void CPlay::addExtraExecParameters(TExec* execTask, Task::Stage taskStage)
12298

12399
QString CPlay::getServerOverride(const Fp::GameData& gd)
124100
{
125-
QString override = gd.isNull() ? QString() : gd.parameters().server();
101+
QString override = gd.isNull() ? QString() : gd.parsedParameters().server();
126102
if(!override.isNull())
127103
logEvent(LOG_EVENT_SERVER_OVERRIDE.arg(override));
128104

@@ -192,33 +168,23 @@ Qx::Error CPlay::handleEntry(const Fp::Game& game)
192168
}
193169

194170
// Get game's additional apps
195-
Fp::Db::EntryFilter addAppFilter{.type = Fp::Db::EntryType::AddApp, .parent = game.id()};
196-
197-
Fp::DbError addAppSearchError;
198-
Fp::Db::QueryBuffer addAppSearchResult;
199-
200-
addAppSearchError = db->queryEntrys(addAppSearchResult, addAppFilter);
201-
if(addAppSearchError.isValid())
171+
Fp::Db::AddAppFilter aaf{.parent = game.id()};
172+
QList<Fp::AddApp> addAppSearchResult;
173+
if(auto err = db->searchAddApps(addAppSearchResult, aaf); err.isValid())
202174
{
203-
postDirective<DError>(addAppSearchError);
204-
return addAppSearchError;
175+
postDirective<DError>(err);
176+
return err;
205177
}
206178

207179
// Enqueue auto-run before apps
208-
for(int i = 0; i < addAppSearchResult.size; i++)
180+
for(const auto& aa : std::as_const(addAppSearchResult))
209181
{
210-
// Go to next record
211-
addAppSearchResult.result.next();
212-
213-
// Build
214-
Fp::AddApp addApp = buildAdditionalApp(addAppSearchResult);
215-
216182
// Enqueue if auto-run before
217-
if(addApp.isAutorunBefore())
183+
if(aa.isAutorunBefore())
218184
{
219-
logEvent(LOG_EVENT_FOUND_AUTORUN.arg(addApp.name()));
185+
logEvent(LOG_EVENT_FOUND_AUTORUN.arg(aa.name()));
220186

221-
if(sError = enqueueAdditionalApp(addApp, game, Task::Stage::Auxiliary); sError.isValid())
187+
if(sError = enqueueAdditionalApp(aa, game, Task::Stage::Auxiliary); sError.isValid())
222188
return sError;
223189
}
224190
}
@@ -237,24 +203,21 @@ Qx::Error CPlay::handleEntry(const Fp::Game& game)
237203
Qx::Error CPlay::handleEntry(const Fp::AddApp& addApp)
238204
{
239205
logEvent(LOG_EVENT_ID_MATCH_ADDAPP.arg(addApp.name(),
240-
addApp.parentId().toString(QUuid::WithoutBraces)));
206+
addApp.parentGameId().toString(QUuid::WithoutBraces)));
241207

242208
Qx::Error sError;
243209
Fp::Db* db = mCore.fpInstall().database();
244210

245211
// Get parent info
246-
QUuid parentId = addApp.parentId();
247-
Fp::Entry parentEntry;
212+
QUuid parentId = addApp.parentGameId();
248213
Fp::Game parentGame;
249214
Fp::GameData parentGameData;
250215

251-
if(Fp::DbError gdErr = db->getEntry(parentEntry, parentId); gdErr.isValid())
216+
if(Fp::DbError gdErr = db->getGame(parentGame, parentId); gdErr.isValid())
252217
{
253218
postDirective<DError>(gdErr);
254219
return gdErr;
255220
}
256-
Q_ASSERT(std::holds_alternative<Fp::Game>(parentEntry));
257-
parentGame = std::get<Fp::Game>(parentEntry);
258221

259222
if(Fp::DbError gdErr = db->getGameData(parentGameData, parentId); gdErr.isValid())
260223
{
@@ -269,8 +232,7 @@ Qx::Error CPlay::handleEntry(const Fp::AddApp& addApp)
269232
QString serverOverride = getServerOverride(parentGameData);
270233

271234
// Enqueue services if needed
272-
bool needsServices = addApp.appPath() != Fp::Db::Table_Add_App::ENTRY_MESSAGE && addApp.appPath() != Fp::Db::Table_Add_App::ENTRY_EXTRAS;
273-
if(needsServices && (sError = mCore.enqueueStartupTasks(serverOverride)).isValid())
235+
if(addApp.isPlayable() && (sError = mCore.enqueueStartupTasks(serverOverride)).isValid())
274236
return sError;
275237

276238
// Handle datapack tasks
@@ -288,24 +250,24 @@ Qx::Error CPlay::handleEntry(const Fp::AddApp& addApp)
288250
return sError;
289251

290252
// Enqueue service shutdown if needed
291-
if(needsServices)
253+
if(addApp.isPlayable())
292254
mCore.enqueueShutdownTasks();
293255

294256
return Qx::Error();
295257
}
296258

297259
Qx::Error CPlay::enqueueAdditionalApp(const Fp::AddApp& addApp, const Fp::Game& parent, Task::Stage taskStage)
298260
{
299-
if(addApp.appPath() == Fp::Db::Table_Add_App::ENTRY_MESSAGE)
261+
if(addApp.isMessage())
300262
{
301263
TMessage* messageTask = new TMessage(mCore);
302264
messageTask->setStage(taskStage);
303265
messageTask->setText(addApp.launchCommand());
304-
messageTask->setBlocking(addApp.isWaitExit());
266+
messageTask->setBlocking(addApp.isWaitForExit());
305267

306268
mCore.enqueueSingleTask(messageTask);
307269
}
308-
else if(addApp.appPath() == Fp::Db::Table_Add_App::ENTRY_EXTRAS)
270+
else if(addApp.isExtra())
309271
{
310272
TExtra* extraTask = new TExtra(mCore);
311273
extraTask->setStage(taskStage);
@@ -351,7 +313,7 @@ Qx::Error CPlay::enqueueGame(const Fp::Game& game, const Fp::GameData& gameData,
351313

352314
TExec* CPlay::createStdGameExecTask(const Fp::Game& game, const Fp::GameData& gameData, Task::Stage taskStage)
353315
{
354-
QString gamePath = mCore.resolveFullAppPath(!gameData.isNull() ? gameData.appPath() : game.appPath(),
316+
QString gamePath = mCore.resolveFullAppPath(!gameData.isNull() ? gameData.applicationPath() : game.applicationPath(),
355317
game.platformName());
356318
QFileInfo gamePathInfo(gamePath);
357319
QString param = !gameData.isNull() ? gameData.launchCommand() : game.launchCommand();
@@ -370,7 +332,7 @@ TExec* CPlay::createStdGameExecTask(const Fp::Game& game, const Fp::GameData& ga
370332

371333
TExec* CPlay::createStdAddAppExecTask(const Fp::AddApp& addApp, const Fp::Game& parent, Task::Stage taskStage)
372334
{
373-
QString addAppPath = mCore.resolveFullAppPath(addApp.appPath(), parent.platformName());
335+
QString addAppPath = mCore.resolveFullAppPath(addApp.applicationPath(), parent.platformName());
374336
QFileInfo addAppPathInfo(addAppPath);
375337
QString param = addApp.launchCommand();
376338

@@ -381,7 +343,7 @@ TExec* CPlay::createStdAddAppExecTask(const Fp::AddApp& addApp, const Fp::Game&
381343
addAppTask->setDirectory(addAppPathInfo.absoluteDir());
382344
addAppTask->setParameters(param);
383345
addAppTask->setEnvironment(mCore.childTitleProcessEnvironment());
384-
addAppTask->setProcessType(addApp.isWaitExit() || taskStage == Task::Stage::Primary ? TExec::ProcessType::Blocking : TExec::ProcessType::Deferred);
346+
addAppTask->setProcessType(addApp.isWaitForExit() || taskStage == Task::Stage::Primary ? TExec::ProcessType::Blocking : TExec::ProcessType::Deferred);
385347

386348
return addAppTask;
387349
}
@@ -475,7 +437,7 @@ Qx::Error CPlay::perform()
475437
}
476438

477439
// Handle entry
478-
return std::visit([this](auto arg) { return this->handleEntry(arg); }, entry);
440+
return entry.visit([this](auto arg) { return this->handleEntry(arg); });
479441
}
480442

481443
//Public:

lib/backend/src/command/c-play.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,6 @@ class CPlay : public TitleCommand
116116
public:
117117
CPlay(Core& coreRef, const QStringList& commandLine);
118118

119-
//-Class Functions------------------------------------------------------------------------------------------------------
120-
private:
121-
// Helper
122-
static Fp::AddApp buildAdditionalApp(const Fp::Db::QueryBuffer& addAppResult);
123-
124119
//-Instance Functions------------------------------------------------------------------------------------------------------
125120
private:
126121
void addExtraExecParameters(TExec* execTask, Task::Stage taskStage);

lib/backend/src/command/title-command.cpp

Lines changed: 19 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -60,64 +60,30 @@ Qx::Error TitleCommand::randomlySelectId(QUuid& mainIdBuffer, QUuid& subIdBuffer
6060
Fp::Db* database = mCore.fpInstall().database();
6161

6262
// Query all main games
63-
Fp::Db::QueryBuffer mainGameIdQuery;
64-
searchError = database->queryAllGameIds(mainGameIdQuery, lbFilter);
65-
if(searchError.isValid())
63+
QList<QUuid> playableIds;
64+
if(searchError = database->getAllGameIds(playableIds, lbFilter); searchError.isValid())
6665
{
6766
postDirective<DError>(searchError);
6867
return searchError;
6968
}
70-
71-
QVector<QUuid> playableIds;
72-
73-
// Enumerate main game IDs
74-
for(int i = 0; i < mainGameIdQuery.size; i++)
75-
{
76-
// Go to next record
77-
mainGameIdQuery.result.next();
78-
79-
// Add ID to list
80-
QString gameIdString = mainGameIdQuery.result.value(Fp::Db::Table_Game::COL_ID).toString();
81-
QUuid gameId = QUuid(gameIdString);
82-
if(!gameId.isNull())
83-
playableIds.append(gameId);
84-
else
85-
logError(Qx::GenericError(Qx::Warning, 12011, LOG_WRN_INVALID_RAND_ID.arg(gameIdString)));
86-
}
69+
// NOTE: We used to check if ids were valid here and omit them if so. If bad IDs are found in DB, reintroduce.
8770
logEvent(LOG_EVENT_PLAYABLE_COUNT.arg(QLocale(QLocale::system()).toString(playableIds.size())));
8871

8972
// Select main game
9073
mainIdBuffer = playableIds.value(QRandomGenerator::global()->bounded(playableIds.size()));
9174
logEvent(LOG_EVENT_INIT_RAND_ID.arg(mainIdBuffer.toString(QUuid::WithoutBraces)));
9275

9376
// Get entry's playable additional apps
94-
Fp::Db::EntryFilter addAppFilter{.type = Fp::Db::EntryType::AddApp, .parent = mainIdBuffer, .playableOnly = true};
77+
Fp::Db::AddAppFilter aaf{.parent = mainIdBuffer, .playableOnly = true};
9578

96-
Fp::Db::QueryBuffer addAppQuery;
97-
searchError = database->queryEntrys(addAppQuery, addAppFilter);
98-
if(searchError.isValid())
79+
QList<QUuid> playableSubIds;
80+
if(searchError = database->searchAddAppIds(playableSubIds, aaf); searchError.isValid())
9981
{
10082
postDirective<DError>(searchError);
10183
return searchError;
10284
}
103-
logEvent(LOG_EVENT_INIT_RAND_PLAY_ADD_COUNT.arg(addAppQuery.size));
104-
105-
QVector<QUuid> playableSubIds;
106-
107-
// Enumerate entry's playable additional apps
108-
for(int i = 0; i < addAppQuery.size; i++)
109-
{
110-
// Go to next record
111-
addAppQuery.result.next();
112-
113-
// Add ID to list
114-
QString addAppIdString = addAppQuery.result.value(Fp::Db::Table_Game::COL_ID).toString();
115-
QUuid addAppId = QUuid(addAppIdString);
116-
if(!addAppId.isNull())
117-
playableSubIds.append(addAppId);
118-
else
119-
logError(Qx::GenericError(Qx::Warning, 12101, LOG_WRN_INVALID_RAND_ID.arg(addAppIdString)));
120-
}
85+
// NOTE: We used to check if ids were valid here and omit them if so. If bad IDs are found in DB, reintroduce.
86+
logEvent(LOG_EVENT_INIT_RAND_PLAY_ADD_COUNT.arg(playableSubIds.size()));
12187

12288
// Select final ID
12389
int randIndex = QRandomGenerator::global()->bounded(playableSubIds.size() + 1);
@@ -151,41 +117,34 @@ Qx::Error TitleCommand::getRandomSelectionInfo(QString& infoBuffer, QUuid mainId
151117
Fp::Db* database = mCore.fpInstall().database();
152118

153119
// Get main entry info
154-
Fp::Entry entry_v;
155-
searchError = database->getEntry(entry_v, mainId);
156-
if(searchError.isValid())
120+
Fp::Game game;
121+
if(searchError = database->getGame(game, mainId); searchError.isValid())
157122
{
158123
postDirective<DError>(searchError);
159124
return searchError;
160125
}
161126

162-
Q_ASSERT(std::holds_alternative<Fp::Game>(entry_v));
163-
Fp::Game mainEntry = std::get<Fp::Game>(entry_v);
164-
165127
// Populate buffer with primary info
166-
infoFillTemplate = infoFillTemplate.arg(mainEntry.title(),
167-
mainEntry.developer(),
168-
mainEntry.publisher(),
169-
mainEntry.library());
128+
infoFillTemplate = infoFillTemplate.arg(game.title(),
129+
game.developer(),
130+
game.publisher(),
131+
game.library());
170132

171-
// Determine variant
133+
// Handle possible sub info
172134
if(subId.isNull())
173135
infoFillTemplate = infoFillTemplate.arg(u"N/A"_s);
174136
else
175137
{
176138
// Get sub entry info
177-
searchError = database->getEntry(entry_v, subId);
178-
if(searchError.isValid())
139+
Fp::AddApp addApp;
140+
if(searchError = database->getAddApp(addApp, subId); searchError.isValid())
179141
{
180142
postDirective<DError>(searchError);
181143
return searchError;
182144
}
183145

184-
Q_ASSERT(std::holds_alternative<Fp::AddApp>(entry_v));
185-
Fp::AddApp subEntry = std::get<Fp::AddApp>(entry_v);
186-
187-
// Populate buffer with variant info
188-
infoFillTemplate = infoFillTemplate.arg(subEntry.name());
146+
// Populate buffer with info
147+
infoFillTemplate = infoFillTemplate.arg(addApp.name());
189148
}
190149

191150
// Set filled template to buffer

lib/backend/src/command/title-command.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class TitleCommand : public Command
5656
//-Class Variables------------------------------------------------------------------------------------------------------
5757
private:
5858
// Logging - Errors
59-
static inline const QString LOG_WRN_INVALID_RAND_ID = u"A UUID found in the database during Random operation is invalid (%1)"_s;
59+
//static inline const QString LOG_WRN_INVALID_RAND_ID = u"A UUID found in the database during Random operation is invalid (%1)"_s;
6060

6161
// Logging - Messages
6262
static inline const QString LOG_EVENT_SEL_RAND = u"Selecting a playable title at random..."_s;

0 commit comments

Comments
 (0)