Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Diegiwg committed Jul 10, 2024
2 parents 911c0f3 + 5f345ce commit 412ef18
Show file tree
Hide file tree
Showing 44 changed files with 553 additions and 138 deletions.
18 changes: 9 additions & 9 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions launcher/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)
// Minecraft mods
m_settings->registerSetting("ModMetadataDisabled", false);
m_settings->registerSetting("ModDependenciesDisabled", false);
m_settings->registerSetting("SkipModpackUpdatePrompt", false);

// Minecraft offline player name
m_settings->registerSetting("LastOfflinePlayerName", "");
Expand Down
26 changes: 26 additions & 0 deletions launcher/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1691,4 +1691,30 @@ QString getPathNameInLocal8bit(const QString& file)
}
#endif

QString getUniqueResourceName(const QString& filePath)
{
auto newFileName = filePath;
if (!newFileName.endsWith(".disabled")) {
return newFileName; // prioritize enabled mods
}
newFileName.chop(9);
if (!QFile::exists(newFileName)) {
return filePath;
}
QFileInfo fileInfo(filePath);
auto baseName = fileInfo.completeBaseName();
auto path = fileInfo.absolutePath();

int counter = 1;
do {
if (counter == 1) {
newFileName = FS::PathCombine(path, baseName + ".duplicate");
} else {
newFileName = FS::PathCombine(path, baseName + ".duplicate" + QString::number(counter));
}
counter++;
} while (QFile::exists(newFileName));

return newFileName;
}
} // namespace FS
2 changes: 2 additions & 0 deletions launcher/FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -560,4 +560,6 @@ uintmax_t hardLinkCount(const QString& path);
QString getPathNameInLocal8bit(const QString& file);
#endif

QString getUniqueResourceName(const QString& filePath);

} // namespace FS
28 changes: 22 additions & 6 deletions launcher/InstanceList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,13 +372,13 @@ void InstanceList::undoTrashInstance()

auto top = m_trashHistory.pop();

while (QDir(top.polyPath).exists()) {
while (QDir(top.path).exists()) {
top.id += "1";
top.polyPath += "1";
top.path += "1";
}

qDebug() << "Moving" << top.trashPath << "back to" << top.polyPath;
QFile(top.trashPath).rename(top.polyPath);
qDebug() << "Moving" << top.trashPath << "back to" << top.path;
QFile(top.trashPath).rename(top.path);

m_instanceGroupIndex[top.id] = top.groupName;
increaseGroupCount(top.groupName);
Expand Down Expand Up @@ -635,8 +635,8 @@ InstancePtr InstanceList::loadInstance(const InstanceId& id)

QString inst_type = instanceSettings->get("InstanceType").toString();

// NOTE: Some PolyMC versions didn't save the InstanceType properly. We will just bank on the probability that this is probably a OneSix
// instance
// NOTE: Some launcher versions didn't save the InstanceType properly. We will just bank on the probability that this is probably a
// OneSix instance
if (inst_type == "OneSix" || inst_type.isEmpty()) {
inst.reset(new MinecraftInstance(m_globalSettings, instanceSettings, instanceRoot));
} else {
Expand Down Expand Up @@ -710,6 +710,12 @@ void InstanceList::saveGroupList()
groupsArr.insert(name, groupObj);
}
toplevel.insert("groups", groupsArr);
// empty string represents ungrouped "group"
if (m_collapsedGroups.contains("")) {
QJsonObject ungrouped;
ungrouped.insert("hidden", QJsonValue(true));
toplevel.insert("ungrouped", ungrouped);
}
QJsonDocument doc(toplevel);
try {
FS::write(groupFileName, doc.toJson());
Expand Down Expand Up @@ -805,6 +811,16 @@ void InstanceList::loadGroupList()
increaseGroupCount(groupName);
}
}

