-
Notifications
You must be signed in to change notification settings - Fork 614
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config): support custom app dir in windows (#582)
* feat(backend): custom app dir in windows * feat(frontend): support to change app dir
- Loading branch information
1 parent
68e1ad2
commit 2e48df0
Showing
11 changed files
with
172 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,5 @@ pub mod init; | |
pub mod resolve; | ||
pub mod tmpl; | ||
// mod winhelp; | ||
#[cfg(windows)] | ||
pub mod winreg; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use std::{ | ||
io::ErrorKind, | ||
path::{Path, PathBuf}, | ||
}; | ||
|
||
use anyhow::Result; | ||
use winreg::{enums::*, RegKey}; | ||
|
||
pub fn get_app_dir() -> Result<Option<PathBuf>> { | ||
let hcu = RegKey::predef(HKEY_CURRENT_USER); | ||
let key = match hcu.open_subkey("Software\\Clash Nyanpasu") { | ||
Ok(key) => key, | ||
Err(e) => { | ||
if let ErrorKind::NotFound = e.kind() { | ||
return Ok(None); | ||
} | ||
return Err(e.into()); | ||
} | ||
}; | ||
let path: String = key.get_value("AppDir")?; | ||
if path.is_empty() { | ||
return Ok(None); | ||
} | ||
Ok(Some(PathBuf::from(path))) | ||
} | ||
|
||
pub fn set_app_dir(path: &Path) -> Result<()> { | ||
let hcu = RegKey::predef(HKEY_CURRENT_USER); | ||
let (key, _) = hcu.create_subkey("Software\\Clash Nyanpasu")?; | ||
let path = path.to_str().unwrap(); // safe to unwrap | ||
key.set_value("AppDir", &path)?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters