MiKTeX 26.5-next
A scalable TeX distribution
Loading...
Searching...
No Matches
RepositoryManifest.h
1/* RepositoryManifest.h: -*- C++ -*-
2
3 Copyright (C) 2001-2020 Christian Schenk
4
5 This file is part of MiKTeX Package Manager.
6
7 MiKTeX Package Manager is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2, or
10 (at your option) any later version.
11
12 MiKTeX Package Manager is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
14 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with MiKTeX Package Manager; if not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
21
22#if !defined(E1DE3BC21F3F417ABD371823C8CBEB1A)
23#define E1DE3BC21F3F417ABD371823C8CBEB1A
24
25#include <memory>
26#include <string>
27
28#include <miktex/Core/Cfg>
29#include <miktex/Core/MD5>
30#include <miktex/Util/PathName>
31#include <miktex/Core/Utils>
32
33#include <miktex/Archive/Extractor>
34
35MPM_INTERNAL_BEGIN_NAMESPACE;
36
37class RepositoryManifest
38{
39private:
40 std::unique_ptr<MiKTeX::Core::Cfg> cfg;
41
42public:
43 RepositoryManifest() :
45 {
46 }
47
48public:
49 virtual ~RepositoryManifest()
50 {
51 }
52
53public:
54 MiKTeX::Core::MD5 GetDigest()
55 {
56 return cfg->GetDigest();
57 }
58
59public:
60 void Load(const MiKTeX::Util::PathName& path)
61 {
62#if defined(WITH_PACKAGE_DB_SIGNING)
63 bool mustBeSigned = true;
64#else
65 bool mustBeSigned = false;
66#endif
67 cfg->Read(path, mustBeSigned);
68 }
69
70private:
72
73public:
74 std::string FirstPackage()
75 {
76 keyIt = cfg->begin();
77 return keyIt == cfg->end() ? "" : (*keyIt)->GetName();
78 }
79
80public:
81 std::string NextPackage()
82 {
83 ++keyIt;
84 return keyIt == cfg->end() ? "" : (*keyIt)->GetName();
85 return "";
86 }
87
88public:
89 void Clear()
90 {
92 }
93
94public:
95 std::size_t GetArchiveFileSize(const std::string& packageId)
96 {
97 auto val = cfg->GetValue(packageId, "CabSize");
98 if (val == nullptr)
99 {
100 MIKTEX_FATAL_ERROR_2(T_("Unknown archive file size."), "package", packageId);
101 }
102 return MiKTeX::Core::Utils::ToSizeT(val->AsString());
103 }
104
105public:
106 MiKTeX::Core::MD5 GetArchiveFileDigest(const std::string& packageId)
107 {
108 auto val = cfg->GetValue(packageId, "CabMD5");
109 if (val == nullptr || val->AsString().empty())
110 {
111 MIKTEX_FATAL_ERROR_2(T_("Unknown archive file digest."), "package", packageId);
112 }
113 return MiKTeX::Core::MD5::Parse(val->AsString());
114 }
115
116public:
117 std::string GetMinTargetSystemVersion(const std::string& packageId)
118 {
119 auto val = cfg->GetValue(packageId, "MinTargetSystemVersion");
120 return val == nullptr ? "" : val->AsString();
121 }
122
123public:
124 MiKTeX::Core::MD5 GetPackageDigest(const std::string& packageId)
125 {
126 auto val = cfg->GetValue(packageId, "MD5");
127 if (val == nullptr || val->AsString().empty())
128 {
129 MIKTEX_FATAL_ERROR_2(T_("Unknown package digest."), "package", packageId);
130 }
131 return MiKTeX::Core::MD5::Parse(val->AsString());
132 }
133
134public:
135 std::time_t GetTimePackaged(const std::string& packageId)
136 {
137 auto val = cfg->GetValue(packageId, "TimePackaged");
138 if (val == nullptr)
139 {
140 MIKTEX_FATAL_ERROR_2(T_("Unknown package time-stamp."), "package", packageId);
141 }
142 std::time_t time = MiKTeX::Core::Utils::ToTimeT(val->AsString());
143 if (!IsValidTimeT(time))
144 {
145 MIKTEX_FATAL_ERROR_2(T_("Invalid package time-stamp."), "package", packageId, "timeStamp", val->AsString());
146 }
147 return time;
148 }
149
150public:
151 MiKTeX::Packages::PackageLevel GetPackageLevel(const std::string& packageId)
152 {
153 auto val = cfg->GetValue(packageId, "Level");
154 if (val == nullptr || val->AsString().empty())
155 {
156 MIKTEX_FATAL_ERROR_2(T_("Unknown package level."), "package", packageId);
157 }
158 return CharToPackageLevel(val->AsString()[0]);
159 }
160
161public:
162 std::string GetPackageVersion(const std::string& packageId)
163 {
164 auto val = cfg->GetValue(packageId, "Version");
165 return val == nullptr ? "" : val->AsString();
166 }
167
168public:
169 std::string GetPackageTargetSystem(const std::string& packageId)
170 {
171 auto val = cfg->GetValue(packageId, "TargetSystem");
172 return val == nullptr ? "" : val->AsString();
173 }
174
175public:
176 MiKTeX::Archive::ArchiveFileType GetArchiveFileType(const std::string& packageId)
177 {
178 auto val = cfg->GetValue(packageId, "Type");
179 if (val == nullptr || val->AsString().empty() || val->AsString() == "MSCab")
180 {
181 return MiKTeX::Archive::ArchiveFileType::MSCab;
182 }
183 else if (val->AsString() == "TarBzip2")
184 {
185 return MiKTeX::Archive::ArchiveFileType::TarBzip2;
186 }
187 else if (val->AsString() == "TarLzma")
188 {
189 return MiKTeX::Archive::ArchiveFileType::TarLzma;
190 }
191 else
192 {
193 MIKTEX_FATAL_ERROR_2(T_("Unknown archive file type."), "package", packageId, "type", val->AsString());
194 }
195 }
196
197private:
198 static MiKTeX::Packages::PackageLevel CharToPackageLevel(int ch)
199 {
200 switch (toupper(ch))
201 {
206 default:
207 MIKTEX_FATAL_ERROR_2(T_("Invalid package level."), "level", std::to_string(ch));
208 }
209 }
210};
211
212MPM_INTERNAL_END_NAMESPACE;
213
214#endif
Implements an interator for INI sections.
Definition Cfg.h:136
static std::unique_ptr< Cfg > Create()
Instances of this struct represent MD5 values.
Definition MD5.h:46
static MD5 Parse(const std::string &hexString)
Instances of this class can be used to store path names.
Definition PathName.h:64
bool IsValidTimeT(std::time_t time)
Definition definitions.h:35
PackageLevel
Package level.
Definition RepositoryInfo.h:40
@ Basic
Basic package set.
Definition RepositoryInfo.h:45
@ Advanced
Advanced package set.
Definition RepositoryInfo.h:47
@ Complete
Complete package set.
Definition RepositoryInfo.h:49
@ Essential
Essential package set.
Definition RepositoryInfo.h:43