1 #pragma once
2 #ifdef USE_ONLINE_UPDATE
3 // Description:
4 //   Online update check.
5 //
6 // Copyright (C) 2005 Frank Becker
7 //
8 // This program is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU General Public License as published by the Free Software
10 // Foundation;  either version 2 of the License,  or (at your option) any  later
11 // version.
12 //
13 // This program is distributed in the hope that it will be useful,  but  WITHOUT
14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
16 //
17 
18 #include <list>
19 #include <string>
20 
21 #include <Trace.hpp>
22 #include <Singleton.hpp>
23 #include "SDL/SDL_thread.h"
24 
25 class OnlineUpdate
26 {
27 friend class Singleton<OnlineUpdate>;
28 public:
29     struct NewsItem
30     {
31 	std::string title;
32 	std::string date;
33 	std::string text;
34 	float r;
35 	float g;
36 	float b;
37     };
38 
39     enum UpdateStatus
40     {
41 	eNotChecking,
42 	eDownloading,
43 	eFailure,
44 	eSuccess,
45 	eLAST
46     };
47 
48     void init( const std::string &defaultUpdateURL);
49     void getUpdate( void);
getUpdateStatus(void)50     UpdateStatus getUpdateStatus( void) { return _status; }
51 
isLatest(void)52     bool isLatest( void) { return _isLatest; }
getLatestVersion(void)53     const std::string getLatestVersion( void) { return _latestVersion; }
getLatestVersionDate(void)54     const std::string getLatestVersionDate( void) { return _latestVersionDate; }
getLatestVersionText(void)55     const std::string getLatestVersionText( void) { return _latestVersionText; }
56 
getNewsItems(void)57     std::list<NewsItem*>& getNewsItems( void) { return _newsItemList; }
58 
59 private:
60     ~OnlineUpdate();
61     OnlineUpdate( void);
62     OnlineUpdate( const OnlineUpdate&);
63     OnlineUpdate &operator=( const OnlineUpdate&);
64 
65     static int run(void *data);
66     static size_t write(void *buffer, size_t size, size_t nmemb, void *data);
67 
68     bool process( void);
69     void loadUpdateCache(void);
70     void loadUpdateCache(const std::string &updateCache);
71 
72     std::string _updateURL;
73     SDL_Thread *_thread;
74     std::string _text;
75     UpdateStatus _status;
76     bool _isLatest;
77     std::string _latestVersion;
78     std::string _latestVersionDate;
79     std::string _latestVersionText;
80     std::list<NewsItem*> _newsItemList;
81 };
82 
83 typedef Singleton<OnlineUpdate> OnlineUpdateS;
84 #endif
85