Skip to content

Commit 2bdb4e4

Browse files
authored
fix(print): Print the last installed weidu mod from the weidu.log in the game directory (#181)
2 parents e0467da + 3c92b5c commit 2bdb4e4

File tree

6 files changed

+24
-31
lines changed

6 files changed

+24
-31
lines changed

Cargo.lock

Lines changed: 11 additions & 11 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
@@ -1,6 +1,6 @@
11
[package]
22
name = "mod_installer"
3-
version = "11.4.0"
3+
version = "11.4.1"
44
edition = "2021"
55
authors = [ "dark0dave" ]
66
documentation = "https://raw.githubusercontent.com/dark0dave/mod_installer/main/README.md"

default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{ pkgs ? import <nixpkgs> { } }:
22
pkgs.rustPlatform.buildRustPackage rec {
33
pname = "mod_installer";
4-
version = "11.4.0";
4+
version = "11.4.1";
55
cargoLock.lockFile = ./Cargo.lock;
66
src = pkgs.lib.cleanSource ./.;
77
buildInputs = with pkgs; [

shell.nix

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ with import <nixpkgs> {};
33
stdenv.mkDerivation {
44
name = "rust-env";
55
buildInputs = [
6-
cargo
7-
git
8-
gnupg
96
openssl
107
pre-commit
118
rustup

src/installers.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::path::PathBuf;
22
use std::{collections::HashMap, error::Error, path::Path, sync::Arc};
33

4-
use crate::utils::{delete_folder, search_or_download, validate_install};
4+
use crate::utils::{delete_folder, get_last_installed, search_or_download};
55
use crate::{
66
config::args::{Eet, Options},
77
config::parser_config::ParserConfig,
@@ -56,7 +56,7 @@ pub(crate) fn normal_install(
5656
}
5757

5858
if !mod_folder_present_in_game_directory(&game_directory, &weidu_mod.name) {
59-
log::info!(
59+
log::debug!(
6060
"Copying mod directory, from {:?} to, {:?}",
6161
mod_folder,
6262
game_directory.join(&weidu_mod.name)
@@ -73,10 +73,14 @@ pub(crate) fn normal_install(
7373
.into());
7474
}
7575
InstallationResult::Success => {
76-
if options.check_last_installed {
77-
validate_install(game_dir, weidu_mod)?;
76+
let last_installed = get_last_installed(game_dir)?;
77+
if options.check_last_installed && last_installed.ne(weidu_mod) {
78+
return Err(format!(
79+
"Last installed {last_installed:?} does not match component installed: {weidu_mod:?}"
80+
)
81+
.into());
7882
}
79-
log::info!("Installed mod {:?}", &weidu_mod);
83+
log::info!("Installed mod {:?}", &last_installed);
8084
}
8185
InstallationResult::Warnings(msg) => {
8286
log::warn!("{msg}");

src/utils.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,19 +160,11 @@ pub fn try_download_mod(weidu_mod: &Component) -> Result<PathBuf, Box<dyn Error>
160160
}
161161
}
162162

163-
pub fn validate_install(game_dir: &Path, component: &Component) -> Result<(), Box<dyn Error>> {
163+
pub fn get_last_installed(game_dir: &Path) -> Result<Component, Box<dyn Error>> {
164164
let file = File::open(game_dir.join("weidu.log"))?;
165165
let reader = BufReader::new(file);
166166
let last_line = reader.lines().last().ok_or("")??;
167-
let last_installed = Component::try_from(last_line)?;
168-
if last_installed.ne(component) {
169-
Err(format!(
170-
"Last installed {last_installed:?} does not match component installed: {component:?}"
171-
)
172-
.into())
173-
} else {
174-
Ok(())
175-
}
167+
Component::try_from(last_line)
176168
}
177169

178170
pub fn sleep(millis: u64) {

0 commit comments

Comments
 (0)