summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2006-07-18 15:52:42 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2006-07-18 15:52:42 +0000
commit151abcad30a0e1582b91b58b4a42343f5686979c (patch)
tree74327dc22f72763716e293f803fe2849ae397847 /src
parentd6f4f362895b1b0aa3681a8255c7f996457d79cd (diff)
downloadmana-client-151abcad30a0e1582b91b58b4a42343f5686979c.tar.gz
mana-client-151abcad30a0e1582b91b58b4a42343f5686979c.tar.bz2
mana-client-151abcad30a0e1582b91b58b4a42343f5686979c.tar.xz
mana-client-151abcad30a0e1582b91b58b4a42343f5686979c.zip
Updated the updating system. It will now only load those updates
specified in the downloaded resources.txt file, and in the order in which they are mentioned (the top one being the most significant).
Diffstat (limited to 'src')
-rw-r--r--src/gui/updatewindow.cpp55
-rw-r--r--src/gui/updatewindow.h3
-rw-r--r--src/main.cpp32
-rw-r--r--src/resources/resourcemanager.cpp33
-rw-r--r--src/resources/resourcemanager.h12
5 files changed, 52 insertions, 83 deletions
diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp
index 4f43d1fc..8f43903f 100644
--- a/src/gui/updatewindow.cpp
+++ b/src/gui/updatewindow.cpp
@@ -42,6 +42,8 @@
#include "../utils/tostring.h"
+#include "../resources/resourcemanager.h"
+
UpdaterWindow::UpdaterWindow():
Window("Updating..."),
mThread(NULL), mMutex(NULL), mDownloadStatus(UPDATE_NEWS),
@@ -99,10 +101,13 @@ UpdaterWindow::~UpdaterWindow()
mThread = NULL;
}
- free(mMemoryBuffer);
+ if (mMemoryBuffer)
+ {
+ free(mMemoryBuffer);
+ }
+
// Remove downloaded files
remove((mBasePath + "/updates/news.txt").c_str());
- remove((mBasePath + "/updates/resources.txt").c_str());
remove((mBasePath + "/updates/download.temp").c_str());
delete[] mCurlError;
@@ -147,30 +152,29 @@ void UpdaterWindow::action(const std::string& eventId)
void UpdaterWindow::loadNews()
{
- int contentsLength = mDownloadedBytes;
- char *fileContents = mMemoryBuffer;
-
- if (!fileContents)
+ if (!mMemoryBuffer)
{
logger->log("Couldn't load news");
return;
}
// Reallocate and include terminating 0 character
- fileContents = (char*)realloc(fileContents, contentsLength + 1);
- fileContents[contentsLength] = '\0';
+ mMemoryBuffer = (char*)realloc(mMemoryBuffer, mDownloadedBytes + 1);
+ mMemoryBuffer[mDownloadedBytes] = '\0';
mBrowserBox->clearRows();
// Tokenize and add each line separately
- char *line = strtok(fileContents, "\n");
+ char *line = strtok(mMemoryBuffer, "\n");
while (line != NULL)
{
mBrowserBox->addRow(line);
line = strtok(NULL, "\n");
}
- //free(fileContents);
+ // Free the memory buffer now that we don't need it anymore
+ free(mMemoryBuffer);
+ mMemoryBuffer = NULL;
mScrollArea->setVerticalScrollAmount(0);
setVisible(true);
@@ -335,16 +339,11 @@ void UpdaterWindow::logic()
case UPDATE_NEWS:
if (mDownloadComplete)
{
- // Try to open news.txt
+ // Parse current memory buffer as news and dispose of the data
loadNews();
- // Doesn't matter if it couldn't find news.txt,
- // go to the next step
+
mCurrentFile = "resources.txt";
- if (mMemoryBuffer != NULL)
- {
- free(mMemoryBuffer);
- mMemoryBuffer = NULL;
- }
+ mStoreInMemory = false;
download();
mDownloadStatus = UPDATE_LIST;
}
@@ -352,22 +351,10 @@ void UpdaterWindow::logic()
case UPDATE_LIST:
if (mDownloadComplete)
{
- if (mMemoryBuffer != NULL)
- {
- // Tokenize and add each line separately
- char *line = strtok(mMemoryBuffer, "\n");
- while (line != NULL)
- {
- mFiles.push_back(line);
- line = strtok(NULL, "\n");
- }
- mStoreInMemory = false;
- mDownloadStatus = UPDATE_RESOURCES;
- }
- else {
- logger->log("Unable to download resources.txt");
- mDownloadStatus = UPDATE_ERROR;
- }
+ ResourceManager *resman = ResourceManager::getInstance();
+ mFiles = resman->loadTextFile("updates/resources.txt");
+ mStoreInMemory = false;
+ mDownloadStatus = UPDATE_RESOURCES;
}
break;
case UPDATE_RESOURCES:
diff --git a/src/gui/updatewindow.h b/src/gui/updatewindow.h
index ad554375..5f049e18 100644
--- a/src/gui/updatewindow.h
+++ b/src/gui/updatewindow.h
@@ -74,7 +74,8 @@ class UpdaterWindow : public Window, public gcn::ActionListener
void enable();
/**
- * Loads and display news
+ * Loads and display news. Assumes the news file contents have been loaded
+ * into the memory buffer.
*/
void loadNews();
diff --git a/src/main.cpp b/src/main.cpp
index 20a1771c..a4ef390e 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -163,10 +163,6 @@ void init_engine()
// Add the main data directory to our PhysicsFS search path
resman->addToSearchPath("data", true);
resman->addToSearchPath(TMW_DATADIR "data", true);
- // Add zip files to PhysicsFS
- resman->searchAndAddArchives("/", ".zip", true);
- // Updates, these override other files
- resman->searchAndAddArchives("/updates", ".zip", false);
// Fill configuration with defaults
config.setValue("host", "animesites.de");
@@ -391,6 +387,22 @@ void parseOptions(int argc, char *argv[], Options &options)
}
}
+/**
+ * Reads the file "updates/resources.txt" and attempts to load each update
+ * mentioned in it.
+ */
+void loadUpdates()
+{
+ const std::string updatesFile = "updates/resources.txt";
+ ResourceManager *resman = ResourceManager::getInstance();
+ std::vector<std::string> lines = resman->loadTextFile(updatesFile);
+
+ for (unsigned int i = 0; i < lines.size(); ++i)
+ {
+ resman->addToSearchPath(lines[i], false);
+ }
+}
+
CharServerHandler charServerHandler;
LoginData loginData;
LoginHandler loginHandler;
@@ -503,14 +515,17 @@ int main(int argc, char *argv[])
SDL_Event event;
- if (options.skipUpdate && state != ERROR_STATE)
- {
+ if (options.skipUpdate && state != ERROR_STATE) {
+ loadUpdates();
state = LOGIN_STATE;
}
+ else {
+ state = UPDATE_STATE;
+ }
unsigned int oldstate = !state; // We start with a status change.
- Window *currentDialog = NULL;
+ Window *currentDialog = NULL;
Image *login_wallpaper = NULL;
Game *game = NULL;
@@ -581,8 +596,7 @@ int main(int argc, char *argv[])
switch (oldstate)
{
case UPDATE_STATE:
- ResourceManager::getInstance()->
- searchAndAddArchives("/updates", ".zip", 0);
+ loadUpdates();
break;
// Those states don't cause a network disconnect
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index 1cdf5a65..a6dc692b 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -72,37 +72,10 @@ ResourceManager::setWriteDir(const std::string &path)
void
ResourceManager::addToSearchPath(const std::string &path, bool append)
{
+ logger->log("Adding to PhysicsFS: %s", path.c_str());
PHYSFS_addToSearchPath(path.c_str(), append ? 1 : 0);
}
-void
-ResourceManager::searchAndAddArchives(const std::string &path,
- const std::string &ext,
- bool append)
-{
- const char *dirSep = PHYSFS_getDirSeparator();
- char **list = PHYSFS_enumerateFiles(path.c_str());
-
- for (char **i = list; *i != NULL; i++)
- {
- size_t len = strlen(*i);
-
- if (len > ext.length() && !ext.compare((*i)+(len - ext.length())))
- {
- std::string file, realPath, archive;
-
- file = path + "/" + (*i);
- realPath = std::string(PHYSFS_getRealDir(file.c_str()));
- archive = realPath + path + dirSep + (*i);
-
- logger->log("Adding to PhysicsFS: %s", archive.c_str());
- addToSearchPath(archive, append);
- }
- }
-
- PHYSFS_freeList(list);
-}
-
bool
ResourceManager::mkdir(const std::string &path)
{
@@ -289,9 +262,9 @@ ResourceManager::loadTextFile(const std::string &fileName)
}
std::istringstream iss(std::string(fileContents, contentsLength));
-
std::string line;
- while(getline(iss, line, '\n')) {
+
+ while (getline(iss, line, '\n')) {
lines.push_back(line);
}
diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h
index 37fbe213..8d60ae8c 100644
--- a/src/resources/resourcemanager.h
+++ b/src/resources/resourcemanager.h
@@ -73,20 +73,14 @@ class ResourceManager
setWriteDir(const std::string &path);
/**
- * Adds a directory or archive to the search path.
+ * Adds a directory or archive to the search path. If append is true
+ * then the directory is added to the end of the search path, otherwise
+ * it is added at the front.
*/
void
addToSearchPath(const std::string &path, bool append);
/**
- * Searches for zip files and adds them to the search path.
- */
- void
- searchAndAddArchives(const std::string &path,
- const std::string &ext,
- bool append);
-
- /**
* Creates a directory in the write path
*/
bool