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 60 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 170 of file updaterwindow.cpp.

173  :
174  // TRANSLATORS: updater window name
175  Window(_("Updating..."), Modal_false, nullptr, "update.xml"),
176  ActionListener(),
177  KeyListener(),
178  mDownloadProgress(0.0F),
179  mUpdateHost(updateHost),
180  mUpdatesDir(updatesDir),
181  mUpdatesDirReal(updatesDir),
182  mCurrentFile("news.txt"),
184  mDownloadMutex(),
185  mCurrentChecksum(0),
186  mMemoryBuffer(nullptr),
187  mDownload(nullptr),
188  mUpdateFiles(),
192  // TRANSLATORS: updater window label
193  mLabel(new Label(this, _("Connecting..."))),
194  // TRANSLATORS: updater window button
195  mCancelButton(new Button(this, _("Cancel"), "cancel", BUTTON_SKIN, this)),
196  // TRANSLATORS: updater window button
197  mPlayButton(new Button(this, _("Play"), "play", BUTTON_SKIN, this)),
198  mProgressBar(new ProgressBar(this, 0.0, 310, 0,
200  "updateprogressbar.xml", "updateprogressbar_fill.xml")),
202  "browserbox.xml")),
204  Opaque_true, "update_background.xml")),
206  mDownloadedBytes(0),
207  mUpdateIndex(0),
209  mUpdateType(updateType),
210  mStoreInMemory(true),
211  mDownloadComplete(true),
212  mUserCancel(false),
213  mLoadUpdates(applyUpdates),
214  mValidateXml(false),
215  mSkipPatches(false)
216 {
217  setWindowName("UpdaterWindow");
218  setResizable(true);
219  setDefaultSize(450, 400, ImagePosition::CENTER, 0, 0);
220  setMinWidth(310);
221  setMinHeight(220);
222 
227  mBrowserBox->setEnableKeys(true);
228  mBrowserBox->setEnableTabs(true);
230  mPlayButton->setEnabled(false);
231 
232  ContainerPlacer placer(nullptr, nullptr);
233  placer = getPlacer(0, 0);
234 
235  placer(0, 0, mScrollArea, 5, 3).setPadding(3);
236  placer(0, 3, mLabel, 5, 1);
237  placer(0, 4, mProgressBar, 5, 1);
238  placer(3, 5, mCancelButton, 1, 1);
239  placer(4, 5, mPlayButton, 1, 1);
240 
241  Layout &layout = getLayout();
242  layout.setRowHeight(0, LayoutType::SET);
243 
244  addKeyListener(this);
245 
246  if (mUpdateHost.empty())
247  {
248  const STD_VECTOR<std::string> &mirrors = settings.updateMirrors;
249  if (mirrors.begin() != mirrors.end())
250  mUpdateHost = *mirrors.begin();
251  mSkipPatches = true;
252  }
253 
254  loadWindowState();
255 }
const std::string BUTTON_SKIN
Definition: button.h:89
Definition: button.h:102
Definition: label.h:91
void setRowHeight(const int n, const int h)
Definition: layoutcell.cpp:128
Definition: layout.h:45
void setSmoothProgress(bool smoothProgress)
Definition: progressbar.h:125
std::vector< std::string > updateMirrors
Definition: settings.h:129
void setOpaque(Opaque opaque)
void setEnableKeys(const bool n)
void setEnableImages(const bool n)
void setEnableTabs(const bool n)
void setProcessVars(const bool n)
void setLinkHandler(LinkHandler *linkHandler)
char * mMemoryBuffer
unsigned int mUpdateIndex
std::string mUpdateServerPath
Button * mPlayButton
Mutex mDownloadMutex
UpdateTypeT mUpdateType
std::string mUpdatesDir
ItemLinkHandler * mItemLinkHandler
std::vector< UpdateFile > mUpdateFiles
std::string mCurrentFile
std::string mUpdateHost
StaticBrowserBox * mBrowserBox
ScrollArea * mScrollArea
std::vector< UpdateFile > mTempUpdateFiles
std::string mNewLabelCaption
unsigned long mCurrentChecksum
ProgressBar * mProgressBar
Button * mCancelButton
UpdateDownloadStatusT mDownloadStatus
Net::Download * mDownload
std::string mUpdatesDirReal
unsigned int mUpdateIndexOffset
bool mDownloadComplete
float mDownloadProgress
void setEnabled(const bool enabled)
Definition: widget.h:352
void addKeyListener(KeyListener *const keyListener)
Definition: widget.cpp:272
void setResizable(const bool resize)
Definition: window.cpp:627
ContainerPlacer getPlacer(const int x, const int y)
Definition: window.cpp:1391
Layout & getLayout()
Definition: window.cpp:1365
void setWindowName(const std::string &name)
Definition: window.h:355
Window(const std::string &caption, const Modal modal, Window *const parent, std::string skin)
Definition: window.cpp:109
void setMinHeight(const int height)
Definition: window.cpp:604
void setMinWidth(const int width)
Definition: window.cpp:591
void setDefaultSize()
Definition: window.cpp:1198
void loadWindowState()
Definition: window.cpp:1087
#define _(s)
Definition: gettext.h:35
const bool Modal_false
Definition: modal.h:30
const bool Opaque_false
Definition: opaque.h:30
const bool Opaque_true
Definition: opaque.h:30
Settings settings
Definition: settings.cpp:32

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.

