diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Cargo.lock | 5 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | data - Copy.db | bin | 0 -> 24576 bytes | |||
-rw-r--r-- | data.db | bin | 24576 -> 20480 bytes | |||
-rw-r--r-- | planmodlist.xopp | bin | 244518 -> 243533 bytes | |||
-rw-r--r-- | src/commands/io.rs | 79 | ||||
-rw-r--r-- | src/commands/modification.rs | 25 | ||||
-rw-r--r-- | src/input.rs | 2 |
9 files changed, 97 insertions, 16 deletions
@@ -5,3 +5,4 @@ | |||
5 | /test_tmp | 5 | /test_tmp |
6 | .planmodlist.autosave.xopp | 6 | .planmodlist.autosave.xopp |
7 | data.db.cp | 7 | data.db.cp |
8 | export.toml | ||
@@ -657,6 +657,7 @@ dependencies = [ | |||
657 | "serde", | 657 | "serde", |
658 | "serde_json", | 658 | "serde_json", |
659 | "tokio", | 659 | "tokio", |
660 | "toml", | ||
660 | ] | 661 | ] |
661 | 662 | ||
662 | [[package]] | 663 | [[package]] |
@@ -1259,9 +1260,9 @@ dependencies = [ | |||
1259 | 1260 | ||
1260 | [[package]] | 1261 | [[package]] |
1261 | name = "toml" | 1262 | name = "toml" |
1262 | version = "0.5.9" | 1263 | version = "0.5.10" |
1263 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1264 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1264 | checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" | 1265 | checksum = "1333c76748e868a4d9d1017b5ab53171dfd095f70c712fdb4653a406547f598f" |
1265 | dependencies = [ | 1266 | dependencies = [ |
1266 | "serde", | 1267 | "serde", |
1267 | ] | 1268 | ] |
@@ -14,3 +14,4 @@ config = "0.13.2" | |||
14 | rusqlite = { version = "0.28.0", features = ["bundled"] } | 14 | rusqlite = { version = "0.28.0", features = ["bundled"] } |
15 | futures-util = "0.3.14" | 15 | futures-util = "0.3.14" |
16 | chrono = "0.4.22" | 16 | chrono = "0.4.22" |
17 | toml = "0.5.10" | ||
diff --git a/data - Copy.db b/data - Copy.db new file mode 100644 index 0000000..da57b82 --- /dev/null +++ b/data - Copy.db | |||
Binary files differ | |||
Binary files differ | |||
diff --git a/planmodlist.xopp b/planmodlist.xopp index 6405294..30007d4 100644 --- a/planmodlist.xopp +++ b/planmodlist.xopp | |||
Binary files differ | |||
diff --git a/src/commands/io.rs b/src/commands/io.rs index dc1f408..47991c5 100644 --- a/src/commands/io.rs +++ b/src/commands/io.rs | |||
@@ -1,12 +1,81 @@ | |||
1 | use crate::{input::{Input, Subcmd}, config::Cfg}; | 1 | use std::fs::File; |
2 | use std::io::prelude::*; | ||
3 | use serde::{Serialize, Deserialize}; | ||
2 | 4 | ||
3 | pub fn io(_config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> { | 5 | use crate::{input::{Input, Subcmd}, db::{lists_get, userlist_get_all_ids, lists_get_all_ids, lists_insert}, config::Cfg, Modloader, mod_add, List}; |
6 | |||
7 | #[derive(Debug, Serialize, Deserialize)] | ||
8 | struct Export { | ||
9 | lists: Vec<ExportList> | ||
10 | } | ||
11 | |||
12 | #[derive(Debug, Serialize, Deserialize)] | ||
13 | struct ExportList { | ||
14 | id: String, | ||
15 | mods: String, | ||
16 | launcher: String, | ||
17 | mc_version: String, | ||
18 | download_folder: Option<String>, | ||
19 | } | ||
20 | |||
21 | impl ExportList { | ||
22 | pub fn from(config: Cfg, list_id: String, download: bool) -> Result<Self, Box<dyn std::error::Error>> { | ||
23 | |||
24 | let list = lists_get(config.clone(), String::from(&list_id))?; | ||
25 | |||
26 | let mut dl_folder = None; | ||
27 | if download == true { dl_folder = Some(list.download_folder) }; | ||
28 | |||
29 | let mods = userlist_get_all_ids(config, list_id)?.join("|"); | ||
30 | |||
31 | Ok(Self { id: list.id, mods, launcher: list.modloader.stringify(), mc_version: list.mc_version, download_folder: dl_folder }) | ||
32 | } | ||
33 | } | ||
34 | |||
35 | pub async fn io(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> { | ||
4 | 36 | ||
5 | match input.subcommand.ok_or("INVALID_INPUT")? { | 37 | match input.subcommand.ok_or("INVALID_INPUT")? { |
6 | Subcmd::Export => {}, | 38 | Subcmd::Export => { export(config, input.args)? }, |
7 | Subcmd::Import => {}, | 39 | Subcmd::Import => { import(config).await? }, |
8 | _ => {}, | 40 | _ => { }, |
41 | } | ||
42 | |||
43 | Ok(()) | ||
44 | } | ||
45 | |||
46 | fn export(config: Cfg, _args: Option<Vec<String>>) -> Result<(), Box<dyn std::error::Error>> { | ||
47 | let list_ids = lists_get_all_ids(config.clone())?; | ||
48 | let mut lists: Vec<ExportList> = vec![]; | ||
49 | for list_id in list_ids { | ||
50 | lists.push(ExportList::from(config.clone(), String::from(list_id), true)?); | ||
9 | } | 51 | } |
52 | |||
53 | let toml = toml::to_string( &Export { lists } )?; | ||
54 | |||
55 | let mut file = File::create("export.toml")?; | ||
56 | file.write_all(&toml.as_bytes())?; | ||
10 | 57 | ||
11 | Ok(()) | 58 | Ok(()) |
12 | } | 59 | } |
60 | |||
61 | async fn import(config: Cfg) -> Result<(), Box<dyn std::error::Error>> { | ||
62 | |||
63 | let mut file = File::open("export.toml")?; | ||
64 | let mut content = String::new(); | ||
65 | file.read_to_string(&mut content)?; | ||
66 | let export: Export = toml::from_str(&content)?; | ||
67 | |||
68 | println!("{:#?}", export); | ||
69 | |||
70 | for exportlist in export.lists { | ||
71 | let list = List { id: exportlist.id, mc_version: exportlist.mc_version, modloader: Modloader::from(&exportlist.launcher)?, download_folder: exportlist.download_folder.ok_or("NO_DL")? }; | ||
72 | lists_insert(config.clone(), list.id.clone(), list.mc_version.clone(), list.modloader.clone(), String::from(&list.download_folder))?; | ||
73 | //TODO currently workaround, too many requests | ||
74 | let mods: Vec<&str> = exportlist.mods.split("|").collect(); | ||
75 | for mod_id in mods { | ||
76 | println!("Adding {}", mod_id); | ||
77 | mod_add(config.clone(), mod_id, list.clone(), false).await?; | ||
78 | } | ||
79 | } | ||
80 | Ok(()) | ||
81 | } | ||
diff --git a/src/commands/modification.rs b/src/commands/modification.rs index 91243fc..f66ce28 100644 --- a/src/commands/modification.rs +++ b/src/commands/modification.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use std::io::{Error, ErrorKind}; | 1 | use std::io::{Error, ErrorKind}; |
2 | 2 | ||
3 | use crate::{modrinth::{project, versions, extract_current_version, Version}, config::Cfg, db::{mods_insert, userlist_remove, mods_get_id, userlist_insert, mods_get_all_ids, userlist_get_all_ids, userlist_get_current_version, lists_get_all_ids, mods_remove}, input::{Input, Subcmd}, get_current_list, files::{delete_version, download_versions}}; | 3 | use crate::{modrinth::{project, versions, extract_current_version, Version}, config::Cfg, db::{mods_insert, userlist_remove, mods_get_id, userlist_insert, mods_get_all_ids, userlist_get_all_ids, userlist_get_current_version, lists_get_all_ids, mods_remove}, input::{Input, Subcmd}, get_current_list, files::{delete_version, download_versions}, List}; |
4 | 4 | ||
5 | pub async fn modification(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> { | 5 | pub async fn modification(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> { |
6 | 6 | ||
@@ -22,10 +22,19 @@ async fn add(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error> | |||
22 | if args.is_empty() { return Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_FEW_ARGUMENTS"))); }; | 22 | if args.is_empty() { return Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_FEW_ARGUMENTS"))); }; |
23 | 23 | ||
24 | let current_list = get_current_list(config.clone())?; | 24 | let current_list = get_current_list(config.clone())?; |
25 | |||
26 | mod_add(config, &args[0], current_list, input.disable_download).await?; | ||
27 | |||
28 | Ok(()) | ||
29 | } | ||
25 | 30 | ||
26 | let project = project(String::from(&config.apis.modrinth), &args[0]).await; | 31 | pub async fn mod_add(config: Cfg, mod_id: &str, list: List, disable_download: bool) -> Result<(), Box<dyn std::error::Error>> { |
32 | |||
33 | println!("Adding mod {}", mod_id); | ||
34 | |||
35 | let project = project(String::from(&config.apis.modrinth), &mod_id).await; | ||
27 | 36 | ||
28 | let available_versions = versions(String::from(&config.apis.modrinth), String::from(&project.id), current_list.clone()).await; | 37 | let available_versions = versions(String::from(&config.apis.modrinth), String::from(&project.id), list.clone()).await; |
29 | 38 | ||
30 | let mut available_versions_vec: Vec<String> = Vec::new(); | 39 | let mut available_versions_vec: Vec<String> = Vec::new(); |
31 | let current_version: Option<Version>; | 40 | let current_version: Option<Version>; |
@@ -52,15 +61,15 @@ async fn add(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error> | |||
52 | } | 61 | } |
53 | 62 | ||
54 | //add to current list and mod table | 63 | //add to current list and mod table |
55 | match userlist_get_all_ids(config.clone(), current_list.clone().id) { | 64 | match userlist_get_all_ids(config.clone(), list.clone().id) { |
56 | Ok(mods) => { | 65 | Ok(mods) => { |
57 | if mods.contains(&project.id) { | 66 | if mods.contains(&project.id) { |
58 | return Err(Box::new(Error::new(ErrorKind::Other, "MOD_ALREADY_ON_LIST"))); } | 67 | return Err(Box::new(Error::new(ErrorKind::Other, "MOD_ALREADY_ON_LIST"))); } |
59 | else { | 68 | else { |
60 | userlist_insert(config.clone(), String::from(¤t_list.id), String::from(&project.id), String::from(¤t_version_id), available_versions_vec, file)?; | 69 | userlist_insert(config.clone(), String::from(&list.id), String::from(&project.id), String::from(¤t_version_id), available_versions_vec, file)?; |
61 | } | 70 | } |
62 | }, | 71 | }, |
63 | Err(..) => userlist_insert(config.clone(), String::from(¤t_list.id), String::from(&project.id), String::from(¤t_version_id), available_versions_vec, file)?, | 72 | Err(..) => userlist_insert(config.clone(), String::from(&list.id), String::from(&project.id), String::from(¤t_version_id), available_versions_vec, file)?, |
64 | }; | 73 | }; |
65 | 74 | ||
66 | match mods_get_all_ids(config.clone()) { | 75 | match mods_get_all_ids(config.clone()) { |
@@ -75,8 +84,8 @@ async fn add(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error> | |||
75 | mods_insert(config.clone(), String::from(&project.id), String::from(&project.title), project.versions)?; | 84 | mods_insert(config.clone(), String::from(&project.id), String::from(&project.title), project.versions)?; |
76 | }, | 85 | }, |
77 | }; | 86 | }; |
78 | 87 | ||
79 | if !input.disable_download && current_version.is_some() { download_versions(current_list, vec![current_version.unwrap()]).await?; } | 88 | if !disable_download && current_version.is_some() { download_versions(list, vec![current_version.unwrap()]).await?; }; |
80 | 89 | ||
81 | Ok(()) | 90 | Ok(()) |
82 | } | 91 | } |
diff --git a/src/input.rs b/src/input.rs index ffc1213..09d05a1 100644 --- a/src/input.rs +++ b/src/input.rs | |||
@@ -144,7 +144,7 @@ pub async fn get_input(config: Cfg) -> Result<(), Box<dyn std::error::Error>> { | |||
144 | download(config, input).await | 144 | download(config, input).await |
145 | }, | 145 | }, |
146 | Cmd::Io => { | 146 | Cmd::Io => { |
147 | io(config, input) | 147 | io(config, input).await |
148 | } | 148 | } |
149 | } | 149 | } |
150 | } | 150 | } |