feat: finish highlevel register
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
use crate::{lowlevel, utilities, win32::{self, concept}};
|
||||
use crate::{
|
||||
lowlevel, utilities,
|
||||
win32::{self, concept},
|
||||
};
|
||||
use regex::Regex;
|
||||
use std::collections::HashMap;
|
||||
use std::ffi::OsStr;
|
||||
@@ -462,9 +465,12 @@ impl Program {
|
||||
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!(
|
||||
"Adding ProgId \"{0}\" subkey...",
|
||||
progid_key.inner().to_string()
|
||||
);
|
||||
|
||||
// Create ProgId subkey
|
||||
debug_println!("Adding ProgId \"{0}\" subkey...", progid_key.inner().to_string());
|
||||
progid_key.ensure(scope)?;
|
||||
// Write ProgId values
|
||||
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_friendly_type_name(scope, name)?;
|
||||
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.
|
||||
@@ -488,24 +498,33 @@ impl Program {
|
||||
// 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)?;
|
||||
|
||||
// According to Microsoft document, when uninstalling application,
|
||||
// it is enough that only delete ProgId keys.
|
||||
// Programmer doesn't need to edit something in Ext keys.
|
||||
// So we delete ProgId subkeys one by one in there.
|
||||
// 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
|
||||
debug_println!("Deleting ProgId \"{0}\" subkey...", progid_key.inner().to_string());
|
||||
progid_key.delete(scope)?;
|
||||
}
|
||||
|
||||
|
||||
// Everything is okey.
|
||||
// Notify changes and return
|
||||
win32::utilities::notify_assoc_changed();
|
||||
@@ -517,8 +536,35 @@ impl Program {
|
||||
/// 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`.
|
||||
pub fn is_registered(&self, view: View) -> Result<bool, ProgramError> {
|
||||
todo!()
|
||||
pub fn is_registered(&self, scope: Scope) -> Result<bool, ProgramError> {
|
||||
// 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> {
|
||||
|
||||
Reference in New Issue
Block a user