feat: add override helper functions
These help us keep track of relevant metadata information about overrides, so that we know what they are when we update a pack. Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
parent
6131346e2f
commit
7024acac06
@ -461,6 +461,8 @@ set(API_SOURCES
|
|||||||
modplatform/helpers/NetworkModAPI.cpp
|
modplatform/helpers/NetworkModAPI.cpp
|
||||||
modplatform/helpers/HashUtils.h
|
modplatform/helpers/HashUtils.h
|
||||||
modplatform/helpers/HashUtils.cpp
|
modplatform/helpers/HashUtils.cpp
|
||||||
|
modplatform/helpers/OverrideUtils.h
|
||||||
|
modplatform/helpers/OverrideUtils.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(FTB_SOURCES
|
set(FTB_SOURCES
|
||||||
|
59
launcher/modplatform/helpers/OverrideUtils.cpp
Normal file
59
launcher/modplatform/helpers/OverrideUtils.cpp
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
#include "OverrideUtils.h"
|
||||||
|
|
||||||
|
#include <QDirIterator>
|
||||||
|
|
||||||
|
#include "FileSystem.h"
|
||||||
|
|
||||||
|
namespace Override {
|
||||||
|
|
||||||
|
void createOverrides(QString name, QString parent_folder, 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(QString name, 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
|
20
launcher/modplatform/helpers/OverrideUtils.h
Normal file
20
launcher/modplatform/helpers/OverrideUtils.h
Normal file
@ -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(QString name, QString parent_folder, 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(QString name, QString parent_folder);
|
||||||
|
|
||||||
|
} // namespace Override
|
Loading…
Reference in New Issue
Block a user