Skip to content

Commit

Permalink
Merge pull request #43 from oblivioncth/dev
Browse files Browse the repository at this point in the history
Merge to master for v0.7.4
  • Loading branch information
oblivioncth authored Nov 27, 2023
2 parents 870b319 + ac077d7 commit 188c94f
Show file tree
Hide file tree
Showing 16 changed files with 218 additions and 107 deletions.
10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ cmake_minimum_required(VERSION 3.24.0...3.26.0)
# Project
# NOTE: DON'T USE TRAILING ZEROS IN VERSIONS
project(FIL
VERSION 0.7.3.1
VERSION 0.7.4
LANGUAGES CXX
DESCRIPTION "Flashpoint Importer for Launchers"
)

# Get helper scripts
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/FetchOBCMake.cmake)
fetch_ob_cmake("v0.3.3")
fetch_ob_cmake("v0.3.4")

# Initialize project according to standard rules
include(OB/Project)
Expand Down Expand Up @@ -64,18 +64,18 @@ set(FIL_QX_COMPONENTS

include(OB/FetchQx)
ob_fetch_qx(
REF "v0.5.5.1"
REF "v0.5.6"
COMPONENTS
${FIL_QX_COMPONENTS}
)

# Fetch libfp (build and import from source)
include(OB/Fetchlibfp)
ob_fetch_libfp("v0.5.1.1")
ob_fetch_libfp("v0.5.2")

# Fetch CLIFp (build and import from source)
include(OB/FetchCLIFp)
ob_fetch_clifp("v0.9.9")
ob_fetch_clifp("v0.9.10")

# TODO: The shared build of this is essentially useless as only the CLIFp executable
# is deployed, which only works if it's statically linked. There isn't a simple way
Expand Down
2 changes: 1 addition & 1 deletion app/src/clifp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

//-Class Functions--------------------------------------------------------------------------------------------
//Public:
QString CLIFp::standardCLIFpPath(const Fp::Install& fpInstall) { return fpInstall.fullPath() + '/' + EXE_NAME; }
QString CLIFp::standardCLIFpPath(const Fp::Install& fpInstall) { return fpInstall.dir().absoluteFilePath(EXE_NAME); }

bool CLIFp::hasCLIFp(const Fp::Install& fpInstall)
{
Expand Down
28 changes: 14 additions & 14 deletions app/src/frontend/attractmode/am-install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,6 @@ Qx::Error Install::populateExistingDocs()
return Qx::Error();
}

QString Install::translateDocName(const QString& originalName, Fe::DataDoc::Type type) const
{
// Perform general kosherization
QString translatedName = Qx::kosherizeFileName(originalName);

// Prefix platforms/playlists
if(type == Fe::DataDoc::Type::Platform)
translatedName.prepend(PLATFORM_TAG_PREFIX);
else if(type == Fe::DataDoc::Type::Playlist)
translatedName.prepend(PLAYLIST_TAG_PREFIX);

return translatedName;
}

QString Install::executableSubPath() const { return MAIN_EXE_PATH; }

QString Install::imageDestinationPath(Fp::ImageType imageType, const Fe::Game* game) const
Expand Down Expand Up @@ -350,6 +336,20 @@ QString Install::versionString() const
return u"UNKNOWN VERSION"_s;
}

QString Install::translateDocName(const QString& originalName, Fe::DataDoc::Type type) const
{
// Perform general kosherization
QString translatedName = Qx::kosherizeFileName(originalName);

// Prefix platforms/playlists
if(type == Fe::DataDoc::Type::Platform)
translatedName.prepend(PLATFORM_TAG_PREFIX);
else if(type == Fe::DataDoc::Type::Playlist)
translatedName.prepend(PLAYLIST_TAG_PREFIX);

return translatedName;
}

