diff options
| author | Filip Wandzio <contact@philw.dev> | 2026-01-22 23:14:08 +0100 |
|---|---|---|
| committer | Filip Wandzio <contact@philw.dev> | 2026-01-22 23:14:08 +0100 |
| commit | 72ddd7b7704f2087a52c9c0552446682918c513b (patch) | |
| tree | e5134f215ea82c1fc8eda17b34e426a7b1dfafc6 /src/util | |
| download | dml-72ddd7b7704f2087a52c9c0552446682918c513b.tar.gz dml-72ddd7b7704f2087a52c9c0552446682918c513b.zip | |
Implement basic game files download logic
Implement core clap arguments
Respect XDG_BASE_DIR
Currently library extraction is broken because it assumes every instace has it's own library folder. This should be refactored so instances share libraries
Signed-off-by: Filip Wandzio <contact@philw.dev>
Diffstat (limited to '')
| -rw-r--r-- | src/util/fs.rs | 12 | ||||
| -rw-r--r-- | src/util/mod.rs | 2 | ||||
| -rw-r--r-- | src/util/sha1.rs | 14 |
3 files changed, 28 insertions, 0 deletions
diff --git a/src/util/fs.rs b/src/util/fs.rs new file mode 100644 index 0000000..b86c0d7 --- /dev/null +++ b/src/util/fs.rs | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | #![allow(dead_code)] | ||
| 2 | |||
| 3 | use std::path::Path; | ||
| 4 | |||
| 5 | use crate::errors::McError; | ||
| 6 | |||
| 7 | pub async fn remove_if_exists(path: &Path) -> Result<(), McError> { | ||
| 8 | if path.exists() { | ||
| 9 | tokio::fs::remove_file(path).await?; | ||
| 10 | } | ||
| 11 | Ok(()) | ||
| 12 | } | ||
diff --git a/src/util/mod.rs b/src/util/mod.rs new file mode 100644 index 0000000..8176b9b --- /dev/null +++ b/src/util/mod.rs | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | pub mod fs; | ||
| 2 | pub mod sha1; | ||
diff --git a/src/util/sha1.rs b/src/util/sha1.rs new file mode 100644 index 0000000..c5f1021 --- /dev/null +++ b/src/util/sha1.rs | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | #![allow(dead_code)] | ||
| 2 | |||
| 3 | use std::path::Path; | ||
| 4 | |||
| 5 | use sha1::{Digest, Sha1}; | ||
| 6 | |||
| 7 | use crate::errors::McError; | ||
| 8 | |||
| 9 | pub async fn sha1_hex(path: &Path) -> Result<String, McError> { | ||
| 10 | let data = tokio::fs::read(path).await?; | ||
| 11 | let mut hasher = Sha1::new(); | ||
| 12 | hasher.update(&data); | ||
| 13 | Ok(format!("{:x}", hasher.finalize())) | ||
| 14 | } | ||
