| 1 |
#pragma once |
| 2 |
#include <apt-pkg/aptconfiguration.h> |
| 3 |
#include <apt-pkg/configuration.h> |
| 4 |
#include <apt-pkg/init.h> |
| 5 |
#include <apt-pkg/pkgsystem.h> |
| 6 |
#include <sstream> |
| 7 |
#include "rust/cxx.h" |
| 8 |
|
| 9 |
#include "types.h" |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
void init_config() { pkgInitConfig(*_config); } |
| 16 |
|
| 17 |
|
| 18 |
void init_system() { pkgInitSystem(*_config, _system); } |
| 19 |
|
| 20 |
struct ConfigTree { |
| 21 |
const Configuration::Item* ptr; |
| 22 |
|
| 23 |
bool end() const { return ptr == 0; } |
| 24 |
|
| 25 |
UniquePtr<ConfigTree> raw_next() const { return std::make_unique<ConfigTree>(ptr->Next); } |
| 26 |
|
| 27 |
UniquePtr<ConfigTree> unique() const { return std::make_unique<ConfigTree>(ptr); } |
| 28 |
|
| 29 |
UniquePtr<ConfigTree> parent() const { return std::make_unique<ConfigTree>(ptr->Parent); } |
| 30 |
|
| 31 |
UniquePtr<ConfigTree> child() const { return std::make_unique<ConfigTree>(ptr->Child); } |
| 32 |
|
| 33 |
String tag() const { return ptr->Tag; } |
| 34 |
|
| 35 |
String value() const { return ptr->Value; } |
| 36 |
|
| 37 |
ConfigTree(const Configuration::Item* base) : ptr(base){}; |
| 38 |
}; |
| 39 |
|
| 40 |
UniquePtr<ConfigTree> root_tree() { return std::make_unique<ConfigTree>(_config->Tree(0)); } |
| 41 |
|
| 42 |
UniquePtr<ConfigTree> tree(String key) { |
| 43 |
return std::make_unique<ConfigTree>(_config->Tree(key.c_str())); |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
String dump() { |
| 48 |
std::stringstream String_stream; |
| 49 |
_config->Dump(String_stream); |
| 50 |
return String_stream.str(); |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
String find(String key, String default_value) { |
| 55 |
return _config->Find(key.c_str(), default_value.c_str()); |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
String find_file(String key, String default_value) { |
| 60 |
return _config->FindFile(key.c_str(), default_value.c_str()); |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
String find_dir(String key, String default_value) { |
| 65 |
return _config->FindDir(key.c_str(), default_value.c_str()); |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
bool find_bool(String key, bool default_value) { |
| 70 |
return _config->FindB(key.c_str(), default_value); |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
int find_int(String key, i32 default_value) { return _config->FindI(key.c_str(), default_value); } |
| 75 |
|
| 76 |
|
| 77 |
Vec<String> find_vector(String key) { |
| 78 |
std::vector<std::string> vector = _config->FindVector(key.c_str()); |
| 79 |
Vec<String> rust_vector; |
| 80 |
|
| 81 |
for (const std::string& str : vector) { |
| 82 |
rust_vector.push_back(str); |
| 83 |
} |
| 84 |
|
| 85 |
return rust_vector; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
Vec<String> get_architectures() { |
| 91 |
Vec<String> rust_vector; |
| 92 |
|
| 93 |
for (const std::string& str : APT::Configuration::getArchitectures()) { |
| 94 |
rust_vector.push_back(str); |
| 95 |
} |
| 96 |
|
| 97 |
return rust_vector; |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
void set(String key, String value) { _config->Set(key.c_str(), value.c_str()); } |
| 102 |
|
| 103 |
|
| 104 |
bool exists(String key) { return _config->Exists(key.c_str()); } |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
void clear(String key) { _config->Clear(key.c_str()); } |
| 111 |
|
| 112 |
|
| 113 |
void clear_all() { _config->Clear(); } |
| 114 |
|
| 115 |
|
| 116 |
void clear_value(String key, String value) { _config->Clear(key.c_str(), value.c_str()); } |