aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modderbaas/src/minemod.rs28
1 files changed, 19 insertions, 9 deletions
diff --git a/modderbaas/src/minemod.rs b/modderbaas/src/minemod.rs
index 6be0ab4..00acc3a 100644
--- a/modderbaas/src/minemod.rs
+++ b/modderbaas/src/minemod.rs
@@ -43,6 +43,9 @@ pub struct MineMod {
path: PathBuf,
}
+/// The name of the mod configuration file.
+const MOD_CONF: &str = "mod.conf";
+
impl MineMod {
/// Opens the given directory as a mod.
pub fn open<P: AsRef<Path>>(path: P) -> Result<MineMod> {
@@ -50,7 +53,7 @@ impl MineMod {
}
fn open_path(path: &Path) -> Result<MineMod> {
- let conf = path.join("mod.conf");
+ let conf = path.join(MOD_CONF);
let depends = path.join("depends.txt");
if !conf.is_file() && !depends.is_file() {
return Err(Error::InvalidModDir(path.into()));
@@ -65,7 +68,7 @@ impl MineMod {
}
fn read_conf(&self) -> Result<HashMap<String, String>> {
- let conf = self.path.join("mod.conf");
+ let conf = self.path.join(MOD_CONF);
kvstore::read(&conf)
}
@@ -76,12 +79,19 @@ impl MineMod {
.file_name()
.map(|s| s.to_str().expect("Non-UTF8 directory encountered"));
- let conf = self.read_conf()?;
- conf.get("name")
- .map(String::as_str)
- .or(fallback)
- .map(Into::into)
- .ok_or_else(|| Error::InvalidModDir(self.path.clone()))
+ // Same reasoning as dependencies()
+ if self.path.join(MOD_CONF).is_file() {
+ let conf = self.read_conf()?;
+ conf.get("name")
+ .map(String::as_str)
+ .or(fallback)
+ .map(Into::into)
+ .ok_or_else(|| Error::InvalidModDir(self.path.clone()))
+ } else {
+ fallback
+ .map(Into::into)
+ .ok_or_else(|| Error::InvalidModDir(self.path.clone()))
+ }
}
/// Returns all dependencies of this mod.
@@ -89,7 +99,7 @@ impl MineMod {
// We could do this with Result combinators and default values, but we also don't want to
// end up swallowing errors (like filesystem errors). Therefore, we do some basic checks
// first and propagate the errors.
- if self.path.join("mod.conf").is_file() {
+ if self.path.join(MOD_CONF).is_file() {
// First try to extract dependencies from mod.conf (the new way)
let conf = self.read_conf()?;
if let Some(depstr) = conf.get("depends") {