From 222db257d7de12f1077eb43d448d6b357d4642e7 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Tue, 4 Nov 2008 21:50:17 +0000 Subject: Merged revisions 4332 via svnmerge from https://themanaworld.svn.sourceforge.net/svnroot/themanaworld/tmw/branches/0.0 ........ r4332 | b_lindeijer | 2008-06-05 09:33:12 +0200 (Thu, 05 Jun 2008) | 5 lines Added command line argument to specify the update host (-H). Also, to avoid problems when files with the same name are served by different update hosts, the updates are now stored in an update host specific directory. Based on a patch by Sanga. ........ --- src/gui/updatewindow.cpp | 52 +++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 18 deletions(-) (limited to 'src/gui/updatewindow.cpp') diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index 10d0c826..22bf8c13 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -46,8 +46,6 @@ #include "../resources/resourcemanager.h" -extern std::string homeDir; - /** * Calculates the Alder-32 checksum for the given file. */ @@ -68,14 +66,38 @@ unsigned long fadler32(FILE *file) return adler; } -UpdaterWindow::UpdaterWindow(): +/** + * Load the given file into a vector of strings. + */ +std::vector +loadTextFile(const std::string &fileName) +{ + std::vector lines; + std::ifstream fin(fileName.c_str()); + + if (!fin) { + logger->log("Couldn't load text file: %s", fileName.c_str()); + return lines; + } + + std::string line; + + while (getline(fin, line)) + lines.push_back(line); + + return lines; +} + + +UpdaterWindow::UpdaterWindow(const std::string &updateHost, + const std::string &updatesDir): Window("Updating..."), mThread(NULL), mDownloadStatus(UPDATE_NEWS), - mUpdateHost(""), + mUpdateHost(updateHost), + mUpdatesDir(updatesDir), mCurrentFile("news.txt"), mCurrentChecksum(0), - mBasePath(""), mStoreInMemory(true), mDownloadComplete(true), mUserCancel(false), @@ -119,10 +141,6 @@ UpdaterWindow::UpdaterWindow(): setVisible(true); mCancelButton->requestFocus(); - mUpdateHost = - config.getValue("updatehost", "http://updates.themanaworld.org"); - mBasePath = homeDir; - // Try to download the updates list download(); } @@ -141,7 +159,7 @@ UpdaterWindow::~UpdaterWindow() } // Remove possibly leftover temporary download - ::remove((mBasePath + "/updates/download.temp").c_str()); + ::remove((mUpdatesDir + "/download.temp").c_str()); delete[] mCurlError; } @@ -280,9 +298,7 @@ int UpdaterWindow::downloadThread(void *ptr) } else { - // Download in the proper folder : ./updates under win, - // /home/user/.tmw/updates for unices - outFilename = uw->mBasePath + "/updates/download.temp"; + outFilename = uw->mUpdatesDir + "/download.temp"; outfile = fopen(outFilename.c_str(), "w+b"); curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile); } @@ -349,8 +365,8 @@ int UpdaterWindow::downloadThread(void *ptr) fclose(outfile); // Give the file the proper name - std::string newName(uw->mBasePath + "/updates/" + - uw->mCurrentFile.c_str()); + const std::string newName = + uw->mUpdatesDir + "/" + uw->mCurrentFile; // Any existing file with this name is deleted first, otherwise // the rename will fail on Windows. @@ -438,8 +454,7 @@ void UpdaterWindow::logic() case UPDATE_LIST: if (mDownloadComplete) { - ResourceManager *resman = ResourceManager::getInstance(); - mLines = resman->loadTextFile("updates/resources2.txt"); + mLines = loadTextFile(mUpdatesDir + "/resources2.txt"); mStoreInMemory = false; mDownloadStatus = UPDATE_RESOURCES; } @@ -463,7 +478,8 @@ void UpdaterWindow::logic() ss >> std::hex >> mCurrentChecksum; std::ifstream temp( - (mBasePath + "/updates/" + mCurrentFile).c_str()); + (mUpdatesDir + "/" + mCurrentFile).c_str()); + if (!temp.is_open()) { temp.close(); -- cgit v1.2.3-70-g09d2