| 1 |
#pragma once |
| 2 |
#include <apt-pkg/algorithms.h> |
| 3 |
#include <apt-pkg/cachefile.h> |
| 4 |
#include <apt-pkg/install-progress.h> |
| 5 |
#include <apt-pkg/pkgsystem.h> |
| 6 |
#include <apt-pkg/version.h> |
| 7 |
#include <cstdint> |
| 8 |
#include <sstream> |
| 9 |
#include "rust/cxx.h" |
| 10 |
|
| 11 |
#include "types.h" |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
inline void handle_errors() { |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
if (_error->PendingError()) { throw std::runtime_error("convert to AptErrors"); } |
| 22 |
} |
| 23 |
|
| 24 |
|
| 25 |
inline const char* handle_str(const char* str) { |
| 26 |
if (!str || !strcmp(str, "")) { throw std::runtime_error("&str doesn't exist"); } |
| 27 |
return str; |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
inline String handle_string(std::string string) { |
| 32 |
if (string.empty()) { throw std::runtime_error("String doesn't exist"); } |
| 33 |
return string; |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
inline i32 cmp_versions(str ver1, str ver2) { |
| 42 |
if (!_system) { pkgInitSystem(*_config, _system); } |
| 43 |
|
| 44 |
const char* end1 = ver1.begin() + strlen(ver1.begin()); |
| 45 |
const char* end2 = ver2.begin() + strlen(ver2.begin()); |
| 46 |
|
| 47 |
return _system->VS->DoCmpVersion(ver1.begin(), end1, ver2.begin(), end2); |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
inline String get_apt_progress_string(f32 percent, u32 output_width) { |
| 52 |
return APT::Progress::PackageManagerFancy::GetTextProgressStr(percent, output_width); |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
inline void apt_lock() { |
| 57 |
_system->Lock(); |
| 58 |
handle_errors(); |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
inline void apt_unlock() { |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
_system->UnLock(true); |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
inline void apt_lock_inner() { |
| 71 |
_system->LockInner(); |
| 72 |
handle_errors(); |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
inline void apt_unlock_inner() { |
| 77 |
|
| 78 |
_system->UnLockInner(); |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
inline bool apt_is_locked() { return _system->IsLocked(); } |