summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorChuck Miller <shadowmil@gmail.com>2009-12-19 04:40:42 -0500
committerChuck Miller <shadowmil@gmail.com>2009-12-19 05:08:56 -0500
commitcbc14c8a3c6614987d2331057e114d92336cbac0 (patch)
treea3693bd6ac6aca39a34a2d9a9f644873d63ecf32 /src/gui
parent117cc13e863b788bfc8adef9468dba54c4909b9b (diff)
downloadmana-client-cbc14c8a3c6614987d2331057e114d92336cbac0.tar.gz
mana-client-cbc14c8a3c6614987d2331057e114d92336cbac0.tar.bz2
mana-client-cbc14c8a3c6614987d2331057e114d92336cbac0.tar.xz
mana-client-cbc14c8a3c6614987d2331057e114d92336cbac0.zip
Added support for resources.xml from update server... Also added option to download music optionally
I had to edit the XML wrapper a bit, basicilly its constructor can now take a optional thrid arguement which will tell it to use a resman or open the file directly Also I added fallback support for the old resouce2.txt so servers don't have to upgrade if they do not want to
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/setup_audio.cpp14
-rw-r--r--src/gui/setup_audio.h4
-rw-r--r--src/gui/updatewindow.cpp137
-rw-r--r--src/gui/updatewindow.h20
4 files changed, 151 insertions, 24 deletions
diff --git a/src/gui/setup_audio.cpp b/src/gui/setup_audio.cpp
index 990a3ce8..5b1a86b9 100644
--- a/src/gui/setup_audio.cpp
+++ b/src/gui/setup_audio.cpp
@@ -38,7 +38,9 @@ Setup_Audio::Setup_Audio():
mMusicVolume((int)config.getValue("musicVolume", 60)),
mSfxVolume((int)config.getValue("sfxVolume", 100)),
mSoundEnabled(config.getValue("sound", 0)),
+ mDownloadEnabled(config.getValue("download-music", false)),
mSoundCheckBox(new CheckBox(_("Sound"), mSoundEnabled)),
+ mDownloadMusicCheckBox(new CheckBox(_("Download music"), mDownloadEnabled)),
mSfxSlider(new Slider(0, sound.getMaxVolume())),
mMusicSlider(new Slider(0, sound.getMaxVolume()))
{
@@ -71,6 +73,7 @@ Setup_Audio::Setup_Audio():
place(1, 1, sfxLabel);
place(0, 2, mMusicSlider);
place(1, 2, musicLabel);
+ place(0, 3, mDownloadMusicCheckBox);
setDimension(gcn::Rectangle(0, 0, 365, 280));
}
@@ -78,11 +81,20 @@ Setup_Audio::Setup_Audio():
void Setup_Audio::apply()
{
mSoundEnabled = mSoundCheckBox->isSelected();
+ mDownloadEnabled = mDownloadMusicCheckBox->isSelected();
mSfxVolume = (int) config.getValue("sfxVolume", 100);
mMusicVolume = (int) config.getValue("musicVolume", 60);
config.setValue("sound", mSoundEnabled);
+ // Display a message if user has selected to download music,
+ // And if downloadmusic is not already enabled
+ if (mDownloadEnabled && !config.getValue("download-music", false))
+ {
+ new OkDialog(_("Notice"),_("You may have to restart your client if you want to download new music"));
+ }
+ config.setValue("download-music", mDownloadEnabled);
+
if (mSoundEnabled)
{
try
@@ -104,6 +116,7 @@ void Setup_Audio::apply()
void Setup_Audio::cancel()
{
mSoundCheckBox->setSelected(mSoundEnabled);
+ mDownloadMusicCheckBox->setSelected(mDownloadEnabled);
sound.setSfxVolume(mSfxVolume);
mSfxSlider->setValue(mSfxVolume);
@@ -112,6 +125,7 @@ void Setup_Audio::cancel()
mMusicSlider->setValue(mMusicVolume);
config.setValue("sound", mSoundEnabled);
+ config.setValue("download-music", mDownloadEnabled);
config.setValue("sfxVolume", mSfxVolume);
config.setValue("musicVolume", mMusicVolume);
}
diff --git a/src/gui/setup_audio.h b/src/gui/setup_audio.h
index b398a880..6cb3e1f3 100644
--- a/src/gui/setup_audio.h
+++ b/src/gui/setup_audio.h
@@ -40,9 +40,9 @@ class Setup_Audio : public SetupTab, public gcn::ActionListener
private:
int mMusicVolume, mSfxVolume;
- bool mSoundEnabled;
+ bool mSoundEnabled, mDownloadEnabled;
- gcn::CheckBox *mSoundCheckBox;
+ gcn::CheckBox *mSoundCheckBox, *mDownloadMusicCheckBox;
gcn::Slider *mSfxSlider, *mMusicSlider;
};
diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp
index afb87430..600c0bfd 100644
--- a/src/gui/updatewindow.cpp
+++ b/src/gui/updatewindow.cpp
@@ -40,30 +40,83 @@
#include "utils/gettext.h"
#include "utils/stringutils.h"
+#include "utils/xml.h"
#include <iostream>
+#include <fstream>
/**
- * Load the given file into a vector of strings.
+ * Load the given file into a vector of updateFiles.
*/
-std::vector<std::string> loadTextFile(const std::string &fileName)
+std::vector<updateFile> loadXMLFile(const std::string &fileName)
{
- std::vector<std::string> lines;
- std::ifstream fin(fileName.c_str());
+ std::vector<updateFile> files;
+ XML::Document doc(fileName, false);
+ xmlNodePtr rootNode = doc.rootNode();
- if (!fin) {
- logger->log("Couldn't load text file: %s", fileName.c_str());
- return lines;
+ if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "updates"))
+ {
+ logger->log("Error loading update file: %s", fileName.c_str());
+ return files;
}
- std::string line;
-
- while (getline(fin, line))
- lines.push_back(line);
+ for_each_xml_child_node(fileNode, rootNode)
+ {
+ // Ignore all tags except for the "update" tags
+ if (!xmlStrEqual(fileNode->name, BAD_CAST "update"))
+ continue;
+
+ updateFile file;
+ file.name = XML::getProperty(fileNode, "file", "");
+ file.hash = XML::getProperty(fileNode, "hash", "");
+ file.type = XML::getProperty(fileNode, "type", "data");
+ file.desc = XML::getProperty(fileNode, "description", "");
+ if (XML::getProperty(fileNode, "required", "yes") == "yes")
+ {
+ file.required = true;
+ }
+ else
+ {
+ file.required = false;
+ }
+ files.push_back(file);
+ }
- return lines;
+ return files;
}
+std::vector<updateFile> loadTxtFile(const std::string &fileName)
+{
+ std::vector<updateFile> files;
+ std::ifstream fileHandler;
+ fileHandler.open(fileName.c_str(), std::ios::in);
+
+ if (fileHandler.is_open())
+ {
+ while (fileHandler.good())
+ {
+ char name[256], hash[50];
+ fileHandler.getline(name, 256, ' ');
+ fileHandler.getline(hash, 50);
+
+ updateFile thisFile;
+ thisFile.name = name;
+ thisFile.hash = hash;
+ thisFile.type = "data";
+ thisFile.required = true;
+ thisFile.desc = "";
+
+ files.push_back(thisFile);
+ }
+ }
+ else
+ {
+ logger->log("Error loading update file: %s", fileName.c_str());
+ }
+ fileHandler.close();
+
+ return files;
+}
UpdaterWindow::UpdaterWindow(const std::string &updateHost,
const std::string &updatesDir):
@@ -80,7 +133,7 @@ UpdaterWindow::UpdaterWindow(const std::string &updateHost,
mDownloadedBytes(0),
mMemoryBuffer(NULL),
mDownload(NULL),
- mLineIndex(0)
+ mUpdateIndex(0)
{
mBrowserBox = new BrowserBox;
mScrollArea = new ScrollArea(mBrowserBox);
@@ -119,6 +172,7 @@ UpdaterWindow::UpdaterWindow(const std::string &updateHost,
UpdaterWindow::~UpdaterWindow()
{
+ loadUpdates();
if (mDownload)
{
mDownload->cancel();
@@ -300,8 +354,21 @@ void UpdaterWindow::download()
mDownload->start();
}
+void UpdaterWindow::loadUpdates()
+{
+ ResourceManager *resman = ResourceManager::getInstance();
+
+ for (mUpdateIndex = 0; mUpdateIndex < mUpdateFiles.size(); mUpdateIndex++)
+ {
+ resman->addToSearchPath(mUpdatesDir + "/" + mUpdateFiles[mUpdateIndex].name, false);
+ }
+}
+
void UpdaterWindow::logic()
{
+ const std::string xmlUpdateFile = "resources.xml";
+ const std::string txtUpdateFile = "resources2.txt";
+
// Update Scroll logic
mScrollArea->logic();
@@ -342,7 +409,7 @@ void UpdaterWindow::logic()
// Parse current memory buffer as news and dispose of the data
loadNews();
- mCurrentFile = "resources2.txt";
+ mCurrentFile = xmlUpdateFile;
mStoreInMemory = false;
mDownloadStatus = UPDATE_LIST;
download(); // download() changes mDownloadComplete to false
@@ -351,7 +418,25 @@ void UpdaterWindow::logic()
case UPDATE_LIST:
if (mDownloadComplete)
{
- mLines = loadTextFile(mUpdatesDir + "/resources2.txt");
+ if (mCurrentFile == xmlUpdateFile)
+ {
+ mUpdateFiles = loadXMLFile(mUpdatesDir + "/" + xmlUpdateFile);
+ if (mUpdateFiles.size() == 0)
+ {
+ logger->log("Warning this server does not have a %s file falling back to %s",xmlUpdateFile.c_str(),txtUpdateFile.c_str());
+
+ // If the resources.xml file fails, fall back onto a older version
+ mCurrentFile = txtUpdateFile;
+ mStoreInMemory = false;
+ mDownloadStatus = UPDATE_LIST;
+ download();
+ break;
+ }
+ }
+ else if (mCurrentFile == txtUpdateFile)
+ {
+ mUpdateFiles = loadTxtFile(mUpdatesDir + "/" + txtUpdateFile);
+ }
mStoreInMemory = false;
mDownloadStatus = UPDATE_RESOURCES;
}
@@ -359,12 +444,23 @@ void UpdaterWindow::logic()
case UPDATE_RESOURCES:
if (mDownloadComplete)
{
- if (mLineIndex < mLines.size())
+ if (mUpdateIndex < mUpdateFiles.size())
{
- std::stringstream line(mLines[mLineIndex]);
- line >> mCurrentFile;
+ updateFile thisFile = mUpdateFiles[mUpdateIndex];
+ if (!thisFile.required)
+ {
+ // This statement checks to see if the file type is music, and if download-music is true
+ // If it fails, this statement returns true, and results in not downloading the file
+ // Else it will ignore the break, and download the file.
+ if ( !(thisFile.type == "music" && config.getValue("download-music", false)) )
+ {
+ mUpdateIndex++;
+ break;
+ }
+ }
+ mCurrentFile = thisFile.name;
std::string checksum;
- line >> checksum;
+ checksum = thisFile.hash;
std::stringstream ss(checksum);
ss >> std::hex >> mCurrentChecksum;
@@ -378,9 +474,10 @@ void UpdaterWindow::logic()
}
else
{
+ temp.close();
logger->log("%s already here", mCurrentFile.c_str());
}
- mLineIndex++;
+ mUpdateIndex++;
}
else
{
diff --git a/src/gui/updatewindow.h b/src/gui/updatewindow.h
index 8388b722..55415938 100644
--- a/src/gui/updatewindow.h
+++ b/src/gui/updatewindow.h
@@ -39,6 +39,16 @@ class Button;
class ProgressBar;
class ScrollArea;
+struct updateFile
+{
+ public:
+ std::string name;
+ std::string hash;
+ std::string type;
+ bool required;
+ std::string desc;
+};
+
/**
* Update progress window GUI
*
@@ -96,6 +106,12 @@ private:
void download();
/**
+ * Loads the updates this window has gotten into the resource manager
+ */
+ void loadUpdates();
+
+
+ /**
* A download callback for progress updates.
*/
static int updateProgress(void *ptr, DownloadStatus status,
@@ -160,10 +176,10 @@ private:
Net::Download *mDownload;
/** List of files to download. */
- std::vector<std::string> mLines;
+ std::vector<updateFile> mUpdateFiles;
/** Index of the file to be downloaded. */
- unsigned int mLineIndex;
+ unsigned int mUpdateIndex;
gcn::Label *mLabel; /**< Progress bar caption. */
Button *mCancelButton; /**< Button to stop the update process. */