Skip to main content

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
);
dir
QDir
Directory containing the resources.
instance
BaseInstance*
The instance this model belongs to.
is_indexed
bool
Whether resources have metadata indexing.
create_dir
bool
Whether to create the directory if it doesn’t exist.

Resource Access

size()
qsizetype
Returns the number of resources in the model.
empty()
bool
Returns true if the model has no resources.
at(int index)
Resource&
Returns the resource at the specified index.
find(QString id)
Resource::Ptr
Finds a resource by its internal ID.
allResources()
QList<Resource*>
Returns all resources as a list.
selectedResources(const QModelIndexList& indexes)
QList<Resource*>
Returns resources for the given model indexes.

File Operations

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.

Updating and Parsing

update()
bool
Creates and starts an update task to refresh the resource list. Returns false if update is already running.
resolveResource(Resource::Ptr res)
void
Creates a parse task for a resource to load its metadata.
hasPendingParseTasks()
bool
Returns true if there are pending parse tasks.

File System Watching

startWatching()
bool
Starts watching the resource directory for changes. Returns true on success.
stopWatching()
bool
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)
QSortFilterProxyModel*
Creates a proxy model for filtering and sorting.
columnToSortKey(size_t column)
SortType
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

requiresList(QString id)
QStringList
Returns list of mod IDs that this mod requires.
requiredByList(QString id)
QStringList
Returns list of mod IDs that require this mod.
getAffectedMods(const QModelIndexList& indexes, EnableAction action)
QModelIndexList
Returns mods that would be affected by enabling/disabling the given mods (due to dependencies).

Mod-Specific Operations

setResourceEnabled(const QModelIndexList& indexes, EnableAction action)
bool
Enables/disables mods while respecting dependencies. Returns true on success.
isValid()
bool
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

fileinfo()
QFileInfo
Returns file information for this resource.
name()
QString
Returns the display name of the resource.
internal_id()
QString
Returns the internal ID used for indexing.
type()
ResourceType
Returns the resource type.
status()
ResourceStatus
Returns the installation status.
enabled()
bool
Returns true if the resource is enabled.
valid()
bool
Returns true if the resource is valid.

Size and Date

sizeStr()
QString
Returns human-readable size string (e.g., “2.5 MB”).
sizeInfo()
qint64
Returns size in bytes.
dateTimeChanged()
QDateTime
Returns the last modification date.

Metadata

metadata()
std::shared_ptr<Metadata::ModStruct>
Returns the resource metadata (download info, versions, etc.).
setMetadata(std::shared_ptr<Metadata::ModStruct>&& metadata)
void
Sets the resource metadata.
provider()
QString
Returns the provider name (e.g., “CurseForge”, “Modrinth”).
homepage()
QString
Returns the resource’s homepage URL.

Operations

enable(EnableAction action)
bool
Enables, disables, or toggles the resource. Returns true if state changed.
destroy(const QDir& index_dir, bool preserve_metadata, bool attempt_trash)
bool
Deletes all files for this resource. Returns true on success.
destroyMetadata(const QDir& index_dir)
void
Deletes only the metadata for this resource.

Compatibility

issues()
QStringList
Returns list of compatibility issues with the instance.
updateIssues(const BaseInstance* inst)
void
Updates the issues list based on instance compatibility.
hasIssues()
bool
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();