winget_types/manifests/version.rs
1use crate::{
2 LanguageTag, Manifest, ManifestType, ManifestVersion, PackageIdentifier, PackageVersion,
3};
4
5#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
6#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
7#[cfg_attr(feature = "serde", serde(rename_all = "PascalCase"))]
8pub struct VersionManifest {
9 /// The unique identifier for a given package.
10 ///
11 /// This value is generally in the form of `Publisher.Package`. It is case-sensitive, and this
12 /// value must match the folder structure under the partition directory in GitHub.
13 pub package_identifier: PackageIdentifier,
14
15 /// The version of the package.
16 ///
17 /// It is related to the specific release this manifests targets. In some cases you will see a
18 /// perfectly formed [semantic version] number, and in other cases you might see something
19 /// different. These may be date driven, or they might have other characters with some package
20 /// specific meaning for example.
21 ///
22 /// The Windows Package Manager client uses this version to determine if an upgrade for a
23 /// package is available. In some cases, packages may be released with a marketing driven
24 /// version, and that causes trouble with the [`winget upgrade`] command.
25 ///
26 /// The current best practice is to use the value reported in Add / Remove Programs when this
27 /// version of the package is installed. In some cases, packages do not report a version
28 /// resulting in an upgrade loop or other unwanted behavior.
29 ///
30 /// [semantic version]: https://semver.org/
31 /// [`winget upgrade`]: https://docs.microsoft.com/windows/package-manager/winget/upgrade
32 pub package_version: PackageVersion,
33
34 /// The default locale for package metadata.
35 ///
36 /// The format is BCP-47. This value identifies the language for meta-data to be displayed to a
37 /// user when no locale file matching their preferences is available.
38 ///
39 /// The validation pipelines use this value to ensure the corresponding locale file is present
40 /// and conforms with the defaultLocale YAML specification.
41 default_locale: LanguageTag,
42
43 /// The manifest type.
44 ///
45 /// Must have the value [`version`]. The Microsoft community package repository validation
46 /// pipelines also use this value to determine appropriate validation rules when evaluating this
47 /// file.
48 ///
49 /// [`version`]: ManifestType::Version
50 #[cfg_attr(feature = "serde", serde(default = "ManifestType::version"))]
51 manifest_type: ManifestType,
52
53 /// The manifest syntax version.
54 ///
55 /// Must have the value `1.12.0`. The Microsoft community package repository validation
56 /// pipelines also use this value to determine appropriate validation rules when evaluating this
57 /// file.
58 #[cfg_attr(feature = "serde", serde(default))]
59 manifest_version: ManifestVersion,
60}
61
62impl VersionManifest {
63 /// Creates a new [`VersionManifest`] from a [`PackageIdentifier`], a
64 /// [`PackageVersion`], and a default locale tag.
65 pub fn new(
66 package_identifier: PackageIdentifier,
67 package_version: PackageVersion,
68 default_locale: LanguageTag,
69 ) -> Self {
70 Self {
71 package_identifier,
72 package_version,
73 default_locale,
74 manifest_type: ManifestType::Version,
75 manifest_version: ManifestVersion::default(),
76 }
77 }
78
79 /// Returns the default locale.
80 #[must_use]
81 #[inline]
82 pub const fn default_locale(&self) -> &LanguageTag {
83 &self.default_locale
84 }
85
86 /// Returns the manifest version.
87 #[must_use]
88 #[inline]
89 pub const fn manifest_version(&self) -> ManifestVersion {
90 self.manifest_version
91 }
92
93 pub fn update(&mut self, package_version: &PackageVersion) {
94 self.package_version.clone_from(package_version);
95 self.manifest_type = ManifestType::Version;
96 self.update_manifest_version();
97 }
98}
99
100impl Manifest for VersionManifest {
101 const SCHEMA: &'static str = "https://aka.ms/winget-manifest.version.1.12.0.schema.json";
102
103 const TYPE: ManifestType = ManifestType::Version;
104
105 fn package_identifier(&self) -> &PackageIdentifier {
106 &self.package_identifier
107 }
108
109 fn package_version(&self) -> &PackageVersion {
110 &self.package_version
111 }
112
113 fn manifest_version(&self) -> ManifestVersion {
114 self.manifest_version
115 }
116
117 fn update_manifest_version(&mut self) {
118 self.manifest_version.update();
119 }
120}
121
122impl Default for VersionManifest {
123 fn default() -> Self {
124 Self {
125 package_identifier: PackageIdentifier::default(),
126 package_version: PackageVersion::default(),
127 default_locale: LanguageTag::default(),
128 manifest_type: ManifestType::Version,
129 manifest_version: ManifestVersion::default(),
130 }
131 }
132}