CARDS 2.3.99
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 
55  FileDownload(std::string url, std::string dirName, std::string fileName, bool progress);
56 
66  FileDownload(std::string url, std::string dirName, std::string fileName, std::string MD5Sum , bool progress);
67 
75  FileDownload(std::vector<InfoFile> destinationFiles,bool progress);
76 
81  {
82  curl_slist_free_all(m_slist);
83  curl_global_cleanup();
84  curl_easy_cleanup(m_curl);
85  }
86 
87  private:
88 
92  bool checkMD5sum();
93 
97  void downloadFile();
98 
99  static int updateProgressHandle(void *p, double dltotal, double dlnow, double ultotal, double ulnow);
100  static size_t writeToStreamHandle(void *buffer, size_t size, size_t nmemb, void *stream);
101  int updateProgress(void *p, double dltotal, double dlnow, double ultotal, double ulnow);
102  size_t writeToStream(void *buffer, size_t size, size_t nmemb, void *stream);
103  void initFileToDownload(std::string _url, std::string _file);
104 
108  bool checkUpToDate();
109  struct dwlProgress
110  {
111  double lastruntime;
112  CURL *curl;
113  };
114  struct curl_slist *m_slist;
115  void updateProgress();
116 
117  CURL* m_curl;
118  CURLcode m_curlCode;
119  dwlProgress m_downloadProgress;
120  InfoFile m_destinationFile;
121  std::string m_url;
122  std::string m_downloadFileName;
123  bool m_checkMD5;
124  bool m_progress;
125  std::string m_MD5Sum;
126 };
127 
128 #endif /* FILEDOWNLOAD_H */
129 // vim:set ts=2 :
FileDownload(std::string url, std::string dirName, std::string fileName, bool progress)
Definition: file_download.cxx:57
File Download class.
Definition: file_download.h:43
Definition: file_utils.h:53
~FileDownload()
Definition: file_download.h:80