CARDS 2.4.121
Package manager for the NuTyX GNU/Linux distribution
file_download.h
1 //
2 // file_download.h
3 //
4 // Copyright (c) 2013 - 2020 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 #include "pkgdbh.h"
35 
36 
46 {
47  public:
48  double dlnow;
49  double dltotal;
50  double dlspeed;
51  std::string filename;
52 };
53 
54 class FileDownload;
55 
65 {
66  friend FileDownload;
67 public:
70 
71  protected:
72 
79 };
80 
90 {
91  public:
92 
101  FileDownload(std::string url, std::string dirName, std::string fileName, bool progress);
102 
112  FileDownload(std::string fileInfo, std::string url, std::string dirName, std::string fileName, std::string MD5Sum , bool progress);
113 
121  FileDownload(std::vector<InfoFile> destinationFiles,bool progress);
122 
127  {
128  curl_slist_free_all(m_slist);
129  curl_global_cleanup();
130  curl_easy_cleanup(m_curl);
131  }
132 
133  static void SuscribeToEvents(FileDownloadEvent* callback);
134  static void UnSuscribeFromEvents(FileDownloadEvent* callback);
135 
136 
137  private:
138 
142  bool checkMD5sum();
143 
147  void downloadFile();
148 
149  static int updateProgressHandle(void *p, double dltotal, double dlnow, double ultotal, double ulnow);
150  static size_t writeToStreamHandle(void *buffer, size_t size, size_t nmemb, void *stream);
151  int updateProgress(void *p, double dltotal, double dlnow, double ultotal, double ulnow);
152  size_t writeToStream(void *buffer, size_t size, size_t nmemb, void *stream);
153  void initFileToDownload(std::string _url, std::string _file);
154 
158  bool checkUpToDate();
159  void SendProgressEvent(FileDownloadState event);
160  struct dwlProgress
161  {
162  std::string name;
163  double lastruntime;
164  CURL *curl;
165  };
166  struct curl_slist *m_slist;
167 
168  CURL* m_curl;
169  CURLcode m_curlCode;
170  dwlProgress m_downloadProgress;
171  InfoFile m_destinationFile;
172  std::string m_url;
173  std::string m_downloadFileName;
174  std::string m_fileInfo;
175  bool m_checkMD5;
176  bool m_progress;
177  std::string m_MD5Sum;
178  static std::set<FileDownloadEvent*> m_arrCallBacks;
179 };
180 
181 #endif /* FILEDOWNLOAD_H */
182 // vim:set ts=2 :
FileDownload
File Download class.
Definition: file_download.h:90
FileDownloadEvent
File Download Event class.
Definition: file_download.h:65
FileDownloadEvent::OnFileDownloadProgressInfo
virtual void OnFileDownloadProgressInfo(FileDownloadState state)
Definition: file_download.h:78
FileDownload::~FileDownload
~FileDownload()
Definition: file_download.h:126
InfoFile
Definition: file_utils.h:54
FileDownloadState
File Download State class.
Definition: file_download.h:46
FileDownload::FileDownload
FileDownload(std::string url, std::string dirName, std::string fileName, bool progress)
Definition: file_download.cxx:68