diff options
author | flow <flowlnlnln@gmail.com> | 2022-09-26 08:25:12 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-26 08:25:12 -0300 |
commit | 370c3aa5985698351e706e61c660a3a566a5f09b (patch) | |
tree | 5bd62ceec118396d676cf3799edafdb806e4375d /launcher/modplatform/helpers | |
parent | 58a5331f7bafb149c18f560a0363daab65521262 (diff) | |
parent | dd6f670dec7dfd1a9ad6f4595ad5447ac735c737 (diff) | |
download | PrismLauncher-370c3aa5985698351e706e61c660a3a566a5f09b.tar.gz PrismLauncher-370c3aa5985698351e706e61c660a3a566a5f09b.tar.bz2 PrismLauncher-370c3aa5985698351e706e61c660a3a566a5f09b.zip |
Merge pull request #894 from flowln/update_from_external_source
epic PR
Diffstat (limited to 'launcher/modplatform/helpers')
-rw-r--r-- | launcher/modplatform/helpers/OverrideUtils.cpp | 59 | ||||
-rw-r--r-- | launcher/modplatform/helpers/OverrideUtils.h | 20 |
2 files changed, 79 insertions, 0 deletions
diff --git a/launcher/modplatform/helpers/OverrideUtils.cpp b/launcher/modplatform/helpers/OverrideUtils.cpp new file mode 100644 index 00000000..65b5f760 --- /dev/null +++ b/launcher/modplatform/helpers/OverrideUtils.cpp @@ -0,0 +1,59 @@ +#include "OverrideUtils.h" + +#include <QDirIterator> + +#include "FileSystem.h" + +namespace Override { + +void createOverrides(const QString& name, const QString& parent_folder, const QString& override_path) +{ + QString file_path(FS::PathCombine(parent_folder, name + ".txt")); + if (QFile::exists(file_path)) + QFile::remove(file_path); + + FS::ensureFilePathExists(file_path); + + QFile file(file_path); + file.open(QFile::WriteOnly); + + QDirIterator override_iterator(override_path, QDirIterator::Subdirectories); + while (override_iterator.hasNext()) { + auto override_file_path = override_iterator.next(); + QFileInfo info(override_file_path); + if (info.isFile()) { + // Absolute path with temp directory -> relative path + override_file_path = override_file_path.split(name).last().remove(0, 1); + + file.write(override_file_path.toUtf8()); + file.write("\n"); + } + } + + file.close(); +} + +QStringList readOverrides(const QString& name, const QString& parent_folder) +{ + QString file_path(FS::PathCombine(parent_folder, name + ".txt")); + + QFile file(file_path); + if (!file.exists()) + return {}; + + QStringList previous_overrides; + + file.open(QFile::ReadOnly); + + QString entry; + do { + entry = file.readLine(); + previous_overrides.append(entry.trimmed()); + } while (!entry.isEmpty()); + + file.close(); + + return previous_overrides; +} + +} // namespace Override diff --git a/launcher/modplatform/helpers/OverrideUtils.h b/launcher/modplatform/helpers/OverrideUtils.h new file mode 100644 index 00000000..536261a2 --- /dev/null +++ b/launcher/modplatform/helpers/OverrideUtils.h @@ -0,0 +1,20 @@ +#pragma once + +#include <QString> + +namespace Override { + +/** This creates a file in `parent_folder` that holds information about which + * overrides are in `override_path`. + * + * If there's already an existing such file, it will be ovewritten. + */ +void createOverrides(const QString& name, const QString& parent_folder, const QString& override_path); + +/** This reads an existing overrides archive, returning a list of overrides. + * + * If there's no such file in `parent_folder`, it will return an empty list. + */ +QStringList readOverrides(const QString& name, const QString& parent_folder); + +} // namespace Override |