Skip to content

Commit

Permalink
Fix mod name parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
raiguard committed Nov 6, 2021
1 parent 98e1689 commit 7958f87
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
- These sets can be configured in `fmm.toml`
## Changes
- "Mod is already enabled" messages were removed - they hurt more than they helped
## Bugfixes
- Fixed that versionless mod folders with an underscore would not be parsed correctly

# v0.2.0 - 2021-11-03
## Features
Expand Down
27 changes: 16 additions & 11 deletions src/directory.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::HashMap;
use std::error::Error;
use std::ffi::OsString;
use std::fs;
use std::fs::{DirEntry, File};
use std::io::Read;
Expand All @@ -17,26 +18,30 @@ pub struct Directory {
pub mod_list_path: PathBuf,
}

fn parse_file_name(file_name: &OsString) -> Option<(String, Version)> {
let (name, version) = file_name
.to_str()?
.trim_end_matches(".zip")
.rsplit_once("_")?;

if let Ok(version) = Version::parse(version) {
Some((name.to_string(), version))
} else {
None
}
}

impl Directory {
pub fn new(dir: PathBuf) -> Result<Self, Box<dyn Error>> {
// Get all mods in the directory
let mod_entries = fs::read_dir(&dir)?
.filter_map(|entry| {
let entry = entry.ok()?;
let file_name = entry.file_name();

if let Some((mod_name, version)) = file_name.to_str()?.rsplit_once("_") {
let (version, _) = version.rsplit_once(".").unwrap_or((version, "")); // Strip file extension
Some((
mod_name.to_string(),
ModVersion {
entry,
version: Version::parse(version).ok()?,
},
))
if let Some((mod_name, version)) = parse_file_name(&entry.file_name()) {
Some((mod_name, ModVersion { entry, version }))
} else {
let info_json = read_info_json(&entry)?;

Some((
info_json.name,
ModVersion {
Expand Down

0 comments on commit 7958f87

Please sign in to comment.