-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwsjcpp_package_downloader_github.cpp
More file actions
96 lines (79 loc) · 3.78 KB
/
Copy pathwsjcpp_package_downloader_github.cpp
File metadata and controls
96 lines (79 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "wsjcpp_package_downloader_github.h"
#include <wsjcpp_core.h>
#include <wsjcpp_package_manager.h>
#include <sstream>
// ---------------------------------------------------------------------
// WsjcppPackageDownloaderGithub
WsjcppPackageDownloaderGithub::WsjcppPackageDownloaderGithub()
: WsjcppPackageDownloaderBase("github") {
TAG = "WsjcppPackageDownloaderGithub";
m_sGithubPrefix = "https://github.com/";
}
// ---------------------------------------------------------------------
bool WsjcppPackageDownloaderGithub::canDownload(const std::string &sPackage) {
return sPackage.compare(0, m_sGithubPrefix.size(), m_sGithubPrefix) == 0;
}
// ---------------------------------------------------------------------
bool WsjcppPackageDownloaderGithub::downloadToCache(
const std::string &sPackage,
const std::string &sCacheDir,
WsjcppPackageManagerDependence &dep,
std::string &sError
) {
std::cout << "Try download package to " << sCacheDir << std::endl;
std::string sPackageGithubPath = sPackage.substr(m_sGithubPrefix.size());
// std::cout << "sPackageGithubPath: " << sPackageGithubPath << std::endl;
std::istringstream f(sPackageGithubPath);
std::string packageName = "";
std::string s;
if (getline(f, s, ':')) {
packageName = s;
}
std::string packageVersion = sPackageGithubPath.substr(packageName.size()+1);
std::string sWsjcppBaseUrl = "https://raw.githubusercontent.com/" + packageName + "/" + packageVersion + "/";
std::string sWsjcppUrl = sWsjcppBaseUrl + "/wsjcpp.yml";
std::cout << "Downloading " << sWsjcppBaseUrl << "/wsjcpp.yml" << std::endl;
if (!WsjcppPackageDownloaderBase::downloadFileOverHttps(sWsjcppBaseUrl + "/wsjcpp.yml", sCacheDir + "/wsjcpp.yml")) {
WsjcppLog::err(TAG, "Could not download " + sWsjcppBaseUrl);
return false;
}
WsjcppPackageManager pkg(sCacheDir);
if (!pkg.load()) {
sError = "Could not load " + sCacheDir;
return false;
}
// downlod sources
std::vector<WsjcppPackageManagerDistributionFile> vSources = pkg.getListOfDistributionFiles();
for (int i = 0; i < vSources.size(); i++) {
WsjcppPackageManagerDistributionFile src = vSources[i];
if (!WsjcppPackageDownloaderBase::prepareCacheSubdirForFile(sCacheDir, src.getSourceFile(), sError)) {
return false;
}
std::string sDownloadedWsjCppSourceFrom = sWsjcppBaseUrl + "/" + src.getSourceFile();
std::string sDownloadedWsjCppSourceTo = sCacheDir + "/" + src.getSourceFile();
std::cout << "Downloading " << sDownloadedWsjCppSourceFrom << std::endl;
// WsjcppLog::info(TAG, "\nDownloading " + sDownloadedWsjCppSourceFrom + " \n\t-> \n\t" + sDownloadedWsjCppSourceTo + "\n\t[sha1:" + src.getSha1() + "]");
if (!WsjcppPackageDownloaderBase::downloadFileOverHttps(sDownloadedWsjCppSourceFrom, sDownloadedWsjCppSourceTo)) {
WsjcppLog::err(TAG, "Could not download " + sDownloadedWsjCppSourceFrom);
return false;
}
if (!pkg.updateSourceFile(src.getSourceFile(), false)) {
sError = "Could not update file '" + sDownloadedWsjCppSourceFrom + "'";
return false;
}
}
pkg.save();
// temporary fix for init package
if (!WsjcppCore::dirExists("./src.wsjcpp/")) {
WsjcppCore::makeDir("./src.wsjcpp/");
}
std::string sInstallationDir = "./src.wsjcpp/" + WsjcppPackageDownloaderBase::prepareCacheSubFolderName(pkg.getName());
// WsjcppPackageManagerDependence dep;
dep.setName(pkg.getName());
dep.setVersion(pkg.getVersion());
dep.setUrl(sPackage);
dep.setInstallationDir(sInstallationDir);
dep.setOrigin("https://github.com/");
return true;
}
// ---------------------------------------------------------------------