ManaPlus
updaterwindow.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2004-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef GUI_WINDOWS_UPDATERWINDOW_H
25 #define GUI_WINDOWS_UPDATERWINDOW_H
26 
28 
30 #include "enums/net/updatetype.h"
31 
33 
34 #include "gui/widgets/window.h"
35 
36 #include "resources/updatefile.h"
37 
38 #include "utils/mutex.h"
39 
41 #include "listeners/keylistener.h"
42 
43 class Button;
44 class ItemLinkHandler;
45 class Label;
46 class ProgressBar;
47 class ScrollArea;
48 class StaticBrowserBox;
49 
50 namespace Net
51 {
52  class Download;
53 } // namespace Net
54 
60 class UpdaterWindow final : public Window,
61  public ActionListener,
62  public KeyListener
63 {
64  public:
74  UpdaterWindow(const std::string &restrict updateHost,
75  const std::string &restrict updatesDir,
76  const bool applyUpdates,
77  const UpdateTypeT updateType);
78 
80 
81 
84  ~UpdaterWindow() override final;
85 
86  void postInit() override final;
87 
91  void setProgress(const float p);
92 
96  void setLabel(const std::string &);
97 
101  void enable();
102 
107  void loadNews();
108 
109  void loadPatch();
110 
111  void action(const ActionEvent &event) override final;
112 
113  void keyPressed(KeyEvent &event) override final;
114 
115  void logic() override final;
116 
117  void loadFile(std::string file);
118 
119  void deleteSelf();
120 
121  static void loadLocalUpdates(const std::string &dir);
122 
123  static void unloadUpdates(const std::string &dir);
124 
125  static void addUpdateFile(const std::string &restrict path,
126  const std::string &restrict fixPath,
127  const std::string &restrict file,
128  const Append append);
129 
130  static void removeUpdateFile(const std::string &restrict path,
131  const std::string &restrict fixPath,
132  const std::string &filerestrict);
133 
134  static void loadManaPlusUpdates(const std::string &dir);
135 
136  static void unloadManaPlusUpdates(const std::string &dir);
137 
138  static unsigned long getFileHash(const std::string &filePath);
139 
140  static void loadMods(const std::string &dir,
141  const STD_VECTOR<UpdateFile> &updateFiles);
142 
143  static void loadDirMods(const std::string &dir);
144 
145  static void unloadMods(const std::string &dir);
146 
147  private:
148  void download();
149 
153  void loadUpdates();
154 
158  static int updateProgress(void *ptr,
159  const DownloadStatusT status,
160  size_t dt,
161  const size_t dn);
162 
166  static size_t memoryWrite(void *ptr, size_t size, size_t nmemb,
167  void *stream);
168 
169  static bool validateFile(const std::string &filePath,
170  const unsigned long hash) A_WARN_UNUSED;
171 
174 
176  std::string mUpdateHost;
177 
179  std::string mUpdatesDir;
180 
181  std::string mUpdatesDirReal;
182 
184  std::string mCurrentFile;
185 
187  std::string mNewLabelCaption;
188 
189  // The mutex used to guard access to mNewLabelCaption
190  // and mDownloadProgress.
192 
194  unsigned long mCurrentChecksum;
195 
198 
201 
203  STD_VECTOR<UpdateFile> mUpdateFiles;
204 
206  STD_VECTOR<UpdateFile> mTempUpdateFiles;
207 
208  std::string mUpdateServerPath;
209 
217 
220 
223 
225  unsigned int mUpdateIndex;
226 
228  unsigned int mUpdateIndexOffset;
229 
231 
236 
239 
242 
245 
247 
249 };
250 
252 
253 #endif // GUI_WINDOWS_UPDATERWINDOW_H
bool Append
Definition: append.h:30
Definition: button.h:102
Definition: label.h:91
Definition: mutex.h:34
char * mMemoryBuffer
unsigned int mUpdateIndex
std::string mUpdateServerPath
Button * mPlayButton
void setProgress(const float p)
Mutex mDownloadMutex
UpdateTypeT mUpdateType
static void loadLocalUpdates(const std::string &dir)
std::string mUpdatesDir
static size_t memoryWrite(void *ptr, size_t size, size_t nmemb, void *stream)
ItemLinkHandler * mItemLinkHandler
std::vector< UpdateFile > mUpdateFiles
static bool validateFile(const std::string &filePath, const unsigned long hash)
static void removeUpdateFile(const std::string &path, const std::string &fixPath, const std::string &filerestrict)
static void loadMods(const std::string &dir, const std::vector< UpdateFile > &updateFiles)
UpdaterWindow(const std::string &updateHost, const std::string &updatesDir, const bool applyUpdates, const UpdateTypeT updateType)
void action(const ActionEvent &event)
static void unloadManaPlusUpdates(const std::string &dir)
static unsigned long getFileHash(const std::string &filePath)
static void loadDirMods(const std::string &dir)
void loadFile(std::string file)
std::string mCurrentFile
std::string mUpdateHost
StaticBrowserBox * mBrowserBox
ScrollArea * mScrollArea
static void unloadUpdates(const std::string &dir)
static void unloadMods(const std::string &dir)
std::vector< UpdateFile > mTempUpdateFiles
std::string mNewLabelCaption
unsigned long mCurrentChecksum
void keyPressed(KeyEvent &event)
ProgressBar * mProgressBar
Button * mCancelButton
static int updateProgress(void *ptr, const DownloadStatusT status, size_t dt, const size_t dn)
void setLabel(const std::string &)
UpdateDownloadStatusT mDownloadStatus
static void loadManaPlusUpdates(const std::string &dir)
Net::Download * mDownload
std::string mUpdatesDirReal
unsigned int mUpdateIndexOffset
bool mDownloadComplete
float mDownloadProgress
static void addUpdateFile(const std::string &path, const std::string &fixPath, const std::string &file, const Append append)
Definition: window.h:102
DownloadStatus ::T DownloadStatusT
#define restrict
Definition: localconsts.h:165
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define A_NONNULLPOINTER
Definition: localconsts.h:266
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
int size()
Definition: emotedb.cpp:306
UpdateDownloadStatus ::T UpdateDownloadStatusT
UpdaterWindow * updaterWindow
UpdateType ::T UpdateTypeT
Definition: updatetype.h:36