Qx::Error Install::preImport(const ImportDetails& details)
{
//-Ensure that required directories exist----------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion app/src/frontend/attractmode/am-install.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ class Install : public Fe::Install
// Install management
void nullify() override;
Qx::Error populateExistingDocs() override;
QString translateDocName(const QString& originalName, Fe::DataDoc::Type type) const override;

// Info
QString executableSubPath() const override;
Expand Down Expand Up @@ -119,6 +118,7 @@ class Install : public Fe::Install
QString name() const override;
QList<Fe::ImageMode> preferredImageModeOrder() const override;
QString versionString() const override;
QString translateDocName(const QString& originalName, Fe::DataDoc::Type type) const override;

// Import stage notifier hooks
Qx::Error preImport(const ImportDetails& details) override;
Expand Down
2 changes: 1 addition & 1 deletion app/src/frontend/fe-data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ PlaylistDoc::PlaylistDoc(Install* const parent, const QString& docPath, QString

//-Instance Functions--------------------------------------------------------------------------------------------------
//Private:
DataDoc::Type PlaylistDoc::type() const { return Type::Platform; }
DataDoc::Type PlaylistDoc::type() const { return Type::Playlist; }

//===============================================================================================================
// PlaylistDoc::Reader
Expand Down
11 changes: 6 additions & 5 deletions app/src/frontend/fe-install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ void Install::nullify()
InstallFoundation::nullify();
}

QString Install::translateDocName(const QString& originalName, DataDoc::Type type) const
{
// Redundant with base version, but here to make it clear its part of the main Install interface
return InstallFoundation::translateDocName(originalName, type);
}

//Public:
void Install::softReset()
Expand Down Expand Up @@ -106,6 +101,12 @@ Qx::Error Install::postImageProcessing() { return {}; }
Qx::Error Install::prePlaylistsImport() { return {}; }
Qx::Error Install::postPlaylistsImport() { return {}; }

QString Install::translateDocName(const QString& originalName, DataDoc::Type type) const
{
// Redundant with base version, but here to make it clear its part of the main Install interface
return InstallFoundation::translateDocName(originalName, type);
}

Fe::DocHandlingError Install::checkoutPlatformDoc(std::unique_ptr<PlatformDoc>& returnBuffer, const QString& name)
{
// Translate to frontend doc name
Expand Down
2 changes: 1 addition & 1 deletion app/src/frontend/fe-install.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ class Install : public InstallFoundation
// Install management
virtual void nullify() override;
virtual Qx::Error populateExistingDocs() override = 0;
virtual QString translateDocName(const QString& originalName, DataDoc::Type type) const override;

// Doc Handling
virtual std::shared_ptr<PlatformDoc::Reader> preparePlatformDocCheckout(std::unique_ptr<PlatformDoc>& platformDoc, const QString& translatedName) = 0;
Expand Down Expand Up @@ -94,6 +93,7 @@ class Install : public InstallFoundation
virtual Qx::Error postPlaylistsImport();

// Doc handling
virtual QString translateDocName(const QString& originalName, DataDoc::Type type) const override;
Fe::DocHandlingError checkoutPlatformDoc(std::unique_ptr<PlatformDoc>& returnBuffer, const QString& name);
Fe::DocHandlingError checkoutPlaylistDoc(std::unique_ptr<PlaylistDoc>& returnBuffer, const QString& name);
Fe::DocHandlingError commitPlatformDoc(std::unique_ptr<PlatformDoc> platformDoc);
Expand Down
42 changes: 29 additions & 13 deletions app/src/frontend/fe-installfoundation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ void InstallFoundation::softReset()
{
mRevertableFilePaths.clear();
mModifiedDocuments.clear();
mDeletedDocuments.clear();
mLeasedDocuments.clear();
mImportDetails.reset();
}
Expand Down Expand Up @@ -170,13 +171,16 @@ Fe::DocHandlingError InstallFoundation::checkoutDataDocument(DataDoc* docToOpen,

Fe::DocHandlingError InstallFoundation::commitDataDocument(DataDoc* docToSave, std::shared_ptr<DataDoc::Writer> docWriter)
{
// Create backup and add to modified list if required
if(!mModifiedDocuments.contains(docToSave->identifier()))
DataDoc::Identifier id = docToSave->identifier();
bool wasDeleted = mDeletedDocuments.contains(id);
bool wasModified = mDeletedDocuments.contains(id);
bool wasUntouched = !wasDeleted && !wasModified;

// Handle backup/revert prep
if(wasUntouched)
{
// Insert
QString docPath = docToSave->path();
mModifiedDocuments.insert(docToSave->identifier());
mRevertableFilePaths.append(docPath);
mRevertableFilePaths.append(docPath); // Correctly handles if doc ends up deleted

// Backup
if(QFile::exists(docPath))
Expand All @@ -190,28 +194,40 @@ Fe::DocHandlingError InstallFoundation::commitDataDocument(DataDoc* docToSave, s
}

if(!QFile::copy(docPath, backupPath))
return Fe::DocHandlingError(*docToSave, Fe::DocHandlingError::CantRemoveBackup);
return Fe::DocHandlingError(*docToSave, Fe::DocHandlingError::CantCreateBackup);
}
}

// Write to file if it contains content
Fe::DocHandlingError saveWriteError;
// Error State
Fe::DocHandlingError commitError;

// Handle modification
if(!docToSave->isEmpty())
saveWriteError = docWriter->writeOutOf();
{
mModifiedDocuments.insert(id);
if(wasDeleted)
mDeletedDocuments.remove(id);

// Set document permissions
allowUserWriteOnFile(docToSave->path());
commitError = docWriter->writeOutOf();
allowUserWriteOnFile(docToSave->path());
}
else // Handle deletion
{
mDeletedDocuments.insert(id);
if(wasModified)
mModifiedDocuments.remove(id);
}

// Remove handle reservation
mLeasedDocuments.remove(docToSave->identifier());

// Return write status and let document ptr auto delete
return saveWriteError;
return commitError;
}

QList<QString> InstallFoundation::modifiedPlatforms() const { return modifiedDataDocs(DataDoc::Type::Platform); }

QList<QString> InstallFoundation::modifiedPlaylists() const { return modifiedDataDocs(DataDoc::Type::Platform);}
QList<QString> InstallFoundation::modifiedPlaylists() const { return modifiedDataDocs(DataDoc::Type::Playlist);}

//Public:
bool InstallFoundation::isValid() const { return mValid; }
Expand Down
1 change: 1 addition & 0 deletions app/src/frontend/fe-installfoundation.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class InstallFoundation
// Document tracking
QSet<DataDoc::Identifier> mExistingDocuments;
QSet<DataDoc::Identifier> mModifiedDocuments;
QSet<DataDoc::Identifier> mDeletedDocuments;
QSet<DataDoc::Identifier> mLeasedDocuments;

// Backup/Deletion tracking
Expand Down
64 changes: 46 additions & 18 deletions app/src/frontend/launchbox/lb-data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ void PlaylistDoc::Reader::parsePlaylistGame()
existingPlaylistGame->setLBDatabaseId(optIdx.value_or(0));
}
else
static_cast<PlaylistDoc*>(mTargetDocument)->mLaunchBoxDatabaseIdTracker->release(existingPlaylistGame->lbDatabaseId());
static_cast<PlaylistDoc*>(mTargetDocument)->mLaunchBoxDatabaseIdTracker->reserve(existingPlaylistGame->lbDatabaseId());

// Add to document
targetDocExistingPlaylistGames()[existingPlaylistGame->gameId()] = existingPlaylistGame;
Expand Down Expand Up @@ -1090,36 +1090,64 @@ ParentsDoc::ParentsDoc(Install* const parent, const QString& xmlPath, const DocK
//Private:
Fe::DataDoc::Type ParentsDoc::type() const { return Fe::DataDoc::Type::Config; }

//Public:
bool ParentsDoc::isEmpty() const { return mParents.isEmpty(); }

bool ParentsDoc::containsPlatformCategory(QStringView platformCategory)
bool ParentsDoc::removeIfPresent(qsizetype idx)
{
for(const Parent& p : mParents)
if(p.platformCategoryName() == platformCategory)
return true;
if(idx != -1)
{
mParents.remove(idx);
return true;
}

return false;
}

bool ParentsDoc::containsPlatformUnderCategory(QStringView platform, QStringView platformCategory)
qsizetype ParentsDoc::findPlatformCategory(QStringView platformCategory, QStringView parentCategory) const
{
for(const Parent& p : mParents)
if(p.parentPlatformCategoryName() == platformCategory && p.platformName() == platform)
return true;
for(auto i = 0; i < mParents.size(); i++)
{
auto p = mParents.at(i);
if(p.platformCategoryName() == platformCategory && p.parentPlatformCategoryName() == parentCategory)
return i;
}

return false;
return -1;
}

bool ParentsDoc::containsPlaylistUnderCategory(const QUuid& playlistId, QStringView platformCategory)
qsizetype ParentsDoc::findPlatform(QStringView platform, QStringView parentCategory) const
{
for(const Parent& p : mParents)
if(p.parentPlatformCategoryName() == platformCategory && p.playlistId() == playlistId)
return true;
for(auto i = 0; i < mParents.size(); i++)
{
auto p = mParents.at(i);
if(p.platformName() == platform && p.parentPlatformCategoryName() == parentCategory)
return i;
}

return false;
return -1;
}

qsizetype ParentsDoc::findPlaylist(const QUuid& playlistId, QStringView parentCategory) const
{
for(auto i = 0; i < mParents.size(); i++)
{
auto p = mParents.at(i);
if(p.playlistId() == playlistId && p.parentPlatformCategoryName() == parentCategory)
return i;
}

return -1;
}

//Public:
bool ParentsDoc::isEmpty() const { return mParents.isEmpty(); }

bool ParentsDoc::containsPlatformCategory(QStringView platformCategory, QStringView parentCategory) const { return findPlatformCategory(platformCategory, parentCategory) != -1; }
bool ParentsDoc::containsPlatform(QStringView platform, QStringView parentCategory) const { return findPlatform(platform, parentCategory) != -1; }
bool ParentsDoc::containsPlaylist(const QUuid& playlistId, QStringView parentCategory) const { return findPlaylist(playlistId, parentCategory) != -1; }

bool ParentsDoc::removePlatformCategory(QStringView platformCategory, QStringView parentCategory) { return removeIfPresent(findPlatformCategory(platformCategory, parentCategory)); }
bool ParentsDoc::removePlatform(QStringView platform, QStringView parentCategory) { return removeIfPresent(findPlatform(platform, parentCategory)); }
bool ParentsDoc::removePlaylist(const QUuid& playlistId, QStringView parentCategory) { return removeIfPresent(findPlaylist(playlistId, parentCategory)); }

const QList<Parent>& ParentsDoc::parents() const { return mParents; }

void ParentsDoc::addParent(const Parent& parent) { mParents.append(parent); }
Expand Down
20 changes: 17 additions & 3 deletions app/src/frontend/launchbox/lb-data.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,27 @@ class ParentsDoc : public Fe::DataDoc
//-Instance Functions--------------------------------------------------------------------------------------------------
private:
Type type() const override;
bool removeIfPresent(qsizetype idx);

qsizetype findPlatformCategory(QStringView platformCategory, QStringView parentCategory) const;
qsizetype findPlatform(QStringView platform, QStringView parentCategory) const;
qsizetype findPlaylist(const QUuid& playlistId, QStringView parentCategory) const;

public:
bool isEmpty() const override;

bool containsPlatformCategory(QStringView platformCategory);
bool containsPlatformUnderCategory(QStringView platform, QStringView platformCategory);
bool containsPlaylistUnderCategory(const QUuid& playlistId, QStringView platformCategory);
/* NOTE: The methods here than take an optional parent category won't look for any of their type
* if no parent is specified, but rather one that explicitly has no parent. If these is needed for
* some reason, consider adding "any" variants of the functions (i.e. containsAnyPlatformCategory(), etc.)
*/
bool containsPlatformCategory(QStringView platformCategory, QStringView parentCategory = {}) const;
bool containsPlatform(QStringView platform, QStringView parentCategory = {}) const;
bool containsPlaylist(const QUuid& playlistId, QStringView parentCategory = {}) const;

bool removePlatformCategory(QStringView platformCategory, QStringView parentCategory = {});
bool removePlatform(QStringView platform, QStringView parentCategory = {});
bool removePlaylist(const QUuid& playlistId, QStringView parentCategory = {});


const QList<Parent>& parents() const;

Expand Down
Loading

0 comments on commit 188c94f

Please sign in to comment.