Skip to content

Commit 70227dd

Browse files
committed
refactor: Convert some things from static to const and refactor into drop-consts
Signed-off-by: quexeky <[email protected]>
1 parent ef9f8ca commit 70227dd

File tree

21 files changed

+73
-41
lines changed

21 files changed

+73
-41
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ members = [
88
"utils",
99
"cloud_saves",
1010
"download_manager",
11-
"games",
11+
"games", "drop-consts",
1212
]
1313

1414
resolver = "3"

cloud_saves/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition = "2024"
66
[dependencies]
77
database = { version = "0.1.0", path = "../database" }
88
dirs = "6.0.0"
9+
drop-consts = { version = "0.1.0", path = "../drop-consts" }
910
log = "0.4.28"
1011
regex = "1.11.3"
1112
rustix = "1.1.2"

cloud_saves/src/backup_manager.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use std::{collections::HashMap, path::PathBuf, str::FromStr};
22

33
#[cfg(target_os = "linux")]
44
use database::platform::Platform;
5-
use database::{GameVersion, db::DATA_ROOT_DIR};
5+
use database::GameVersion;
6+
use drop_consts::DATA_ROOT_DIR;
67
use log::warn;
78

89
use crate::error::BackupError;

database/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition = "2024"
66
[dependencies]
77
chrono = "0.4.42"
88
dirs = "6.0.0"
9+
drop-consts = { version = "0.1.0", path = "../drop-consts" }
910
log = "0.4.28"
1011
native_model = { version = "0.6.4", features = ["rmp_serde_1_3"], git = "https://github.com/Drop-OSS/native_model.git"}
1112
rustbreak = "2.0.0"

database/src/db.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::{
2-
path::PathBuf,
3-
sync::{Arc, LazyLock},
2+
sync::LazyLock,
43
};
54

65
use rustbreak::{DeSerError, DeSerializer};
@@ -10,19 +9,6 @@ use crate::interface::{DatabaseImpls, DatabaseInterface};
109

1110
pub static DB: LazyLock<DatabaseInterface> = LazyLock::new(DatabaseInterface::set_up_database);
1211

13-
#[cfg(not(debug_assertions))]
14-
static DATA_ROOT_PREFIX: &str = "drop";
15-
#[cfg(debug_assertions)]
16-
static DATA_ROOT_PREFIX: &str = "drop-debug";
17-
18-
pub static DATA_ROOT_DIR: LazyLock<Arc<PathBuf>> = LazyLock::new(|| {
19-
Arc::new(
20-
dirs::data_dir()
21-
.expect("Failed to get data dir")
22-
.join(DATA_ROOT_PREFIX),
23-
)
24-
});
25-
2612
// Custom JSON serializer to support everything we need
2713
#[derive(Debug, Default, Clone)]
2814
pub struct DropDatabaseSerializer;
@@ -39,7 +25,7 @@ impl<T: native_model::Model + Serialize + DeserializeOwned> DeSerializer<T>
3925
s.read_to_end(&mut buf)
4026
.map_err(|e| rustbreak::error::DeSerError::Other(e.into()))?;
4127
let (val, _version) =
42-
native_model::decode(buf).map_err(|e| DeSerError::Internal(e.to_string()))?;
28+
native_model::decode(buf).map_err(|e| rustbreak::error::DeSerError::Internal(e.to_string()))?;
4329
Ok(val)
4430
}
4531
}

database/src/interface.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ use std::{
77
};
88

99
use chrono::Utc;
10+
use drop_consts::DATA_ROOT_DIR;
1011
use log::{debug, error, info, warn};
1112
use rustbreak::{PathDatabase, RustbreakError};
1213
use url::Url;
1314

1415
use crate::{
15-
db::{DATA_ROOT_DIR, DB, DropDatabaseSerializer},
16+
db::{DB, DropDatabaseSerializer},
1617
models::data::Database,
1718
};
1819

drop-consts/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "drop-consts"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]
7+
dirs = "6.0.0"

drop-consts/src/lib.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use std::{cell::LazyCell, path::PathBuf};
2+
3+
#[cfg(not(debug_assertions))]
4+
pub const DATA_ROOT_PREFIX: &str = "drop";
5+
#[cfg(debug_assertions)]
6+
pub const DATA_ROOT_PREFIX: &str = "drop-debug";
7+
8+
pub const DATA_ROOT_DIR: LazyCell<PathBuf> = LazyCell::new(|| {
9+
dirs::data_dir()
10+
.expect("Failed to get data dir")
11+
.join(DATA_ROOT_PREFIX)
12+
});
13+
14+
pub const DROP_DATA_PATH: &str = ".dropdata";
15+
16+
// Downloads
17+
pub const MAX_PACKET_LENGTH: usize = 4096 * 4;
18+
pub const BUMP_SIZE: usize = 4096 * 16;
19+
20+
pub const RETRY_COUNT: usize = 3;
21+
22+
pub const TARGET_BUCKET_SIZE: usize = 63 * 1000 * 1000;
23+
pub const MAX_FILES_PER_BUCKET: usize = (1024 / 4) - 1;

games/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ throttle_my_fn = "0.2.6"
2424
utils = { version = "0.1.0", path = "../utils" }
2525
native_model = { version = "0.6.4", features = ["rmp_serde_1_3"], git = "https://github.com/Drop-OSS/native_model.git"}
2626
serde_json = "1.0.145"
27+
drop-consts = { version = "0.1.0", path = "../drop-consts" }

0 commit comments

Comments
 (0)