mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-14 16:51:18 +10:00
feat(settings): finish download dir CRUD interface
This commit is contained in:
@ -101,7 +101,7 @@ impl DatabaseImpls for DatabaseInterface {
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn add_new_download_dir(new_dir: String) -> Result<(), String> {
|
||||
pub fn add_download_dir(new_dir: String) -> Result<(), String> {
|
||||
// Check the new directory is all good
|
||||
let new_dir_path = Path::new(&new_dir);
|
||||
if new_dir_path.exists() {
|
||||
@ -124,6 +124,9 @@ pub fn add_new_download_dir(new_dir: String) -> Result<(), String> {
|
||||
|
||||
// Add it to the dictionary
|
||||
let mut lock = DB.borrow_data_mut().unwrap();
|
||||
if lock.games.install_dirs.contains(&new_dir) {
|
||||
return Err("Download directory already used".to_string());
|
||||
}
|
||||
lock.games.install_dirs.push(new_dir);
|
||||
drop(lock);
|
||||
DB.save().unwrap();
|
||||
@ -131,6 +134,16 @@ pub fn add_new_download_dir(new_dir: String) -> Result<(), String> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn delete_download_dir(index: usize) -> Result<(), String> {
|
||||
let mut lock = DB.borrow_data_mut().unwrap();
|
||||
lock.games.install_dirs.remove(index);
|
||||
drop(lock);
|
||||
DB.save().unwrap();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Will, in future, return disk/remaining size
|
||||
// Just returns the directories that have been set up
|
||||
#[tauri::command]
|
||||
|
||||
@ -10,7 +10,7 @@ mod tests;
|
||||
|
||||
use crate::db::DatabaseImpls;
|
||||
use auth::{auth_initiate, generate_authorization_header, recieve_handshake};
|
||||
use db::{add_new_download_dir, fetch_download_dir_stats, DatabaseInterface, DATA_ROOT_DIR};
|
||||
use db::{add_download_dir, delete_download_dir, fetch_download_dir_stats, DatabaseInterface, DATA_ROOT_DIR};
|
||||
use downloads::download_commands::*;
|
||||
use downloads::download_manager::DownloadManagerBuilder;
|
||||
use downloads::download_manager_interface::DownloadManager;
|
||||
@ -126,7 +126,8 @@ pub fn run() {
|
||||
// Library
|
||||
fetch_library,
|
||||
fetch_game,
|
||||
add_new_download_dir,
|
||||
add_download_dir,
|
||||
delete_download_dir,
|
||||
fetch_download_dir_stats,
|
||||
// Downloads
|
||||
download_game,
|
||||
|
||||
Reference in New Issue
Block a user