bool ungroupedHidden = false;
if (rootObj.value("ungrouped").isObject()) {
QJsonObject ungrouped = rootObj.value("ungrouped").toObject();
ungroupedHidden = ungrouped.value("hidden").toBool(false);
}
if (ungroupedHidden) {
// empty string represents ungrouped "group"
m_collapsedGroups.insert("");
}
m_groupsLoaded = true;
qDebug() << "Group list loaded.";
}
Expand Down
2 changes: 1 addition & 1 deletion launcher/InstanceList.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ enum class GroupsState { NotLoaded, Steady, Dirty };

struct TrashHistoryItem {
QString id;
QString polyPath;
QString path;
QString trashPath;
QString groupName;
};
Expand Down
5 changes: 5 additions & 0 deletions launcher/InstanceTask.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "InstanceTask.h"

#include "Application.h"
#include "settings/SettingsObject.h"
#include "ui/dialogs/CustomMessageBox.h"

#include <QPushButton>
Expand All @@ -22,6 +24,9 @@ InstanceNameChange askForChangingInstanceName(QWidget* parent, const QString& ol

ShouldUpdate askIfShouldUpdate(QWidget* parent, QString original_version_name)
{
if (APPLICATION->settings()->get("SkipModpackUpdatePrompt").toBool())
return ShouldUpdate::SkipUpdating;

auto info = CustomMessageBox::selectable(
parent, QObject::tr("Similar modpack was found!"),
QObject::tr(
Expand Down
101 changes: 101 additions & 0 deletions launcher/minecraft/Library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@
#include <net/ApiDownload.h>
#include <net/ChecksumValidator.h>

/**
* @brief Collect applicable files for the library.
*
* Depending on whether the library is native or not, it adds paths to the
* appropriate lists for jar files, native libraries for 32-bit, and native
* libraries for 64-bit.
*
* @param runtimeContext The current runtime context.
* @param jar List to store paths for jar files.
* @param native List to store paths for native libraries.
* @param native32 List to store paths for 32-bit native libraries.
* @param native64 List to store paths for 64-bit native libraries.
* @param overridePath Optional path to override the default storage path.
*/
void Library::getApplicableFiles(const RuntimeContext& runtimeContext,
QStringList& jar,
QStringList& native,
Expand All @@ -50,6 +64,7 @@ void Library::getApplicableFiles(const RuntimeContext& runtimeContext,
const QString& overridePath) const
{
bool local = isLocal();
// Lambda function to get the absolute file path
auto actualPath = [&](QString relPath) {
relPath = FS::RemoveInvalidPathChars(relPath);
QFileInfo out(FS::PathCombine(storagePrefix(), relPath));
Expand All @@ -59,6 +74,7 @@ void Library::getApplicableFiles(const RuntimeContext& runtimeContext,
}
return out.absoluteFilePath();
};

QString raw_storage = storageSuffix(runtimeContext);
if (isNative()) {
if (raw_storage.contains("${arch}")) {
Expand All @@ -76,6 +92,19 @@ void Library::getApplicableFiles(const RuntimeContext& runtimeContext,
}
}

/**
* @brief Get download requests for the library files.
*
* Depending on whether the library is native or not, and the current runtime context,
* this function prepares download requests for the necessary files. It handles both local
* and remote files, checks for stale cache entries, and adds checksummed downloads.
*
* @param runtimeContext The current runtime context.
* @param cache Pointer to the HTTP meta cache.
* @param failedLocalFiles List to store paths for failed local files.
* @param overridePath Optional path to override the default storage path.
* @return QList<Net::NetRequest::Ptr> List of download requests.
*/
QList<Net::NetRequest::Ptr> Library::getDownloads(const RuntimeContext& runtimeContext,
class HttpMetaCache* cache,
QStringList& failedLocalFiles,
Expand All @@ -85,6 +114,7 @@ QList<Net::NetRequest::Ptr> Library::getDownloads(const RuntimeContext& runtimeC
bool stale = isAlwaysStale();
bool local = isLocal();

// Lambda function to check if a local file exists
auto check_local_file = [&](QString storage) {
QFileInfo fileinfo(storage);
QString fileName = fileinfo.fileName();
Expand All @@ -97,6 +127,7 @@ QList<Net::NetRequest::Ptr> Library::getDownloads(const RuntimeContext& runtimeC
return true;
};

// Lambda function to add a download request
auto add_download = [&](QString storage, QString url, QString sha1) {
if (local) {
return check_local_file(storage);
Expand Down Expand Up @@ -197,6 +228,15 @@ QList<Net::NetRequest::Ptr> Library::getDownloads(const RuntimeContext& runtimeC
return out;
}

/**
* @brief Check if the library is active in the given runtime context.
*
* This function evaluates rules to determine if the library should be active,
* considering both general rules and native compatibility.
*
* @param runtimeContext The current runtime context.
* @return bool True if the library is active, false otherwise.
*/
bool Library::isActive(const RuntimeContext& runtimeContext) const
{
bool result = true;
Expand All @@ -217,16 +257,35 @@ bool Library::isActive(const RuntimeContext& runtimeContext) const
return result;
}

/**
* @brief Check if the library is considered local.
*
* @return bool True if the library is local, false otherwise.
*/
bool Library::isLocal() const
{
return m_hint == "local";
}

/**
* @brief Check if the library is always considered stale.
*
* @return bool True if the library is always stale, false otherwise.
*/
bool Library::isAlwaysStale() const
{
return m_hint == "always-stale";
}

/**
* @brief Get the compatible native classifier for the current runtime context.
*
* This function attempts to match the current runtime context with the appropriate
* native classifier.
*
* @param runtimeContext The current runtime context.
* @return QString The compatible native classifier, or an empty string if none is found.
*/
QString Library::getCompatibleNative(const RuntimeContext& runtimeContext) const
{
// try to match precise classifier "[os]-[arch]"
Expand All @@ -241,16 +300,31 @@ QString Library::getCompatibleNative(const RuntimeContext& runtimeContext) const
return entry.value();
}

/**
* @brief Set the storage prefix for the library.
*
* @param prefix The storage prefix to set.
*/
void Library::setStoragePrefix(QString prefix)
{
m_storagePrefix = prefix;
}

/**
* @brief Get the default storage prefix for libraries.
*
* @return QString The default storage prefix.
*/
QString Library::defaultStoragePrefix()
{
return "libraries/";
}

/**
* @brief Get the current storage prefix for the library.
*
* @return QString The current storage prefix.
*/
QString Library::storagePrefix() const
{
if (m_storagePrefix.isEmpty()) {
Expand All @@ -259,6 +333,15 @@ QString Library::storagePrefix() const
return m_storagePrefix;
}

/**
* @brief Get the filename for the library in the current runtime context.
*
* This function determines the appropriate filename for the library, taking into
* account native classifiers if applicable.
*
* @param runtimeContext The current runtime context.
* @return QString The filename of the library.
*/
QString Library::filename(const RuntimeContext& runtimeContext) const
{
if (!m_filename.isEmpty()) {
Expand All @@ -280,13 +363,31 @@ QString Library::filename(const RuntimeContext& runtimeContext) const
return nativeSpec.getFileName();
}

/**
* @brief Get the display name for the library in the current runtime context.
*
* This function returns the display name for the library, defaulting to the filename
* if no display name is set.
*
* @param runtimeContext The current runtime context.
* @return QString The display name of the library.
*/
QString Library::displayName(const RuntimeContext& runtimeContext) const
{
if (!m_displayname.isEmpty())
return m_displayname;
return filename(runtimeContext);
}

/**
* @brief Get the storage suffix for the library in the current runtime context.
*
* This function determines the appropriate storage suffix for the library, taking into
* account native classifiers if applicable.
*
* @param runtimeContext The current runtime context.
* @return QString The storage suffix of the library.
*/
QString Library::storageSuffix(const RuntimeContext& runtimeContext) const
{
// non-native? use only the gradle specifier
Expand Down
Loading

0 comments on commit 412ef18

Please sign in to comment.