ManaPlus
Functions | Variables
updaterwindow.cpp File Reference

(986a3bf)

#include "gui/windows/updaterwindow.h"
#include "client.h"
#include "configuration.h"
#include "main.h"
#include "settings.h"
#include "enums/gui/layouttype.h"
#include "fs/files.h"
#include "fs/mkdir.h"
#include "fs/paths.h"
#include "fs/virtfs/fs.h"
#include "gui/widgets/button.h"
#include "gui/widgets/containerplacer.h"
#include "gui/widgets/itemlinkhandler.h"
#include "gui/widgets/label.h"
#include "gui/widgets/layout.h"
#include "gui/widgets/progressbar.h"
#include "gui/widgets/scrollarea.h"
#include "gui/widgets/staticbrowserbox.h"
#include "net/download.h"
#include "net/updatetypeoperators.h"
#include "resources/db/moddb.h"
#include "utils/delete2.h"
#include "utils/foreach.h"
#include "utils/gettext.h"
#include <sys/stat.h>
#include <fstream>
#include <sstream>
#include "debug.h"

Go to the source code of this file.

Functions

const std::string xmlUpdateFile ("resources.xml")
 
const std::string txtUpdateFile ("resources2.txt")
 
const std::string updateServer2 ("http://download.manaplus.org/manaplus/updates/")
 
const std::string updateServer3 ("http://download2.manaplus.org/manaplus/updates/")
 
const std::string updateServer4 ("http://download.evolonline.org/manaplus/updates/")
 
const std::string updateServer5 ("http://download3.manaplus.org/manaplus/updates/")
 
static std::vector< UpdateFileloadXMLFile (const std::string &fileName, const bool loadMods)
 
static std::vector< UpdateFileloadTxtFile (const std::string &fileName)
 

Variables

UpdaterWindowupdaterWindow = 0
 

Function Documentation

◆ loadTxtFile()

static std::vector<UpdateFile> loadTxtFile ( const std::string &  fileName)
static

Definition at line 134 of file updaterwindow.cpp.

135 {
136  STD_VECTOR<UpdateFile> files;
137  std::ifstream fileHandler;
138  fileHandler.open(fileName.c_str(), std::ios::in);
139 
140  if (fileHandler.is_open())
141  {
142  while (fileHandler.good())
143  {
144  char name[256];
145  char hash[50];
146  fileHandler.getline(name, 256, ' ');
147  fileHandler.getline(hash, 50);
148 
149  UpdateFile thisFile;
150  thisFile.name = name;
151  thisFile.hash = hash;
152  thisFile.type = "data";
153  thisFile.group.clear();
154  thisFile.required = true;
155  thisFile.desc.clear();
156 
157  if (!thisFile.name.empty() && checkPath(thisFile.name))
158  files.push_back(thisFile);
159  }
160  }
161  else
162  {
163  logger->log("Error loading update file: %s", fileName.c_str());
164  }
165  fileHandler.close();
166 
167  return files;
168 }
void log(const char *const log_text,...)
Definition: logger.cpp:269
Logger * logger
Definition: logger.cpp:89
bool checkPath(const std::string &path)
Definition: paths.cpp:121
std::string group
Definition: updatefile.h:50
std::string type
Definition: updatefile.h:48
std::string hash
Definition: updatefile.h:47
std::string name
Definition: updatefile.h:46
bool required
Definition: updatefile.h:51
std::string desc
Definition: updatefile.h:49
std::string fileName
Definition: testmain.cpp:39

References checkPath(), UpdateFile::desc, fileName, UpdateFile::group, UpdateFile::hash, Logger::log(), logger, UpdateFile::name, UpdateFile::required, and UpdateFile::type.

Referenced by UpdaterWindow::loadLocalUpdates(), UpdaterWindow::loadUpdates(), UpdaterWindow::logic(), and UpdaterWindow::unloadUpdates().

◆ loadXMLFile()

static std::vector<UpdateFile> loadXMLFile ( const std::string &  fileName,
const bool  loadMods 
)
static

Load the given file into a vector of updateFiles.

Definition at line 80 of file updaterwindow.cpp.

82 {
83  STD_VECTOR<UpdateFile> files;
85  XmlNodeConstPtrConst rootNode = doc.rootNode();
86 
87  if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "updates"))
88  {
89  logger->log("Error loading update file: %s", fileName.c_str());
90  return files;
91  }
92 
93  for_each_xml_child_node(fileNode, rootNode)
94  {
95  const bool isMod = xmlNameEqual(fileNode, "mod");
96  if (!xmlNameEqual(fileNode, "update") && !isMod)
97  continue;
98 
99  UpdateFile file;
100  file.name = XML::getProperty(fileNode, "file", "");
101  file.hash = XML::getProperty(fileNode, "hash", "");
102  file.type = XML::getProperty(fileNode, "type", "data");
103  file.desc = XML::getProperty(fileNode, "description", "");
104  file.group = XML::getProperty(fileNode, "group", "");
105  if (!file.group.empty() && (!isMod || !loadMods))
106  continue;
107 
108  const std::string version = XML::getProperty(
109  fileNode, "version", "");
110  if (!version.empty())
111  {
112  if (version > CHECK_VERSION)
113  continue;
114  }
115  const std::string notVersion = XML::getProperty(
116  fileNode, "notVersion", "");
117  if (!notVersion.empty())
118  {
119  if (notVersion <= CHECK_VERSION)
120  continue;
121  }
122  if (XML::getProperty(fileNode, "required", "yes") == "yes")
123  file.required = true;
124  else
125  file.required = false;
126 
127  if (checkPath(file.name))
128  files.push_back(file);
129  }
130 
131  return files;
132 }
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:161
#define CHECK_VERSION
Definition: main.h:45
int getProperty(const xmlNodePtr node, const char *const name, int def)
Definition: libxml.cpp:174
const bool SkipError_false
Definition: skiperror.h:30
const bool UseVirtFs_false
Definition: usevirtfs.h:30

References CHECK_VERSION, checkPath(), UpdateFile::desc, fileName, for_each_xml_child_node, XML::getProperty(), UpdateFile::group, UpdateFile::hash, Logger::log(), logger, UpdateFile::name, UpdateFile::required, XML::Document::rootNode(), SkipError_false, UpdateFile::type, and UseVirtFs_false.

Referenced by UpdaterWindow::loadLocalUpdates(), UpdaterWindow::loadManaPlusUpdates(), UpdaterWindow::loadMods(), UpdaterWindow::loadUpdates(), UpdaterWindow::logic(), UpdaterWindow::unloadManaPlusUpdates(), and UpdaterWindow::unloadUpdates().

◆ txtUpdateFile()

const std::string txtUpdateFile ( "resources2.txt"  )

◆ updateServer2()

const std::string updateServer2 ( "http://download.manaplus.org/manaplus/updates/"  )

Referenced by UpdaterWindow::logic().

◆ updateServer3()

const std::string updateServer3 ( "http://download2.manaplus.org/manaplus/updates/"  )

Referenced by UpdaterWindow::download().

◆ updateServer4()

const std::string updateServer4 ( "http://download.evolonline.org/manaplus/updates/"  )

Referenced by UpdaterWindow::download().

◆ updateServer5()

const std::string updateServer5 ( "http://download3.manaplus.org/manaplus/updates/"  )

Referenced by UpdaterWindow::download().

◆ xmlUpdateFile()

const std::string xmlUpdateFile ( "resources.xml"  )

Variable Documentation

◆ updaterWindow

UpdaterWindow* updaterWindow = 0