ManaPlus
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
UpdaterWindow Class Reference

#include <updaterwindow.h>

Inheritance diagram for UpdaterWindow:
Window ActionListener KeyListener BasicContainer2 MouseListener WidgetListener BasicContainer Widget WidgetDeathListener Widget2

Public Member Functions

 UpdaterWindow (const std::string &updateHost, const std::string &updatesDir, const bool applyUpdates, const UpdateTypeT updateType)
 
 ~UpdaterWindow ()
 
void postInit ()
 
void setProgress (const float p)
 
void setLabel (const std::string &)
 
void enable ()
 
void loadNews ()
 
void loadPatch ()
 
void action (const ActionEvent &event)
 
void keyPressed (KeyEvent &event)
 
void logic ()
 
void loadFile (std::string file)
 
void deleteSelf ()
 
- Public Member Functions inherited from Window
 Window (const std::string &caption, const Modal modal, Window *const parent, std::string skin)
 
 ~Window ()
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
void setContentSize (int width, int height)
 
void setLocationRelativeTo (const Widget *const widget)
 
void setLocationHorisontallyRelativeTo (const Widget *const widget)
 
void setLocationRelativeTo (const ImagePosition::Type &position, int offsetX, int offsetY)
 
void setResizable (const bool resize)
 
void redraw ()
 
void widgetResized (const Event &event)
 
void widgetMoved (const Event &event)
 
void widgetHidden (const Event &event)
 
void setCloseButton (const bool flag)
 
bool getCloseButton () const
 
void setAllowClose (const bool b)
 
bool getAlowClose () const
 
bool isResizable () const
 
void setMinWidth (const int width)
 
int getMinWidth () const
 
void setMinHeight (const int height)
 
int getMinHeight () const
 
void setMaxWidth (const int width)
 
int getMaxWidth () const
 
void setMaxHeight (const int height)
 
int getMaxHeight () const
 
void setShowTitle (bool flag)
 
void setStickyButton (const bool flag)
 
void setSticky (const bool sticky)
 
bool isSticky () const
 
void setStickyButtonLock (const bool sticky)
 
bool isStickyButtonLock () const
 
virtual void setVisible (Visible visible)
 
void setVisible (const Visible visible, const bool forceSticky)
 
bool isDefaultVisible () const
 
void setDefaultVisible (const bool save)
 
bool willSaveVisible () const
 
void setSaveVisible (const bool save)
 
WindowgetParentWindow () const
 
virtual void scheduleDelete ()
 
void mousePressed (MouseEvent &event)
 
void mouseDragged (MouseEvent &event)
 
void mouseMoved (MouseEvent &event)
 
void mouseReleased (MouseEvent &event)
 
void mouseExited (MouseEvent &event)
 
void mouseEntered (MouseEvent &event)
 
void updateResizeHandler (MouseEvent &event)
 
void setWindowName (const std::string &name)
 
const std::string & getWindowName () const
 
void loadWindowState ()
 
void saveWindowState ()
 
void setDefaultSize (const int defaultX, const int defaultY, int defaultWidth, int defaultHeight)
 
void setDefaultSize ()
 
void setDefaultSize (const int defaultWidth, const int defaultHeight, const ImagePosition::Type &position, const int offsetx, const int offsetY)
 
virtual void resetToDefaultSize ()
 
void adjustPositionAfterResize (const int oldScreenWidth, const int oldScreenHeight)
 
LayoutgetLayout ()
 
void clearLayout ()
 
void reflowLayout (int w, int h)
 
LayoutCellplace (const int x, const int y, Widget *const wg, const int w, const int h)
 
ContainerPlacer getPlacer (const int x, const int y)
 
void center ()
 
void centerHorisontally ()
 
virtual void close ()
 
void setModal (const Modal modal)
 
Rect getWindowArea () const
 
bool isResizeAllowed (const MouseEvent &event) const
 
void setCaptionFont (Font *font)
 
void enableVisibleSound (bool b)
 
bool isWindowVisible () const
 
void setPadding (int padding)
 
int getPadding () const
 
void setTitleBarHeight (unsigned int height)
 
unsigned int getTitleBarHeight () const
 
void setCaption (const std::string &caption)
 
const std::string & getCaption () const
 
void setAlignment (Graphics::Alignment alignment)
 
Graphics::Alignment getAlignment () const
 
void setMovable (Move movable)
 
bool isMovable () const
 
Rect getChildrenArea ()
 
virtual void resizeToContent ()
 
- Public Member Functions inherited from BasicContainer2
 BasicContainer2 (const Widget2 *const widget)
 
 ~BasicContainer2 ()
 
void setOpaque (Opaque opaque)
 
bool isOpaque () const
 
virtual void add (Widget *const widget)
 
void addXY (Widget *const widget, const int x, const int y)
 
- Public Member Functions inherited from BasicContainer
 BasicContainer (const Widget2 *const widget)
 
 ~BasicContainer ()
 
void showWidgetPart (Widget *const widget, const Rect &area)
 
void moveToTop (Widget *const widget)
 
void moveToBottom (Widget *const widget)
 
void focusNext ()
 
void focusPrevious ()
 
void setFocusHandler (FocusHandler *const focusHandler)
 
void setInternalFocusHandler (FocusHandler *const focusHandler)
 
WidgetgetWidgetAt (int x, int y)
 
void death (const Event &event)
 
WidgetfindFirstWidget (const std::set< Widget *> &list)
 
void add (Widget *const widget)
 
virtual void remove (Widget *const widget)
 
virtual void clear ()
 
- Public Member Functions inherited from Widget
 Widget (const Widget2 *const widget)
 
 ~Widget ()
 
virtual void drawFrame (Graphics *graphics)
 
virtual void safeDrawFrame (Graphics *graphics)
 
void setFrameSize (const unsigned int frameSize)
 
unsigned int getFrameSize () const
 
WidgetgetParent () const
 
void setWidth (const int width)
 
int getWidth () const
 
void setHeight (const int height)
 
int getHeight () const
 
void setSize (const int width, const int height)
 
void setX (const int x)
 
int getX () const
 
void setY (const int y)
 
int getY () const
 
void setPosition (const int x, const int y)
 
void setDimension (const Rect &dimension)
 
const RectgetDimension () const
 
void setFocusable (const bool focusable)
 
bool isFocusable () const
 
virtual bool isFocused () const
 
void setEnabled (const bool enabled)
 
bool isEnabled () const
 
void setVisible (Visible visible)
 
bool isVisible () const
 
void setBaseColor (const Color &color)
 
const ColorgetBaseColor () const
 
void setForegroundColor (const Color &color)
 
const ColorgetForegroundColor () const
 
void setBackgroundColor (const Color &color)
 
const ColorgetBackgroundColor () const
 
virtual void requestFocus ()
 
virtual void requestMoveToTop ()
 
virtual void requestMoveToBottom ()
 
FocusHandlergetFocusHandler ()
 
void addActionListener (ActionListener *const actionListener)
 
void removeActionListener (ActionListener *const actionListener)
 
void addDeathListener (WidgetDeathListener *const deathListener)
 
void removeDeathListener (WidgetDeathListener *const deathListener)
 
void addMouseListener (MouseListener *const mouseListener)
 
void removeMouseListener (MouseListener *const mouseListener)
 
void addKeyListener (KeyListener *const keyListener)
 
void removeKeyListener (KeyListener *const keyListener)
 
void addFocusListener (FocusListener *const focusListener)
 
void removeFocusListener (FocusListener *const focusListener)
 
void addWidgetListener (WidgetListener *const widgetListener)
 
void removeWidgetListener (WidgetListener *const widgetListener)
 
void setActionEventId (const std::string &actionEventId)
 
const std::string & getActionEventId () const
 
virtual void getAbsolutePosition (int &x, int &y) const
 
virtual void setParent (Widget *parent)
 
FontgetFont () const
 
void setFont (Font *const font)
 
virtual void fontChanged ()
 
bool isTabInEnabled () const
 
void setTabInEnabled (const bool enabled)
 
bool isTabOutEnabled () const
 
void setTabOutEnabled (const bool enabled)
 
void requestModalFocus ()
 
virtual void requestModalMouseInputFocus ()
 
virtual void releaseModalFocus ()
 
virtual void releaseModalMouseInputFocus ()
 
virtual bool isModalFocused () const
 
virtual bool isModalMouseInputFocused () const
 
const std::list< MouseListener * > & getMouseListeners () const A_CONST
 
const std::list< KeyListener * > & getKeyListeners () const A_CONST
 
const std::list< FocusListener * > & getFocusListeners () const A_CONST
 
virtual FocusHandlergetInternalFocusHandler ()
 
void setInternalFocusHandler (FocusHandler *const internalFocusHandler)
 
void setId (const std::string &id)
 
const std::string & getId () const
 
virtual void showPart (const Rect &rectangle)
 
bool isAllowLogic () const
 
void setMouseConsume (const bool b)
 
bool isMouseConsume () const
 
void setRedraw (const bool b)
 
virtual bool isSelectable () const
 
void setSelectable (const bool selectable)
 
void windowResized ()
 
- Public Member Functions inherited from Widget2
virtual ~Widget2 ()
 
