HoverRace  2.0
TrackDownloadDialog.h
Go to the documentation of this file.
1 #ifdef HR_LEGACY_BUILD
2 
3 // TrackDownloadDialog.h
4 // Header for the track downloader.
5 //
6 // Copyright (c) 2008, 2009 Michael Imamura.
7 //
8 // Licensed under GrokkSoft HoverRace SourceCode License v1.0(the "License");
9 // you may not use this file except in compliance with the License.
10 //
11 // A copy of the license should have been attached to the package from which
12 // you have taken this file. If you can not find the license you can not use
13 // this file.
14 //
15 //
16 // The author makes no representations about the suitability of
17 // this software for any purpose. It is provided "as is" "AS IS",
18 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
19 // implied.
20 //
21 // See the License for the specific language governing permissions
22 // and limitations under the License.
23 
24 #pragma once
25 
26 #include <string>
27 
28 typedef void CURL;
29 
30 namespace HoverRace {
31 namespace Client {
32 
37 class TrackDownloadDialog
38 {
39  private:
40  TrackDownloadDialog() { }
41  public:
42  TrackDownloadDialog(const std::string &name);
43  ~TrackDownloadDialog();
44 
45  bool ShowModal(HINSTANCE hinst, HWND parent);
46 
47  private:
48  enum state_t {
49  ST_INITIALIZING,
50  ST_DOWNLOADING,
51  ST_EXTRACTING,
52  ST_FINISHED,
53  ST_LAST
54  };
55  const char **GetStateNames();
56  void SetState(state_t st);
57  void UpdateDialogProgress(HWND hwnd);
58 
59  void ThreadProc();
60 
61  BOOL DlgProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
62  static BOOL CALLBACK DlgFunc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
63 
64  size_t WriteProc(void *ptr, size_t size, size_t nmemb);
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  bool ExtractTrackFile();
70 
71  private:
72  std::string name;
73  std::string trackFilename;
74  HWND dlgHwnd;
75  CURL *trackDl;
76  char *curlErrorBuf;
77  volatile state_t state;
78  volatile bool cancel;
79 
80  typedef unsigned char dlBuf_t;
81  dlBuf_t *dlBuf;
82  volatile size_t bufSize;
83  size_t bufCapacity;
84  volatile size_t bufTotal;
85 };
86 
87 } // namespace Client
88 } // namespace HoverRace
89 #endif
Definition: Announcement.h:24