Skip to content

Commit

Permalink
Merge pull request #72 from Umatriz/downloaders_refactor
Browse files Browse the repository at this point in the history
Remove temporary files after installing Forge
  • Loading branch information
Umatriz authored Aug 9, 2024
2 parents a1f50f9 + 23d8a91 commit 50f26da
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 19 deletions.
1 change: 1 addition & 0 deletions crates/client/src/views/add_profile_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ impl View for AddProfileMenu<'_> {
&& match selected_loader {
Loader::Fabric { version } => func(version.as_ref()),
Loader::Vanilla => unreachable!(),
Loader::Forge => unreachable!(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/nomi-core/src/instance/launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{
markers::Undefined,
repository::{
java_runner::JavaRunner,
manifest::{Arguments, Manifest, VersionType},
manifest::{Manifest, VersionType},
},
};

Expand Down
22 changes: 11 additions & 11 deletions crates/nomi-core/src/loaders/forge.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
use std::{
borrow::Cow,
collections::HashMap,
fmt::Debug,
fs::File,
io::{BufRead, Read},
marker::PhantomData,
path::{Path, PathBuf},
slice::Iter,
};

use anyhow::{anyhow, bail};
use itertools::Itertools;
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use tokio::{
io::{AsyncWriteExt, BufReader},
process::Command,
};
use tokio::{io::AsyncWriteExt, process::Command};
use tracing::{error, info, warn};
use zip::read::ZipFile;

Expand All @@ -24,27 +18,25 @@ use crate::{
downloads::{
download_file,
progress::ProgressSender,
traits::{DownloadResult, DownloadStatus, Downloader},
traits::{DownloadResult, Downloader},
DownloadQueue, FileDownloader, LibrariesDownloader, LibrariesMapper,
},
game_paths::GamePaths,
instance::{launch::CLASSPATH_SEPARATOR, profile::LoaderProfile},
loaders::vanilla::VanillaLibrariesMapper,
markers::Undefined,
maven_data::{MavenArtifact, MavenData},
repository::{
java_runner::JavaRunner,
manifest::{Argument, Arguments, Library},
simple_args::SimpleArgs,
simple_lib::SimpleLib,
},
utils::path_to_string,
PinnedFutureWithBounds, DOT_NOMI_TEMP_DIR,
};

const FORGE_REPO_URL: &str = "https://maven.minecraftforge.net";

const NEO_FORGE_REPO_URL: &str = "https://maven.neoforged.net/releases/";
const _NEO_FORGE_REPO_URL: &str = "https://maven.neoforged.net/releases/";

/// Some versions require to have a suffix
const FORGE_SUFFIXES: &[(&str, &[&str])] = &[
Expand Down Expand Up @@ -370,6 +362,14 @@ impl Downloader for Forge {
.await?;
}

// Remove temporary files
if let Some(binpatch_dir) = forge_binpatch_path(&game_version, &forge_version).parent() {
tokio::fs::remove_dir_all(binpatch_dir).await?;
};

let forge_installer = forge_installer_path(&game_version, &forge_version);
tokio::fs::remove_file(forge_installer).await?;

Ok(())
}

Expand Down
4 changes: 2 additions & 2 deletions crates/nomi-core/src/maven_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{fmt::Display, path::PathBuf};
use itertools::Itertools;
use regex::Regex;
use serde::{Deserialize, Serialize};
use tracing::{error, warn};
use tracing::error;

#[derive(Debug, Default)]
pub struct MavenData {
Expand Down Expand Up @@ -111,7 +111,7 @@ mod tests {
fn maven_artifact_parse_test() {
let artifact = MavenArtifact::new("de.oceanlabs.mcp:mcp_config:1.20.1-20230612.114412@zip");

println!("{:#?}", artifact);
println!("{artifact:#?}");
}

#[test]
Expand Down
1 change: 0 additions & 1 deletion crates/nomi-core/tests/forge_new_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::path::PathBuf;

use nomi_core::{
configs::profile::{ProfileState, VersionProfile},
downloads::traits::Downloader,
game_paths::GamePaths,
instance::{
launch::{arguments::UserData, LaunchSettings},
Expand Down
5 changes: 1 addition & 4 deletions crates/nomi-core/tests/forge_old_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ use nomi_core::{
logs::PrintLogs,
Instance,
},
loaders::{
forge::{Forge, ForgeVersion},
vanilla::Vanilla,
},
loaders::forge::{Forge, ForgeVersion},
repository::java_runner::JavaRunner,
MINECRAFT_DIR,
};
Expand Down

0 comments on commit 50f26da

Please sign in to comment.