MiKTeX 23.10-next
A scalable TeX distribution
Loading...
Searching...
No Matches
PackageInfo.h
Go to the documentation of this file.
1
14#pragma once
15
16#include "config.h"
17
18#include <cstddef>
19#include <ctime>
20
21#include <string>
22#include <vector>
23
24#include <miktex/Core/MD5>
25#include <miktex/Core/Session>
26
27#include "definitions.h"
28#include "RepositoryInfo.h"
29
30MIKTEX_PACKAGES_BEGIN_NAMESPACE;
31
34{
36 std::size_t archiveFileSize = 0;
37
39 std::string copyrightOwner;
40
42 std::string copyrightYear;
43
45 std::string creator;
46
48 std::string ctanPath;
49
51 std::string description;
52
55
57 std::string displayName;
58
60 std::string id;
61
63 bool isObsolete = false;
64
66 bool isRemovable = false;
67
69 std::vector<std::string> docFiles;
70
72 std::string licenseType;
73
76
78 RepositoryReleaseState releaseState = RepositoryReleaseState::Unknown;
79
81 std::vector<std::string> requiredBy;
82
84 std::vector<std::string> requiredPackages;
85
87 std::vector<std::string> runFiles;
88
90 std::size_t sizeDocFiles = 0;
91
93 std::size_t sizeSourceFiles = 0;
94
96 std::size_t sizeRunFiles = 0;
97
99 std::vector<std::string> sourceFiles;
100
102 std::string targetSystem;
103
105 std::time_t timeInstalledCommon = InvalidTimeT;
106
108 std::time_t timeInstalledUser = InvalidTimeT;
109
111 std::time_t timePackaged = InvalidTimeT;
112
114 std::string title;
115
117 std::string version;
118
120 std::string versionDate;
121
123 unsigned long GetRefCount() const
124 {
125 return static_cast<unsigned long>(requiredBy.size());
126 }
127
130 unsigned long GetNumFiles() const
131 {
132 return static_cast<unsigned long>(runFiles.size() + docFiles.size() + sourceFiles.size());
133 }
134
137 std::size_t GetSize() const
138 {
139 return sizeRunFiles + sizeDocFiles + sizeSourceFiles;
140 }
141
143 std::time_t GetTimeInstalled() const
144 {
145 return IsValidTimeT(timeInstalledUser) ? timeInstalledUser : timeInstalledCommon;
146 }
147
149 bool IsContained() const
150 {
151 return GetRefCount() > 0;
152 }
153
155 bool IsContainer() const
156 {
157 return !requiredPackages.empty();
158 }
159
161 bool IsInstalled() const
162 {
163 return IsValidTimeT(timeInstalledUser) || IsValidTimeT(timeInstalledCommon);
164 }
165
168 {
169 switch (scope)
170 {
172 return IsValidTimeT(timeInstalledUser);
174 return IsValidTimeT(timeInstalledCommon);
175 default:
176 MIKTEX_UNEXPECTED();
177 }
178 }
179
182 bool IsPureContainer() const
183 {
184 return IsContainer() && GetNumFiles() <= 1;
185 }
186
188 void SetTimeInstalled(std::time_t timeInstalled, MiKTeX::Core::ConfigurationScope scope)
189 {
190 switch (scope)
191 {
193 timeInstalledUser = timeInstalled;
194 break;
196 timeInstalledCommon = timeInstalled;
197 break;
198 default:
199 MIKTEX_UNEXPECTED();
200 }
201 }
202};
203
204inline bool operator==(const PackageInfo& lhs, const PackageInfo& rhs)
205{
206 return true
207 && lhs.copyrightOwner == rhs.copyrightOwner
208 && lhs.copyrightYear == rhs.copyrightYear
209 && lhs.creator == rhs.creator
210 && lhs.ctanPath == rhs.ctanPath
211 && lhs.description == rhs.description
212 && lhs.digest == rhs.digest
213 && lhs.displayName == rhs.displayName
214 && lhs.id == rhs.id
215 && lhs.licenseType == rhs.licenseType
216 && lhs.requiredPackages == rhs.requiredPackages
217 && lhs.sizeDocFiles == rhs.sizeDocFiles
218 && lhs.sizeSourceFiles == rhs.sizeSourceFiles
219 && lhs.targetSystem == rhs.targetSystem
220 && lhs.timePackaged == rhs.timePackaged
221 && lhs.title == rhs.title
222 && lhs.version == rhs.version
223 && lhs.versionDate == rhs.versionDate
224#if 0
225 // there was a time when the calculation of sizeRunFiles was broken
226 // maybe due to .tpm file treatment
227 && lhs.sizeRunFiles == rhs.sizeRunFiles
228#endif
229 ;
230}
231
232MIKTEX_PACKAGES_END_NAMESPACE;
Instances of this struct represent MD5 values.
Definition: MD5.h:46
ConfigurationScope
MiKTeX configuration scope.
Definition: Session.h:103
@ User
User configuration scope.
@ Common
Common (system-wide) configuration scope.
constexpr std::time_t InvalidTimeT
An invalid timestamp.
Definition: definitions.h:30
bool IsValidTimeT(std::time_t time)
Definition: definitions.h:35
RepositoryReleaseState
Repository release state.
Definition: RepositoryInfo.h:174
Package record.
Definition: PackageInfo.h:34
void SetTimeInstalled(std::time_t timeInstalled, MiKTeX::Core::ConfigurationScope scope)
Gets the time, the package was installed.
Definition: PackageInfo.h:188
std::string description
Multi-line package description.
Definition: PackageInfo.h:51
std::string copyrightOwner
The copyright owner of the package.
Definition: PackageInfo.h:39
std::string ctanPath
Relative path to the package directory on a CTAN mirror.
Definition: PackageInfo.h:48
std::string copyrightYear
Copyright year.
Definition: PackageInfo.h:42
bool IsInstalled() const
Checks to see whether the package is installed.
Definition: PackageInfo.h:161
bool IsPureContainer() const
Definition: PackageInfo.h:182
std::string displayName
Display name.
Definition: PackageInfo.h:57
std::vector< std::string > requiredBy
List of dependents.
Definition: PackageInfo.h:81
MiKTeX::Core::MD5 digest
MD5 of the package.
Definition: PackageInfo.h:54
std::string creator
Name of creator (packer).
Definition: PackageInfo.h:45
std::string versionDate
The version/date of the package.
Definition: PackageInfo.h:120
std::string minTargetSystemVersion
The minimum required target system version.
Definition: PackageInfo.h:75
std::size_t GetSize() const
Definition: PackageInfo.h:137
std::vector< std::string > sourceFiles
The source file list.
Definition: PackageInfo.h:99
std::vector< std::string > requiredPackages
List of required packages.
Definition: PackageInfo.h:84
std::time_t GetTimeInstalled() const
Gets the time, the package was installed.
Definition: PackageInfo.h:143
unsigned long GetNumFiles() const
Definition: PackageInfo.h:130
std::string id
Package ID.
Definition: PackageInfo.h:60
bool IsContained() const
Checks to see if this package has dependents.
Definition: PackageInfo.h:149
std::string version
Informal version information.
Definition: PackageInfo.h:117
std::vector< std::string > docFiles
The doc file list.
Definition: PackageInfo.h:69
std::string title
One-line package description.
Definition: PackageInfo.h:114
bool IsContainer() const
Tests for a container package.
Definition: PackageInfo.h:155
std::string targetSystem
Target system.
Definition: PackageInfo.h:102
bool IsInstalled(MiKTeX::Core::ConfigurationScope scope) const
Checks to see whether the package is installed in the specified scope.
Definition: PackageInfo.h:167
unsigned long GetRefCount() const
Gets the number of dependents.
Definition: PackageInfo.h:123
std::string licenseType
The license type of the package.
Definition: PackageInfo.h:72
std::vector< std::string > runFiles
The run file list.
Definition: PackageInfo.h:87