const ColorgetThemeColor (const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
 
const ColorgetThemeCharColor (const signed char c, bool &valid) const A_INLINE
 
virtual void setWidget2 (const Widget2 *const widget)
 
void setPalette (int palette)
 
void checkPalette ()
 
void setForegroundColor2 (const Color &color)
 
WidgetgetWindow () const
 
virtual void setWindow (Widget *const window)
 
- Public Member Functions inherited from WidgetDeathListener
virtual ~WidgetDeathListener ()
 
- Public Member Functions inherited from MouseListener
virtual ~MouseListener ()
 
virtual void mouseClicked (MouseEvent &event)
 
virtual void mouseWheelMovedUp (MouseEvent &event)
 
virtual void mouseWheelMovedDown (MouseEvent &event)
 
- Public Member Functions inherited from WidgetListener
virtual ~WidgetListener ()
 
virtual void widgetShown (const Event &event)
 
- Public Member Functions inherited from ActionListener
virtual ~ActionListener ()
 
- Public Member Functions inherited from KeyListener
virtual ~KeyListener ()
 
virtual void keyReleased (KeyEvent &event)
 

Static Public Member Functions

static void loadLocalUpdates (const std::string &dir)
 
static void unloadUpdates (const std::string &dir)
 
static void addUpdateFile (const std::string &path, const std::string &fixPath, const std::string &file, const Append append)
 
static void removeUpdateFile (const std::string &path, const std::string &fixPath, const std::string &filerestrict)
 
static void loadManaPlusUpdates (const std::string &dir)
 
static void unloadManaPlusUpdates (const std::string &dir)
 
static unsigned long getFileHash (const std::string &filePath)
 
static void loadMods (const std::string &dir, const std::vector< UpdateFile > &updateFiles)
 
static void loadDirMods (const std::string &dir)
 
static void unloadMods (const std::string &dir)
 
- Static Public Member Functions inherited from Window
static void setWindowContainer (WindowContainer *const windowContainer)
 
- Static Public Member Functions inherited from Widget
static void setGlobalFont (Font *const font)
 
static FontgetGloablFont ()
 
static void cleanGlobalFont ()
 
static bool widgetExists (const Widget *const widget)
 
static void distributeWindowResizeEvent ()
 
static WidgetcallPostInit (Widget *const widget)
 

Private Member Functions

void download ()
 
void loadUpdates ()
 

Static Private Member Functions

static int updateProgress (void *ptr, const DownloadStatusT status, size_t dt, const size_t dn)
 
static size_t memoryWrite (void *ptr, size_t size, size_t nmemb, void *stream)
 
static bool validateFile (const std::string &filePath, const unsigned long hash)
 

Private Attributes

float mDownloadProgress
 
std::string mUpdateHost
 
std::string mUpdatesDir
 
std::string mUpdatesDirReal
 
std::string mCurrentFile
 
std::string mNewLabelCaption
 
Mutex mDownloadMutex
 
unsigned long mCurrentChecksum
 
char * mMemoryBuffer
 
Net::DownloadmDownload
 
std::vector< UpdateFilemUpdateFiles
 
std::vector< UpdateFilemTempUpdateFiles
 
std::string mUpdateServerPath
 
ItemLinkHandlermItemLinkHandler
 
LabelmLabel
 
ButtonmCancelButton
 
ButtonmPlayButton
 
ProgressBarmProgressBar
 
StaticBrowserBoxmBrowserBox
 
ScrollAreamScrollArea
 
UpdateDownloadStatusT mDownloadStatus
 
int mDownloadedBytes
 
unsigned int mUpdateIndex
 
unsigned int mUpdateIndexOffset
 
UpdateTypeT mUpdateType
 
bool mStoreInMemory
 
bool mDownloadComplete
 
bool mUserCancel
 
bool mLoadUpdates
 
bool mValidateXml
 
bool mSkipPatches
 

Additional Inherited Members

- Data Fields inherited from Widget
Visible mVisible
 
- Protected Types inherited from BasicContainer
typedef std::vector< Widget * > WidgetList
 
typedef WidgetList::iterator WidgetListIterator
 
typedef WidgetList::const_iterator WidgetListConstIterator
 
typedef WidgetList::reverse_iterator WidgetListReverseIterator
 
typedef WidgetList::const_reverse_iterator WidgetListCReverseIterator
 
- Protected Types inherited from Widget
typedef std::list< MouseListener * > MouseListenerList
 
typedef MouseListenerList::iterator MouseListenerIterator
 
typedef std::list< KeyListener * > KeyListenerList
 
typedef KeyListenerList::iterator KeyListenerIterator
 
typedef std::list< ActionListener * > ActionListenerList
 
typedef ActionListenerList::iterator ActionListenerIterator
 
typedef std::list< WidgetDeathListener * > WidgetDeathListenerList
 
typedef WidgetDeathListenerList::iterator WidgetDeathListenerIterator
 
typedef std::list< FocusListener * > FocusListenerList
 
typedef FocusListenerList::iterator FocusListenerIterator
 
typedef std::list< WidgetListener * > WidgetListenerList
 
typedef WidgetListenerList::iterator WidgetListenerIterator
 
- Protected Member Functions inherited from Window
bool canMove () const
 
int getOption (const std::string &name, const int def) const
 
bool getOptionBool (const std::string &name, const bool def) const
 
void setTitlePadding (const int p)
 
int getTitlePadding () const
 
- Protected Member Functions inherited from BasicContainer
virtual void drawChildren (Graphics *const graphics)
 
virtual void safeDrawChildren (Graphics *const graphics)
 
virtual void logicChildren ()
 
- Protected Member Functions inherited from Widget
void distributeActionEvent ()
 
void distributeResizedEvent ()
 
void distributeMovedEvent ()
 
void distributeHiddenEvent ()
 
void distributeShownEvent ()
 
- Protected Member Functions inherited from Widget2
 Widget2 (const Widget2 *const widget)
 
- Protected Member Functions inherited from WidgetDeathListener
 WidgetDeathListener ()
 
- Protected Member Functions inherited from MouseListener
 MouseListener ()
 
- Protected Member Functions inherited from WidgetListener
 WidgetListener ()
 
- Protected Member Functions inherited from ActionListener
 ActionListener ()
 
- Protected Member Functions inherited from KeyListener
 KeyListener ()
 
- Protected Attributes inherited from Window
std::string mCaption
 
Graphics::Alignment mAlignment
 
int mPadding
 
unsigned int mTitleBarHeight
 
Move mMovable
 
int mDragOffsetX
 
int mDragOffsetY
 
bool mMoved
 
SkinmSkin
 
int mDefaultX
 
int mDefaultY
 
int mDefaultWidth
 
int mDefaultHeight
 
int mCaptionOffsetX
 
int mCaptionOffsetY
 
bool mShowTitle
 
bool mLastRedraw
 
- Protected Attributes inherited from BasicContainer2
Opaque mOpaque
 
- Protected Attributes inherited from BasicContainer
WidgetList mWidgets
 
WidgetList mLogicWidgets
 
- Protected Attributes inherited from Widget
MouseListenerList mMouseListeners
 
KeyListenerList mKeyListeners
 
ActionListenerList mActionListeners
 
WidgetDeathListenerList mDeathListeners
 
FocusListenerList mFocusListeners
 
WidgetListenerList mWidgetListeners
 
Color mForegroundColor
 
Color mBackgroundColor
 
Color mBaseColor
 
Rect mDimension
 
std::string mActionEventId
 
std::string mId
 
FocusHandlermFocusHandler
 
FocusHandlermInternalFocusHandler
 
WidgetmParent
 
FontmCurrentFont
 
unsigned int mFrameSize
 
bool mFocusable
 
bool mTabIn
 
bool mTabOut
 
bool mEnabled
 
bool mAllowLogic
 
bool mMouseConsume
 
bool mRedraw
 
bool mSelectable
 
- Protected Attributes inherited from Widget2
int mPaletteOffset
 
WidgetmWindow
 
Color mForegroundColor2
 
- Static Protected Attributes inherited from Widget
static FontmGlobalFont = 0
 

Detailed Description

Update progress window GUI

Definition at line 59 of file updaterwindow.h.

Constructor & Destructor Documentation

◆ UpdaterWindow()

UpdaterWindow::UpdaterWindow ( const std::string &  updateHost,
const std::string &  updatesDir,
const bool  applyUpdates,
const UpdateTypeT  updateType 
)

Constructor.

Parameters
updateHostHost where to get the updated files.
updatesDirDirectory where to store updates (should be absolute and already created).
applyUpdatesIf true, the update window will pass the updates to teh resource manager.

Definition at line 169 of file updaterwindow.cpp.

References Widget::addKeyListener(), ImagePosition::CENTER, Window::getLayout(), Window::getPlacer(), Window::loadWindowState(), mBrowserBox, mCancelButton, mItemLinkHandler, mLabel, mPlayButton, mProgressBar, mScrollArea, mSkipPatches, mUpdateHost, Opaque_false, LayoutType::SET, Window::setDefaultSize(), Widget::setEnabled(), StaticBrowserBox::setEnableImages(), StaticBrowserBox::setEnableKeys(), StaticBrowserBox::setEnableTabs(), StaticBrowserBox::setLinkHandler(), Window::setMinHeight(), Window::setMinWidth(), StaticBrowserBox::setOpaque(), StaticBrowserBox::setProcessVars(), Window::setResizable(), LayoutCell::setRowHeight(), ProgressBar::setSmoothProgress(), settings, Window::setWindowName(), and Settings::updateMirrors.

172  :
173  // TRANSLATORS: updater window name
174  Window(_("Updating..."), Modal_false, nullptr, "update.xml"),
175  ActionListener(),
176  KeyListener(),
177  mDownloadProgress(0.0F),
178  mUpdateHost(updateHost),
179  mUpdatesDir(updatesDir),
180  mUpdatesDirReal(updatesDir),
181  mCurrentFile("news.txt"),
183  mDownloadMutex(),
184  mCurrentChecksum(0),
185  mMemoryBuffer(nullptr),
186  mDownload(nullptr),
187  mUpdateFiles(),
191  // TRANSLATORS: updater window label
192  mLabel(new Label(this, _("Connecting..."))),
193  // TRANSLATORS: updater window button
194  mCancelButton(new Button(this, _("Cancel"), "cancel", BUTTON_SKIN, this)),
195  // TRANSLATORS: updater window button
196  mPlayButton(new Button(this, _("Play"), "play", BUTTON_SKIN, this)),
197  mProgressBar(new ProgressBar(this, 0.0, 310, 0,
199  "updateprogressbar.xml", "updateprogressbar_fill.xml")),
201  "browserbox.xml")),
203  Opaque_true, "update_background.xml")),
205  mDownloadedBytes(0),
206  mUpdateIndex(0),
208  mUpdateType(updateType),
209  mStoreInMemory(true),
210  mDownloadComplete(true),
211  mUserCancel(false),
212  mLoadUpdates(applyUpdates),
213  mValidateXml(false),
214  mSkipPatches(false)
215 {
216  setWindowName("UpdaterWindow");
217  setResizable(true);
218  setDefaultSize(450, 400, ImagePosition::CENTER, 0, 0);
219  setMinWidth(310);
220  setMinHeight(220);
221 
226  mBrowserBox->setEnableKeys(true);
227  mBrowserBox->setEnableTabs(true);
229  mPlayButton->setEnabled(false);
230 
231  ContainerPlacer placer(nullptr, nullptr);
232  placer = getPlacer(0, 0);
233 
234  placer(0, 0, mScrollArea, 5, 3).setPadding(3);
235  placer(0, 3, mLabel, 5, 1);
236  placer(0, 4, mProgressBar, 5, 1);
237  placer(3, 5, mCancelButton, 1, 1);
238  placer(4, 5, mPlayButton, 1, 1);
239 
240  Layout &layout = getLayout();
241  layout.setRowHeight(0, LayoutType::SET);
242 
243  addKeyListener(this);
244 
245  if (mUpdateHost.empty())
246  {
247  const STD_VECTOR<std::string> &mirrors = settings.updateMirrors;
248  if (mirrors.begin() != mirrors.end())
249  mUpdateHost = *mirrors.begin();
250  mSkipPatches = true;
251  }
252 
253  loadWindowState();
254 }
void setDefaultSize()
Definition: window.cpp:1193
#define _(s)
Definition: gettext.h:34
std::string mUpdatesDir
void loadWindowState()
Definition: window.cpp:1082
std::string mUpdateServerPath
void setProcessVars(const bool n)
UpdateTypeT mUpdateType
void setMinWidth(const int width)
Definition: window.cpp:586
void setEnableKeys(const bool n)
std::vector< UpdateFile > mTempUpdateFiles
Definition: button.h:96
unsigned int mUpdateIndex
StaticBrowserBox * mBrowserBox
UpdateDownloadStatusT mDownloadStatus
void setSmoothProgress(bool smoothProgress)
Definition: progressbar.h:124
void setEnableImages(const bool n)
std::vector< std::string > updateMirrors
Definition: settings.h:127
Mutex mDownloadMutex
unsigned long mCurrentChecksum
Button * mPlayButton
Settings settings
Definition: settings.cpp:31
void setLinkHandler(LinkHandler *linkHandler)
std::string mUpdatesDirReal
const std::string BUTTON_SKIN
Definition: button.h:88
Definition: label.h:87
float mDownloadProgress
const bool Opaque_false
Definition: opaque.h:29
void addKeyListener(KeyListener *const keyListener)
Definition: widget.cpp:271
Button * mCancelButton
void setMinHeight(const int height)
Definition: window.cpp:599
ContainerPlacer getPlacer(const int x, const int y)
Definition: window.cpp:1386
void setEnabled(const bool enabled)
Definition: widget.h:351
ProgressBar * mProgressBar
ItemLinkHandler * mItemLinkHandler
Layout & getLayout()
Definition: window.cpp:1360
ScrollArea * mScrollArea
void setOpaque(Opaque opaque)
char * mMemoryBuffer
bool mDownloadComplete
const bool Opaque_true
Definition: opaque.h:29
void setEnableTabs(const bool n)
unsigned int mUpdateIndexOffset
void setResizable(const bool resize)
Definition: window.cpp:622
std::string mUpdateHost
std::vector< UpdateFile > mUpdateFiles
Definition: layout.h:43
void setRowHeight(const int n, const int h)
Definition: layoutcell.cpp:127
std::string mCurrentFile
Window(const std::string &caption, const Modal modal, Window *const parent, std::string skin)
Definition: window.cpp:108
std::string mNewLabelCaption
void setWindowName(const std::string &name)
Definition: window.h:354
Net::Download * mDownload

