pub fn write_settings() {
    let default_set = Settings::default();
    let default_wl = Watchlist::default();
    let set_file = settings_dir();

    let mut directory = dirs::config_dir().unwrap();
    directory.push("nyaadle");

    let directory = String::from(directory.to_str().unwrap());

    // If the settings file doesn't exist, create it.
    if !Path::new(&set_file).exists() {
        println!("nyaadle.db not found. Creating it right now.");
        // create directory
        if !Path::new(&directory).exists() {
            std::fs::create_dir(&directory).expect("Unable to create directory");
        }
        // Create nyaadle.db and add dl-dir
        let db_conn = db_create(&set_file);
        let db_ar_write = db_write_dir(&set_file, &default_set.ar_key, &default_set.ar_val);
        let db_dl_write = db_write_dir(&set_file, &default_set.dl_key, &default_set.dl_val);
        let db_url_write = db_write_dir(&set_file, &default_set.url_key, &default_set.url_val);
        let db_log_write = db_write_dir(&set_file, &default_set.log_key, &default_set.log_val);
        let db_log_file = File::create(&default_set.log_val);
        match db_log_file {
            Ok(_) => println!("Created log file."),
            Err(_) => println!("Failed to create log file"),
        }

        // Append watch-list to nyaadle.db
        let db_wl_write = db_write_wl(&set_file, &default_wl.title, &default_wl.option);
        if db_conn == Ok(())
            && db_ar_write == Ok(())
            && db_dl_write == Ok(())
            && db_wl_write == Ok(())
            && db_url_write == Ok(())
            && db_log_write == Ok(())
        {
            println!("nyaadle.db created.");
            println!(
                "You can change settings by editing the config file in {}",
                &set_file
            );
        } else {
            println!("Failed to create nyaadle.db");
        }
    }
}
/// Checks if the config directory exists and then creates it if it's not found.
Checks if the config directory exists and then creates it if it's not found.
Checks if the config directory exists and then creates it if it ' s not found .
pub fn write_settings() {
    let default_set = Settings::default();
    let default_wl = Watchlist::default();
    let set_file = settings_dir();
    let mut directory = dirs::config_dir().unwrap();
    directory.push("nyaadle");
    let directory = String::from(directory.to_str().unwrap());
    // If the settings file doesn't exist, create it.
    if !Path::new(&set_file).exists() {
        println!("nyaadle.db not found. Creating it right now.");
        // create directory
        if !Path::new(&directory).exists() {
            std::fs::create_dir(&directory).expect("Unable to create directory");
        }
        // Create nyaadle.db and add dl-dir
        let db_conn = db_create(&set_file);
        let db_ar_write = db_write_dir(&set_file, &default_set.ar_key, &default_set.ar_val);
        let db_dl_write = db_write_dir(&set_file, &default_set.dl_key, &default_set.dl_val);
        let db_url_write = db_write_dir(&set_file, &default_set.url_key, &default_set.url_val);
        let db_log_write = db_write_dir(&set_file, &default_set.log_key, &default_set.log_val);
        let db_log_file = File::create(&default_set.log_val);
        match db_log_file {
            Ok(_) => println!("Created log file."),
            Err(_) => println!("Failed to create log file"),
        }
        // Append watch-list to nyaadle.db
        let db_wl_write = db_write_wl(&set_file, &default_wl.title, &default_wl.option);
        if db_conn == Ok(())
            && db_ar_write == Ok(())
            && db_dl_write == Ok(())
            && db_wl_write == Ok(())
            && db_url_write == Ok(())
            && db_log_write == Ok(())
        {
            println!("nyaadle.db created.");
            println!(
                "You can change settings by editing the config file in {}",
                &set_file
            );
        } else {
            println!("Failed to create nyaadle.db");
        }
    }
}
pub fn write_settings ( ) { let default_set = Settings :: default ( ) ; let default_wl = Watchlist :: default ( ) ; let set_file = settings_dir ( ) ; let mut directory = dirs :: config_dir ( ) . unwrap ( ) ; directory . push ( " " ) ; let directory = String :: from ( directory . to_str ( ) . unwrap ( ) ) ; // If the settings file doesn't exist, create it. if ! Path :: new ( & set_file ) . exists ( ) { println ! ( " " ) ; // create directory if ! Path :: new ( & directory ) . exists ( ) { std :: fs :: create_dir ( & directory ) . expect ( " " ) ; } // Create nyaadle.db and add dl-dir let db_conn = db_create ( & set_file ) ; let db_ar_write = db_write_dir ( & set_file , & default_set . ar_key , & default_set . ar_val ) ; let db_dl_write = db_write_dir ( & set_file , & default_set . dl_key , & default_set . dl_val ) ; let db_url_write = db_write_dir ( & set_file , & default_set . url_key , & default_set . url_val ) ; let db_log_write = db_write_dir ( & set_file , & default_set . log_key , & default_set . log_val ) ; let db_log_file = File :: create ( & default_set . log_val ) ; match db_log_file { Ok ( _ ) => println ! ( " " ) , Err ( _ ) => println ! ( " " ) , } // Append watch-list to nyaadle.db let db_wl_write = db_write_wl ( & set_file , & default_wl . title , & default_wl . option ) ; if db_conn == Ok ( ( ) ) && db_ar_write == Ok ( ( ) ) && db_dl_write == Ok ( ( ) ) && db_wl_write == Ok ( ( ) ) && db_url_write == Ok ( ( ) ) && db_log_write == Ok ( ( ) ) { println ! ( " " ) ; println ! ( " " set_file ) ; } else { println ! ( " " ) ; } } }
Checks if the config directory exists and then creates it if it's not found.
Checks if the config directory exists and then creates it if it ' s not found .