1
0

Compare commits

..

2 Commits

Author SHA1 Message Date
e325ba08f1 feat: finish highlevel register 2026-05-08 10:56:47 +08:00
03d17fad6e feat: finish highlevel unregister 2026-05-08 10:45:43 +08:00

View File

@@ -1,4 +1,7 @@
use crate::{lowlevel, utilities, win32::{self, concept}}; use crate::{
lowlevel, utilities,
win32::{self, concept},
};
use regex::Regex; use regex::Regex;
use std::collections::HashMap; use std::collections::HashMap;
use std::ffi::OsStr; use std::ffi::OsStr;
@@ -462,9 +465,12 @@ impl Program {
debug_println!("Adding ProgId subkey..."); debug_println!("Adding ProgId subkey...");
for program_progid_key in &mut self.ext_keys { for program_progid_key in &mut self.ext_keys {
let progid_key = &mut program_progid_key.progid_key; let progid_key = &mut program_progid_key.progid_key;
debug_println!(
"Adding ProgId \"{0}\" subkey...",
progid_key.inner().to_string()
);
// Create ProgId subkey // Create ProgId subkey
debug_println!("Adding ProgId \"{0}\" subkey...", progid_key.inner().to_string());
progid_key.ensure(scope)?; progid_key.ensure(scope)?;
// Write ProgId values // Write ProgId values
let name = Some(&program_progid_key.name.inner); let name = Some(&program_progid_key.name.inner);
@@ -472,6 +478,10 @@ impl Program {
progid_key.set_shell_verb(scope, &program_progid_key.behavior.inner)?; progid_key.set_shell_verb(scope, &program_progid_key.behavior.inner)?;
progid_key.set_friendly_type_name(scope, name)?; progid_key.set_friendly_type_name(scope, name)?;
progid_key.set_default_icon(scope, Some(&program_progid_key.icon.inner))?; progid_key.set_default_icon(scope, Some(&program_progid_key.icon.inner))?;
// Add this progid to file extension "open with" list.
let ext_key = &mut program_progid_key.ext_key;
ext_key.add_into_open_with_progids(scope, progid_key.inner())?;
} }
// Everything is okey. // Everything is okey.
@@ -485,7 +495,40 @@ impl Program {
/// No matter whether there is registration of this application, /// No matter whether there is registration of this application,
/// this function always make sure that there is no registration after running this function. /// this function always make sure that there is no registration after running this function.
pub fn unregister(&mut self, scope: Scope) -> Result<(), ProgramError> { pub fn unregister(&mut self, scope: Scope) -> Result<(), ProgramError> {
todo!() // Delete App Paths subkey
debug_println!("Deleting App Paths subkey...");
self.app_paths_key.delete(scope)?;
// Delete Applications subkey
debug_println!("Deleting Applications subkey...");
self.applications_key.delete(scope)?;
// Delete ProgId subkeys one by one.
debug_println!("Adding ProgId subkey...");
for program_progid_key in &mut self.ext_keys {
let progid_key = &mut program_progid_key.progid_key;
debug_println!(
"Deleting ProgId \"{0}\" subkey...",
progid_key.inner().to_string()
);
// YYC MARK:
// According to Microsoft document, when uninstalling application,
// there is no need to reset the default open way of file extension.
// So we simply remove it from "open with" list.
// Remove this ProgId from file extension "open with" list.
let ext_key = &mut program_progid_key.ext_key;
ext_key.remove_from_open_with_progids(scope, progid_key.inner())?;
// Delete ProgId subkey
progid_key.delete(scope)?;
}
// Everything is okey.
// Notify changes and return
win32::utilities::notify_assoc_changed();
Ok(())
} }
/// Check whether this application has been registered in given view. /// Check whether this application has been registered in given view.
@@ -493,8 +536,35 @@ impl Program {
/// Please note that this is a rough check and do not validate any data. /// Please note that this is a rough check and do not validate any data.
/// ///
/// The return value only ensures the pre-requirement of `register` and `unregister`. /// The return value only ensures the pre-requirement of `register` and `unregister`.
pub fn is_registered(&self, view: View) -> Result<bool, ProgramError> { pub fn is_registered(&self, scope: Scope) -> Result<bool, ProgramError> {
todo!() // Check App Paths subkey.
debug_println!("Checking App Paths subkey...");
if !self.app_paths_key.is_exist(scope)? {
return Ok(false);
}
// Check Application subkey.
debug_println!("Checking Applications subkey...");
if !self.applications_key.is_exist(scope.into())? {
return Ok(false);
}
// Check ProgId subkey.
debug_println!("Checking ProgId subkey...");
for program_progid_key in &self.ext_keys {
let progid_key = &program_progid_key.progid_key;
debug_println!(
"Checking ProgId \"{0}\" subkey...",
progid_key.inner().to_string()
);
if !progid_key.is_exist(scope.into())? {
return Ok(false);
}
}
// Every subkeys are roughly existing.
Ok(true)
} }
pub fn link_ext(&self, scope: Scope, index: usize) -> Result<(), ProgramError> { pub fn link_ext(&self, scope: Scope, index: usize) -> Result<(), ProgramError> {