Skip to content

Commit 54b4cbc

Browse files
authored
Feature/complete rewrite (#87)
* Migration to 0.4 and beginning of the pure component implementation * Further refactoring * Fixed errors to start the rework * Further styling and refactoring * Further refactoring * further work * Further progress towards the rewrite * Further progress to make the cache object shareable through the views * Further progress regarding the refactoring * Disabled caching due to the complete rewrite * Further work * Simplified the catalog logic * Further refactoring * Re-enabled plugin installation * Further progress * Further progress * Further progress * Further progress * Renaming and removal of unneccessary files. * Progress * Implemented a proper database trait for better testing * Fixed tests * Implemented integration tests for every cache function * Further refactoring * Some renaming. Set the foundation for the internal refactoring * Further refactoring * Further progress * removed unneccessary test * removed print statement * simplified test * Implemented installer tests and fixed bugs * Moved central plugin struct into separate module * More bug fixes * More bugfixes * removed print * Removed print * Added delete functionality * renamed variable * Further refinement * Implemented the update all functionality * Added db refresh functionality * Fixed plugin deletion bug
1 parent 062b817 commit 54b4cbc

31 files changed

+3118
-3098
lines changed

Cargo.lock

Lines changed: 1138 additions & 1207 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@ exclude = [
2222
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
2323

2424
[dependencies]
25-
iced = { version = "^0", features = ["tokio", "image"] }
25+
iced = { version = "^0", features = ["tokio", "image", "pure", "wgpu"] }
2626
reqwest = { version = "^0", features = ["blocking", "json"] }
27+
bytes = "^1"
2728
zip = "^0"
2829
serde = { version = "^1", features = ["derive"] }
2930
serde_json = "^1"
3031
serde-xml-rs = "^0"
3132
dirs = "^4"
3233
rusqlite = { version = "^0", features = ["bundled"] }
34+
r2d2 = "^0"
35+
r2d2_sqlite = "^0"
3336
futures = "^0"
3437
tokio = { version = "^1", features = ["full"]}
3538
image = "^0"
@@ -39,14 +42,11 @@ globset = "^0"
3942
chrono = "^0"
4043
log = { version = "^0", features = ["max_level_debug", "release_max_level_off"] }
4144
env_logger = "^0"
42-
uuid = { version = "^0", features = ["v4"] }
45+
uuid = { version = "^1", features = ["v4"] }
4346
walkdir = "^2"
4447
regex = "^1"
4548
itertools = "^0"
46-
47-
[dev-dependencies]
48-
mockall = "^0"
49-
mockall_double = "^0"
49+
async-trait = "^0"
5050

5151
[build-dependencies]
5252
embed-resource = "^1"

src/core/blacklist.rs

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/core/config.rs

Lines changed: 89 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,108 @@
1+
//! # Config
2+
//!
3+
//! Contains the config logic that is used to determine the storage paths for the `settings` and `plugins` directory.
4+
//! The `settings` directory contains:
5+
//! - settings.json -> Contains all settings that is specified by the user in the `settings` view.
6+
//! - plugins.sqlite3 -> Contains the cache plugins which are installed on the users computer.
7+
//! - tmp/ -> Temporary directory that contains data which is created while installing new plugins.
8+
use dirs::{data_dir, home_dir};
19
use serde::{Deserialize, Serialize};
210
use std::path::PathBuf;
311
use std::{
412
fs::{self, write, File},
513
io::Read,
614
};
715

8-
use crate::gui::views::Paths;
16+
pub fn initialize_directories() {
17+
let storage_dir = get_storage_dir();
918

10-
#[derive(Default, Debug, Clone)]
11-
pub struct Config {
12-
pub settings: PathBuf,
13-
pub plugins_dir: PathBuf,
14-
pub db_file_path: PathBuf,
15-
pub cache_dir: PathBuf,
16-
pub application_settings: SettingsFile,
17-
}
19+
fs::create_dir_all(&get_plugins_dir()).expect("Couldn't create the plugins folder");
20+
fs::create_dir_all(&storage_dir).expect("Couldn't create the storage folder");
21+
fs::create_dir_all(&storage_dir.join("tmp")).expect("Couldn't create the storage folder");
1822

19-
impl Config {
20-
pub fn new(paths: Paths) -> Self {
21-
fs::create_dir_all(&paths.plugins).expect("Couldn't create the plugins folder");
22-
fs::create_dir_all(&paths.settings).expect("Couldn't create the lembas settings folder");
23-
fs::create_dir_all(&paths.cache).expect("Couldn't create the lembas cache folder");
24-
25-
let path = &paths.settings.join("plugins.sqlite3");
26-
27-
let mut initial_settings = SettingsFile::default();
28-
let settings_file_path = &paths.settings.join("settings.json");
29-
30-
if settings_file_path.exists() {
31-
let mut file = File::open(settings_file_path).unwrap();
32-
let mut data = String::new();
33-
file.read_to_string(&mut data).unwrap();
34-
initial_settings = serde_json::from_str(&data).unwrap();
35-
} else {
36-
File::create(&settings_file_path).unwrap();
37-
initial_settings.backup_enabled = true;
38-
initial_settings.feed_url =
39-
String::from("http://api.lotrointerface.com/fav/plugincompendium.xml");
40-
write(
41-
&settings_file_path,
42-
serde_json::to_string(&initial_settings).unwrap(),
43-
)
44-
.unwrap();
45-
}
23+
let settings_file_path = &storage_dir.join("settings.json");
4624

47-
Self {
48-
settings: paths.settings,
49-
plugins_dir: paths.plugins,
50-
db_file_path: path.clone(),
51-
cache_dir: paths.cache,
52-
application_settings: initial_settings,
53-
}
25+
if !settings_file_path.exists() {
26+
create_existing_settings_file(settings_file_path);
5427
}
28+
}
5529

56-
pub fn save_changes(&self) {
57-
let settings_file_path = &self.settings.join("settings.json");
30+
pub fn get_plugins_dir() -> PathBuf {
31+
home_dir()
32+
.expect("Couldn't find your home directory")
33+
.join("Documents")
34+
.join("The Lord of the Rings Online")
35+
.join("Plugins")
36+
}
5837

59-
write(
60-
&settings_file_path,
61-
serde_json::to_string(&self.application_settings).unwrap(),
62-
)
63-
.unwrap();
64-
}
38+
pub fn get_plugins_backup_dir() -> PathBuf {
39+
home_dir()
40+
.expect("Couldn't find your home directory")
41+
.join("Documents")
42+
.join("The Lord of the Rings Online")
43+
.join("Plugins_Backup")
44+
}
45+
46+
pub fn get_storage_dir() -> PathBuf {
47+
data_dir().unwrap().join("lembas")
48+
}
49+
50+
pub fn get_settings_file_path() -> PathBuf {
51+
let storage_dir = get_storage_dir();
52+
53+
storage_dir.join("settings.json")
54+
}
55+
56+
pub fn get_database_file_path() -> PathBuf {
57+
let storage_dir = get_storage_dir();
58+
59+
storage_dir.join("plugins.sqlite3")
6560
}
6661

67-
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
62+
pub fn get_tmp_dir() -> PathBuf {
63+
let storage_dir = get_storage_dir();
64+
65+
storage_dir.join("tmp")
66+
}
67+
68+
pub fn save_settings_changes(settings: &SettingsFile) {
69+
let settings_file_path = get_settings_file_path();
70+
71+
write(
72+
&settings_file_path,
73+
serde_json::to_string(&settings).unwrap(),
74+
)
75+
.unwrap();
76+
}
77+
78+
fn create_existing_settings_file(settings_path: &PathBuf) {
79+
let initial_settings = SettingsFile::default();
80+
File::create(&settings_path).unwrap();
81+
write(
82+
&settings_path,
83+
serde_json::to_string(&initial_settings).unwrap(),
84+
)
85+
.unwrap();
86+
}
87+
88+
pub fn read_existing_settings_file() -> SettingsFile {
89+
let mut file = File::open(get_settings_file_path()).unwrap();
90+
let mut data = String::new();
91+
file.read_to_string(&mut data).unwrap();
92+
serde_json::from_str(&data).unwrap()
93+
}
94+
95+
#[derive(Debug, Clone, Serialize, Deserialize)]
6896
pub struct SettingsFile {
6997
pub backup_enabled: bool,
7098
pub feed_url: String,
7199
}
100+
101+
impl Default for SettingsFile {
102+
fn default() -> Self {
103+
Self {
104+
backup_enabled: true,
105+
feed_url: String::from("http://api.lotrointerface.com/fav/plugincompendium.xml"),
106+
}
107+
}
108+
}

0 commit comments

Comments
 (0)