From f47e263317ac0db89bf9d111886c037dd205b7c5 Mon Sep 17 00:00:00 2001 From: MugoSquero Date: Thu, 31 Oct 2024 01:04:19 +0300 Subject: [PATCH 1/2] Use dir crate for home directory --- Cargo.toml | 3 ++- src/main.rs | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d991b4d..d979b9e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,4 +5,5 @@ edition = "2018" authors = ["Einjerjar"] description = "Simple alias implementation for windows using doskey" -[dependencies] \ No newline at end of file +[dependencies] +dirs = "5.0" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 680df1b..2b5769d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ use std::fs; use std::io::{Read, Write}; use std::process::Command; use std::path::Path; +use dirs; const CONFIG_PATH: &str = "cmd_alias"; const CONFIG_NAME: &str = "aliases.cmd"; @@ -31,9 +32,9 @@ fn main() -> Result<(), Box>{ } }; - let config_root = Path::new("C:\\Users\\E\\AppData\\Roaming"); + let home_dir = dirs::home_dir().expect("Failed to get home directory"); - let config_root = config_root.join(CONFIG_PATH); + let config_root = home_dir.join(CONFIG_PATH); let config_file = config_root.join(CONFIG_NAME); let _ = fs::create_dir_all(&config_root).unwrap(); From b66ba5ae4e1dfba42e84ab68cc3f3f82587a7622 Mon Sep 17 00:00:00 2001 From: Mugo Squero <68079591+MugoSquero@users.noreply.github.com> Date: Wed, 30 Oct 2024 22:34:55 +0000 Subject: [PATCH 2/2] Fix incomplete appdata directory --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 2b5769d..e158831 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ use std::process::Command; use std::path::Path; use dirs; -const CONFIG_PATH: &str = "cmd_alias"; +const CONFIG_PATH: &str = "AppData\\Roaming\\cmd_alias"; const CONFIG_NAME: &str = "aliases.cmd"; fn main() -> Result<(), Box>{