◆ ~UpdaterWindow()

UpdaterWindow::~UpdaterWindow ( )

Destructor

Definition at line 267 of file updaterwindow.cpp.

268 {
269  if (mLoadUpdates)
270  loadUpdates();
271 
272  if (mDownload != nullptr)
273  {
274  mDownload->cancel();
275 
277  }
278  free(mMemoryBuffer);
280 }
unsigned cancel
Definition: download.h:127
#define delete2(var)
Definition: delete2.h:25

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

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 313 of file updaterwindow.cpp.

314 {
315  const std::string &eventId = event.getId();
316  if (eventId == "cancel")
317  {
318  // Register the user cancel
319  mUserCancel = true;
320  // Skip the updating process
322  {
323  if (mDownload != nullptr)
324  mDownload->cancel();
326  }
327  }
328  else if (eventId == "play")
329  {
330  if (client->getState() != State::GAME)
332  else
333  deleteSelf();
334  }
335 }
void setState(const StateT state)
Definition: client.h:66
StateT getState() const
Definition: client.h:69
Client * client
Definition: client.cpp:118
@ GAME
Definition: state.h:49
@ LOAD_DATA
Definition: state.h:45

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().

◆ addUpdateFile()

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

Definition at line 800 of file updaterwindow.cpp.

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

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

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

◆ deleteSelf()

void UpdaterWindow::deleteSelf ( )

Definition at line 1220 of file updaterwindow.cpp.

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

References Window::scheduleDelete(), and updaterWindow.

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

◆ download()

void UpdaterWindow::download ( )
private

Definition at line 581 of file updaterwindow.cpp.

582 {
583  if (mDownload != nullptr)
584  {
585  mDownload->cancel();
586  delete mDownload;
587  }
589  {
590  mDownload = new Net::Download(this,
591  branding.getStringValue("updateMirror1") + mCurrentFile,
593  true, false, mValidateXml);
594  for (int f = 2; f < 8; f ++)
595  {
596  const std::string url = branding.getStringValue(
597  "updateMirror" + toString(f));
598  if (!url.empty())
600  }
601  }
602  else
603  {
604  mDownload = new Net::Download(this,
607  false, false, mValidateXml);
608 
611  {
612  const std::string str = urlJoin(mUpdateServerPath, mCurrentFile);
616  }
617  else
618  {
619  const STD_VECTOR<std::string> &mirrors = settings.updateMirrors;
620  FOR_EACH (STD_VECTOR<std::string>::const_iterator, it, mirrors)
621  {
623  mCurrentFile));
624  }
625  }
626  }
627 
628  if (mStoreInMemory)
629  {
631  }
632  else
633  {
635  {
638  }
639  else
640  {
642  mCurrentFile),
643  -1);
644  }
645  }
646 
648  mDownload->noCache();
649 
650  setLabel(mCurrentFile + " (0%)");
651  mDownloadComplete = false;
652 
653  mDownload->start();
654 }
std::string getStringValue(const std::string &key) const
void setFile(const std::string &filename, const int64_t adler32)
Definition: download.cpp:166
void addMirror(const std::string &str)
Definition: download.h:88
void setWriteFunction(WriteFunction write)
Definition: download.cpp:182
void noCache()
Definition: download.cpp:160
bool start()
Definition: download.cpp:188
static size_t memoryWrite(void *ptr, size_t size, size_t nmemb, void *stream)
static int updateProgress(void *ptr, const DownloadStatusT status, size_t dt, const size_t dn)
void setLabel(const std::string &)
Configuration branding
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25
bool url(InputEvent &event)
Definition: commands.cpp:64
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
std::string urlJoin(std::string str1, const std::string &str2)
const std::string updateServer5("http://download3.manaplus.org/manaplus/updates/")
const std::string updateServer4("http://download.evolonline.org/manaplus/updates/")
const std::string updateServer3("http://download2.manaplus.org/manaplus/updates/")

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(), 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().

