summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-01-09 22:18:59 +0300
committerAndrei Karas <akaras@inbox.ru>2014-01-09 22:57:42 +0300
commit923633ae61b255c64dee9cf011382086453286d8 (patch)
treed8851d3b80df477854c2293e3cbea2a026b079ad /src/gui
parente0baa7398ca03060e5fe11c7647ae80ae258beeb (diff)
downloadmv-923633ae61b255c64dee9cf011382086453286d8.tar.gz
mv-923633ae61b255c64dee9cf011382086453286d8.tar.bz2
mv-923633ae61b255c64dee9cf011382086453286d8.tar.xz
mv-923633ae61b255c64dee9cf011382086453286d8.zip
add mods loading based on settings.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/windows/updaterwindow.cpp117
-rw-r--r--src/gui/windows/updaterwindow.h10
2 files changed, 116 insertions, 11 deletions
diff --git a/src/gui/windows/updaterwindow.cpp b/src/gui/windows/updaterwindow.cpp
index 099142cbe..fe3a4cbcf 100644
--- a/src/gui/windows/updaterwindow.cpp
+++ b/src/gui/windows/updaterwindow.cpp
@@ -39,6 +39,8 @@
#include "resources/resourcemanager.h"
+#include "resources/db/moddb.h"
+
#include "utils/gettext.h"
#include "utils/mkdir.h"
#include "utils/paths.h"
@@ -75,14 +77,12 @@ static std::vector<UpdateFile> loadXMLFile(const std::string &fileName)
if (!xmlNameEqual(fileNode, "update"))
continue;
- if (XML::getProperty(fileNode, "group", "default") != "default")
- continue;
-
UpdateFile file;
file.name = XML::getProperty(fileNode, "file", "");
file.hash = XML::getProperty(fileNode, "hash", "");
file.type = XML::getProperty(fileNode, "type", "data");
file.desc = XML::getProperty(fileNode, "description", "");
+ file.group = XML::getProperty(fileNode, "group", "");
const std::string version = XML::getProperty(
fileNode, "version", "");
if (!version.empty())
@@ -128,6 +128,7 @@ static std::vector<UpdateFile> loadTxtFile(const std::string &fileName)
thisFile.name = name;
thisFile.hash = hash;
thisFile.type = "data";
+ thisFile.group = "";
thisFile.required = true;
thisFile.desc.clear();
@@ -573,10 +574,14 @@ void UpdaterWindow::loadUpdates()
const unsigned sz = static_cast<unsigned>(mUpdateFiles.size());
for (mUpdateIndex = 0; mUpdateIndex < sz; mUpdateIndex++)
{
- UpdaterWindow::addUpdateFile(resman, mUpdatesDir, fixPath,
- mUpdateFiles[mUpdateIndex].name, false);
+ const UpdateFile &file = mUpdateFiles[mUpdateIndex];
+ if (!file.group.empty())
+ continue;
+ UpdaterWindow::addUpdateFile(resman, mUpdatesDir,
+ fixPath, file.name, false);
}
loadManaPlusUpdates(mUpdatesDir, resman);
+ loadMods(mUpdatesDir, resman, mUpdateFiles);
}
void UpdaterWindow::loadLocalUpdates(const std::string &dir)
@@ -599,10 +604,14 @@ void UpdaterWindow::loadLocalUpdates(const std::string &dir)
for (unsigned int updateIndex = 0, sz = static_cast<unsigned int>(
updateFiles.size()); updateIndex < sz; updateIndex ++)
{
- UpdaterWindow::addUpdateFile(resman, dir, fixPath,
- updateFiles[updateIndex].name, false);
+ const UpdateFile &file = updateFiles[updateIndex];
+ if (!file.group.empty())
+ continue;
+ UpdaterWindow::addUpdateFile(resman, dir,
+ fixPath, file.name, false);
}
loadManaPlusUpdates(dir, resman);
+ loadMods(dir, resman, updateFiles);
}
void UpdaterWindow::unloadUpdates(const std::string &dir)
@@ -956,13 +965,9 @@ void UpdaterWindow::handleLink(const std::string &link,
gcn::MouseEvent *event A_UNUSED)
{
if (strStartWith(link, "http://") || strStartWith(link, "https://"))
- {
openBrowser(link);
- }
else if (link == "news")
- {
loadFile("news");
- }
}
void UpdaterWindow::loadFile(std::string file)
@@ -977,3 +982,93 @@ void UpdaterWindow::loadFile(std::string file)
for (size_t i = 0, sz = lines.size(); i < sz; ++i)
mBrowserBox->addRow(lines[i]);
}
+
+void UpdaterWindow::loadMods(const std::string &dir,
+ const ResourceManager *const resman,
+ const std::vector<UpdateFile> &updateFiles)
+{
+ ModDB::load();
+ std::string modsString = serverConfig.getValue("mods", "");
+ std::set<std::string> modsList;
+ splitToStringSet(modsList, modsString, '|');
+
+ const std::string fixPath = dir + "/fix";
+ for (unsigned int updateIndex = 0, sz = static_cast<unsigned int>(
+ updateFiles.size()); updateIndex < sz; updateIndex ++)
+ {
+ const UpdateFile &file = updateFiles[updateIndex];
+ if (file.group.empty())
+ continue;
+ const std::set<std::string>::const_iterator
+ it = modsList.find(file.group);
+ if (it != modsList.end())
+ {
+ UpdaterWindow::addUpdateFile(resman, dir,
+ fixPath, file.name, false);
+ }
+ }
+
+ std::vector<UpdateFile> updateFiles2
+ = loadXMLFile(std::string(fixPath).append("/").append(xmlUpdateFile));
+
+ for (unsigned int updateIndex = 0, sz = static_cast<unsigned int>(
+ updateFiles2.size()); updateIndex < sz; updateIndex ++)
+ {
+ const UpdateFile &file = updateFiles2[updateIndex];
+ if (file.group.empty())
+ continue;
+ std::string name = file.name;
+ if (strStartWith(name, "manaplus_"))
+ {
+ const std::set<std::string>::const_iterator
+ it = modsList.find(file.group);
+ if (it != modsList.end())
+ {
+ struct stat statbuf;
+ std::string file = std::string(fixPath).append(
+ "/").append(name);
+ if (!stat(file.c_str(), &statbuf))
+ resman->addToSearchPath(file, false);
+ }
+ }
+ }
+
+}
+
+void UpdaterWindow::loadDirMods(const std::string &dir)
+{
+ ModDB::load();
+ const ResourceManager *const resman = ResourceManager::getInstance();
+ const ModInfos &mods = ModDB::getAll();
+
+ std::string modsString = serverConfig.getValue("mods", "");
+ StringVect modsList;
+ splitToStringVector(modsList, modsString, '|');
+ FOR_EACH (StringVectCIter, it, modsList)
+ {
+ const std::string &name = *it;
+ const ModInfoCIterator modIt = mods.find(name);
+ if (modIt == mods.end())
+ continue;
+ const ModInfo *const mod = (*modIt).second;
+ resman->addToSearchPath(dir + "/" + mod->getLocalDir(), false);
+ }
+}
+
+void UpdaterWindow::unloadMods(const std::string &dir)
+{
+ const ResourceManager *const resman = ResourceManager::getInstance();
+ const ModInfos &mods = ModDB::getAll();
+ std::string modsString = serverConfig.getValue("mods", "");
+ StringVect modsList;
+ splitToStringVector(modsList, modsString, '|');
+ FOR_EACH (StringVectCIter, it, modsList)
+ {
+ const std::string &name = *it;
+ const ModInfoCIterator modIt = mods.find(name);
+ if (modIt == mods.end())
+ continue;
+ const ModInfo *const mod = (*modIt).second;
+ resman->removeFromSearchPath(dir + "/" + mod->getLocalDir());
+ }
+}
diff --git a/src/gui/windows/updaterwindow.h b/src/gui/windows/updaterwindow.h
index 433ab82ad..bddd3ef9e 100644
--- a/src/gui/windows/updaterwindow.h
+++ b/src/gui/windows/updaterwindow.h
@@ -51,6 +51,7 @@ struct UpdateFile final
hash(),
type(),
desc(),
+ group(),
required(false)
{
}
@@ -58,6 +59,7 @@ struct UpdateFile final
std::string hash;
std::string type;
std::string desc;
+ std::string group;
bool required;
};
@@ -151,6 +153,14 @@ class UpdaterWindow final : public Window,
static unsigned long getFileHash(const std::string &filePath);
+ static void loadMods(const std::string &dir,
+ const ResourceManager *const resman,
+ const std::vector<UpdateFile> &updateFiles);
+
+ static void loadDirMods(const std::string &dir);
+
+ static void unloadMods(const std::string &dir);
+
private:
void download();