◆ ~UpdaterWindow()

UpdaterWindow::~UpdaterWindow ( )

Destructor

Definition at line 266 of file updaterwindow.cpp.

References Net::Download::cancel, delete2, loadUpdates(), mDownload, mItemLinkHandler, mLoadUpdates, and mMemoryBuffer.

267 {
268  if (mLoadUpdates)
269  loadUpdates();
270 
271  if (mDownload != nullptr)
272  {
273  mDownload->cancel();
274 
276  }
277  free(mMemoryBuffer);
279 }
unsigned cancel
Definition: download.h:126
#define delete2(var)
Definition: delete2.h:24
ItemLinkHandler * mItemLinkHandler
char * mMemoryBuffer
Net::Download * mDownload

Member Function Documentation

◆ action()

void UpdaterWindow::action ( const ActionEvent actionEvent)
virtual

Called when an action is recieved from a widget. It is used to be able to recieve a notification that an action has occured.

Parameters
actionEventThe event of the action.

Implements ActionListener.

Definition at line 312 of file updaterwindow.cpp.

References Net::Download::cancel, client, deleteSelf(), State::GAME, Client::getState(), State::LOAD_DATA, mDownload, mDownloadStatus, mUserCancel, Client::setState(), UpdateDownloadStatus::UPDATE_COMPLETE, and UpdateDownloadStatus::UPDATE_ERROR.

Referenced by keyPressed().

313 {
314  const std::string &eventId = event.getId();
315  if (eventId == "cancel")
316  {
317  // Register the user cancel
318  mUserCancel = true;
319  // Skip the updating process
321  {
322  if (mDownload != nullptr)
323  mDownload->cancel();
325  }
326  }
327  else if (eventId == "play")
328  {
329  if (client->getState() != State::GAME)
331  else
332  deleteSelf();
333  }
334 }
void setState(const StateT state)
Definition: client.h:65
unsigned cancel
Definition: download.h:126
Client * client
Definition: client.cpp:117
UpdateDownloadStatusT mDownloadStatus
StateT getState() const
Definition: client.h:68
Net::Download * mDownload

◆ addUpdateFile()

void UpdaterWindow::addUpdateFile ( const std::string &  path,
const std::string &  fixPath,
const std::string &  file,
const Append  append 
)
static

Definition at line 799 of file updaterwindow.cpp.

References Append_false, Append_true, VirtFs::mountZip(), and pathJoin().

Referenced by loadLocalUpdates(), loadMods(), and loadUpdates().

803 {
804  const std::string tmpPath = pathJoin(path, file);
805  if (append == Append_false)
806  VirtFs::mountZip(tmpPath, append);
807 
808  const std::string fixFile = pathJoin(fixPath, file);
809  struct stat statbuf;
810  if (stat(fixFile.c_str(), &statbuf) == 0)
811  VirtFs::mountZip(fixFile, append);
812 
813  if (append == Append_true)
814  VirtFs::mountZip(tmpPath, append);
815 }
const bool Append_true
Definition: append.h:29
std::string pathJoin(std::string str1, const std::string &str2)
const bool Append_false
Definition: append.h:29
bool mountZip(std::string newDir, const Append append)
Definition: fs.cpp:589

◆ deleteSelf()

void UpdaterWindow::deleteSelf ( )

Definition at line 1219 of file updaterwindow.cpp.

References Window::scheduleDelete().

Referenced by action(), enable(), keyPressed(), and Actions::showHideWindow().

1220 {
1221  scheduleDelete();
1222  updaterWindow = nullptr;
1223 }
UpdaterWindow * updaterWindow
virtual void scheduleDelete()
Definition: window.cpp:826

◆ download()

void UpdaterWindow::download ( )
private

Definition at line 580 of file updaterwindow.cpp.

References Net::Download::addMirror(), branding, Net::Download::cancel, FOR_EACH, Configuration::getStringValue(), mCurrentChecksum, mCurrentFile, mDownload, mDownloadComplete, mDownloadStatus, memoryWrite(), mStoreInMemory, mUpdateHost, mUpdatesDir, mUpdateServerPath, mValidateXml, Net::Download::noCache(), pathJoin(), Net::Download::setFile(), setLabel(), settings, Net::Download::setWriteFunction(), Net::Download::start(), ServerCommandType::str, Catch::toString(), UpdateDownloadStatus::UPDATE_LIST2, UpdateDownloadStatus::UPDATE_PATCH, UpdateDownloadStatus::UPDATE_RESOURCES, UpdateDownloadStatus::UPDATE_RESOURCES2, Settings::updateMirrors, updateProgress(), updateServer3(), updateServer4(), updateServer5(), Actions::url(), and urlJoin().

Referenced by logic(), and postInit().

581 {
582  if (mDownload != nullptr)
583  {
584  mDownload->cancel();
585  delete mDownload;
586  }
588  {
589  mDownload = new Net::Download(this,
590  branding.getStringValue("updateMirror1") + mCurrentFile,
592  true, false, mValidateXml);
593  for (int f = 2; f < 8; f ++)
594  {
595  const std::string url = branding.getStringValue(
596  "updateMirror" + toString(f));
597  if (!url.empty())
599  }
600  }
601  else
602  {
603  mDownload = new Net::Download(this,
605  &updateProgress,
606  false, false, mValidateXml);
607 
610  {
611  const std::string str = urlJoin(mUpdateServerPath, mCurrentFile);
615  }
616  else
617  {
618  const STD_VECTOR<std::string> &mirrors = settings.updateMirrors;
619  FOR_EACH (STD_VECTOR<std::string>::const_iterator, it, mirrors)
620  {
622  mCurrentFile));
623  }
624  }
625  }
626 
627  if (mStoreInMemory)
628  {
630  }
631  else
632  {
634  {
637  }
638  else
639  {
641  mCurrentFile),
642  -1);
643  }
644  }
645 
647  mDownload->noCache();
648 
649  setLabel(mCurrentFile + " (0%)");
650  mDownloadComplete = false;
651 
652  mDownload->start();
653 }
Configuration branding
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
std::string getStringValue(const std::string &key) const
std::string mUpdatesDir
void addMirror(const std::string &str)
Definition: download.h:87
const std::string updateServer3("http://download2.manaplus.org/manaplus/updates/")
std::string mUpdateServerPath
unsigned cancel
Definition: download.h:126
std::string pathJoin(std::string str1, const std::string &str2)
void setWriteFunction(WriteFunction write)
Definition: download.cpp:181
void setLabel(const std::string &)
UpdateDownloadStatusT mDownloadStatus
std::string urlJoin(std::string str1, const std::string &str2)
std::vector< std::string > updateMirrors
Definition: settings.h:127
unsigned long mCurrentChecksum
void setFile(const std::string &filename, const int64_t adler32)
Definition: download.cpp:165
Settings settings
Definition: settings.cpp:31
const std::string updateServer5("http://download3.manaplus.org/manaplus/updates/")
static int updateProgress(void *ptr, const DownloadStatusT status, size_t dt, const size_t dn)
const std::string updateServer4("http://download.evolonline.org/manaplus/updates/")
bool start()
Definition: download.cpp:187
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
void noCache()
Definition: download.cpp:159
bool mDownloadComplete
std::string mUpdateHost
static size_t memoryWrite(void *ptr, size_t size, size_t nmemb, void *stream)
std::string mCurrentFile
bool url(InputEvent &event)
Definition: commands.cpp:63
Net::Download * mDownload

