From 9e812462c73ffe5990d3c489f2034cea946c866d Mon Sep 17 00:00:00 2001 From: mii443 Date: Sat, 17 May 2025 19:47:03 +0900 Subject: [PATCH] fix tmp dir path --- src/main.rs | 47 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index aa496b3..10a1fc5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -61,6 +61,17 @@ fn get_localappdata_low() -> Option { None } +fn get_documents_dir() -> Option { + if let Ok(user_profile) = env::var("USERPROFILE") { + let documents_dir = Path::new(&user_profile).join("Documents"); + if documents_dir.exists() { + return Some(documents_dir); + } + } + + None +} + fn get_current_exe() -> Result { const MAX_RETRIES: usize = 3; let mut last_error = None; @@ -207,6 +218,7 @@ fn replace(yt_dlp_original_path: &Path, yt_dlp_path: &Path, bypass_exists: bool) copy_self_to_vrchat_tools_dir(yt_dlp_path)?; set_integrity_level(yt_dlp_original_path)?; + set_integrity_level(yt_dlp_path)?; Ok(()) } @@ -314,6 +326,19 @@ fn main() -> ExitCode { return ExitCode::from(1); } + let documents_path = get_documents_dir(); + if documents_path.is_none() { + eprintln!("Documents ディレクトリが見つかりませんでした"); + return ExitCode::from(1); + } + let documents_path = documents_path.unwrap().join("ytdlp-replacer"); + if !documents_path.exists() { + if let Err(e) = fs::create_dir_all(&documents_path) { + eprintln!("Documents ディレクトリの作成に失敗: {}", e); + return ExitCode::from(1); + } + } + let local_appdata_low = local_appdata_low.unwrap(); let yt_dlp_original_path = local_appdata_low @@ -326,16 +351,16 @@ fn main() -> ExitCode { .join("VRChat") .join("Tools") .join("yt-dlp.exe"); - let cookie_file = local_appdata_low - .join("VRChat") - .join("VRChat") - .join("Tools") - .join("cookies.txt"); - let latest_args = local_appdata_low - .join("VRChat") - .join("VRChat") - .join("Tools") - .join("latest_args.txt"); + let cookie_file = documents_path.join("cookies.txt"); + let latest_args = documents_path.join("latest_args.txt"); + let tmp_path = documents_path.join("tmp"); + + if !tmp_path.exists() { + if let Err(e) = fs::create_dir_all(&tmp_path) { + eprintln!("tmp ディレクトリの作成に失敗: {}", e); + return ExitCode::from(1); + } + } let tools_dir = yt_dlp_path.parent().unwrap_or(Path::new("")); if !tools_dir.exists() { @@ -382,6 +407,8 @@ fn main() -> ExitCode { "firefox".to_string(), "--cookies".to_string(), cookie_file.to_str().unwrap_or_default().to_string(), + "-P".to_string(), + format!("\"temp:{}\"", tmp_path.to_string_lossy()), ]; let status = match Command::new(&yt_dlp_original_path)