◆ enable()

void UpdaterWindow::enable ( )

Enables play button

Definition at line 296 of file updaterwindow.cpp.

297 {
298  mCancelButton->setEnabled(false);
299  mPlayButton->setEnabled(true);
301 
302  if (client->getState() != State::GAME)
303  {
304  if ((mUpdateType & UpdateType::Close) != 0)
306  }
307  else
308  {
309  deleteSelf();
310  }
311 }
virtual void requestFocus()
Definition: widget.cpp:204

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().

◆ getFileHash()

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

Definition at line 1085 of file updaterwindow.cpp.

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

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

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

◆ 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 337 of file updaterwindow.cpp.

338 {
339  const InputActionT actionId = event.getActionId();
340  if (actionId == InputAction::GUI_CANCEL)
341  {
343  if (client->getState() != State::GAME)
345  else
346  deleteSelf();
347  }
348  else if (actionId == InputAction::GUI_SELECT ||
349  actionId == InputAction::GUI_SELECT2)
350  {
354  {
356  }
357  else
358  {
360  }
361  }
362 }
void action(const ActionEvent &event)
const std::string & getActionEventId() const
Definition: widget.h:605
InputAction ::T InputActionT
Definition: inputaction.h:717
@ LOGIN
Definition: state.h:40

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.

◆ loadDirMods()

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

Definition at line 1171 of file updaterwindow.cpp.

1172 {
1173  ModDB::load();
1174  const ModInfos &mods = ModDB::getAll();
1175 
1176  std::string modsString = serverConfig.getValue("mods", "");
1177  StringVect modsList;
1178  splitToStringVector(modsList, modsString, '|');
1179  FOR_EACH (StringVectCIter, it, modsList)
1180  {
1181  const std::string &name = *it;
1182  const ModInfoCIterator modIt = mods.find(name);
1183  if (modIt == mods.end())
1184  continue;
1185  const ModInfo *const mod = (*modIt).second;
1186  if (mod != nullptr)
1187  {
1188  const std::string &localDir = mod->getLocalDir();
1189  if (!localDir.empty())
1190  {
1191  VirtFs::mountDir(pathJoin(dir, localDir),
1192  Append_false);
1193  }
1194  }
1195  }
1196 }
std::string getValue(const std::string &key, const std::string &deflt) const
const std::string & getLocalDir() const
Definition: modinfo.h:58
Configuration serverConfig
ModInfos::const_iterator ModInfoCIterator
Definition: modinfo.h:70
std::map< std::string, ModInfo * > ModInfos
Definition: modinfo.h:68
void load()
Definition: moddb.cpp:42
const ModInfos & getAll()
Definition: moddb.cpp:116
bool mountDir(std::string newDir, const Append append)
Definition: fs.cpp:393
void splitToStringVector(StringVect &tokens, const std::string &text, const char separator)
StringVect::const_iterator StringVectCIter
Definition: stringvector.h:31
std::vector< std::string > StringVect
Definition: stringvector.h:29

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

Referenced by loadMods().

◆ loadFile()

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

