From 9cea91975451a7abb6f15e08f7fb6c20efed152c Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Fri, 15 Jul 2005 23:43:22 +0000 Subject: Fixed compiler warnings and added plain text file loading to resource manager. --- src/gui/help.cpp | 24 ++++-------------------- src/gui/updatewindow.cpp | 21 ++++++--------------- 2 files changed, 10 insertions(+), 35 deletions(-) (limited to 'src/gui') diff --git a/src/gui/help.cpp b/src/gui/help.cpp index cff36da8..3ff8f0f4 100644 --- a/src/gui/help.cpp +++ b/src/gui/help.cpp @@ -87,27 +87,11 @@ void HelpWindow::loadHelp(const std::string &helpFile) void HelpWindow::loadFile(const std::string &file) { ResourceManager *resman = ResourceManager::getInstance(); - const std::string filePath = "help/" + file + ".txt"; - int contentsLength; - char *fileContents = (char*)resman->loadFile(filePath, contentsLength); + std::vector lines = + resman->loadTextFile("help/" + file + ".txt"); - if (!fileContents) + for (unsigned int i = 0; i < lines.size(); ++i) { - logger->log("Couldn't load help file: %s", filePath.c_str()); - return; + browserBox->addRow(lines[i]); } - - // Reallocate and include terminating 0 character - fileContents = (char*)realloc(fileContents, contentsLength + 1); - fileContents[contentsLength] = '\0'; - - // Tokenize and add each line separately - char *line = strtok(fileContents, "\n"); - while (line != NULL) - { - browserBox->addRow(line); - line = strtok(NULL, "\n"); - } - - free(fileContents); } diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index 75f94b4b..473cc171 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -127,25 +127,16 @@ void UpdaterWindow::action(const std::string& eventId) void UpdaterWindow::loadNews() { - browserBox->clearRows(); ResourceManager *resman = ResourceManager::getInstance(); - int contentsLength; - std::ifstream newsFile(TMW_DATADIR "data/news.txt"); - if (!newsFile.is_open()) - { - logger->log("Couldn't load news.txt"); - browserBox->addRow("Error"); - return; - } + std::vector lines = resman->loadTextFile("news.txt"); - // Tokenize and add each line separately - std::string line(""); - while (!newsFile.eof()) + browserBox->clearRows(); + + for (unsigned int i = 0; i < lines.size(); ++i) { - getline(newsFile, line); - browserBox->addRow(line); + browserBox->addRow(lines[i]); } - newsFile.close(); + scrollArea->setVerticalScrollAmount(0); setVisible(true); } -- cgit v1.2.3-70-g09d2