summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client.cpp48
-rw-r--r--src/client.h1
-rw-r--r--src/gui/updaterwindow.cpp56
-rw-r--r--src/gui/updaterwindow.h10
4 files changed, 109 insertions, 6 deletions
diff --git a/src/client.cpp b/src/client.cpp
index cb17f4919..705670277 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -300,7 +300,8 @@ Client::Client(const Options &options) :
mSkin(nullptr),
mButtonPadding(1),
mButtonSpacing(3),
- mKeyboardHeight(0)
+ mKeyboardHeight(0),
+ mOldUpdates()
{
mInstance = this;
@@ -1205,8 +1206,34 @@ int Client::gameExec()
switch (mState)
{
case STATE_CHOOSE_SERVER:
+ {
BLOCK_START("Client::gameExec STATE_CHOOSE_SERVER")
logger->log1("State: CHOOSE SERVER");
+ const ResourceManager *const resman
+ = ResourceManager::getInstance();
+ if (mOptions.dataPath.empty())
+ {
+ // Add customdata directory
+ resman->searchAndRemoveArchives(
+ "customdata/",
+ "zip");
+ }
+
+ if (!mOldUpdates.empty())
+ {
+ UpdaterWindow::unloadUpdates(mOldUpdates);
+ mOldUpdates.clear();
+ }
+
+ if (!mOptions.skipUpdate)
+ {
+ resman->searchAndRemoveArchives(
+ mUpdatesDir + "/local/",
+ "zip");
+
+ resman->removeFromSearchPath(mLocalDataDir + dirSeparator
+ + mUpdatesDir + "/local/");
+ }
loginData.clearUpdateHost();
serverVersion = 0;
@@ -1235,6 +1262,7 @@ int Client::gameExec()
}
BLOCK_END("Client::gameExec STATE_CHOOSE_SERVER")
break;
+ }
case STATE_CONNECT_SERVER:
BLOCK_START("Client::gameExec STATE_CONNECT_SERVER")
@@ -1330,6 +1358,7 @@ int Client::gameExec()
case STATE_UPDATE:
BLOCK_START("Client::gameExec STATE_UPDATE")
+ logger->log1("State: UPDATE");
// Determine which source to use for the update host
if (!mOptions.updateHost.empty())
mUpdateHost = mOptions.updateHost;
@@ -1337,22 +1366,29 @@ int Client::gameExec()
mUpdateHost = loginData.updateHost;
initUpdatesDir();
+ if (!mOldUpdates.empty())
+ UpdaterWindow::unloadUpdates(mOldUpdates);
+
if (mOptions.skipUpdate)
{
mState = STATE_LOAD_DATA;
+ mOldUpdates = "";
}
else if (loginData.updateType & LoginData::Upd_Skip)
{
- UpdaterWindow::loadLocalUpdates(mLocalDataDir
- + dirSeparator + mUpdatesDir);
+ mOldUpdates = mLocalDataDir
+ + dirSeparator + mUpdatesDir;
+ UpdaterWindow::loadLocalUpdates(mOldUpdates);
mState = STATE_LOAD_DATA;
}
else
{
- logger->log1("State: UPDATE");
+ mOldUpdates = mLocalDataDir
+ + dirSeparator + mUpdatesDir;
mCurrentDialog = new UpdaterWindow(mUpdateHost,
- mLocalDataDir + dirSeparator + mUpdatesDir,
- mOptions.dataPath.empty(), loginData.updateType);
+ mOldUpdates,
+ mOptions.dataPath.empty(),
+ loginData.updateType);
}
BLOCK_END("Client::gameExec STATE_UPDATE")
break;
diff --git a/src/client.h b/src/client.h
index 1f577a4da..d9229c271 100644
--- a/src/client.h
+++ b/src/client.h
@@ -428,6 +428,7 @@ private:
int mButtonPadding;
int mButtonSpacing;
int mKeyboardHeight;
+ std::string mOldUpdates;
};
#endif // CLIENT_H
diff --git a/src/gui/updaterwindow.cpp b/src/gui/updaterwindow.cpp
index 197b97e3a..a29514994 100644
--- a/src/gui/updaterwindow.cpp
+++ b/src/gui/updaterwindow.cpp
@@ -594,6 +594,29 @@ void UpdaterWindow::loadLocalUpdates(const std::string &dir)
loadManaPlusUpdates(dir, resman);
}
+void UpdaterWindow::unloadUpdates(const std::string &dir)
+{
+ const ResourceManager *const resman = ResourceManager::getInstance();
+
+ std::vector<UpdateFile> updateFiles
+ = loadXMLFile(std::string(dir).append("/").append(xmlUpdateFile));
+
+ if (updateFiles.empty())
+ {
+ updateFiles = loadTxtFile(std::string(dir).append(
+ "/").append(txtUpdateFile));
+ }
+
+ std::string fixPath = dir + "/fix";
+ for (unsigned int updateIndex = 0, sz = static_cast<unsigned int>(
+ updateFiles.size()); updateIndex < sz; updateIndex ++)
+ {
+ UpdaterWindow::removeUpdateFile(resman, dir, fixPath,
+ updateFiles[updateIndex].name);
+ }
+ unloadManaPlusUpdates(dir, resman);
+}
+
void UpdaterWindow::loadManaPlusUpdates(const std::string &dir,
const ResourceManager *const resman)
{
@@ -615,6 +638,27 @@ void UpdaterWindow::loadManaPlusUpdates(const std::string &dir,
}
}
+void UpdaterWindow::unloadManaPlusUpdates(const std::string &dir,
+ const ResourceManager *const resman)
+{
+ std::string fixPath = dir + "/fix";
+ std::vector<UpdateFile> updateFiles
+ = loadXMLFile(std::string(fixPath).append("/").append(xmlUpdateFile));
+
+ for (unsigned int updateIndex = 0, sz = static_cast<unsigned int>(
+ updateFiles.size()); updateIndex < sz; updateIndex ++)
+ {
+ std::string name = updateFiles[updateIndex].name;
+ if (strStartWith(name, "manaplus_"))
+ {
+ struct stat statbuf;
+ std::string file = std::string(fixPath).append("/").append(name);
+ if (!stat(file.c_str(), &statbuf))
+ resman->removeFromSearchPath(file);
+ }
+ }
+}
+
void UpdaterWindow::addUpdateFile(const ResourceManager *const resman,
const std::string &path,
const std::string &fixPath,
@@ -634,6 +678,18 @@ void UpdaterWindow::addUpdateFile(const ResourceManager *const resman,
resman->addToSearchPath(tmpPath, append);
}
+void UpdaterWindow::removeUpdateFile(const ResourceManager *const resman,
+ const std::string &path,
+ const std::string &fixPath,
+ const std::string &file)
+{
+ resman->removeFromSearchPath(std::string(path).append("/").append(file));
+ const std::string fixFile = std::string(fixPath).append("/").append(file);
+ struct stat statbuf;
+ if (!stat(fixFile.c_str(), &statbuf))
+ resman->removeFromSearchPath(fixFile);
+}
+
void UpdaterWindow::logic()
{
BLOCK_START("UpdaterWindow::logic")
diff --git a/src/gui/updaterwindow.h b/src/gui/updaterwindow.h
index 1ee35195a..3cc8392e5 100644
--- a/src/gui/updaterwindow.h
+++ b/src/gui/updaterwindow.h
@@ -126,15 +126,25 @@ class UpdaterWindow final : public Window,
static void loadLocalUpdates(const std::string &dir);
+ static void unloadUpdates(const std::string &dir);
+
static void addUpdateFile(const ResourceManager *const resman,
const std::string &path,
const std::string &fixPath,
const std::string &file,
const bool append);
+ static void removeUpdateFile(const ResourceManager *const resman,
+ const std::string &path,
+ const std::string &fixPath,
+ const std::string &file);
+
static void loadManaPlusUpdates(const std::string &dir,
const ResourceManager *const resman);
+ static void unloadManaPlusUpdates(const std::string &dir,
+ const ResourceManager *const resman);
+
private:
void download();