summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/commands/download.rs90
-rw-r--r--src/commands/io.rs12
-rw-r--r--src/commands/list.rs3
-rw-r--r--src/commands/mod.rs2
-rw-r--r--src/commands/update.rs2
-rw-r--r--src/input.rs15
6 files changed, 85 insertions, 39 deletions
diff --git a/src/commands/download.rs b/src/commands/download.rs
index 9f70499..0f9011c 100644
--- a/src/commands/download.rs
+++ b/src/commands/download.rs
@@ -1,49 +1,69 @@
1use crate::{files::{get_downloaded_versions, download_versions, delete_version, disable_version}, db::userlist_get_all_current_versions_with_mods, modrinth::get_raw_versions}; 1use crate::{files::{get_downloaded_versions, download_versions, delete_version, disable_version}, db::{userlist_get_all_current_versions_with_mods, lists_get_all_ids, lists_get}, modrinth::get_raw_versions};
2#[allow(unused_imports)] 2use crate::{List, get_current_list, config::Cfg, input::Input};
3use crate::{List, get_current_list, config::Cfg, db::userlist_get_all_downloads, input::Input};
4 3
5pub async fn download(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> { 4pub async fn download(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> {
6 5
7 let current_list = get_current_list(config.clone())?; 6 let mut liststack: Vec<List> = vec![];
7 if input.all_lists {
8 let list_ids = lists_get_all_ids(config.clone())?;
9 for id in list_ids {
10 liststack.push(lists_get(config.clone(), id)?);
11 }
12 } else {
13 let current = get_current_list(config.clone())?;
14 println!("Checking for updates of mods in {}", current.id);
15 liststack.push(current)
16 }
8 17
9 let downloaded_versions = get_downloaded_versions(current_list.clone())?; 18 for current_list in liststack {
10 let current_version_ids = userlist_get_all_current_versions_with_mods(config.clone(), String::from(&current_list.id))?; 19 let downloaded_versions = get_downloaded_versions(current_list.clone())?;
20 let current_version_ids = userlist_get_all_current_versions_with_mods(config.clone(), String::from(&current_list.id))?;
11 21
12 let mut to_download: Vec<String> = vec![]; 22 let mut to_download: Vec<String> = vec![];
13 //(mod_id, version_id) 23 //(mod_id, version_id)
14 let mut to_disable: Vec<(String, String)> = vec![]; 24 let mut to_disable: Vec<(String, String)> = vec![];
15 25
16 for version in current_version_ids { 26 for version in current_version_ids {
17 let mod_id = version.0; 27 let mod_id = version.0;
18 let current_version = version.1; 28 let current_version = version.1;
19 29
20 let current_download = downloaded_versions.get(&mod_id); 30 let current_download = downloaded_versions.get(&mod_id);
21 31
22 if current_download.is_none() { 32 if current_download.is_none() || input.clean {
23 to_download.push(current_version);
24 } else {
25 let downloaded_version = current_download.ok_or("SOMETHING_HAS_REALLY_GONE_WRONG")?;
26 if &current_version != downloaded_version {
27 to_disable.push((mod_id.clone(), String::from(downloaded_version)));
28 to_download.push(current_version); 33 to_download.push(current_version);
34 } else {
35 let downloaded_version = current_download.ok_or("SOMETHING_HAS_REALLY_GONE_WRONG")?;
36 if &current_version != downloaded_version {
37 to_disable.push((mod_id.clone(), String::from(downloaded_version)));
38 to_download.push(current_version);
39 }
29 } 40 }
30 } 41 }
31 } 42
32 43 if input.clean {
33 if !to_download.is_empty() { 44 let dl_path = &current_list.download_folder;
34 download_versions(current_list.clone(), get_raw_versions(String::from(&config.apis.modrinth), to_download).await).await?; 45 println!("Cleaning {}", dl_path);
35 } else { 46 for entry in std::fs::read_dir(dl_path)? {
36 println!("There are no new versions to download"); 47 let entry = entry?;
37 } 48 std::fs::remove_file(entry.path())?;
38 49 }
39 if !to_disable.is_empty() { 50 }
40 for ver in to_disable { 51
41 if input.delete_old { 52 if !to_download.is_empty() {
42 println!("Deleting version {} for mod {}", ver.1, ver.0); 53 download_versions(current_list.clone(), get_raw_versions(String::from(&config.apis.modrinth), to_download).await).await?;
43 delete_version(current_list.clone(), ver.1)?; 54 } else {
44 } else { 55 println!("There are no new versions to download");
45 disable_version(config.clone(), current_list.clone(), ver.1, ver.0)?; 56 }
46 }; 57
58 if !to_disable.is_empty() {
59 for ver in to_disable {
60 if input.delete_old {
61 println!("Deleting version {} for mod {}", ver.1, ver.0);
62 delete_version(current_list.clone(), ver.1)?;
63 } else {
64 disable_version(config.clone(), current_list.clone(), ver.1, ver.0)?;
65 };
66 }
47 } 67 }
48 } 68 }
49 69
diff --git a/src/commands/io.rs b/src/commands/io.rs
new file mode 100644
index 0000000..dc1f408
--- /dev/null
+++ b/src/commands/io.rs
@@ -0,0 +1,12 @@
1use crate::{input::{Input, Subcmd}, config::Cfg};
2
3pub fn io(_config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> {
4
5 match input.subcommand.ok_or("INVALID_INPUT")? {
6 Subcmd::Export => {},
7 Subcmd::Import => {},
8 _ => {},
9 }
10
11 Ok(())
12}
diff --git a/src/commands/list.rs b/src/commands/list.rs
index 76965df..096ce65 100644
--- a/src/commands/list.rs
+++ b/src/commands/list.rs
@@ -21,6 +21,9 @@ pub fn list(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>>
21 }, 21 },
22 Subcmd::Remove => { 22 Subcmd::Remove => {
23 remove(config, input.args.ok_or("")?) 23 remove(config, input.args.ok_or("")?)
24 },
25 _ => {
26 Err(Box::new(Error::new(ErrorKind::InvalidInput, "WRONG_SUBCOMMAND")))
24 } 27 }
25 } 28 }
26} 29}
diff --git a/src/commands/mod.rs b/src/commands/mod.rs
index 20badcb..0d5bd00 100644
--- a/src/commands/mod.rs
+++ b/src/commands/mod.rs
@@ -3,9 +3,11 @@ pub mod list;
3pub mod update; 3pub mod update;
4pub mod setup; 4pub mod setup;
5pub mod download; 5pub mod download;
6pub mod io;
6 7
7pub use modification::*; 8pub use modification::*;
8pub use list::*; 9pub use list::*;
9pub use update::*; 10pub use update::*;
10pub use setup::*; 11pub use setup::*;
11pub use download::*; 12pub use download::*;
13pub use io::*;
diff --git a/src/commands/update.rs b/src/commands/update.rs
index 498b6a9..0895efb 100644
--- a/src/commands/update.rs
+++ b/src/commands/update.rs
@@ -41,7 +41,7 @@ pub async fn update(config: Cfg, input: Input) -> Result<(), Box<dyn std::error:
41 let version_db_string = project.versions.join("|"); 41 let version_db_string = project.versions.join("|");
42 42
43 //Adding to stack if not the same versions in the list OR if clean == true 43 //Adding to stack if not the same versions in the list OR if clean == true
44 if input.clone().clean || (version_db_string != current_version.versions) { 44 if input.clean || (version_db_string != current_version.versions) {
45 updatestack.push(match specific_update(config.clone(), input.clone(), current_list.clone(), project.clone()).await { 45 updatestack.push(match specific_update(config.clone(), input.clone(), current_list.clone(), project.clone()).await {
46 Ok(ver) => { 46 Ok(ver) => {
47 current_versions.push((disable_version, p_id)); 47 current_versions.push((disable_version, p_id));
diff --git a/src/input.rs b/src/input.rs
index 41b0c29..ffc1213 100644
--- a/src/input.rs
+++ b/src/input.rs
@@ -1,5 +1,5 @@
1use std::env; 1use std::env;
2use crate::{config::Cfg, list, modification, update, setup, download, error::{MLError, ErrorType, MLE}}; 2use crate::{config::Cfg, list, modification, update, setup, download, io, error::{MLError, ErrorType, MLE}};
3 3
4#[derive(Debug, Clone, PartialEq, Eq)] 4#[derive(Debug, Clone, PartialEq, Eq)]
5pub struct Input { 5pub struct Input {
@@ -77,7 +77,8 @@ pub enum Cmd {
77 List, 77 List,
78 Update, 78 Update,
79 Download, 79 Download,
80 Setup 80 Setup,
81 Io
81} 82}
82 83
83impl Cmd { 84impl Cmd {
@@ -88,6 +89,7 @@ impl Cmd {
88 "update" => Self::Update, 89 "update" => Self::Update,
89 "download" => Self::Download, 90 "download" => Self::Download,
90 "setup" => Self::Setup, 91 "setup" => Self::Setup,
92 "io" => Self::Io,
91 _ => return Err(MLError::new(ErrorType::ArgumentError, "Unknown command")) 93 _ => return Err(MLError::new(ErrorType::ArgumentError, "Unknown command"))
92 }; 94 };
93 Ok(cmd) 95 Ok(cmd)
@@ -98,7 +100,9 @@ impl Cmd {
98pub enum Subcmd { 100pub enum Subcmd {
99 Add, 101 Add,
100 Remove, 102 Remove,
101 Change 103 Change,
104 Export,
105 Import,
102} 106}
103 107
104impl Subcmd { 108impl Subcmd {
@@ -107,6 +111,8 @@ impl Subcmd {
107 "add" => Self::Add, 111 "add" => Self::Add,
108 "remove" => Self::Remove, 112 "remove" => Self::Remove,
109 "change" => Self::Change, 113 "change" => Self::Change,
114 "export" => Self::Export,
115 "import" => Self::Import,
110 _ => return Err(MLError::new(ErrorType::ArgumentError, "SUBCMD_NOT_FOUND")) 116 _ => return Err(MLError::new(ErrorType::ArgumentError, "SUBCMD_NOT_FOUND"))
111 }; 117 };
112 Ok(cmd) 118 Ok(cmd)
@@ -136,6 +142,9 @@ pub async fn get_input(config: Cfg) -> Result<(), Box<dyn std::error::Error>> {
136 }, 142 },
137 Cmd::Download => { 143 Cmd::Download => {
138 download(config, input).await 144 download(config, input).await
145 },
146 Cmd::Io => {
147 io(config, input)
139 } 148 }
140 } 149 }
141} 150}