CARDS 2.4.87
Package manager for the NuTyX GNU/Linux distribution
file_download.h
1 //
2 // file_download.h
3 //
4 // Copyright (c) 2013-2015 by NuTyX team (http://nutyx.org)
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
20 //
21 
26 #ifndef FILEDOWNLOAD_H
27 #define FILEDOWNLOAD_H
28 
29 
30 #include <curl/curl.h>
31 
32 #include "string_utils.h"
33 #include "file_utils.h"
34 
44 {
45  public:
46  double dlnow;
47  double dltotal;
48  double dlspeed;
49  std::string filename;
50 };
51 
52 class FileDownload;
53 
63 {
64  friend FileDownload;
65 public:
68 
69  protected:
70 
77 };
78 
88 {
89  public:
90 
99  FileDownload(std::string url, std::string dirName, std::string fileName, bool progress);
100 
110  FileDownload(std::string url, std::string dirName, std::string fileName, std::string MD5Sum , bool progress);
111 
119  FileDownload(std::vector<InfoFile> destinationFiles,bool progress);
120 
125  {
126  curl_slist_free_all(m_slist);
127  curl_global_cleanup();
128  curl_easy_cleanup(m_curl);
129  }
130 
131  static void SuscribeToEvents(FileDownloadEvent* callback);
132  static void UnSuscribeFromEvents(FileDownloadEvent* callback);
133  private:
134 
138  bool checkMD5sum();
139 
143  void downloadFile();
144 
145  static int updateProgressHandle(void *p, double dltotal, double dlnow, double ultotal, double ulnow);
146  static size_t writeToStreamHandle(void *buffer, size_t size, size_t nmemb, void *stream);
147  int updateProgress(void *p, double dltotal, double dlnow, double ultotal, double ulnow);
148  size_t writeToStream(void *buffer, size_t size, size_t nmemb, void *stream);
149  void initFileToDownload(std::string _url, std::string _file);
150 
154  bool checkUpToDate();
155  void SendProgressEvent(FileDownloadState event);
156  struct dwlProgress
157  {
158  double lastruntime;
159  CURL *curl;
160  };
161  struct curl_slist *m_slist;
162 
163  CURL* m_curl;
164  CURLcode m_curlCode;
165  dwlProgress m_downloadProgress;
166  InfoFile m_destinationFile;
167  std::string m_url;
168  std::string m_downloadFileName;
169  bool m_checkMD5;
170  bool m_progress;
171  std::string m_MD5Sum;
172  static std::set<FileDownloadEvent*> m_arrCallBacks;
173 };
174 
175 #endif /* FILEDOWNLOAD_H */
176 // vim:set ts=2 :
File Download Event class.
Definition: file_download.h:62
File Download State class.
Definition: file_download.h:43
FileDownload(std::string url, std::string dirName, std::string fileName, bool progress)
Definition: file_download.cxx:67
virtual void OnFileDownloadProgressInfo(FileDownloadState state)
Definition: file_download.h:76
File Download class.
Definition: file_download.h:87
Definition: file_utils.h:53
~FileDownload()
Definition: file_download.h:124