55std::vector<UpdateFile>
loadXMLFile(
const std::string &fileName)
57 std::vector<UpdateFile> files;
61 if (!rootNode || rootNode.
name() !=
"updates")
63 Log::info(
"Error loading update file: %s", fileName.c_str());
67 for (
auto fileNode : rootNode.
children())
70 if (fileNode.name() !=
"update")
74 file.
name = fileNode.getProperty(
"file", std::string());
75 file.
hash = fileNode.getProperty(
"hash", std::string());
76 file.
type = fileNode.getProperty(
"type",
"data");
77 file.
desc = fileNode.getProperty(
"description", std::string());
78 file.
required = fileNode.getProperty(
"required",
"yes") ==
"yes";
80 files.push_back(file);
86std::vector<UpdateFile>
loadTxtFile(
const std::string &fileName)
88 std::vector<UpdateFile> files;
89 std::ifstream fileHandler;
90 fileHandler.open(fileName, std::ios::in);
92 if (fileHandler.is_open())
94 while (fileHandler.good())
98 fileHandler.getline(name, 256,
' ');
99 fileHandler.getline(hash, 50);
102 thisFile.
name = name;
103 thisFile.
hash = hash;
104 thisFile.
type =
"data";
107 if (!thisFile.
name.empty())
108 files.push_back(thisFile);
113 Log::info(
"Error loading update file: %s", fileName.c_str());
121 const std::string &updatesDir,
124 mUpdateHost(updateHost),
125 mUpdatesDir(updatesDir),
126 mLoadUpdates(applyUpdates),
144 mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
156 addKeyListener(
this);
186 if (event.getId() ==
"cancel")
188 else if (event.getId() ==
"play")
194 gcn::Key key = keyEvent.getKey();
237 std::optional<unsigned long> adler32)
279 const auto state =
mDownload->getState();
280 float progress = 0.0f;
282 switch (state.status) {
285 progress = state.progress;
299 std::string error =
"##1";
302 error +=
_(
"The update process is incomplete. "
303 "It is strongly recommended that you try again later.");
306 int maxScroll =
mScrollArea->getVerticalMaxScroll();
339 Log::warn(
"This server does not have a %s"
340 " file falling back to %s",
370 unsigned long checksum;
371 std::stringstream ss(thisFile.
hash);
372 ss >> std::hex >> checksum;
375 FILE *file = fopen(filename.c_str(),
"r+b");
A simple browser box able to handle links and forward events to the parent conteiner.
void addRows(std::string_view rows)
Adds one or more text rows to the browser, separated by ' '.
void setLinkHandler(LinkHandler *handler)
Sets the handler for links.
void clearRows()
Remove all rows.
@ AUTO_WRAP
Maybe it needs a fix or to be redone.
static void setState(State state)
void setRowHeight(int n, int h)
LayoutCell & setPadding(int p)
Sets the padding around the cell content.
This class is an helper for setting the position of widgets.
@ AUTO_SET
Uses the share as the new size.
static unsigned long fadler32(FILE *file)
Calculates the Alder-32 checksum for the given file.
void setProgress(float progress)
Sets the current progress.
void setSmoothProgress(bool smoothProgress)
Set whether the progress is moved smoothly.
static bool addToSearchPath(const std::string &path, bool append)
Adds a directory or archive to the search path.
unsigned int mUpdateIndex
Index of the file to be downloaded.
Button * mPlayButton
Button to start playing.
std::string mUpdatesDir
Place where the updates are stored (absolute path).
std::unique_ptr< LinkHandler > mLinkHandler
std::vector< UpdateFile > mUpdateFiles
List of files to download.
BrowserBox * mBrowserBox
Box to display news.
std::unique_ptr< Net::Download > mDownload
Download handle.
std::string mCurrentFile
The file currently downloading.
void loadNews()
Loads and display news.
std::string mUpdateHost
Host where we get the updated files.
DialogState mDialogState
Status of the current download.
ScrollArea * mScrollArea
Used to scroll news box.
void startDownload(const std::string &fileName, bool storeInMemory, std::optional< unsigned long > adler32={})
ProgressBar * mProgressBar
Update progress bar.
~UpdaterWindow() override
void loadUpdates()
Loads the updates this window has gotten into the resource manager.
Button * mCancelButton
Button to stop the update process.
void action(const gcn::ActionEvent &event) override
void setLabel(const std::string &)
void keyPressed(gcn::KeyEvent &keyEvent) override
bool mLoadUpdates
Tells ~UpdaterWindow() if it should load updates.
gcn::Label * mLabel
Progress bar caption.
UpdaterWindow(const std::string &updateHost, const std::string &updatesDir, bool applyUpdates)
Constructor.
virtual void setVisible(bool visible)
Overloads window setVisible by Guichan to allow sticky window handling.
void setMinHeight(int height)
Sets the minimum height of the window.
Layout & getLayout()
Gets the layout handler for this window.
void setWindowName(const std::string &name)
Sets the name of the window.
void setResizable(bool resize)
Sets whether or not the window can be resized.
LayoutCell & place(int x, int y, gcn::Widget *, int w=1, int h=1)
Adds a widget to the window and sets it at given cell.
void setDefaultSize()
Set the default win pos and size to the current ones.
void loadWindowState()
Reads the position (and the size for resizable windows) in the configuration based on the given strin...
void setMinWidth(int width)
Sets the minimum width of the window.
A helper class for parsing an XML document, which also cleans it up again (RAII).
Node rootNode() const
Returns the root node of the document (or NULL if there was a load error).
std::string_view name() const
Children children() const
Config config
Global settings (config.xml)
void warn(const char *log_text,...) LOG_PRINTF_ATTR
void info(const char *log_text,...) LOG_PRINTF_ATTR
std::string toString(const T &arg)
Converts the given value to a string using std::stringstream.
std::vector< UpdateFile > loadTxtFile(const std::string &fileName)
std::vector< UpdateFile > loadXMLFile(const std::string &fileName)
Load the given file into a vector of updateFiles.
constexpr char xmlUpdateFile[]
constexpr char txtUpdateFile[]