-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3a25fcd
commit 9429570
Showing
7 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
pub mod bepinex; | ||
pub mod bepinex_loader; | ||
pub mod doorstop; | ||
pub mod mods; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use std::{fs::{File, self}, path::PathBuf, io}; | ||
|
||
use crate::mods::spacedock::SpaceDockAPI; | ||
|
||
pub struct ModInstaller { | ||
pub install_path: PathBuf, | ||
} | ||
|
||
impl ModInstaller { | ||
pub fn new(install_path: PathBuf) -> Self { | ||
return Self { | ||
install_path, | ||
}; | ||
} | ||
|
||
pub async fn install_from_spacedock(&self, id: i32) { | ||
let api = SpaceDockAPI::new(); | ||
let url = api.get_mod_download(id).await; | ||
|
||
let response = reqwest::get(url) | ||
.await | ||
.expect("Could not download the mod!"); | ||
|
||
let body = response | ||
.bytes() | ||
.await | ||
.expect("Could not read the mod!"); | ||
|
||
let mut out_file = File::create(self.install_path.join(".mod.zip")) | ||
.expect("Could not create the mod file!"); | ||
|
||
io::copy(&mut body.as_ref(), &mut out_file) | ||
.expect("Could not copy the mod to the file!"); | ||
|
||
zip_extensions::read::zip_extract( | ||
&PathBuf::from(&self.install_path.join(".mod.zip")), | ||
&PathBuf::from(&self.install_path), | ||
) | ||
.expect("Could not extract the mod!"); | ||
|
||
fs::remove_file(self.install_path.join(".mod.zip")) | ||
.expect("Could not delete the mod file!"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
pub struct LatestSchema { | ||
pub friendly_version: String, | ||
pub game_version: String, | ||
pub id: i32, | ||
pub created: String, | ||
pub download_path: String, | ||
pub changelog: Option<String>, | ||
pub downloads: i32, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod release; | ||
pub mod latest; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters