HoverRace  2.0
DownloadUpdateDialog.h
Go to the documentation of this file.
1 #ifdef HR_LEGACY_BUILD
2 // DownloadUpdateDialog.h
3 // Dialog to download an update from the server and notify user of progress.
4 //
5 // Copyright (c) 2009 Ryan Curtin
6 //
7 // Licensed under GrokkSoft HoverRace SourceCode License v1.0(the "License");
8 // you may not use this file except in compliance with the License.
9 //
10 // A copy of the license should have been attached to the package from which
11 // you have taken this file. If you can not find the license you can not use
12 // this file.
13 //
14 //
15 // The author makes no representations about the suitability of
16 // this software for any purpose. It is provided "as is" "AS IS",
17 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
18 // implied.
19 //
20 // See the License for the specific language governing permissions
21 // and limitations under the License.
22 
23 #pragma once
24 
25 #include <string>
26 
27 #include "../../engine/Util/OS.h"
28 
29 typedef void CURL;
30 
31 namespace HoverRace {
32 namespace Client {
33 
40 class DownloadUpdateDialog
41 {
42  public:
43  DownloadUpdateDialog(const std::string &baseUrl, const Util::OS::path_t &filename, const Util::OS::path_t &destDir);
44  ~DownloadUpdateDialog();
45 
46  bool ShowModal(HINSTANCE hinst, HWND parent);
47 
48  private:
49  enum state_t {
50  ST_INITIALIZING,
51  ST_DOWNLOADING,
52  ST_FINISHED,
53  ST_LAST
54  };
55 
56  const char **GetStateNames();
57  void SetState(state_t st);
58  void UpdateDialogProgress(HWND hwnd);
59 
60  void ThreadProc();
61 
62  BOOL DlgProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
63  static BOOL CALLBACK DlgFunc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
64 
65  static size_t WriteFunc(void *ptr, size_t size, size_t nmemb, void *stream);
66  size_t ProgressProc(double dlTotal, double dlNow);
67  static size_t ProgressFunc(void *clientp, double dlTotal, double dlNow, double, double);
68 
69  private:
70  std::string baseUrl;
71  Util::OS::path_t filename;
72  Util::OS::path_t destDir;
73 
74  HWND dlgHwnd;
75 
76  CURL *updateDl;
77  char *curlErrorBuf;
78 
79  volatile state_t state;
80  volatile bool cancel;
81 
82  FILE *outFile;
83 
84  volatile size_t bufSize;
85  size_t bufCapacity;
86  volatile size_t bufTotal;
87 };
88 
89 } // namespace Client
90 } // namespace HoverRace
91 #endif
boost::filesystem::path path_t
Definition: OS.h:57
Definition: Announcement.h:24
Definition: Symbol.h:253