ResourceFolderModel
Base model for managing external resources like mods, resource packs, and shaders.
Class: ResourceFolderModel
Header: launcher/minecraft/mod/ResourceFolderModel.h
Inherits: QAbstractListModel
Constructor
ResourceFolderModel(
const QDir& dir,
BaseInstance* instance,
bool is_indexed,
bool create_dir,
QObject* parent = nullptr
);
Directory containing the resources.
The instance this model belongs to.
Whether resources have metadata indexing.
Whether to create the directory if it doesn’t exist.
Resource Access
Returns the number of resources in the model.
Returns true if the model has no resources.
Returns the resource at the specified index.
Finds a resource by its internal ID.
Returns all resources as a list.
selectedResources(const QModelIndexList& indexes)
Returns resources for the given model indexes.
File Operations
Install
Uninstall
Enable/Disable
bool installResource(QString path);
Installs a resource from a file path, moving it to the instance directory.void installResourceWithFlameMetadata(
QString path,
ModPlatform::IndexedVersion& vers
);
Installs a resource with CurseForge metadata.bool uninstallResource(const QString& file_name, bool preserve_metadata = false);
Removes a resource by filename.bool deleteResources(const QModelIndexList& indexes);
Deletes multiple resources.void deleteMetadata(const QModelIndexList& indexes);
Deletes only the metadata for resources.enum class EnableAction { ENABLE, DISABLE, TOGGLE };
bool setResourceEnabled(const QModelIndexList& indexes, EnableAction action);
Enables, disables, or toggles resources.
Updating and Parsing
Creates and starts an update task to refresh the resource list. Returns false if update is already running.
resolveResource(Resource::Ptr res)
Creates a parse task for a resource to load its metadata.
Returns true if there are pending parse tasks.
File System Watching
Starts watching the resource directory for changes. Returns true on success.
Stops watching the directory. Returns true on success.
Sorting and Filtering
enum class SortType {
NAME, DATE, VERSION, ENABLED,
PACK_FORMAT, PROVIDER, SIZE, SIDE,
MC_VERSIONS, LOADERS, RELEASE_TYPE,
REQUIRES, REQUIRED_BY
};
createFilterProxyModel(QObject* parent)
Creates a proxy model for filtering and sorting.
columnToSortKey(size_t column)
Converts a column index to its sort type.
Model Columns
enum Columns {
ActiveColumn = 0,
NameColumn,
DateColumn,
ProviderColumn,
SizeColumn,
NUM_COLUMNS
};
Signals
signals:
void updateFinished();
void parseFinished();
Example Usage
#include "minecraft/mod/ResourceFolderModel.h"
ResourceFolderModel* model = /* ... */;
// Update resource list
if (model->update()) {
connect(model, &ResourceFolderModel::updateFinished, []() {
qDebug() << "Resources updated";
});
}
// Install a resource
if (model->installResource("/path/to/resource.jar")) {
qDebug() << "Resource installed";
}
// Enable/disable resources
QModelIndexList indexes = /* selected indexes */;
model->setResourceEnabled(indexes, EnableAction::TOGGLE);
// Access resources
for (int i = 0; i < model->size(); i++) {
Resource& res = model->at(i);
qDebug() << res.name() << "-" << res.sizeStr();
}
ModFolderModel
Specialized model for managing Minecraft mods with dependency tracking.
Class: ModFolderModel
Header: launcher/minecraft/mod/ModFolderModel.h
Inherits: ResourceFolderModel
Constructor
ModFolderModel(
const QDir& dir,
BaseInstance* instance,
bool is_indexed,
bool create_dir,
QObject* parent = nullptr
);
Extended Columns
enum Columns {
ActiveColumn = 0,
ImageColumn,
NameColumn,
VersionColumn,
DateColumn,
ProviderColumn,
SizeColumn,
SideColumn, // Client/Server side
LoadersColumn, // Fabric, Forge, etc.
McVersionsColumn, // Compatible MC versions
ReleaseTypeColumn, // Release, Beta, Alpha
RequiresColumn, // Dependencies
RequiredByColumn, // Reverse dependencies
NUM_COLUMNS
};
Dependency Tracking
Returns list of mod IDs that this mod requires.
requiredByList(QString id)
Returns list of mod IDs that require this mod.
getAffectedMods(const QModelIndexList& indexes, EnableAction action)
Returns mods that would be affected by enabling/disabling the given mods (due to dependencies).
Mod-Specific Operations
setResourceEnabled(const QModelIndexList& indexes, EnableAction action)
Enables/disables mods while respecting dependencies. Returns true on success.
Returns true if the mod folder is valid.
Type Helpers
The RESOURCE_HELPERS macro provides type-safe accessors:
Mod& at(int index);
const Mod& at(int index) const;
QList<Mod*> selectedMods(const QModelIndexList& indexes);
QList<Mod*> allMods();
Example Usage
#include "minecraft/mod/ModFolderModel.h"
#include "minecraft/MinecraftInstance.h"
MinecraftInstance* inst = /* ... */;
ModFolderModel* mods = inst->loaderModList();
// List all mods
for (auto* mod : mods->allMods()) {
qDebug() << mod->name() << mod->version();
qDebug() << " Side:" << mod->side();
qDebug() << " Loaders:" << mod->loaders();
qDebug() << " MC versions:" << mod->mcVersions();
}
// Check dependencies
for (int i = 0; i < mods->size(); i++) {
Mod& mod = mods->at(i);
QStringList deps = mods->requiresList(mod.internal_id());
if (!deps.isEmpty()) {
qDebug() << mod.name() << "requires:" << deps;
}
}
// Disable a mod (and check affected mods)
QModelIndexList toDisable = /* ... */;
QModelIndexList affected = mods->getAffectedMods(toDisable, EnableAction::DISABLE);
if (!affected.isEmpty()) {
qDebug() << "Warning: disabling will affect" << affected.size() << "other mods";
}
mods->setResourceEnabled(toDisable, EnableAction::DISABLE);
ResourcePackFolderModel
Model for managing Minecraft resource packs.
Class: ResourcePackFolderModel
Header: launcher/minecraft/mod/ResourcePackFolderModel.h
Inherits: ResourceFolderModel
Constructor
explicit ResourcePackFolderModel(
const QDir& dir,
BaseInstance* instance,
bool is_indexed,
bool create_dir,
QObject* parent = nullptr
);
Columns
enum Columns {
ActiveColumn = 0,
ImageColumn,
NameColumn,
PackFormatColumn, // Resource pack format version
DateColumn,
ProviderColumn,
SizeColumn,
NUM_COLUMNS
};
Type Helpers
ResourcePack& at(int index);
const ResourcePack& at(int index) const;
QList<ResourcePack*> selectedResourcePacks(const QModelIndexList& indexes);
QList<ResourcePack*> allResourcePacks();
Example Usage
#include "minecraft/mod/ResourcePackFolderModel.h"
#include "minecraft/MinecraftInstance.h"
MinecraftInstance* inst = /* ... */;
ResourcePackFolderModel* packs = inst->resourcePackList();
// List resource packs
for (auto* pack : packs->allResourcePacks()) {
qDebug() << pack->name();
qDebug() << " Format:" << pack->packFormat();
qDebug() << " Size:" << pack->sizeStr();
}
// Install a resource pack
if (packs->installResource("/downloads/awesome-pack.zip")) {
qDebug() << "Resource pack installed";
}
// Enable all packs
QModelIndexList all;
for (int i = 0; i < packs->rowCount(); i++) {
all.append(packs->index(i, 0));
}
packs->setResourceEnabled(all, EnableAction::ENABLE);
Resource
Base class representing a single managed resource.
Class: Resource
Header: launcher/minecraft/mod/Resource.h
Inherits: QObject
Resource Types
enum class ResourceType {
UNKNOWN,
ZIPFILE, // Zip archive
SINGLEFILE, // Single file
FOLDER, // Directory
LITEMOD // LiteMod format
};
Resource Status
enum class ResourceStatus {
INSTALLED, // Both JAR and metadata present
NOT_INSTALLED, // Only metadata present
NO_METADATA, // Only JAR present
UNKNOWN // Default status
};
Properties
Returns file information for this resource.
Returns the display name of the resource.
Returns the internal ID used for indexing.
Returns the resource type.
Returns the installation status.
Returns true if the resource is enabled.
Returns true if the resource is valid.
Size and Date
Returns human-readable size string (e.g., “2.5 MB”).
Returns the last modification date.
metadata()
std::shared_ptr<Metadata::ModStruct>
Returns the resource metadata (download info, versions, etc.).
setMetadata(std::shared_ptr<Metadata::ModStruct>&& metadata)
Sets the resource metadata.
Returns the provider name (e.g., “CurseForge”, “Modrinth”).
Returns the resource’s homepage URL.
Operations
enable(EnableAction action)
Enables, disables, or toggles the resource. Returns true if state changed.
destroy(const QDir& index_dir, bool preserve_metadata, bool attempt_trash)
Deletes all files for this resource. Returns true on success.
destroyMetadata(const QDir& index_dir)
Deletes only the metadata for this resource.
Compatibility
Returns list of compatibility issues with the instance.
updateIssues(const BaseInstance* inst)
Updates the issues list based on instance compatibility.
Returns true if there are compatibility issues.
Example Usage
#include "minecraft/mod/Resource.h"
Resource& resource = /* ... */;
// Get basic info
qDebug() << "Name:" << resource.name();
qDebug() << "Type:" << (int)resource.type();
qDebug() << "Size:" << resource.sizeStr();
qDebug() << "Modified:" << resource.dateTimeChanged().toString();
// Check metadata
if (auto meta = resource.metadata()) {
qDebug() << "Provider:" << resource.provider();
qDebug() << "Homepage:" << resource.homepage();
}
// Check compatibility
BaseInstance* inst = /* ... */;
resource.updateIssues(inst);
if (resource.hasIssues()) {
qDebug() << "Issues:" << resource.issues();
}
// Enable/disable
resource.enable(EnableAction::TOGGLE);
qDebug() << "Enabled:" << resource.enabled();