◆ enable()

void UpdaterWindow::enable ( )

Enables play button

Definition at line 295 of file updaterwindow.cpp.

References client, UpdateType::Close, deleteSelf(), State::GAME, Client::getState(), State::LOAD_DATA, mCancelButton, mPlayButton, mUpdateType, Widget::requestFocus(), Widget::setEnabled(), and Client::setState().

Referenced by logic().

296 {
297  mCancelButton->setEnabled(false);
298  mPlayButton->setEnabled(true);
300 
301  if (client->getState() != State::GAME)
302  {
303  if ((mUpdateType & UpdateType::Close) != 0)
305  }
306  else
307  {
308  deleteSelf();
309  }
310 }
void setState(const StateT state)
Definition: client.h:65
UpdateTypeT mUpdateType
Client * client
Definition: client.cpp:117
Button * mPlayButton
virtual void requestFocus()
Definition: widget.cpp:203
Button * mCancelButton
void setEnabled(const bool enabled)
Definition: widget.h:351
StateT getState() const
Definition: client.h:68

◆ getFileHash()

unsigned long UpdaterWindow::getFileHash ( const std::string &  filePath)
static

Definition at line 1084 of file updaterwindow.cpp.

References Net::Download::adlerBuffer(), VirtFs::loadFile(), and ServerCommandType::size.

Referenced by LocalPlayer::setTestParticle(), and LocalPlayer::slowLogic().

1085 {
1086  int size = 0;
1087  const char *const buf = VirtFs::loadFile(filePath, size);
1088  if (buf == nullptr)
1089  return 0;
1090  unsigned long res = Net::Download::adlerBuffer(buf, size);
1091  delete [] buf;
1092  return res;
1093 }
const char * loadFile(std::string filename, int &fileSize)
Definition: fs.cpp:858
static unsigned long adlerBuffer(const char *const buffer, int size)
Definition: download.cpp:146

◆ keyPressed()

void UpdaterWindow::keyPressed ( KeyEvent event)
virtual

Called if a key is pressed when the widget has keyboard focus. If a key is held down the widget will generate multiple key presses.

Parameters
eventDiscribes the event.

Reimplemented from KeyListener.

Definition at line 336 of file updaterwindow.cpp.

References action(), client, deleteSelf(), State::GAME, Widget::getActionEventId(), Client::getState(), InputAction::GUI_CANCEL, InputAction::GUI_SELECT, InputAction::GUI_SELECT2, State::LOGIN, mCancelButton, mDownloadStatus, mPlayButton, Client::setState(), UpdateDownloadStatus::UPDATE_COMPLETE, UpdateDownloadStatus::UPDATE_ERROR, and UpdateDownloadStatus::UPDATE_IDLE.

337 {
338  const InputActionT actionId = event.getActionId();
339  if (actionId == InputAction::GUI_CANCEL)
340  {
342  if (client->getState() != State::GAME)
344  else
345  deleteSelf();
346  }
347  else if (actionId == InputAction::GUI_SELECT ||
348  actionId == InputAction::GUI_SELECT2)
349  {
353  {
355  }
356  else
357  {
359  }
360  }
361 }
void action(const ActionEvent &event)
void setState(const StateT state)
Definition: client.h:65
const std::string & getActionEventId() const
Definition: widget.h:604
Client * client
Definition: client.cpp:117
UpdateDownloadStatusT mDownloadStatus
Button * mPlayButton
InputAction ::T InputActionT
Definition: inputaction.h:715
Button * mCancelButton
StateT getState() const
Definition: client.h:68

◆ loadDirMods()

void UpdaterWindow::loadDirMods ( const std::string &  dir)
static

Definition at line 1170 of file updaterwindow.cpp.

References Append_false, FOR_EACH, ModDB::getAll(), ModInfo::getLocalDir(), ConfigurationObject::getValue(), ModDB::load(), VirtFs::mountDir(), pathJoin(), serverConfig, and splitToStringVector().

Referenced by loadMods(), and Client::stateSwitchLogin1().

1171 {
1172  ModDB::load();
1173  const ModInfos &mods = ModDB::getAll();
1174 
1175  std::string modsString = serverConfig.getValue("mods", "");
1176  StringVect modsList;
1177  splitToStringVector(modsList, modsString, '|');
1178  FOR_EACH (StringVectCIter, it, modsList)
1179  {
1180  const std::string &name = *it;
1181  const ModInfoCIterator modIt = mods.find(name);
1182  if (modIt == mods.end())
1183  continue;
1184  const ModInfo *const mod = (*modIt).second;
1185  if (mod != nullptr)
1186  {
1187  const std::string &localDir = mod->getLocalDir();
1188  if (!localDir.empty())
1189  {
1190  VirtFs::mountDir(pathJoin(dir, localDir),
1191  Append_false);
1192  }
1193  }
1194  }
1195 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
StringVect::const_iterator StringVectCIter
Definition: stringvector.h:30
void splitToStringVector(StringVect &tokens, const std::string &text, const char separator)
bool mountDir(std::string newDir, const Append append)
Definition: fs.cpp:392
std::string pathJoin(std::string str1, const std::string &str2)
const ModInfos & getAll()
Definition: moddb.cpp:115
std::vector< std::string > StringVect
Definition: stringvector.h:28
Configuration serverConfig
const std::string & getLocalDir() const
Definition: modinfo.h:57
void load()
Definition: moddb.cpp:41
ModInfos::const_iterator ModInfoCIterator
Definition: modinfo.h:69
const bool Append_false
Definition: append.h:29
std::string getValue(const std::string &key, const std::string &deflt) const
std::map< std::string, ModInfo * > ModInfos
Definition: modinfo.h:67

◆ loadFile()

void UpdaterWindow::loadFile ( std::string  file)

Definition at line 1095 of file updaterwindow.cpp.

References StaticBrowserBox::addRow(), StaticBrowserBox::clearRows(), Files::loadTextFileLocal(), mBrowserBox, mUpdatesDir, Catch::trim(), and StaticBrowserBox::updateHeight().

1096 {
1098  trim(file);
1099 
1100  StringVect lines;
1101  Files::loadTextFileLocal(mUpdatesDir + "/local/help/news.txt", lines);
1102 
1103  for (size_t i = 0, sz = lines.size(); i < sz; ++i)
1104  mBrowserBox->addRow(lines[i], false);
1106 }
std::string mUpdatesDir
bool loadTextFileLocal(const std::string &fileName, StringVect &lines)
Definition: files.cpp:228
StaticBrowserBox * mBrowserBox
std::vector< std::string > StringVect
Definition: stringvector.h:28
std::string trim(std::string const &str)
void addRow(const std::string &row, const bool atTop)

◆ loadLocalUpdates()

void UpdaterWindow::loadLocalUpdates ( const std::string &  dir)
static

Definition at line 687 of file updaterwindow.cpp.

References addUpdateFile(), Append_false, CAST_U32, UpdateFile::group, loadManaPlusUpdates(), loadMods(), loadTxtFile(), loadXMLFile(), Logger::log(), logger, UpdateFile::name, pathJoin(), txtUpdateFile(), and xmlUpdateFile().

Referenced by Client::stateSwitchLogin1().

688 {
689  STD_VECTOR<UpdateFile> updateFiles = loadXMLFile(
690  pathJoin(dir, xmlUpdateFile),
691  false);
692 
693  if (updateFiles.empty())
694  {
695  logger->log("Warning this server does not have a"
696  " %s file falling back to %s", xmlUpdateFile.c_str(),
697  txtUpdateFile.c_str());
698  updateFiles = loadTxtFile(pathJoin(dir,
699  txtUpdateFile));
700  }
701 
702  const std::string fixPath = dir + "/fix";
703  for (unsigned int updateIndex = 0,
704  fsz = CAST_U32(updateFiles.size());
705  updateIndex < fsz;
706  updateIndex++)
707  {
708  const UpdateFile &file = updateFiles[updateIndex];
709  if (!file.group.empty())
710  continue;
712  fixPath,
713  file.name,
714  Append_false);
715  }
716  loadManaPlusUpdates(dir);
717  loadMods(dir, updateFiles);
718 }
#define CAST_U32
Definition: cast.h:30
std::string pathJoin(std::string str1, const std::string &str2)
static void addUpdateFile(const std::string &path, const std::string &fixPath, const std::string &file, const Append append)
std::string group
Definition: updatefile.h:49
const std::string xmlUpdateFile("resources.xml")
static std::vector< UpdateFile > loadXMLFile(const std::string &fileName, const bool loadMods)
Logger * logger
Definition: logger.cpp:88
static void loadManaPlusUpdates(const std::string &dir)
static std::vector< UpdateFile > loadTxtFile(const std::string &fileName)
const bool Append_false
Definition: append.h:29
const std::string txtUpdateFile("resources2.txt")
static void loadMods(const std::string &dir, const std::vector< UpdateFile > &updateFiles)
void log(const char *const log_text,...)
Definition: logger.cpp:264
std::string name
Definition: updatefile.h:45

◆ loadManaPlusUpdates()

void UpdaterWindow::loadManaPlusUpdates ( const std::string &  dir)
static

Definition at line 745 of file updaterwindow.cpp.

References Append_false, CAST_U32, fileName, UpdateFile::group, loadXMLFile(), VirtFs::mountZip(), UpdateFile::name, pathJoin(), strStartWith(), and xmlUpdateFile().

Referenced by loadLocalUpdates(), and loadUpdates().

