From 33587089cf7d87bbc2104e80746fdddc7a5498e1 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Thu, 23 Jun 2005 17:43:47 +0000 Subject: Help files are now loaded through the resource manager. --- src/gui/help.cpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'src/gui/help.cpp') diff --git a/src/gui/help.cpp b/src/gui/help.cpp index a842d42e..5a5f42cc 100644 --- a/src/gui/help.cpp +++ b/src/gui/help.cpp @@ -26,7 +26,7 @@ #include "button.h" #include "textbox.h" #include "../main.h" -#include +#include "../resources/resourcemanager.h" HelpWindow::HelpWindow(): Window("Help") @@ -86,23 +86,28 @@ void HelpWindow::loadHelp(const std::string &helpFile) void HelpWindow::loadFile(const std::string &file) { - std::string filePath = TMW_DATADIR "data/help/" + file + ".txt"; + ResourceManager *resman = ResourceManager::getInstance(); + const std::string filePath = "help/" + file + ".txt"; + int contentsLength; + char *fileContents = (char*)resman->loadFile(filePath, contentsLength); - std::ifstream fin; - fin.open(filePath.c_str()); - - if (fin.fail()) + if (!fileContents) { logger->log("Couldn't load help file: %s", filePath.c_str()); return; } - while (!fin.eof()) + // 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) { - std::string line = ""; - getline(fin, line); browserBox->addRow(line); + line = strtok(NULL, "\n"); } - fin.close(); + free(fileContents); } -- cgit v1.2.3-70-g09d2