18 #include <type_traits>
20 #include "../util/btassert.h"
21 #include "../util/directory.h"
26 #pragma GCC diagnostic push
27 #pragma GCC diagnostic ignored "-Wsuggest-override"
28 #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
29 #include <installmgr.h>
30 #include <multimapwdef.h>
33 #pragma GCC diagnostic pop
36 using namespace sword;
44 if (
source.directory[
source.directory.length()-1 ] ==
'/') {
47 static_assert(std::is_same_v<decltype(
source.type), SWBuf>);
48 if (
source.type ==
"FTP") {
49 config[
"Sources"].emplace(
"FTPSource",
source.getConfEnt());
51 else if (
source.type ==
"SFTP") {
52 config[
"Sources"].emplace(
"SFTPSource",
source.getConfEnt());
54 else if (
source.type ==
"HTTP") {
55 config[
"Sources"].emplace(
"HTTPSource",
source.getConfEnt());
57 else if (
source.type ==
"HTTPS") {
58 config[
"Sources"].emplace(
"HTTPSSource",
source.getConfEnt());
61 else if (
source.type ==
"DIR") {
62 config[
"Sources"].emplace(
"DIRSource",
source.getConfEnt());
69 sword::InstallSource
source(
const QString &name) {
71 auto const source = mgr.sources.find(name.toLatin1().data());
72 if (
source != mgr.sources.end()) {
77 auto const sections = config.getSections();
78 auto const sourcesSection = sections.find(
"Sources");
79 if (sourcesSection != sections.end()) {
81 sourcesSection->second.lower_bound(
"DIRSource");
82 auto const sourceEnd =
83 sourcesSection->second.upper_bound(
"DIRSource");
85 while (sourceBegin != sourceEnd) {
86 InstallSource is(
"DIR", sourceBegin->second.c_str());
87 if (is.caption == name) {
96 InstallSource is(
"EMPTY");
97 is.caption =
"unknown caption";
98 is.source =
"unknown source";
99 is.directory =
"unknown dir";
105 sword::InstallSource is =
source(name );
110 SWBuf sourceConfigEntry = is.getConfEnt();
111 bool notFound =
true;
112 auto it(config[
"Sources"].begin());
113 while (it != config[
"Sources"].end()) {
115 if (it->second == sourceConfigEntry) {
116 config[
"Sources"].erase(it);
123 qDebug() <<
"source was not found, trying without uid";
125 QString sce(sourceConfigEntry.c_str());
126 QStringList l = sce.split(
'|');
128 sce = l.join(
'|').append(
'|');
129 it = config[
"Sources"].begin();
130 while (it != config[
"Sources"].end()) {
131 if (it->second == sce) {
132 config[
"Sources"].erase(it);
144 return source.type ==
"FTP"
147 ||
source.type ==
"HTTPS";
152 + QStringLiteral(
"/InstallMgr");
156 {
return configPath() + QStringLiteral(
"/InstallMgr.conf"); }
165 for (
auto const & sourcePair : mgr.sources)
166 names << QString::fromLocal8Bit(sourcePair.second->caption.c_str());
170 auto const sourcesSection = config.getSections().find(
"Sources");
171 if (sourcesSection != config.getSections().end()) {
172 auto sourceBegin = sourcesSection->second.lower_bound(
"DIRSource");
173 auto const sourceEnd = sourcesSection->second.upper_bound(
"DIRSource");
175 while (sourceBegin != sourceEnd) {
176 InstallSource is(
"DIR", sourceBegin->second.c_str());
177 names << QString::fromLatin1(is.caption.c_str());
186 std::unique_ptr<CSwordBackend>
backend(sword::InstallSource
const & is) {
188 auto ret(std::make_unique<CSwordBackend>(
isRemote(is)
189 ? is.localShadow.c_str()
190 : is.directory.c_str(),
bool isRemote(const sword::InstallSource &source)
bool deleteSource(const QString &name)
bool addSource(sword::InstallSource &source)
sword::InstallSource source(const QString &name)
QStringList sourceNameList()
std::unique_ptr< CSwordBackend > backend(sword::InstallSource const &is)
const QDir & getUserHomeSwordDir()