746 {
747  std::string fixPath = dir + "/fix";
748  STD_VECTOR<UpdateFile> updateFiles = loadXMLFile(
749  pathJoin(fixPath, xmlUpdateFile),
750  false);
751 
752  for (unsigned int updateIndex = 0,
753  fsz = CAST_U32(updateFiles.size());
754  updateIndex < fsz;
755  updateIndex++)
756  {
757  const UpdateFile &file = updateFiles[updateIndex];
758  if (!file.group.empty())
759  continue;
760  const std::string name = file.name;
761  if (strStartWith(name, "manaplus_"))
762  {
763  struct stat statbuf;
764  std::string fileName = pathJoin(fixPath,
765  name);
766  if (stat(fileName.c_str(), &statbuf) == 0)
767  {
768  VirtFs::mountZip(fileName,
769  Append_false);
770  }
771  }
772  }
773 }
#define CAST_U32
Definition: cast.h:30
bool strStartWith(const std::string &str1, const std::string &str2)
std::string fileName
Definition: testmain.cpp:38
std::string pathJoin(std::string str1, const std::string &str2)
std::string group
Definition: updatefile.h:49
const std::string xmlUpdateFile("resources.xml")
static std::vector< UpdateFile > loadXMLFile(const std::string &fileName, const bool loadMods)
const bool Append_false
Definition: append.h:29
bool mountZip(std::string newDir, const Append append)
Definition: fs.cpp:589
std::string name
Definition: updatefile.h:45

◆ loadMods()

void UpdaterWindow::loadMods ( const std::string &  dir,
const std::vector< UpdateFile > &  updateFiles 
)
static

Definition at line 1108 of file updaterwindow.cpp.

References addUpdateFile(), Append_false, CAST_U32, fileName, ConfigurationObject::getValue(), UpdateFile::group, ModDB::load(), loadDirMods(), loadXMLFile(), VirtFs::mountZip(), UpdateFile::name, pathJoin(), serverConfig, splitToStringSet(), strStartWith(), and xmlUpdateFile().

Referenced by loadLocalUpdates(), and loadUpdates().

1110 {
1111  ModDB::load();
1112  std::string modsString = serverConfig.getValue("mods", "");
1113  std::set<std::string> modsList;
1114  splitToStringSet(modsList, modsString, '|');
1115 
1116  const std::string fixPath = dir + "/fix";
1117  for (unsigned int updateIndex = 0,
1118  fsz = CAST_U32(updateFiles.size());
1119  updateIndex < fsz;
1120  updateIndex ++)
1121  {
1122  const UpdateFile &file = updateFiles[updateIndex];
1123  if (file.group.empty())
1124  continue;
1125  const std::set<std::string>::const_iterator
1126  it = modsList.find(file.group);
1127  if (it != modsList.end())
1128  {
1130  fixPath,
1131  file.name,
1132  Append_false);
1133  }
1134  }
1135 
1136  STD_VECTOR<UpdateFile> updateFiles2 = loadXMLFile(
1137  pathJoin(fixPath, xmlUpdateFile),
1138  true);
1139 
1140  for (unsigned int updateIndex = 0,
1141  fsz = CAST_U32(updateFiles2.size());
1142  updateIndex < fsz;
1143  updateIndex++)
1144  {
1145  const UpdateFile &file = updateFiles2[updateIndex];
1146  if (file.group.empty())
1147  continue;
1148  std::string name = file.name;
1149  if (strStartWith(name, "manaplus_"))
1150  {
1151  const std::set<std::string>::const_iterator
1152  it = modsList.find(file.group);
1153  if (it != modsList.end())
1154  {
1155  struct stat statbuf;
1156  std::string fileName = pathJoin(fixPath,
1157  name);
1158  if (stat(fileName.c_str(), &statbuf) == 0)
1159  {
1160  VirtFs::mountZip(fileName,
1161  Append_false);
1162  }
1163  }
1164  }
1165  }
1166 
1167  loadDirMods(dir + "/local/");
1168 }
#define CAST_U32
Definition: cast.h:30
bool strStartWith(const std::string &str1, const std::string &str2)
void splitToStringSet(std::set< std::string > &tokens, const std::string &text, const char separator)
std::string fileName
Definition: testmain.cpp:38
std::string pathJoin(std::string str1, const std::string &str2)
static void addUpdateFile(const std::string &path, const std::string &fixPath, const std::string &file, const Append append)
std::string group
Definition: updatefile.h:49
const std::string xmlUpdateFile("resources.xml")
static void loadDirMods(const std::string &dir)
static std::vector< UpdateFile > loadXMLFile(const std::string &fileName, const bool loadMods)
Configuration serverConfig
void load()
Definition: moddb.cpp:41
const bool Append_false
Definition: append.h:29
std::string getValue(const std::string &key, const std::string &deflt) const
bool mountZip(std::string newDir, const Append append)
Definition: fs.cpp:589
std::string name
Definition: updatefile.h:45

◆ loadNews()

void UpdaterWindow::loadNews ( )

Loads and display news. Assumes the news file contents have been loaded into the memory buffer.

Definition at line 363 of file updaterwindow.cpp.

References _, StaticBrowserBox::addRow(), StaticBrowserBox::clearRows(), Logger::log1(), logger, mBrowserBox, mDownloadedBytes, mkdir_r(), mMemoryBuffer, mScrollArea, mUpdatesDir, ScrollArea::setVerticalScrollAmount(), and StaticBrowserBox::updateHeight().

Referenced by logic().

364 {
365  if (mMemoryBuffer == nullptr)
366  {
367  logger->log1("Couldn't load news");
368  return;
369  }
370 
371  // Reallocate and include terminating 0 character
372  mMemoryBuffer = static_cast<char*>(realloc(
374  if (mMemoryBuffer == nullptr)
375  {
376  logger->log1("Couldn't load news");
377  return;
378  }
381 
382  std::string newsName = mUpdatesDir + "/local/help/news.txt";
383  mkdir_r((mUpdatesDir + "/local/help/").c_str());
384  bool firstLine(true);
385  std::ofstream file;
386  std::stringstream ss(mMemoryBuffer);
387  std::string line;
388  file.open(newsName.c_str(), std::ios::out);
389  int cnt = 0;
390  const int maxNews = 50;
391  while (std::getline(ss, line, '\n'))
392  {
393  cnt ++;
394  if (firstLine)
395  {
396  firstLine = false;
397  const size_t i = line.find("##9 Latest client version: ##6");
398  if (i == 0u)
399  continue;
400 
401  if (file.is_open())
402  file << line << std::endl;
403  if (cnt < maxNews)
404  mBrowserBox->addRow(line, false);
405  }
406  else
407  {
408  if (file.is_open())
409  file << line << std::endl;
410  if (cnt < maxNews)
411  mBrowserBox->addRow(line, false);
412  }
413  }
414 
415  file.close();
416  if (cnt > maxNews)
417  {
418  mBrowserBox->addRow("", false);
419  // TRANSLATORS: updater window checkbox
420  mBrowserBox->addRow("news", _("Show all news (can be slow)"));
421  mBrowserBox->addRow("", false);
422  }
423  // Free the memory buffer now that we don't need it anymore
424  free(mMemoryBuffer);
425  mMemoryBuffer = nullptr;
426  mDownloadedBytes = 0;
427 
430 }
#define _(s)
Definition: gettext.h:34
std::string mUpdatesDir
void log1(const char *const log_text)
Definition: logger.cpp:233
int mkdir_r(const char *const pathname)
Create a directory, making leading components first if necessary.
Definition: mkdir.cpp:108
StaticBrowserBox * mBrowserBox
void setVerticalScrollAmount(const int vScroll)
Logger * logger
Definition: logger.cpp:88
ScrollArea * mScrollArea
char * mMemoryBuffer
void addRow(const std::string &row, const bool atTop)

◆ loadPatch()

void UpdaterWindow::loadPatch ( )

Definition at line 432 of file updaterwindow.cpp.

References StaticBrowserBox::addRow(), branding, CHECK_VERSION, Configuration::getStringValue(), Logger::log1(), logger, mBrowserBox, mDownloadedBytes, mMemoryBuffer, mScrollArea, serverVersion, ScrollArea::setVerticalScrollAmount(), strprintf(), StaticBrowserBox::updateHeight(), Actions::url(), and ServerCommandType::version.

Referenced by logic().

433 {
434  if (mMemoryBuffer == nullptr)
435  {
436  logger->log1("Couldn't load patch");
437  return;
438  }
439 
440  // Reallocate and include terminating 0 character
441  mMemoryBuffer = static_cast<char*>(
442  realloc(mMemoryBuffer, mDownloadedBytes + 1));
443  if (mMemoryBuffer == nullptr)
444  {
445  logger->log1("Couldn't load patch");
446  return;
447  }
449 
450  std::string version;
451 
452  // Tokenize and add each line separately
453  char *line = strtok(mMemoryBuffer, "\n");
454  if (line != nullptr)
455  {
456  version = line;
457  if (serverVersion < 1)
458  {
459  line = strtok(nullptr, "\n");
460  if (line != nullptr)
461  {
462  mBrowserBox->addRow(strprintf("##9 Latest client version: "
463  "##6ManaPlus %s##0", line), true);
464  }
465  }
466  if (version > CHECK_VERSION)
467  {
468  mBrowserBox->addRow("", true);
469 #if defined(ANDROID)
470  const std::string url = "androidDownloadUrl";
471  const std::string text = "androidDownloadUrl";
472 #elif defined(WIN32)
473  const std::string url = "windowsDownloadUrl";
474  const std::string text = "windowsDownloadUrl";
475 #else // defined(ANDROID)
476 
477  const std::string url = "otherDownloadUrl";
478  const std::string text = "otherDownloadUrl";
479 #endif // defined(ANDROID)
480 
481  mBrowserBox->addRow(std::string(" ##1[@@").append(
482  branding.getStringValue(url)).append("|").append(
483  branding.getStringValue(text)).append("@@]"), true);
484  mBrowserBox->addRow("##1You can download it from", true);
485  mBrowserBox->addRow("##1ManaPlus updated.", true);
486  }
487  else
488  {
489  mBrowserBox->addRow("You have latest client version.", true);
490  }
491  }
492 
493  // Free the memory buffer now that we don't need it anymore
494  free(mMemoryBuffer);
495  mMemoryBuffer = nullptr;
496  mDownloadedBytes = 0;
497 
500 }
Configuration branding
std::string getStringValue(const std::string &key) const
void log1(const char *const log_text)
Definition: logger.cpp:233
int serverVersion
Definition: client.cpp:123
StaticBrowserBox * mBrowserBox
void setVerticalScrollAmount(const int vScroll)
Logger * logger
Definition: logger.cpp:88
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
#define CHECK_VERSION
Definition: main.h:44
ScrollArea * mScrollArea
char * mMemoryBuffer
bool url(InputEvent &event)
Definition: commands.cpp:63
void addRow(const std::string &row, const bool atTop)

◆ loadUpdates()

void UpdaterWindow::loadUpdates ( )
private

Loads the updates this window has gotten into the resource manager

Definition at line 655 of file updaterwindow.cpp.

References addUpdateFile(), Append_false, CAST_U32, UpdateFile::group, loadManaPlusUpdates(), loadMods(), loadTxtFile(), loadXMLFile(), Logger::log(), logger, mUpdateFiles, mUpdateIndex, mUpdatesDir, UpdateFile::name, pathJoin(), txtUpdateFile(), and xmlUpdateFile().

Referenced by ~UpdaterWindow().

656 {
657  if (mUpdateFiles.empty())
658  { // updates not downloaded
660  false);
661  if (mUpdateFiles.empty())
662  {
663  logger->log("Warning this server does not have a"
664  " %s file falling back to %s", xmlUpdateFile.c_str(),
665  txtUpdateFile.c_str());
667  txtUpdateFile));
668  }
669  }
670 
671  std::string fixPath = mUpdatesDir + "/fix";
672  const unsigned sz = CAST_U32(mUpdateFiles.size());
673  for (mUpdateIndex = 0; mUpdateIndex < sz; mUpdateIndex++)
674  {
675  const UpdateFile &file = mUpdateFiles[mUpdateIndex];
676  if (!file.group.empty())
677  continue;
679  fixPath,
680  file.name,
681  Append_false);
682  }
685 }
#define CAST_U32
Definition: cast.h:30
std::string mUpdatesDir
std::string pathJoin(std::string str1, const std::string &str2)
static void addUpdateFile(const std::string &path, const std::string &fixPath, const std::string &file, const Append append)
std::string group
Definition: updatefile.h:49
const std::string xmlUpdateFile("resources.xml")
unsigned int mUpdateIndex
static std::vector< UpdateFile > loadXMLFile(const std::string &fileName, const bool loadMods)
Logger * logger
Definition: logger.cpp:88
static void loadManaPlusUpdates(const std::string &dir)
static std::vector< UpdateFile > loadTxtFile(const std::string &fileName)
const bool Append_false
Definition: append.h:29
const std::string txtUpdateFile("resources2.txt")
static void loadMods(const std::string &dir, const std::vector< UpdateFile > &updateFiles)
void log(const char *const log_text,...)
Definition: logger.cpp:264
std::vector< UpdateFile > mUpdateFiles
std::string name
Definition: updatefile.h:45