Definition at line 1096 of file updaterwindow.cpp.

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

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

◆ loadLocalUpdates()

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

Definition at line 688 of file updaterwindow.cpp.

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

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

◆ loadManaPlusUpdates()

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

Definition at line 746 of file updaterwindow.cpp.

747 {
748  std::string fixPath = dir + "/fix";
749  STD_VECTOR<UpdateFile> updateFiles = loadXMLFile(
750  pathJoin(fixPath, xmlUpdateFile),
751  false);
752 
753  for (unsigned int updateIndex = 0,
754  fsz = CAST_U32(updateFiles.size());
755  updateIndex < fsz;
756  updateIndex++)
757  {
758  const UpdateFile &file = updateFiles[updateIndex];
759  if (!file.group.empty())
760  continue;
761  const std::string name = file.name;
762  if (strStartWith(name, "manaplus_"))
763  {
764  struct stat statbuf;
765  std::string fileName = pathJoin(fixPath,
766  name);
767  if (stat(fileName.c_str(), &statbuf) == 0)
768  {
770  Append_false);
771  }
772  }
773  }
774 }
bool strStartWith(const std::string &str1, const std::string &str2)
std::string fileName
Definition: testmain.cpp:39

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

Referenced by loadLocalUpdates(), and loadUpdates().

◆ loadMods()

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

Definition at line 1109 of file updaterwindow.cpp.

1111 {
1112  ModDB::load();
1113  std::string modsString = serverConfig.getValue("mods", "");
1114  std::set<std::string> modsList;
1115  splitToStringSet(modsList, modsString, '|');
1116 
1117  const std::string fixPath = dir + "/fix";
1118  for (unsigned int updateIndex = 0,
1119  fsz = CAST_U32(updateFiles.size());
1120  updateIndex < fsz;
1121  updateIndex ++)
1122  {
1123  const UpdateFile &file = updateFiles[updateIndex];
1124  if (file.group.empty())
1125  continue;
1126  const std::set<std::string>::const_iterator
1127  it = modsList.find(file.group);
1128  if (it != modsList.end())
1129  {
1131  fixPath,
1132  file.name,
1133  Append_false);
1134  }
1135  }
1136 
1137  STD_VECTOR<UpdateFile> updateFiles2 = loadXMLFile(
1138  pathJoin(fixPath, xmlUpdateFile),
1139  true);
1140 
1141  for (unsigned int updateIndex = 0,
1142  fsz = CAST_U32(updateFiles2.size());
1143  updateIndex < fsz;
1144  updateIndex++)
1145  {
1146  const UpdateFile &file = updateFiles2[updateIndex];
1147  if (file.group.empty())
1148  continue;
1149  std::string name = file.name;
1150  if (strStartWith(name, "manaplus_"))
1151  {
1152  const std::set<std::string>::const_iterator
1153  it = modsList.find(file.group);
1154  if (it != modsList.end())
1155  {
1156  struct stat statbuf;
1157  std::string fileName = pathJoin(fixPath,
1158  name);
1159  if (stat(fileName.c_str(), &statbuf) == 0)
1160  {
1162  Append_false);
1163  }
1164  }
1165  }
1166  }
1167 
1168  loadDirMods(dir + "/local/");
1169 }
static void loadDirMods(const std::string &dir)
void splitToStringSet(std::set< std::string > &tokens, const std::string &text, const char separator)

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().

◆ loadNews()

void UpdaterWindow::loadNews ( )

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

Definition at line 364 of file updaterwindow.cpp.

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

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

Referenced by logic().

◆ loadPatch()

void UpdaterWindow::loadPatch ( )

Definition at line 433 of file updaterwindow.cpp.

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

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

Referenced by logic().

◆ loadUpdates()

void UpdaterWindow::loadUpdates ( )
private

Loads the updates this window has gotten into the resource manager

Definition at line 656 of file updaterwindow.cpp.

