summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-08-28 21:52:49 +0300
committerAndrei Karas <akaras@inbox.ru>2011-08-28 21:52:49 +0300
commita9345c0e74408538488b0a329202ce611a4a0072 (patch)
tree9e8df5b62f4337286f4785fa7b62a3b256b81b57 /src
parent1d5e1e10214b2f992888045dc750c8d8b7937b21 (diff)
downloadmv-a9345c0e74408538488b0a329202ce611a4a0072.tar.gz
mv-a9345c0e74408538488b0a329202ce611a4a0072.tar.bz2
mv-a9345c0e74408538488b0a329202ce611a4a0072.tar.xz
mv-a9345c0e74408538488b0a329202ce611a4a0072.zip
Add support for auto download content fixes.
Diffstat (limited to 'src')
-rw-r--r--src/gui/updaterwindow.cpp76
-rw-r--r--src/gui/updaterwindow.h13
-rw-r--r--src/utils/stringutils.cpp8
-rw-r--r--src/utils/stringutils.h2
4 files changed, 89 insertions, 10 deletions
diff --git a/src/gui/updaterwindow.cpp b/src/gui/updaterwindow.cpp
index 7534b12a9..ba482919e 100644
--- a/src/gui/updaterwindow.cpp
+++ b/src/gui/updaterwindow.cpp
@@ -54,6 +54,7 @@
const std::string xmlUpdateFile = "resources.xml";
const std::string txtUpdateFile = "resources2.txt";
+const std::string updateServer2 = "http://download.evolonline.org/manaplus/updates/";
std::vector<updateFile> loadXMLFile(const std::string &fileName);
std::vector<updateFile> loadTxtFile(const std::string &fileName);
@@ -137,6 +138,7 @@ UpdaterWindow::UpdaterWindow(const std::string &updateHost,
mDownloadStatus(UPDATE_NEWS),
mUpdateHost(updateHost),
mUpdatesDir(updatesDir),
+ mUpdatesDirReal(updatesDir),
mCurrentFile("news.txt"),
mDownloadProgress(0.0f),
mCurrentChecksum(0),
@@ -147,6 +149,7 @@ UpdaterWindow::UpdaterWindow(const std::string &updateHost,
mMemoryBuffer(NULL),
mDownload(NULL),
mUpdateIndex(0),
+ mUpdateIndexOffset(0),
mLoadUpdates(applyUpdates),
mUpdateType(updateType)
{
@@ -181,6 +184,10 @@ UpdaterWindow::UpdaterWindow(const std::string &updateHost,
setVisible(true);
mCancelButton->requestFocus();
+ mUpdateServerPath = mUpdateHost;
+ removeProtocol(mUpdateServerPath);
+ logger->log("mUpdateServerPath: %s, %s", mUpdateHost.c_str(), mUpdateServerPath.c_str());
+
// Try to download the updates list
download();
}
@@ -539,8 +546,9 @@ void UpdaterWindow::logic()
mProgressBar->setProgress(mDownloadProgress);
if (mUpdateFiles.size() && mUpdateIndex <= mUpdateFiles.size())
{
- mProgressBar->setText(strprintf("%d/%d",
- mUpdateIndex + 1, (int)mUpdateFiles.size() + 1));
+ mProgressBar->setText(strprintf("%d/%d", mUpdateIndex
+ + mUpdateIndexOffset + 1, (int)mUpdateFiles.size()
+ + (int)mTempUpdateFiles.size() + 1));
}
else
{
@@ -582,13 +590,12 @@ void UpdaterWindow::logic()
// Parse current memory buffer as news and dispose of the data
loadPatch();
-/*
- mCurrentFile = "news.txt";
- mStoreInMemory = true;
- mDownloadStatus = UPDATE_NEWS;
- download(); // download() changes mDownloadComplete to false
-*/
- mDownloadStatus = UPDATE_COMPLETE;
+ mUpdateHost = updateServer2 + mUpdateServerPath;
+ mUpdatesDir += "/fix";
+ mCurrentFile = xmlUpdateFile;
+ mStoreInMemory = false;
+ mDownloadStatus = UPDATE_LIST2;
+ download();
}
break;
@@ -681,7 +688,58 @@ void UpdaterWindow::logic()
}
}
break;
+ case UPDATE_LIST2:
+ if (mDownloadComplete)
+ {
+ if (mCurrentFile == xmlUpdateFile)
+ {
+ mTempUpdateFiles = loadXMLFile(
+ mUpdatesDir + "/" + xmlUpdateFile);
+ }
+ mUpdateIndexOffset = mUpdateIndex;
+ mUpdateIndex = 0;
+ mStoreInMemory = false;
+ mDownloadStatus = UPDATE_RESOURCES2;
+ download();
+ }
+ break;
+ case UPDATE_RESOURCES2:
+ if (mDownloadComplete)
+ {
+ if (mUpdateIndex < mTempUpdateFiles.size())
+ {
+ updateFile thisFile = mTempUpdateFiles[mUpdateIndex];
+ mCurrentFile = thisFile.name;
+ std::string checksum;
+ checksum = thisFile.hash;
+ std::stringstream ss(checksum);
+ ss >> std::hex >> mCurrentChecksum;
+
+ std::ifstream temp(
+ (mUpdatesDir + "/" + mCurrentFile).c_str());
+
+ if (!temp.is_open() || !validateFile(mUpdatesDir + "/"
+ + mCurrentFile, mCurrentChecksum))
+ {
+ temp.close();
+ download();
+ }
+ else
+ {
+ temp.close();
+ logger->log("%s already here", mCurrentFile.c_str());
+ }
+ mUpdateIndex++;
+ }
+ else
+ {
+ mUpdatesDir = mUpdatesDirReal;
+ mDownloadStatus = UPDATE_COMPLETE;
+ }
+ }
+ break;
case UPDATE_COMPLETE:
+ mUpdatesDir = mUpdatesDirReal;
enable();
setLabel(_("Completed"));
break;
diff --git a/src/gui/updaterwindow.h b/src/gui/updaterwindow.h
index a1dc556d5..e9a45241f 100644
--- a/src/gui/updaterwindow.h
+++ b/src/gui/updaterwindow.h
@@ -146,7 +146,9 @@ private:
UPDATE_COMPLETE,
UPDATE_NEWS,
UPDATE_RESOURCES,
- UPDATE_PATCH
+ UPDATE_PATCH,
+ UPDATE_LIST2,
+ UPDATE_RESOURCES2
};
/** Status of the current download. */
@@ -158,6 +160,8 @@ private:
/** Place where the updates are stored (absolute path). */
std::string mUpdatesDir;
+ std::string mUpdatesDirReal;
+
/** The file currently downloading. */
std::string mCurrentFile;
@@ -194,9 +198,15 @@ private:
/** List of files to download. */
std::vector<updateFile> mUpdateFiles;
+ /** List of temp files to download. */
+ std::vector<updateFile> mTempUpdateFiles;
+
/** Index of the file to be downloaded. */
unsigned int mUpdateIndex;
+ /** Index offset for disaplay downloaded file. */
+ unsigned int mUpdateIndexOffset;
+
/** Tells ~UpdaterWindow() if it should load updates */
bool mLoadUpdates;
@@ -208,6 +218,7 @@ private:
ProgressBar *mProgressBar; /**< Update progress bar. */
BrowserBox *mBrowserBox; /**< Box to display news. */
ScrollArea *mScrollArea; /**< Used to scroll news box. */
+ std::string mUpdateServerPath;
};
#endif
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp
index 361bc860c..176c5499c 100644
--- a/src/utils/stringutils.cpp
+++ b/src/utils/stringutils.cpp
@@ -578,3 +578,11 @@ bool findCutFirst(std::string &str1, std::string str2)
}
return false;
}
+
+std::string &removeProtocol(std::string &url)
+{
+ int i = url.find("://");
+ if (i != (int)std::string::npos)
+ url = url.substr(i + 3);
+ return url;
+}
diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h
index c0457bc52..25fe11e2d 100644
--- a/src/utils/stringutils.h
+++ b/src/utils/stringutils.h
@@ -201,4 +201,6 @@ bool findCutLast(std::string &str1, std::string str2);
bool findCutFirst(std::string &str1, std::string str2);
+std::string &removeProtocol(std::string &url);
+
#endif // UTILS_STRINGUTILS_H