◆ logic()

void UpdaterWindow::logic ( )
virtual

Called for all widgets in the gui each time Gui::logic is called. You can do logic stuff here like playing an animation.

See also
Gui::logic

Reimplemented from BasicContainer.

Definition at line 828 of file updaterwindow.cpp.

References _, StaticBrowserBox::addRow(), Label::adjustSize(), BLOCK_END, BLOCK_START, CAST_S32, CAST_SIZE, CAST_U32, config, download(), enable(), Configuration::getBoolValue(), Label::getCaption(), Net::Download::getError(), ScrollArea::getVerticalMaxScroll(), UpdateFile::hash, loadNews(), loadPatch(), loadTxtFile(), loadXMLFile(), Logger::log(), logger, ScrollArea::logic(), mBrowserBox, mCurrentChecksum, mCurrentFile, mDownload, mDownloadComplete, mDownloadMutex, mDownloadProgress, mDownloadStatus, mLabel, mNewLabelCaption, mProgressBar, mScrollArea, mSkipPatches, mStoreInMemory, mTempUpdateFiles, mUpdateFiles, mUpdateHost, mUpdateIndex, mUpdateIndexOffset, mUpdatesDir, mUpdatesDirReal, mUpdateServerPath, mValidateXml, UpdateFile::name, pathJoin(), Label::setCaption(), setLabel(), ProgressBar::setProgress(), ProgressBar::setText(), ScrollArea::setVerticalScrollAmount(), strprintf(), Catch::toString(), txtUpdateFile(), UpdateFile::type, UpdateDownloadStatus::UPDATE_COMPLETE, UpdateDownloadStatus::UPDATE_ERROR, UpdateDownloadStatus::UPDATE_IDLE, UpdateDownloadStatus::UPDATE_LIST, UpdateDownloadStatus::UPDATE_LIST2, UpdateDownloadStatus::UPDATE_NEWS, UpdateDownloadStatus::UPDATE_PATCH, UpdateDownloadStatus::UPDATE_RESOURCES, UpdateDownloadStatus::UPDATE_RESOURCES2, StaticBrowserBox::updateHeight(), updateServer2(), validateFile(), and xmlUpdateFile().

829 {
830  BLOCK_START("UpdaterWindow::logic")
831  // Update Scroll logic
832  mScrollArea->logic();
833 
834  // Synchronize label caption when necessary
835  {
837 
839  {
841  mLabel->adjustSize();
842  }
843 
845  if (!mUpdateFiles.empty() &&
847  {
850  mUpdateFiles.size()) + CAST_S32(
851  mTempUpdateFiles.size()) + 1));
852  }
853  else
854  {
855  mProgressBar->setText("");
856  }
857  }
858 
859  switch (mDownloadStatus)
860  {
862  mBrowserBox->addRow("", false);
863  // TRANSLATORS: update message
864  mBrowserBox->addRow(_("##1 The update process is incomplete."),
865  false);
866  // TRANSLATORS: Continues "The update process is incomplete.".
867  mBrowserBox->addRow(_("##1 It is strongly recommended that"),
868  false);
869  // TRANSLATORS: Begins "It is strongly recommended that".
870  mBrowserBox->addRow(_("##1 you try again later."),
871  false);
872  if (mDownload != nullptr)
873  mBrowserBox->addRow(mDownload->getError(), false);
878  break;
880  if (mDownloadComplete)
881  {
882  // Parse current memory buffer as news and dispose of the data
883  loadNews();
884 
885  mValidateXml = true;
887  mStoreInMemory = false;
889  download(); // download() changes mDownloadComplete to false
890  }
891  break;
893  if (mDownloadComplete)
894  {
895  // Parse current memory buffer as news and dispose of the data
896  loadPatch();
897 
899  mUpdatesDir = pathJoin(mUpdatesDir, "fix");
901  mValidateXml = true;
902  mStoreInMemory = false;
904  download();
905  }
906  break;
907 
909  if (mDownloadComplete)
910  {
912  {
915  true);
916 
917  if (mUpdateFiles.empty())
918  {
919  logger->log("Warning this server does not have a %s"
920  " file falling back to %s",
921  xmlUpdateFile.c_str(),
922  txtUpdateFile.c_str());
923 
924  // If the resources.xml file fails,
925  // fall back onto a older version
927  mValidateXml = false;
928  mStoreInMemory = false;
930  download();
931  break;
932  }
933  }
934  else if (mCurrentFile == txtUpdateFile)
935  {
936  mValidateXml = true;
938  txtUpdateFile));
939  }
940  mStoreInMemory = false;
942  }
943  break;
945  if (mDownloadComplete)
946  {
947  if (CAST_SIZE(mUpdateIndex) < mUpdateFiles.size())
948  {
950  if (thisFile.type == "music"
951  && !config.getBoolValue("download-music"))
952  {
953  mUpdateIndex++;
954  break;
955  }
956  mCurrentFile = thisFile.name;
957  std::string checksum;
958  checksum = thisFile.hash;
959  std::stringstream ss(checksum);
960  ss >> std::hex >> mCurrentChecksum;
961 
962  std::ifstream temp(pathJoin(mUpdatesDir,
963  mCurrentFile).c_str());
964 
965  mValidateXml = false;
966  if (!temp.is_open() || !validateFile(pathJoin(
968  mCurrentChecksum))
969  {
970  temp.close();
971  download();
972  }
973  else
974  {
975  temp.close();
976  logger->log("%s already here", mCurrentFile.c_str());
977  }
978  mUpdateIndex++;
979  }
980  else
981  {
982  if (!mSkipPatches)
983  {
984  // Download of updates completed
985  mCurrentFile = "latest.txt";
986  mStoreInMemory = true;
988  mValidateXml = false;
989  download(); // download() changes
990  // mDownloadComplete to false
991  }
992  else
993  {
996  }
997  }
998  }
999  break;
1001  if (mDownloadComplete)
1002  {
1003  if (mCurrentFile == xmlUpdateFile)
1004  {
1007  true);
1008  }
1010  mUpdateIndex = 0;
1011  mValidateXml = true;
1012  mStoreInMemory = false;
1014  download();
1015  }
1016  break;
1018  if (mDownloadComplete)
1019  {
1020  mValidateXml = false;
1021  if (CAST_SIZE(mUpdateIndex)
1022  < mTempUpdateFiles.size())
1023  {
1024  const UpdateFile thisFile = mTempUpdateFiles[mUpdateIndex];
1025  mCurrentFile = thisFile.name;
1026  std::string checksum;
1027  checksum = thisFile.hash;
1028  std::stringstream ss(checksum);
1029  ss >> std::hex >> mCurrentChecksum;
1030 
1031  std::ifstream temp((pathJoin(mUpdatesDir,
1032  mCurrentFile)).c_str());
1033 
1034  if (!temp.is_open() || !validateFile(pathJoin(
1036  mCurrentChecksum))
1037  {
1038  temp.close();
1039  download();
1040  }
1041  else
1042  {
1043  temp.close();
1044  logger->log("%s already here", mCurrentFile.c_str());
1045  }
1046  mUpdateIndex++;
1047  }
1048  else
1049  {
1052  }
1053  }
1054  break;
1057  enable();
1058  // TRANSLATORS: updater window label
1059  setLabel(_("Completed"));
1061  break;
1063  break;
1064  default:
1065  logger->log("UpdaterWindow::logic unknown status: "
1067  break;
1068  }
1069  BLOCK_END("UpdaterWindow::logic")
1070 }
#define CAST_U32
Definition: cast.h:30
#define _(s)
Definition: gettext.h:34
std::string mUpdatesDir
static bool validateFile(const std::string &filePath, const unsigned long hash)
std::string mUpdateServerPath
std::string pathJoin(std::string str1, const std::string &str2)
void setLabel(const std::string &)
#define BLOCK_START(name)
Definition: perfomance.h:78
std::vector< UpdateFile > mTempUpdateFiles
Configuration config
const std::string xmlUpdateFile("resources.xml")
unsigned int mUpdateIndex
StaticBrowserBox * mBrowserBox
static std::vector< UpdateFile > loadXMLFile(const std::string &fileName, const bool loadMods)
#define BLOCK_END(name)
Definition: perfomance.h:79
void setVerticalScrollAmount(const int vScroll)
UpdateDownloadStatusT mDownloadStatus
Mutex mDownloadMutex
unsigned long mCurrentChecksum
int getVerticalMaxScroll()
Logger * logger
Definition: logger.cpp:88
static std::vector< UpdateFile > loadTxtFile(const std::string &fileName)
bool getBoolValue(const std::string &key) const
std::string mUpdatesDirReal
#define CAST_S32
Definition: cast.h:29
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
void setCaption(const std::string &caption)
Definition: label.cpp:261
const char * getError() const
Definition: download.cpp:217
float mDownloadProgress
std::string hash
Definition: updatefile.h:46
ProgressBar * mProgressBar
void setText(const std::string &str)
ScrollArea * mScrollArea
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
std::string type
Definition: updatefile.h:47
bool mDownloadComplete
const std::string txtUpdateFile("resources2.txt")
unsigned int mUpdateIndexOffset
#define CAST_SIZE
Definition: cast.h:33
void log(const char *const log_text,...)
Definition: logger.cpp:264
std::string mUpdateHost
std::vector< UpdateFile > mUpdateFiles
const std::string updateServer2("http://download.manaplus.org/manaplus/updates/")
void adjustSize()
Definition: label.cpp:197
std::string mCurrentFile
std::string mNewLabelCaption
void setProgress(const float progress)
std::string name
Definition: updatefile.h:45
void addRow(const std::string &row, const bool atTop)
const std::string & getCaption() const
Definition: label.h:132
Net::Download * mDownload

