winget_types/version/
mod.rs

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