Merge pull request #3588 from 21pages/fix

try create default video save directory at first
This commit is contained in:
RustDesk 2023-03-10 16:53:41 +08:00 committed by GitHub
commit 2341232ed2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -648,17 +648,26 @@ pub fn get_langs() -> String {
#[inline]
pub fn default_video_save_directory() -> String {
let appname = crate::get_app_name();
// In order to make the function call results of the UI process and the video process the same, no result check is performed.
let try_create = |path: &std::path::Path| {
if !path.exists() {
if std::fs::create_dir_all(path).is_err() {
log::warn!("video directory {:?} create failed.", path);
}
}
path.to_string_lossy().to_string()
};
#[cfg(any(target_os = "android", target_os = "ios"))]
if let Ok(home) = config::APP_HOME_DIR.read() {
let mut path = home.to_owned();
path.push_str("/RustDesk/ScreenRecord");
return path;
return try_create(&std::path::Path::from(path));
}
if let Some(user) = directories_next::UserDirs::new() {
if let Some(video_dir) = user.video_dir() {
return video_dir.join(appname).to_string_lossy().to_string();
return try_create(&video_dir.join(&appname));
}
}
@ -669,12 +678,12 @@ pub fn default_video_save_directory() -> String {
} else {
"Videos"
};
return home.join(name).join(appname).to_string_lossy().to_string();
return try_create(&home.join(name).join(&appname));
}
if let Ok(exe) = std::env::current_exe() {
if let Some(dir) = exe.parent() {
return dir.join("videos").to_string_lossy().to_string();
return try_create(&dir.join("videos"));
}
}
"".to_owned()