Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create stored_saving_location if not existing, fallback to saving_location on error #297

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,27 @@ impl Settings {
pub fn saving_location(&self) -> PathBuf {
let stored_saving_location: PathBuf = self.0.get("saving-location");

if !stored_saving_location.as_os_str().is_empty() {
return stored_saving_location;
}

let saving_location =
glib::user_special_dir(glib::UserDirectory::Videos).unwrap_or_else(glib::home_dir);

if !stored_saving_location.as_os_str().is_empty() {
return self.create_saving_location(stored_saving_location);
}

let kooha_saving_location = saving_location.join("Kooha");
self.create_saving_location(kooha_saving_location)
}

if let Err(err) = fs::create_dir_all(&kooha_saving_location) {
pub fn create_saving_location(&self, saving_location: PathBuf) -> PathBuf {
SeaDve marked this conversation as resolved.
Show resolved Hide resolved
if let Err(err) = fs::create_dir_all(&saving_location) {
tracing::warn!(
"Failed to create dir at `{}`: {:?}",
kooha_saving_location.display(),
saving_location.display(),
err
);
return saving_location;
return glib::user_special_dir(glib::UserDirectory::Videos).unwrap_or_else(glib::home_dir);
}

kooha_saving_location
saving_location
}

pub fn connect_saving_location_changed(
Expand Down