mirror of
https://github.com/vcmi/vcmi.git
synced 2025-09-16 09:26:28 +02:00
Reimplemented computation of installed mod size for Launcher
This commit is contained in:
@@ -320,10 +320,10 @@ QString CModListView::genModInfoText(const ModState & mod)
|
|||||||
result += replaceIfNotEmpty(mod.getRepositoryVersion(), lineTemplate.arg(tr("Latest version")));
|
result += replaceIfNotEmpty(mod.getRepositoryVersion(), lineTemplate.arg(tr("Latest version")));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
result += replaceIfNotEmpty(mod.getVersion(), lineTemplate.arg(tr("Version")));
|
result += replaceIfNotEmpty(mod.getVersion(), lineTemplate.arg(tr("Installed version")));
|
||||||
|
|
||||||
if(!mod.getLocalSizeFormatted().isEmpty())
|
if (mod.isInstalled())
|
||||||
result += replaceIfNotEmpty(mod.getLocalSizeFormatted(), lineTemplate.arg(tr("Size")));
|
result += replaceIfNotEmpty(modStateModel->getInstalledModSizeFormatted(mod.getID()), lineTemplate.arg(tr("Size")));
|
||||||
|
|
||||||
if((!mod.isInstalled() || mod.isUpdateAvailable()) && !mod.getDownloadSizeFormatted().isEmpty())
|
if((!mod.isInstalled() || mod.isUpdateAvailable()) && !mod.getDownloadSizeFormatted().isEmpty())
|
||||||
result += replaceIfNotEmpty(mod.getDownloadSizeFormatted(), lineTemplate.arg(tr("Download size")));
|
result += replaceIfNotEmpty(mod.getDownloadSizeFormatted(), lineTemplate.arg(tr("Download size")));
|
||||||
|
@@ -140,11 +140,6 @@ QString ModState::getDownloadSizeFormatted() const
|
|||||||
return QCoreApplication::translate("File size", "%1 MiB").arg(QString::number(getDownloadSizeMegabytes(), 'f', 1));
|
return QCoreApplication::translate("File size", "%1 MiB").arg(QString::number(getDownloadSizeMegabytes(), 'f', 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ModState::getLocalSizeFormatted() const
|
|
||||||
{
|
|
||||||
return {}; // TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
QString ModState::getAuthors() const
|
QString ModState::getAuthors() const
|
||||||
{
|
{
|
||||||
return QString::fromStdString(impl.getValue("author").String());
|
return QString::fromStdString(impl.getValue("author").String());
|
||||||
|
@@ -46,7 +46,6 @@ public:
|
|||||||
double getDownloadSizeMegabytes() const;
|
double getDownloadSizeMegabytes() const;
|
||||||
size_t getDownloadSizeBytes() const;
|
size_t getDownloadSizeBytes() const;
|
||||||
QString getDownloadSizeFormatted() const;
|
QString getDownloadSizeFormatted() const;
|
||||||
QString getLocalSizeFormatted() const;
|
|
||||||
QString getAuthors() const;
|
QString getAuthors() const;
|
||||||
QString getContact() const;
|
QString getContact() const;
|
||||||
QString getLicenseUrl() const;
|
QString getLicenseUrl() const;
|
||||||
|
@@ -76,38 +76,6 @@ void ModStateController::appendRepositories(const JsonNode & repomap)
|
|||||||
modList->appendRepositories(repomap);
|
modList->appendRepositories(repomap);
|
||||||
}
|
}
|
||||||
|
|
||||||
//void ModStateController::loadMods()
|
|
||||||
//{
|
|
||||||
// CModHandler handler;
|
|
||||||
// auto installedMods = handler.getAllMods();
|
|
||||||
// localMods.clear();
|
|
||||||
//
|
|
||||||
// for(auto modname : installedMods)
|
|
||||||
// {
|
|
||||||
// //calculate mod size
|
|
||||||
// qint64 total = 0;
|
|
||||||
// ResourcePath resDir(CModInfo::getModDir(modname), EResType::DIRECTORY);
|
|
||||||
// if(CResourceHandler::get()->existsResource(resDir))
|
|
||||||
// {
|
|
||||||
// for(QDirIterator iter(QString::fromStdString(CResourceHandler::get()->getResourceName(resDir)->string()), QDirIterator::Subdirectories); iter.hasNext(); iter.next())
|
|
||||||
// total += iter.fileInfo().size();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// boost::filesystem::path name = *CResourceHandler::get()->getResourceName(resID);
|
|
||||||
// auto mod = JsonUtils::JsonFromFile(pathToQString(name));
|
|
||||||
// auto json = JsonUtils::toJson(mod);
|
|
||||||
// json["localSizeBytes"].Float() = total;
|
|
||||||
// if(!name.is_absolute())
|
|
||||||
// json["storedLocally"].Bool() = true;
|
|
||||||
//
|
|
||||||
// mod = JsonUtils::toVariant(json);
|
|
||||||
// QString modNameQt = QString::fromUtf8(modname.c_str()).toLower();
|
|
||||||
// localMods.insert(modNameQt, mod);
|
|
||||||
// modSettings->registerNewMod(modNameQt, json["keepDisabled"].Bool());
|
|
||||||
// }
|
|
||||||
// modList->setLocalModList(localMods);
|
|
||||||
//}
|
|
||||||
|
|
||||||
bool ModStateController::addError(QString modname, QString message)
|
bool ModStateController::addError(QString modname, QString message)
|
||||||
{
|
{
|
||||||
recentErrors.push_back(QString("%1: %2").arg(modname).arg(message));
|
recentErrors.push_back(QString("%1: %2").arg(modname).arg(message));
|
||||||
|
@@ -82,3 +82,13 @@ bool ModStateModel::isModVisible(QString modName) const
|
|||||||
{
|
{
|
||||||
return getMod(modName).isVisible();
|
return getMod(modName).isVisible();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString ModStateModel::getInstalledModSizeFormatted(QString modName) const
|
||||||
|
{
|
||||||
|
return QCoreApplication::translate("File size", "%1 MiB").arg(QString::number(getInstalledModSizeMegabytes(modName), 'f', 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
double ModStateModel::getInstalledModSizeMegabytes(QString modName) const
|
||||||
|
{
|
||||||
|
return modManager->getInstalledModSizeMegabytes(modName.toStdString());
|
||||||
|
}
|
||||||
|
@@ -34,6 +34,9 @@ public:
|
|||||||
QStringList getAllMods() const;
|
QStringList getAllMods() const;
|
||||||
QStringList getSubmods(QString modName) const;
|
QStringList getSubmods(QString modName) const;
|
||||||
|
|
||||||
|
QString getInstalledModSizeFormatted(QString modName) const;
|
||||||
|
double getInstalledModSizeMegabytes(QString modName) const;
|
||||||
|
|
||||||
bool isModExists(QString modName) const;
|
bool isModExists(QString modName) const;
|
||||||
bool isModInstalled(QString modName) const;
|
bool isModInstalled(QString modName) const;
|
||||||
bool isModEnabled(QString modName) const;
|
bool isModEnabled(QString modName) const;
|
||||||
|
@@ -20,20 +20,22 @@
|
|||||||
|
|
||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
static std::string getModSettingsDirectory(const TModID & modName)
|
static std::string getModDirectory(const TModID & modName)
|
||||||
{
|
{
|
||||||
std::string result = modName;
|
std::string result = modName;
|
||||||
boost::to_upper(result);
|
boost::to_upper(result);
|
||||||
boost::algorithm::replace_all(result, ".", "/MODS/");
|
boost::algorithm::replace_all(result, ".", "/MODS/");
|
||||||
return "MODS/" + result + "/MODS/";
|
return "MODS/" + result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string getModSettingsDirectory(const TModID & modName)
|
||||||
|
{
|
||||||
|
return getModDirectory(modName) + "/MODS/";
|
||||||
}
|
}
|
||||||
|
|
||||||
static JsonPath getModDescriptionFile(const TModID & modName)
|
static JsonPath getModDescriptionFile(const TModID & modName)
|
||||||
{
|
{
|
||||||
std::string result = modName;
|
return JsonPath::builtin(getModDirectory(modName) + "/mod");
|
||||||
boost::to_upper(result);
|
|
||||||
boost::algorithm::replace_all(result, ".", "/MODS/");
|
|
||||||
return JsonPath::builtin("MODS/" + result + "/mod");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ModsState::ModsState()
|
ModsState::ModsState()
|
||||||
@@ -89,6 +91,22 @@ uint32_t ModsState::computeChecksum(const TModID & modName) const
|
|||||||
return modChecksum.checksum();
|
return modChecksum.checksum();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double ModsState::getInstalledModSizeMegabytes(const TModID & modName) const
|
||||||
|
{
|
||||||
|
ResourcePath resDir(getModDirectory(modName), EResType::DIRECTORY);
|
||||||
|
std::string path = CResourceHandler::get()->getResourceName(resDir)->string();
|
||||||
|
|
||||||
|
size_t sizeBytes = 0;
|
||||||
|
for(boost::filesystem::recursive_directory_iterator it(path); it != boost::filesystem::recursive_directory_iterator(); ++it)
|
||||||
|
{
|
||||||
|
if(!boost::filesystem::is_directory(*it))
|
||||||
|
sizeBytes += boost::filesystem::file_size(*it);
|
||||||
|
}
|
||||||
|
|
||||||
|
double sizeMegabytes = sizeBytes / double(1024*1024);
|
||||||
|
return sizeMegabytes;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<TModID> ModsState::scanModsDirectory(const std::string & modDir) const
|
std::vector<TModID> ModsState::scanModsDirectory(const std::string & modDir) const
|
||||||
{
|
{
|
||||||
size_t depth = boost::range::count(modDir, '/');
|
size_t depth = boost::range::count(modDir, '/');
|
||||||
@@ -372,6 +390,11 @@ TModList ModManager::getAllMods() const
|
|||||||
return modsStorage->getAllMods();
|
return modsStorage->getAllMods();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double ModManager::getInstalledModSizeMegabytes(const TModID & modName) const
|
||||||
|
{
|
||||||
|
return modsState->getInstalledModSizeMegabytes(modName);
|
||||||
|
}
|
||||||
|
|
||||||
void ModManager::eraseMissingModsFromPreset()
|
void ModManager::eraseMissingModsFromPreset()
|
||||||
{
|
{
|
||||||
const TModList & installedMods = modsState->getInstalledMods();
|
const TModList & installedMods = modsState->getInstalledMods();
|
||||||
|
@@ -32,6 +32,7 @@ public:
|
|||||||
ModsState();
|
ModsState();
|
||||||
|
|
||||||
TModList getInstalledMods() const;
|
TModList getInstalledMods() const;
|
||||||
|
double getInstalledModSizeMegabytes(const TModID & modName) const;
|
||||||
|
|
||||||
uint32_t computeChecksum(const TModID & modName) const;
|
uint32_t computeChecksum(const TModID & modName) const;
|
||||||
};
|
};
|
||||||
@@ -111,6 +112,7 @@ public:
|
|||||||
std::optional<uint32_t> getValidatedChecksum(const TModID & modName) const;
|
std::optional<uint32_t> getValidatedChecksum(const TModID & modName) const;
|
||||||
void setValidatedChecksum(const TModID & modName, std::optional<uint32_t> value);
|
void setValidatedChecksum(const TModID & modName, std::optional<uint32_t> value);
|
||||||
void saveConfigurationState() const;
|
void saveConfigurationState() const;
|
||||||
|
double getInstalledModSizeMegabytes(const TModID & modName) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_END
|
VCMI_LIB_NAMESPACE_END
|
||||||
|
Reference in New Issue
Block a user