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