◆ memoryWrite()

size_t UpdaterWindow::memoryWrite ( void *  ptr,
size_t  size,
size_t  nmemb,
void *  stream 
)
staticprivate

A libcurl callback for writing to memory.

Definition at line 562 of file updaterwindow.cpp.

References CAST_S32, CAST_SIZE, mDownloadedBytes, and mMemoryBuffer.

Referenced by download().

564 {
565  UpdaterWindow *const uw = reinterpret_cast<UpdaterWindow *>(stream);
566  const size_t totalMem = size * nmemb;
567  if (uw == nullptr)
568  return 0;
569  uw->mMemoryBuffer = static_cast<char*>(realloc(uw->mMemoryBuffer,
570  CAST_SIZE(uw->mDownloadedBytes) + totalMem));
571  if (uw->mMemoryBuffer != nullptr)
572  {
573  memcpy(&(uw->mMemoryBuffer[uw->mDownloadedBytes]), ptr, totalMem);
574  uw->mDownloadedBytes += CAST_S32(totalMem);
575  }
576 
577  return totalMem;
578 }
#define CAST_S32
Definition: cast.h:29
char * mMemoryBuffer
#define CAST_SIZE
Definition: cast.h:33

◆ postInit()

void UpdaterWindow::postInit ( )
virtual

Reimplemented from Window.

Definition at line 256 of file updaterwindow.cpp.

References download(), mCancelButton, mUpdateServerPath, Window::postInit(), removeProtocol(), Widget::requestFocus(), Window::setVisible(), and Visible_true.

257 {
262 
263  download();
264 }
std::string & removeProtocol(std::string &url)
const bool Visible_true
Definition: visible.h:29
std::string mUpdateServerPath
virtual void requestFocus()
Definition: widget.cpp:203
Button * mCancelButton
virtual void setVisible(Visible visible)
Definition: window.cpp:773
void postInit()
Definition: window.cpp:248

◆ removeUpdateFile()

void UpdaterWindow::removeUpdateFile ( const std::string &  path,
const std::string &  fixPath,
const std::string &  filerestrict 
)
static

Definition at line 817 of file updaterwindow.cpp.

References pathJoin(), and VirtFs::unmountZip().

Referenced by unloadUpdates().

820 {
821  VirtFs::unmountZip(pathJoin(path, file));
822  const std::string fixFile = pathJoin(fixPath, file);
823  struct stat statbuf;
824  if (stat(fixFile.c_str(), &statbuf) == 0)
825  VirtFs::unmountZip(fixFile);
826 }
std::string pathJoin(std::string str1, const std::string &str2)
bool unmountZip(std::string oldDir)
Definition: fs.cpp:674

◆ setLabel()

void UpdaterWindow::setLabel ( const std::string &  str)

Set's label above progress

Definition at line 288 of file updaterwindow.cpp.

References mDownloadMutex, mNewLabelCaption, and ServerCommandType::str.

Referenced by download(), logic(), and updateProgress().

289 {
290  // Do delayed label text update, since Guichan isn't thread-safe
293 }
Mutex mDownloadMutex
std::string mNewLabelCaption

◆ setProgress()

void UpdaterWindow::setProgress ( const float  p)

Set's progress bar status

Definition at line 281 of file updaterwindow.cpp.

References mDownloadMutex, and mDownloadProgress.

Referenced by updateProgress().

282 {
283  // Do delayed progress bar update, since Guichan isn't thread-safe
285  mDownloadProgress = p;
286 }
Mutex mDownloadMutex
float mDownloadProgress

◆ unloadManaPlusUpdates()

void UpdaterWindow::unloadManaPlusUpdates ( const std::string &  dir)
static

Definition at line 775 of file updaterwindow.cpp.

References CAST_U32, loadXMLFile(), pathJoin(), strStartWith(), VirtFs::unmountZip(), and xmlUpdateFile().

Referenced by unloadUpdates().

776 {
777  const std::string fixPath = dir + "/fix";
778  const STD_VECTOR<UpdateFile> updateFiles = loadXMLFile(
779  pathJoin(fixPath, xmlUpdateFile),
780  true);
781 
782  for (unsigned int updateIndex = 0,
783  fsz = CAST_U32(updateFiles.size());
784  updateIndex < fsz;
785  updateIndex++)
786  {
787  std::string name = updateFiles[updateIndex].name;
788  if (strStartWith(name, "manaplus_"))
789  {
790  struct stat statbuf;
791  const std::string file = pathJoin(
792  fixPath, name);
793  if (stat(file.c_str(), &statbuf) == 0)
794  VirtFs::unmountZip(file);
795  }
796  }
797 }
#define CAST_U32
Definition: cast.h:30
bool strStartWith(const std::string &str1, const std::string &str2)
std::string pathJoin(std::string str1, const std::string &str2)
const std::string xmlUpdateFile("resources.xml")
static std::vector< UpdateFile > loadXMLFile(const std::string &fileName, const bool loadMods)
bool unmountZip(std::string oldDir)
Definition: fs.cpp:674

◆ unloadMods()

void UpdaterWindow::unloadMods ( const std::string &  dir)
static

Definition at line 1197 of file updaterwindow.cpp.

References FOR_EACH, ModDB::getAll(), ModInfo::getLocalDir(), ConfigurationObject::getValue(), pathJoin(), serverConfig, splitToStringVector(), and VirtFs::unmountDir().

Referenced by Client::stateSwitchLogin1().

1198 {
1199  const ModInfos &mods = ModDB::getAll();
1200  std::string modsString = serverConfig.getValue("mods", "");
1201  StringVect modsList;
1202  splitToStringVector(modsList, modsString, '|');
1203  FOR_EACH (StringVectCIter, it, modsList)
1204  {
1205  const std::string &name = *it;
1206  const ModInfoCIterator modIt = mods.find(name);
1207  if (modIt == mods.end())
1208  continue;
1209  const ModInfo *const mod = (*modIt).second;
1210  if (mod != nullptr)
1211  {
1212  const std::string &localDir = mod->getLocalDir();
1213  if (!localDir.empty())
1214  VirtFs::unmountDir(pathJoin(dir, localDir));
1215  }
1216  }
1217 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
StringVect::const_iterator StringVectCIter
Definition: stringvector.h:30
void splitToStringVector(StringVect &tokens, const std::string &text, const char separator)
bool unmountDir(std::string oldDir)
Definition: fs.cpp:517
std::string pathJoin(std::string str1, const std::string &str2)
const ModInfos & getAll()
Definition: moddb.cpp:115
std::vector< std::string > StringVect
Definition: stringvector.h:28
Configuration serverConfig
const std::string & getLocalDir() const
Definition: modinfo.h:57
ModInfos::const_iterator ModInfoCIterator
Definition: modinfo.h:69
std::string getValue(const std::string &key, const std::string &deflt) const
std::map< std::string, ModInfo * > ModInfos
Definition: modinfo.h:67

◆ unloadUpdates()

void UpdaterWindow::unloadUpdates ( const std::string &  dir)
static

Definition at line 720 of file updaterwindow.cpp.

References CAST_U32, loadTxtFile(), loadXMLFile(), pathJoin(), removeUpdateFile(), txtUpdateFile(), unloadManaPlusUpdates(), and xmlUpdateFile().

Referenced by Client::stateSwitchLogin1(), and Client::unloadData().

721 {
722  STD_VECTOR<UpdateFile> updateFiles = loadXMLFile(
723  pathJoin(dir, xmlUpdateFile),
724  true);
725 
726  if (updateFiles.empty())
727  {
728  updateFiles = loadTxtFile(pathJoin(dir,
729  txtUpdateFile));
730  }
731 
732  const std::string fixPath = dir + "/fix";
733  for (unsigned int updateIndex = 0,
734  fsz = CAST_U32(updateFiles.size());
735  updateIndex < fsz;
736  updateIndex++)
737  {
739  fixPath,
740  updateFiles[updateIndex].name);
741  }
743 }
#define CAST_U32
Definition: cast.h:30
std::string pathJoin(std::string str1, const std::string &str2)
const std::string xmlUpdateFile("resources.xml")
static std::vector< UpdateFile > loadXMLFile(const std::string &fileName, const bool loadMods)
static void unloadManaPlusUpdates(const std::string &dir)
static std::vector< UpdateFile > loadTxtFile(const std::string &fileName)
static void removeUpdateFile(const std::string &path, const std::string &fixPath, const std::string &filerestrict)
const std::string txtUpdateFile("resources2.txt")

