summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog24
-rw-r--r--src/gui/updatewindow.cpp92
-rw-r--r--src/gui/updatewindow.h7
3 files changed, 70 insertions, 53 deletions
diff --git a/ChangeLog b/ChangeLog
index 7564a5e6..cd6f2370 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,15 +1,21 @@
-2007-02-01 Philipp Sehmisch <tmw@crushnet.org>
+2007-02-01 Bjørn Lindeijer <bjorn@lindeijer.nl>
+
+ * src/gui/updatewindow.cpp, src/gui/updatewindow.h: A bit of cleanup
+ and defined a helper function for calculating the alder32 checksum of
+ a file. Probably not fixing any bug though.
+
+2007-02-01 Philipp Sehmisch <tmw@crushnet.org>
* data/equipment.xml, data/items.xml,
data/graphics/items/armor-chest-chainmail.png,
- data/graphics/sprites/chest-chainmail-female.png
- data/graphics/sprites/chest-chainmail-female.xml
- data/graphics/sprites/chest-chainmail-male.png
- data/graphics/sprites/chest-chainmail-male.xml: Added chainmail by "The
- Judge". The proposed values are: Item ID: 625, Sprite ID: 25, Defence: 12,
- Weight: 120.
- * data/graphics/sprites/chest-cotton-female.png: Huh? Shouldn't this be on
- svn for ages?
+ data/graphics/sprites/chest-chainmail-female.png,
+ data/graphics/sprites/chest-chainmail-female.xml,
+ data/graphics/sprites/chest-chainmail-male.png,
+ data/graphics/sprites/chest-chainmail-male.xml: Added chainmail by
+ "The Judge". The proposed values are: Item ID: 625, Sprite ID: 25,
+ Defence: 12, Weight: 120.
+ * data/graphics/sprites/chest-cotton-female.png: Huh? Shouldn't this
+ be on svn for ages?
2007-01-30 Eugenio Favalli <elvenprogrammer@gmail.com>
diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp
index 590f756a..670baf29 100644
--- a/src/gui/updatewindow.cpp
+++ b/src/gui/updatewindow.cpp
@@ -46,13 +46,41 @@
#include "../resources/resourcemanager.h"
+/**
+ * Calculates the Alder-32 checksum for the given file.
+ */
+unsigned long fadler32(FILE *file)
+{
+ // Obtain file size
+ fseek(file, 0, SEEK_END);
+ long fileSize = ftell(file);
+ rewind(file);
+
+ // Calculate Adler-32 checksum
+ char *buffer = (char*) malloc(fileSize);
+ fread(buffer, 1, fileSize, file);
+ unsigned long adler = adler32(0L, Z_NULL, 0);
+ adler = adler32(adler, (Bytef*) buffer, fileSize);
+ free(buffer);
+
+ return adler;
+}
+
UpdaterWindow::UpdaterWindow():
Window("Updating..."),
- mThread(NULL), mMutex(NULL), mDownloadStatus(UPDATE_NEWS),
- mUpdateHost(""), mCurrentFile("news.txt"), mBasePath(""),
- mStoreInMemory(true), mDownloadComplete(true), mUserCancel(false),
- mDownloadedBytes(0), mMemoryBuffer(NULL),
- mCurlError(new char[CURL_ERROR_SIZE]), mLineIndex(0)
+ mThread(NULL),
+ mDownloadStatus(UPDATE_NEWS),
+ mUpdateHost(""),
+ mCurrentFile("news.txt"),
+ mCurrentChecksum(0),
+ mBasePath(""),
+ mStoreInMemory(true),
+ mDownloadComplete(true),
+ mUserCancel(false),
+ mDownloadedBytes(0),
+ mMemoryBuffer(NULL),
+ mCurlError(new char[CURL_ERROR_SIZE]),
+ mLineIndex(0)
{
mCurlError[0] = 0;
@@ -212,22 +240,17 @@ int UpdaterWindow::updateProgress(void *ptr,
return 0;
}
-size_t UpdaterWindow::memoryWrite(void *ptr,
- size_t size, size_t nmemb, FILE *stream)
+size_t
+UpdaterWindow::memoryWrite(void *ptr, size_t size, size_t nmemb, FILE *stream)
{
UpdaterWindow *uw = reinterpret_cast<UpdaterWindow *>(stream);
size_t totalMem = size * nmemb;
- uw->mMemoryBuffer = (char*)realloc(uw->mMemoryBuffer,
- uw->mDownloadedBytes + totalMem + 1);
+ uw->mMemoryBuffer = (char*) realloc(uw->mMemoryBuffer,
+ uw->mDownloadedBytes + totalMem);
if (uw->mMemoryBuffer)
{
memcpy(&(uw->mMemoryBuffer[uw->mDownloadedBytes]), ptr, totalMem);
uw->mDownloadedBytes += totalMem;
-
- // Make sure the memory buffer is NULL terminated, because this
- // function is used to download text files that are later parsed as a
- // string.
- uw->mMemoryBuffer[uw->mDownloadedBytes] = 0;
}
return totalMem;
@@ -242,7 +265,8 @@ int UpdaterWindow::downloadThread(void *ptr)
std::string outFilename;
std::string url(uw->mUpdateHost + "/" + uw->mCurrentFile);
- while (attempts < 3 && !uw->mDownloadComplete) {
+ while (attempts < 3 && !uw->mDownloadComplete)
+ {
FILE *outfile = NULL;
uw->setLabel(uw->mCurrentFile + " (0%)");
@@ -288,14 +312,17 @@ int UpdaterWindow::downloadThread(void *ptr)
uw->mDownloadStatus = UPDATE_ERROR;
switch (res)
{
- case CURLE_COULDNT_CONNECT: // give more debug info on that error
- std::cerr << "curl error " << res << " : " << uw->mCurlError << " " << url.c_str()
- << std::endl;
+ case CURLE_COULDNT_CONNECT:
+ // give more debug info on that error
+ std::cerr << "curl error " << res << ": "
+ << uw->mCurlError << " " << url.c_str()
+ << std::endl;
break;
default:
- std::cerr << "curl error " << res << " : " << uw->mCurlError << " host: " << url.c_str()
- << std::endl;
+ std::cerr << "curl error " << res << ": "
+ << uw->mCurlError << " host: " << url.c_str()
+ << std::endl;
}
}
@@ -305,34 +332,22 @@ int UpdaterWindow::downloadThread(void *ptr)
if (!uw->mStoreInMemory)
{
- long fileSize;
- char *buffer;
- // Obtain file size.
- fseek(outfile, 0, SEEK_END);
- fileSize = ftell(outfile);
- rewind(outfile);
- buffer = (char*)malloc(fileSize);
- fread(buffer, 1, fileSize, outfile);
- fclose(outfile);
-
// Give the file the proper name
std::string newName(uw->mBasePath + "/updates/" +
uw->mCurrentFile.c_str());
- // Any existing file with this name is deleted first, otherwise the
- // rename will fail on Windows.
+ // Any existing file with this name is deleted first, otherwise
+ // the rename will fail on Windows.
::remove(newName.c_str());
::rename(outFilename.c_str(), newName.c_str());
// Don't check resources2.txt checksum
if (uw->mDownloadStatus == UPDATE_RESOURCES)
{
- // Calculate Adler-32 checksum
- unsigned long adler = adler32(0L, Z_NULL, 0);
- adler = adler32(adler, (Bytef *)buffer, fileSize);
- free(buffer);
+ unsigned long adler = fadler32(outfile);
- if (uw->mCurrentChecksum != adler) {
+ if (uw->mCurrentChecksum != adler)
+ {
uw->mDownloadComplete = false;
// Remove the corrupted file
::remove(newName.c_str());
@@ -343,6 +358,7 @@ int UpdaterWindow::downloadThread(void *ptr)
}
}
+ fclose(outfile);
}
}
attempts++;
@@ -403,8 +419,8 @@ void UpdaterWindow::logic()
mCurrentFile = "resources2.txt";
mStoreInMemory = false;
- download();
mDownloadStatus = UPDATE_LIST;
+ download();
}
break;
case UPDATE_LIST:
diff --git a/src/gui/updatewindow.h b/src/gui/updatewindow.h
index bbecf176..dcbb51b3 100644
--- a/src/gui/updatewindow.h
+++ b/src/gui/updatewindow.h
@@ -94,7 +94,7 @@ class UpdaterWindow : public Window, public gcn::ActionListener
void download();
/**
- * The tread function that download the files.
+ * The thread function that download the files.
*/
static int downloadThread(void *ptr);
@@ -126,11 +126,6 @@ class UpdaterWindow : public Window, public gcn::ActionListener
SDL_Thread *mThread;
/**
- * A mutex to protect shared data between the threads.
- */
- SDL_mutex *mMutex;
-
- /**
* Status of the current download.
*/
DownloadStatus mDownloadStatus;