/
cap.h
66 lines (48 loc) · 1.89 KB
/
cap.h
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
// engine to install/remove cap files
#ifndef cap_h__
#define cap_h__
#pragma once
#include <filesystem>
#include <string>
#include <string_view>
#include <tuple>
#include "cfg.h"
#include "common/cfg_info.h"
#include "common/wtools.h"
#include "logger.h"
namespace cma::cfg::cap {
// main API
void Install();
// support
bool InstallFileAsCopy(std::wstring_view filename, // checkmk.dat
std::wstring_view target_dir, // @user
std::wstring_view source_dir) // @root/install
noexcept;
bool NeedReinstall(const std::filesystem::path Target,
const std::filesystem::path Src);
bool ReinstallCaps(const std::filesystem::path TargetCap,
const std::filesystem::path SrcCap);
bool ReinstallIni(const std::filesystem::path TargetIni,
const std::filesystem::path SrcIni);
// data structures to use
enum class ProcMode { install, remove, list };
// valid eof is {empty, empty, true}
// valid NOT eod if {name, data, false}
using FileInfo = std::tuple<std::string, std::vector<char>, bool>;
// Main API to install and uninstall plugins cap
bool Process(const std::string CapFileName, ProcMode Mode,
std::vector<std::wstring> &FilesLeftOnDisk);
// converts name in cap to name in actual environment
std::wstring ProcessPluginPath(const std::string &File);
// Low Level API
// Returns -1 is a bad value, not nice
// #TODO think over API
uint32_t ReadFileNameLength(std::ifstream &CapFile);
std::string ReadFileName(std::ifstream &CapFile, uint32_t Length);
std::vector<char> ReadFileData(std::ifstream &CapFile);
FileInfo ExtractFile(std::ifstream &CapFile);
bool StoreFile(const std::wstring &Name, const std::vector<char> &Data);
// idiotic API form thje past. Do not for what hell, but let it stay
bool CheckAllFilesWritable(const std::string &Directory);
} // namespace cma::cfg::cap
#endif // cap_h__