◆ updateProgress()

int UpdaterWindow::updateProgress ( void *  ptr,
const DownloadStatusT  status,
size_t  dt,
const size_t  dn 
)
staticprivate

A download callback for progress updates.

Definition at line 502 of file updaterwindow.cpp.

References DownloadStatus::Cancelled, CAST_S32, client, DownloadStatus::Complete, DownloadStatus::Error, State::GAME, Client::getState(), mCurrentFile, mDownloadComplete, mDownloadStatus, mMemoryBuffer, setLabel(), setProgress(), Catch::toString(), State::UPDATE, UpdateDownloadStatus::UPDATE_COMPLETE, UpdateDownloadStatus::UPDATE_ERROR, and UpdateDownloadStatus::UPDATE_NEWS.

Referenced by download().

506 {
507  UpdaterWindow *const uw = reinterpret_cast<UpdaterWindow *>(ptr);
508  if (uw == nullptr)
509  return -1;
510 
511  if (status == DownloadStatus::Complete)
512  {
513  uw->mDownloadComplete = true;
514  }
515  else if (status == DownloadStatus::Error ||
516  status == DownloadStatus::Cancelled)
517  {
520  { // ignoring error in last state (was UPDATE_PATCH)
522  uw->mDownloadComplete = true;
523  free(uw->mMemoryBuffer);
524  uw->mMemoryBuffer = nullptr;
525  }
526  else
527  {
529  }
530  }
531 
532  if (dt == 0u)
533  dt = 1;
534 
535  float progress = static_cast<float>(dn) /
536  static_cast<float>(dt);
537 
538  if (progress != progress)
539  progress = 0.0F; // check for NaN
540  if (progress < 0.0F)
541  progress = 0.0F; // no idea how this could ever happen,
542  // but why not check for it anyway.
543  if (progress > 1.0F)
544  progress = 1.0F;
545 
546  uw->setLabel(std::string(uw->mCurrentFile).append(" (")
547  .append(toString(CAST_S32(progress * 100))).append("%)"));
548 
549  uw->setProgress(progress);
550 
551  if ((client->getState() != State::UPDATE &&
552  client->getState() != State::GAME) ||
554  {
555  // If the action was canceled return an error code to stop the mThread
556  return -1;
557  }
558 
559  return 0;
560 }
void setLabel(const std::string &)
Client * client
Definition: client.cpp:117
UpdateDownloadStatusT mDownloadStatus
#define CAST_S32
Definition: cast.h:29
char * mMemoryBuffer
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
bool mDownloadComplete
StateT getState() const
Definition: client.h:68
std::string mCurrentFile
void setProgress(const float p)

◆ validateFile()

bool UpdaterWindow::validateFile ( const std::string &  filePath,
const unsigned long  hash 
)
staticprivate

Definition at line 1072 of file updaterwindow.cpp.

References Net::Download::fadler32().

Referenced by logic().

1074 {
1075  FILE *const file = fopen(filePath.c_str(), "rb");
1076  if (file == nullptr)
1077  return false;
1078 
1079  const unsigned long adler = Net::Download::fadler32(file);
1080  fclose(file);
1081  return adler == hash;
1082 }
static unsigned long fadler32(FILE *const file)
Definition: download.cpp:122

Field Documentation

◆ mBrowserBox

StaticBrowserBox* UpdaterWindow::mBrowserBox
private

Definition at line 214 of file updaterwindow.h.

Referenced by loadFile(), loadNews(), loadPatch(), logic(), and UpdaterWindow().

◆ mCancelButton

Button* UpdaterWindow::mCancelButton
private

Definition at line 211 of file updaterwindow.h.

Referenced by enable(), keyPressed(), postInit(), and UpdaterWindow().

◆ mCurrentChecksum

unsigned long UpdaterWindow::mCurrentChecksum
private

The Adler32 checksum of the file currently downloading.

Definition at line 193 of file updaterwindow.h.

Referenced by download(), and logic().

◆ mCurrentFile

std::string UpdaterWindow::mCurrentFile
private

The file currently downloading.

Definition at line 183 of file updaterwindow.h.

Referenced by download(), logic(), and updateProgress().

◆ mDownload

Net::Download* UpdaterWindow::mDownload
private

Download handle.

Definition at line 199 of file updaterwindow.h.

Referenced by action(), download(), logic(), and ~UpdaterWindow().

◆ mDownloadComplete

bool UpdaterWindow::mDownloadComplete
private

Flag that show if current download is complete.

Definition at line 237 of file updaterwindow.h.

Referenced by download(), logic(), and updateProgress().

◆ mDownloadedBytes

int UpdaterWindow::mDownloadedBytes
private

Byte count currently downloaded in mMemoryBuffer.

Definition at line 221 of file updaterwindow.h.

Referenced by loadNews(), loadPatch(), and memoryWrite().

◆ mDownloadMutex

Mutex UpdaterWindow::mDownloadMutex
private

Definition at line 190 of file updaterwindow.h.

Referenced by logic(), setLabel(), and setProgress().

◆ mDownloadProgress

float UpdaterWindow::mDownloadProgress
private

The new progress value to be set in the logic method.

Definition at line 172 of file updaterwindow.h.

Referenced by logic(), and setProgress().

◆ mDownloadStatus

UpdateDownloadStatusT UpdaterWindow::mDownloadStatus
private

Status of the current download.

Definition at line 218 of file updaterwindow.h.

Referenced by action(), download(), keyPressed(), logic(), and updateProgress().

◆ mItemLinkHandler

ItemLinkHandler* UpdaterWindow::mItemLinkHandler
private

Definition at line 209 of file updaterwindow.h.

Referenced by UpdaterWindow(), and ~UpdaterWindow().

◆ mLabel

Label* UpdaterWindow::mLabel
private

Definition at line 210 of file updaterwindow.h.

Referenced by logic(), and UpdaterWindow().

◆ mLoadUpdates

bool UpdaterWindow::mLoadUpdates
private

Tells ~UpdaterWindow() if it should load updates

Definition at line 243 of file updaterwindow.h.

Referenced by ~UpdaterWindow().

◆ mMemoryBuffer

char* UpdaterWindow::mMemoryBuffer
private

Buffer for files downloaded to memory.

Definition at line 196 of file updaterwindow.h.

Referenced by loadNews(), loadPatch(), memoryWrite(), updateProgress(), and ~UpdaterWindow().

◆ mNewLabelCaption

std::string UpdaterWindow::mNewLabelCaption
private

The new label caption to be set in the logic method.

Definition at line 186 of file updaterwindow.h.

Referenced by logic(), and setLabel().

◆ mPlayButton

Button* UpdaterWindow::mPlayButton
private

Definition at line 212 of file updaterwindow.h.

Referenced by enable(), keyPressed(), and UpdaterWindow().

◆ mProgressBar

ProgressBar* UpdaterWindow::mProgressBar
private

Definition at line 213 of file updaterwindow.h.

Referenced by logic(), and UpdaterWindow().

◆ mScrollArea

ScrollArea* UpdaterWindow::mScrollArea
private

Definition at line 215 of file updaterwindow.h.

Referenced by loadNews(), loadPatch(), logic(), and UpdaterWindow().

◆ mSkipPatches

bool UpdaterWindow::mSkipPatches
private

Definition at line 247 of file updaterwindow.h.

Referenced by logic(), and UpdaterWindow().

◆ mStoreInMemory

bool UpdaterWindow::mStoreInMemory
private

A flag to indicate whether to use a memory buffer or a regular file.

Definition at line 234 of file updaterwindow.h.

Referenced by download(), and logic().

◆ mTempUpdateFiles

std::vector<UpdateFile> UpdaterWindow::mTempUpdateFiles
private

List of temp files to download.

Definition at line 205 of file updaterwindow.h.

Referenced by logic().

◆ mUpdateFiles

std::vector<UpdateFile> UpdaterWindow::mUpdateFiles
private

List of files to download.

Definition at line 202 of file updaterwindow.h.

Referenced by loadUpdates(), and logic().

◆ mUpdateHost

std::string UpdaterWindow::mUpdateHost
private

Host where we get the updated files.

Definition at line 175 of file updaterwindow.h.

Referenced by download(), logic(), and UpdaterWindow().

◆ mUpdateIndex

unsigned int UpdaterWindow::mUpdateIndex
private

Index of the file to be downloaded.

Definition at line 224 of file updaterwindow.h.

Referenced by loadUpdates(), and logic().

◆ mUpdateIndexOffset

unsigned int UpdaterWindow::mUpdateIndexOffset
private

Index offset for disaplay downloaded file.

Definition at line 227 of file updaterwindow.h.

Referenced by logic().

◆ mUpdatesDir

std::string UpdaterWindow::mUpdatesDir
private

Place where the updates are stored (absolute path).

Definition at line 178 of file updaterwindow.h.

Referenced by download(), loadFile(), loadNews(), loadUpdates(), and logic().

◆ mUpdatesDirReal

std::string UpdaterWindow::mUpdatesDirReal
private

Definition at line 180 of file updaterwindow.h.

Referenced by logic().

◆ mUpdateServerPath

std::string UpdaterWindow::mUpdateServerPath
private

Definition at line 207 of file updaterwindow.h.

Referenced by download(), logic(), and postInit().

◆ mUpdateType

UpdateTypeT UpdaterWindow::mUpdateType
private

Definition at line 229 of file updaterwindow.h.

Referenced by enable().

◆ mUserCancel

bool UpdaterWindow::mUserCancel
private

Flag that show if the user has canceled the update.

Definition at line 240 of file updaterwindow.h.

Referenced by action().

◆ mValidateXml

bool UpdaterWindow::mValidateXml
private

Definition at line 245 of file updaterwindow.h.

Referenced by download(), and logic().


The documentation for this class was generated from the following files: