Skip to content

Commit 8ff023f

Browse files
committed
Enumerate family packages
1 parent 80cbe80 commit 8ff023f

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

examples/dump.rs

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ fn main() {
33
println!("--------");
44
for fam in appx::repository::families().unwrap() {
55
println!("{}", fam);
6+
for pkg in appx::repository::packages_for_family(&fam).unwrap() {
7+
println!(" {}", pkg);
8+
}
69
}
710
println!();
811

src/repository.rs

+24-4
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,29 @@ pub fn families() -> io::Result<impl Iterator<Item = PackageFamilyName>> { imp::
3333
/// ```
3434
pub fn packages() -> io::Result<impl Iterator<Item = PackageFullName>> { imp::packages() }
3535

36+
/// Get the [PackageFullName]s installed on this computer for a given [PackageFamilyName]
37+
///
38+
/// ### Examples
39+
///
40+
/// ```rust
41+
/// let fam = appx::PackageFamilyName::new("NcsiUwpApp_8wekyb3d8bbwe");
42+
/// for pkg in appx::repository::packages_for_family(&fam).unwrap() {
43+
/// println!("{}", pkg);
44+
/// }
45+
/// ```
46+
pub fn packages_for_family(family: &PackageFamilyName) -> io::Result<impl Iterator<Item = PackageFullName>> { imp::packages_for_family(family) }
47+
48+
3649
/// Check if the [PackageFamilyName] appears on this computer
37-
pub fn has_family(fam: impl Into<PackageFamilyName>) -> bool {
50+
pub fn has_family(fam: &PackageFamilyName) -> bool {
3851
if !cfg!(windows) { return false; }
39-
let fam = fam.into();
4052
let key = reg::Key::hkcr(winstr0!(r"Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\Repository\Families"), reg::Options::NONE, reg::SAM::READ_ONLY);
4153
key.ok().and_then(|key| key.subkey(fam.units0(), reg::Options::NONE, reg::SAM::READ_ONLY).ok()).is_some()
4254
}
4355

4456
/// Check if the [PackageFullName] appears on this computer
45-
pub fn has_package(pfn: impl Into<PackageFullName>) -> bool {
57+
pub fn has_package(pfn: &PackageFullName) -> bool {
4658
if !cfg!(windows) { return false; }
47-
let pfn = pfn.into();
4859
let key = reg::Key::hkcr(winstr0!(r"Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\Repository\Packages"), reg::Options::NONE, reg::SAM::READ_ONLY);
4960
key.ok().and_then(|key| key.subkey(pfn.units0(), reg::Options::NONE, reg::SAM::READ_ONLY).ok()).is_some()
5061
}
@@ -74,6 +85,7 @@ pub fn add_appx_package(path: impl AsRef<Path>) -> io::Result<()> {
7485
use super::*;
7586
pub(super) fn families() -> io::Result<impl Iterator<Item = PackageFamilyName>> { Ok(None.into_iter()) }
7687
pub(super) fn packages() -> io::Result<impl Iterator<Item = PackageFullName >> { Ok(None.into_iter()) }
88+
pub(super) fn packages_for_family(_family: &PackageFamilyName) -> io::Result<impl Iterator<Item = PackageFullName>> { Ok(None.into_iter()) }
7789
}
7890

7991

@@ -110,6 +122,14 @@ pub fn add_appx_package(path: impl AsRef<Path>) -> io::Result<()> {
110122
})
111123
}
112124

125+
pub(super) fn packages_for_family(family: &PackageFamilyName) -> io::Result<impl Iterator<Item = PackageFullName>> {
126+
Ok(PackagesIter {
127+
key: reg::Key::hkcr(winstr0!(r"Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\Repository\Families"), reg::Options::NONE, reg::SAM::READ_ONLY)?
128+
.subkey(family.units0(), reg::Options::NONE, reg::SAM::READ_ONLY)?,
129+
index: 0,
130+
})
131+
}
132+
113133
struct PackagesIter {
114134
key: reg::Key,
115135
index: u32,

0 commit comments

Comments
 (0)