657 {
658  if (mUpdateFiles.empty())
659  { // updates not downloaded
661  false);
662  if (mUpdateFiles.empty())
663  {
664  logger->log("Warning this server does not have a"
665  " %s file falling back to %s", xmlUpdateFile.c_str(),
666  txtUpdateFile.c_str());
668  txtUpdateFile));
669  }
670  }
671 
672  std::string fixPath = mUpdatesDir + "/fix";
673  const unsigned sz = CAST_U32(mUpdateFiles.size());
674  for (mUpdateIndex = 0; mUpdateIndex < sz; mUpdateIndex++)
675  {
676  const UpdateFile &file = mUpdateFiles[mUpdateIndex];
677  if (!file.group.empty())
678  continue;
680  fixPath,
681  file.name,
682  Append_false);
683  }
686 }

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().

◆ 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 829 of file updaterwindow.cpp.

830 {
831  BLOCK_START("UpdaterWindow::logic")
832  // Update Scroll logic
833  mScrollArea->logic();
834 
835  // Synchronize label caption when necessary
836  {
838 
840  {
842  mLabel->adjustSize();
843  }
844 
846  if (!mUpdateFiles.empty() &&
848  {
851  mUpdateFiles.size()) + CAST_S32(
852  mTempUpdateFiles.size()) + 1));
853  }
854  else
855  {
856  mProgressBar->setText("");
857  }
858  }
859 
860  switch (mDownloadStatus)
861  {
863  mBrowserBox->addRow("", false);
864  // TRANSLATORS: update message
865  mBrowserBox->addRow(_("##1 The update process is incomplete."),
866  false);
867  // TRANSLATORS: Continues "The update process is incomplete.".
868  mBrowserBox->addRow(_("##1 It is strongly recommended that"),
869  false);
870  // TRANSLATORS: Begins "It is strongly recommended that".
871  mBrowserBox->addRow(_("##1 you try again later."),
872  false);
873  if (mDownload != nullptr)
874  mBrowserBox->addRow(mDownload->getError(), false);
879  break;
881  if (mDownloadComplete)
882  {
883  // Parse current memory buffer as news and dispose of the data
884  loadNews();
885 
886  mValidateXml = true;
888  mStoreInMemory = false;
890  download(); // download() changes mDownloadComplete to false
891  }
892  break;
894  if (mDownloadComplete)
895  {
896  // Parse current memory buffer as news and dispose of the data
897  loadPatch();
898 
900  mUpdatesDir = pathJoin(mUpdatesDir, "fix");
902  mValidateXml = true;
903  mStoreInMemory = false;
905  download();
906  }
907  break;
908 
910  if (mDownloadComplete)
911  {
913  {
916  true);
917 
918  if (mUpdateFiles.empty())
919  {
920  logger->log("Warning this server does not have a %s"
921  " file falling back to %s",
922  xmlUpdateFile.c_str(),
923  txtUpdateFile.c_str());
924 
925  // If the resources.xml file fails,
926  // fall back onto a older version
928  mValidateXml = false;
929  mStoreInMemory = false;
931  download();
932  break;
933  }
934  }
935  else if (mCurrentFile == txtUpdateFile)
936  {
937  mValidateXml = true;
939  txtUpdateFile));
940  }
941  mStoreInMemory = false;
943  }
944  break;
946  if (mDownloadComplete)
947  {
948  if (CAST_SIZE(mUpdateIndex) < mUpdateFiles.size())
949  {
951  if (thisFile.type == "music"
952  && !config.getBoolValue("download-music"))
953  {
954  mUpdateIndex++;
955  break;
956  }
957  mCurrentFile = thisFile.name;
958  std::string checksum;
959  checksum = thisFile.hash;
960  std::stringstream ss(checksum);
961  ss >> std::hex >> mCurrentChecksum;
962 
963  std::ifstream temp(pathJoin(mUpdatesDir,
964  mCurrentFile).c_str());
965 
966  mValidateXml = false;
967  if (!temp.is_open() || !validateFile(pathJoin(
970  {
971  temp.close();
972  download();
973  }
974  else
975  {
976  temp.close();
977  logger->log("%s already here", mCurrentFile.c_str());
978  }
979  mUpdateIndex++;
980  }
981  else
982  {
983  if (!mSkipPatches)
984  {
985  // Download of updates completed
986  mCurrentFile = "latest.txt";
987  mStoreInMemory = true;
989  mValidateXml = false;
990  download(); // download() changes
991  // mDownloadComplete to false
992  }
993  else
994  {
997  }
998  }
999  }
1000  break;
1002  if (mDownloadComplete)
1003  {
1004  if (mCurrentFile == xmlUpdateFile)
1005  {
1008  true);
1009  }
1011  mUpdateIndex = 0;
1012  mValidateXml = true;
1013  mStoreInMemory = false;
1015  download();
1016  }
1017  break;
1019  if (mDownloadComplete)
1020  {
1021  mValidateXml = false;
1022  if (CAST_SIZE(mUpdateIndex)
1023  < mTempUpdateFiles.size())
1024  {
1025  const UpdateFile thisFile = mTempUpdateFiles[mUpdateIndex];
1026  mCurrentFile = thisFile.name;
1027  std::string checksum;
1028  checksum = thisFile.hash;
1029  std::stringstream ss(checksum);
1030  ss >> std::hex >> mCurrentChecksum;
1031 
1032  std::ifstream temp((pathJoin(mUpdatesDir,
1033  mCurrentFile)).c_str());
1034 
1035  if (!temp.is_open() || !validateFile(pathJoin(
1038  {
1039  temp.close();
1040  download();
1041  }
1042  else
1043  {
1044  temp.close();
1045  logger->log("%s already here", mCurrentFile.c_str());
1046  }
1047  mUpdateIndex++;
1048  }
1049  else
1050  {
1053  }
1054  }
1055  break;
1058  enable();
1059  // TRANSLATORS: updater window label
1060  setLabel(_("Completed"));
1062  break;
1064  break;
1065  default:
1066  logger->log("UpdaterWindow::logic unknown status: "
1068  break;
1069  }
1070  BLOCK_END("UpdaterWindow::logic")
1071 }
#define CAST_S32
Definition: cast.h:30
#define CAST_SIZE
Definition: cast.h:34
bool getBoolValue(const std::string &key) const
void adjustSize()
Definition: label.cpp:200
const std::string & getCaption() const
Definition: label.h:133
void setCaption(const std::string &caption)
Definition: label.cpp:264
const char * getError() const
Definition: download.cpp:218
void setProgress(const float progress)
void setText(const std::string &str)
int getVerticalMaxScroll()
static bool validateFile(const std::string &filePath, const unsigned long hash)
Configuration config
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79
std::string type
Definition: updatefile.h:48
std::string hash
Definition: updatefile.h:47
const std::string updateServer2("http://download.manaplus.org/manaplus/updates/")

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().

◆ 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 563 of file updaterwindow.cpp.

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

References CAST_S32, CAST_SIZE, mDownloadedBytes, mMemoryBuffer, and EmoteDB::size().

Referenced by download().

◆ postInit()

void UpdaterWindow::postInit ( )
virtual

Reimplemented from Window.

Definition at line 257 of file updaterwindow.cpp.

258 {
263 
264  download();
265 }
virtual void setVisible(Visible visible)
Definition: window.cpp:778
void postInit()
Definition: window.cpp:249
std::string & removeProtocol(std::string &url)
const bool Visible_true
Definition: visible.h:30

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

◆ removeUpdateFile()

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

Definition at line 818 of file updaterwindow.cpp.

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

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

Referenced by unloadUpdates().

◆ setLabel()

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

Set's label above progress

Definition at line 289 of file updaterwindow.cpp.

290 {
291  // Do delayed label text update, since Guichan isn't thread-safe
293  mNewLabelCaption = str;
294 }

References mDownloadMutex, and mNewLabelCaption.

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

◆ setProgress()

void UpdaterWindow::setProgress ( const float  p)

Set's progress bar status

Definition at line 282 of file updaterwindow.cpp.

283 {
284  // Do delayed progress bar update, since Guichan isn't thread-safe
286  mDownloadProgress = p;
287 }

References mDownloadMutex, and mDownloadProgress.

Referenced by updateProgress().

◆ unloadManaPlusUpdates()

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

Definition at line 776 of file updaterwindow.cpp.

777 {
778  const std::string fixPath = dir + "/fix";
779  const STD_VECTOR<UpdateFile> updateFiles = loadXMLFile(
780  pathJoin(fixPath, xmlUpdateFile),
781  true);
782 
783  for (unsigned int updateIndex = 0,
784  fsz = CAST_U32(updateFiles.size());
785  updateIndex < fsz;
786  updateIndex++)
787  {
788  std::string name = updateFiles[updateIndex].name;
789  if (strStartWith(name, "manaplus_"))
790  {
791  struct stat statbuf;
792  const std::string file = pathJoin(
793  fixPath, name);
794  if (stat(file.c_str(), &statbuf) == 0)
795  VirtFs::unmountZip(file);
796  }
797  }
798 }

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

Referenced by unloadUpdates().

◆ unloadMods()

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

Definition at line 1198 of file updaterwindow.cpp.

1199 {
1200  const ModInfos &mods = ModDB::getAll();
1201  std::string modsString = serverConfig.getValue("mods", "");
1202  StringVect modsList;
1203  splitToStringVector(modsList, modsString, '|');
1204  FOR_EACH (StringVectCIter, it, modsList)
1205  {
1206  const std::string &name = *it;
1207  const ModInfoCIterator modIt = mods.find(name);
1208  if (modIt == mods.end())
1209  continue;
1210  const ModInfo *const mod = (*modIt).second;
1211  if (mod != nullptr)
1212  {
1213  const std::string &localDir = mod->getLocalDir();
1214  if (!localDir.empty())
1215  VirtFs::unmountDir(pathJoin(dir, localDir));
1216  }
1217  }
1218 }
bool unmountDir(std::string oldDir)
Definition: fs.cpp:518

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

◆ unloadUpdates()

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

Definition at line 721 of file updaterwindow.cpp.

722 {
723  STD_VECTOR<UpdateFile> updateFiles = loadXMLFile(
724  pathJoin(dir, xmlUpdateFile),
725  true);
726 
727  if (updateFiles.empty())
728  {
729  updateFiles = loadTxtFile(pathJoin(dir,
730  txtUpdateFile));
731  }
732 
733  const std::string fixPath = dir + "/fix";
734  for (unsigned int updateIndex = 0,
735  fsz = CAST_U32(updateFiles.size());
736  updateIndex < fsz;
737  updateIndex++)
738  {
740  fixPath,
741  updateFiles[updateIndex].name);
742  }
744 }
static void removeUpdateFile(const std::string &path, const std::string &fixPath, const std::string &filerestrict)
static void unloadManaPlusUpdates(const std::string &dir)

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

Referenced by Client::unloadData().

◆ 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 503 of file updaterwindow.cpp.

507 {
508  UpdaterWindow *const uw = reinterpret_cast<UpdaterWindow *>(ptr);
509  if (uw == nullptr)
510  return -1;
511 
512  if (status == DownloadStatus::Complete)
513  {
514  uw->mDownloadComplete = true;
515  }
516  else if (status == DownloadStatus::Error ||
517  status == DownloadStatus::Cancelled)
518  {
521  { // ignoring error in last state (was UPDATE_PATCH)
523  uw->mDownloadComplete = true;
524  free(uw->mMemoryBuffer);
525  uw->mMemoryBuffer = nullptr;
526  }
527  else
528  {
530  }
531  }
532 
533  if (dt == 0U)
534  dt = 1;
535 
536  float progress = static_cast<float>(dn) /
537  static_cast<float>(dt);
538 
539  if (progress != progress)
540  progress = 0.0F; // check for NaN
541  if (progress < 0.0F)
542  progress = 0.0F; // no idea how this could ever happen,
543  // but why not check for it anyway.
544  if (progress > 1.0F)
545  progress = 1.0F;
546 
547  uw->setLabel(std::string(uw->mCurrentFile).append(" (")
548  .append(toString(CAST_S32(progress * 100))).append("%)"));
549 
550  uw->setProgress(progress);
551 
552  if ((client->getState() != State::UPDATE &&
553  client->getState() != State::GAME) ||
555  {
556  // If the action was canceled return an error code to stop the mThread
557  return -1;
558  }
559 
560  return 0;
561 }
void setProgress(const float p)
@ UPDATE
Definition: state.h:44

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().

◆ validateFile()

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

Definition at line 1073 of file updaterwindow.cpp.

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

References Net::Download::fadler32().

Referenced by logic().

Field Documentation

◆ mBrowserBox

StaticBrowserBox* UpdaterWindow::mBrowserBox
private

Definition at line 215 of file updaterwindow.h.

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

◆ mCancelButton

Button* UpdaterWindow::mCancelButton
private

Definition at line 212 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 194 of file updaterwindow.h.

Referenced by download(), and logic().

◆ mCurrentFile

std::string UpdaterWindow::mCurrentFile
private

The file currently downloading.

Definition at line 184 of file updaterwindow.h.

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

◆ mDownload

Net::Download* UpdaterWindow::mDownload
private

Download handle.

Definition at line 200 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 238 of file updaterwindow.h.

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

◆ mDownloadedBytes

int UpdaterWindow::mDownloadedBytes
private

Byte count currently downloaded in mMemoryBuffer.

Definition at line 222 of file updaterwindow.h.

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

◆ mDownloadMutex

Mutex UpdaterWindow::mDownloadMutex
private

Definition at line 191 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 173 of file updaterwindow.h.

Referenced by logic(), and setProgress().

◆ mDownloadStatus

UpdateDownloadStatusT UpdaterWindow::mDownloadStatus
private

Status of the current download.

Definition at line 219 of file updaterwindow.h.

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

◆ mItemLinkHandler

ItemLinkHandler* UpdaterWindow::mItemLinkHandler
private

Definition at line 210 of file updaterwindow.h.

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

◆ mLabel

Label* UpdaterWindow::mLabel
private

Definition at line 211 of file updaterwindow.h.

Referenced by logic(), and UpdaterWindow().

◆ mLoadUpdates

bool UpdaterWindow::mLoadUpdates
private

Tells ~UpdaterWindow() if it should load updates

Definition at line 244 of file updaterwindow.h.

Referenced by ~UpdaterWindow().

◆ mMemoryBuffer

char* UpdaterWindow::mMemoryBuffer
private

Buffer for files downloaded to memory.

Definition at line 197 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 187 of file updaterwindow.h.

Referenced by logic(), and setLabel().

◆ mPlayButton

Button* UpdaterWindow::mPlayButton
private

Definition at line 213 of file updaterwindow.h.

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

◆ mProgressBar

ProgressBar* UpdaterWindow::mProgressBar
private

Definition at line 214 of file updaterwindow.h.

Referenced by logic(), and UpdaterWindow().

◆ mScrollArea

ScrollArea* UpdaterWindow::mScrollArea
private

Definition at line 216 of file updaterwindow.h.

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

◆ mSkipPatches

bool UpdaterWindow::mSkipPatches
private

Definition at line 248 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 235 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 206 of file updaterwindow.h.

Referenced by logic().

◆ mUpdateFiles

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

List of files to download.

Definition at line 203 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 176 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 225 of file updaterwindow.h.

Referenced by loadUpdates(), and logic().

◆ mUpdateIndexOffset

unsigned int UpdaterWindow::mUpdateIndexOffset
private

Index offset for disaplay downloaded file.

Definition at line 228 of file updaterwindow.h.

Referenced by logic().

◆ mUpdatesDir

std::string UpdaterWindow::mUpdatesDir
private

Place where the updates are stored (absolute path).

Definition at line 179 of file updaterwindow.h.

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

◆ mUpdatesDirReal

std::string UpdaterWindow::mUpdatesDirReal
private

Definition at line 181 of file updaterwindow.h.

Referenced by logic().

◆ mUpdateServerPath

std::string UpdaterWindow::mUpdateServerPath
private

Definition at line 208 of file updaterwindow.h.

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

◆ mUpdateType

UpdateTypeT UpdaterWindow::mUpdateType
private

Definition at line 230 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 241 of file updaterwindow.h.

Referenced by action().

◆ mValidateXml

bool UpdaterWindow::mValidateXml
private

Definition at line 246 of file updaterwindow.h.

Referenced by download(), and logic().


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