diff options
author | Eugenio Favalli <elvenprogrammer@gmail.com> | 2005-07-14 14:07:05 +0000 |
---|---|---|
committer | Eugenio Favalli <elvenprogrammer@gmail.com> | 2005-07-14 14:07:05 +0000 |
commit | e177ae485723da3cefbe49dda066fc9ee5729ce0 (patch) | |
tree | df4fcf2b5e147ef462c9ee74b0110e5924458b20 /src/gui | |
parent | fa555b6077e7cc7ab28c2ec07be1f5fb8a89125c (diff) | |
download | mana-client-e177ae485723da3cefbe49dda066fc9ee5729ce0.tar.gz mana-client-e177ae485723da3cefbe49dda066fc9ee5729ce0.tar.bz2 mana-client-e177ae485723da3cefbe49dda066fc9ee5729ce0.tar.xz mana-client-e177ae485723da3cefbe49dda066fc9ee5729ce0.zip |
- Slimes mirrored frame fix
- Some fixes and improvements to the updater
(It can still show "chinese" text in the label, I guess because but files are
saved correctly)
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/updatewindow.cpp | 109 | ||||
-rw-r--r-- | src/gui/updatewindow.h | 7 |
2 files changed, 88 insertions, 28 deletions
diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index b9d3ea7e..c27fdf8b 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -22,6 +22,7 @@ */ #include "updatewindow.h" +#include "ok_dialog.h" #include "gui.h" #include "../main.h" #include "../log.h" @@ -35,6 +36,7 @@ UpdaterWindow *updaterWindow; SDL_Thread *thread; std::string updateHost = "themanaworld.org/files"; bool downloadComplete = true; +int downloadStatus = UPDATE_RUN; UpdaterWindow::UpdaterWindow() : Window("Updating...") @@ -99,11 +101,21 @@ void UpdaterWindow::draw(gcn::Graphics *graphics) void UpdaterWindow::action(const std::string& eventId) { if (eventId == "cancel") { - state = EXIT; + // Skip the updating process + if (downloadStatus == UPDATE_COMPLETE) + { + state = EXIT; + } + else { + downloadStatus = UPDATE_ERROR; + } } else if (eventId == "play") { state = LOGIN; } + else if (eventId == "ok") { + state = LOGIN; + } } int updateProgress(void *ptr, @@ -120,8 +132,9 @@ int updateProgress(void *ptr, updaterWindow->setLabel(labelString.c_str()); updaterWindow->setProgress(progress); - if (state != UPDATE) { + if (state != UPDATE && downloadStatus != UPDATE_ERROR) { // If the action was canceled return an error code to stop the thread + downloadStatus = UPDATE_ERROR; return -1; } @@ -137,6 +150,7 @@ int downloadThread(void *ptr) std::string url(updateHost); url += "/" + fileName; logger->log("Downloading: %s", url.c_str()); + logger->log(fileName.c_str()); curl = curl_easy_init(); if (curl) @@ -147,13 +161,16 @@ int downloadThread(void *ptr) curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile); curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0); curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, updateProgress); - curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, ptr); + curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, fileName.c_str()); res = curl_easy_perform(curl); fclose(outfile); curl_easy_cleanup(curl); downloadComplete = true; + if (res != 0) { + downloadStatus = UPDATE_ERROR; + } } return 0; @@ -166,11 +183,30 @@ int download(std::string url) if (thread == NULL) { logger->log("Unable to create thread"); + downloadStatus = UPDATE_ERROR; } return 0; } +void checkFile(std::ifstream &in) { + // Check for XML tag (if it is XML tag it is error) + // WARNING: this way we can't use an XML file for resources listing + if (!in.eof()) + { + std::string line; + getline(in, line); + if (line[0] == '<') { + logger->log("Error: resources.txt download error (404)"); + downloadStatus = UPDATE_ERROR; + } + else { + // Return the pointer to the beginning of the file + in.seekg (0, std::ios::beg); + } + } +} + void updateData() { updaterWindow = new UpdaterWindow(); @@ -203,32 +239,49 @@ void updateData() guiInput->pushInput(event); } - // If not alredy downloading another file - if (downloadComplete) { - // Try to open resources.txt - if (!in.is_open()) - { - in.open("resources.txt"); - if (!in.is_open()) - { - logger->error("Unable to open resources.txt"); - } - // TODO: check for error 404 - } - else { - if (!in.eof()) - { - // Download each update - std::string line; - getline(in, line); - download(line); - } - else { - // All updates downloaded - updaterWindow->enable(); - updaterWindow->setLabel("Completed"); + switch (downloadStatus) { + case UPDATE_ERROR: + new OkDialog( + "Error", ("The update process is incomplete. ", + "It is strongly recommended that you try again later"), + updaterWindow); + downloadStatus = UPDATE_IDLE; + break; + case UPDATE_RUN: + // If not alredy downloading another file + if (downloadComplete) { + // Try to open resources.txt + if (!in.is_open()) + { + in.open("resources.txt"); + if (!in.is_open()) + { + logger->log("Unable to open resources.txt"); + downloadStatus = UPDATE_ERROR; + } + else { + checkFile(in); + } + } + else { + if (!in.eof()) + { + // Download each update + std::string line; + getline(in, line); + download(line); + } + else { + // Download of updates completed + downloadStatus = UPDATE_COMPLETE; + updaterWindow->enable(); + updaterWindow->setLabel("Completed"); + } + } } - } + break; + case UPDATE_IDLE: + break; } gui->logic(); diff --git a/src/gui/updatewindow.h b/src/gui/updatewindow.h index 89e13610..e2d6201c 100644 --- a/src/gui/updatewindow.h +++ b/src/gui/updatewindow.h @@ -29,6 +29,13 @@ #include "progressbar.h" #include "button.h" +enum { + UPDATE_ERROR, + UPDATE_IDLE, + UPDATE_RUN, + UPDATE_COMPLETE +}; + /** * Update progress window GUI * |