From d5e60a32ed9cd91b00a17465cd4fa7df431d7699 Mon Sep 17 00:00:00 2001 From: nkorslund Date: Sat, 12 Jul 2008 19:58:13 +0000 Subject: [PATCH] ESM files can be specified in the config file git-svn-id: https://openmw.svn.sourceforge.net/svnroot/openmw/trunk@22 ea6a568a-9f4f-0410-981a-c910a81bb256 --- Makefile | 10 +++++----- core/config.d | 49 +++++++++++++++++++++++++++++++++++++++++++++++ core/filefinder.d | 5 +++++ openmw.d | 21 ++------------------ 4 files changed, 61 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index d6677b5e04..1f936b84d1 100644 --- a/Makefile +++ b/Makefile @@ -37,10 +37,10 @@ all: makedirs openmw esmtool niftool bsatool bored cpp_ogre.o: $(ogre_cpp_files) $(OGCC) -c $< -objs/%.o: %.d +objs/%.o: %.d makedirs $(DMD) -c $< -of$@ -nifobjs/%.o: %.d +nifobjs/%.o: %.d makedirs $(DMD) -debug=warnstd -debug=check -debug=statecheck -debug=strict -debug=verbose -c $< -of$@ # This is a hack for gdmd (dmd-like frontend to gdc), since it does @@ -78,6 +78,6 @@ bored: bored.d $(DMD) $^ clean: - -rm cpp_ogre.o - -rm openmw esmtool niftool bsatool bored - -rm -r objs/ nifobjs/ dsss_objs/ + -rm -f cpp_ogre.o + -rm -f openmw esmtool niftool bsatool bored + -rm -rf objs/ nifobjs/ dsss_objs/ diff --git a/core/config.d b/core/config.d index e5f22df6d1..1c704b8518 100644 --- a/core/config.d +++ b/core/config.d @@ -31,6 +31,7 @@ import std.stdio; import monster.util.string; import core.inifile; +import core.filefinder; import sound.audio; @@ -79,6 +80,9 @@ struct ConfigManager // from separate sessions don't overwrite each other. int screenShotNum; + // Game files to load (max 255) + char[][] gameFiles; + // Directories char[] dataDir; char[] esmDir; @@ -267,6 +271,47 @@ struct ConfigManager musDir = dataDir ~ "Music/Explore/"; musDir2 = dataDir ~ "Music/Battle/"; + // A maximum of 255 game files are allowed. Search the whole range + // in case some holes developed in the number sequence. This isn't + // a great way of specifying files (it's just a copy of the flawed + // model that Morrowind uses), but it will do for the time being. + FileFinder srch = new FileFinder(esmDir, null, Recurse.No); + for(int i = 0;i < 255;i++) + { + char[] s = ini.getString("Game Files", format("GameFile[%d]",i), null); + if(s != null && srch.has(s)) + { + writefln("Adding game file %s", s); + gameFiles ~= esmDir ~ s; + } + } + delete srch; + + if(gameFiles.length == 0) + { + // No game files set. Look in the esmDir for Morrowind.esm. + // We can add Tribunal.esm, and Bloodmoon.esm as defaults too + // later, when we're out of testing mode. + char[][] baseFiles = ["Morrowind.esm"]; + //char[][] baseFiles = ["Morrowind.esm","Tribunal.esm","Bloodmoon.esm"]; + srch = new FileFinder(esmDir, "esm", Recurse.No); + + foreach(ref s; baseFiles) + { + if(srch.has(s)) + { + writefln("Adding game file %s", s); + gameFiles ~= esmDir ~ s; + } + } + delete srch; + } + + // FIXME: Must sort gameFiles so that ESMs come first, then ESPs. + // I don't know if this needs to be done by filename, or by the + // actual file type.. + // Further sort the two groups by file date (oldest first). + /* Don't bother reading every directory seperately bsaDir = ini.getString("General", "BSA Directory", "data/"); esmDir = ini.getString("General", "ESM Directory", "data/"); @@ -326,6 +371,10 @@ struct ConfigManager writeFloat("SFX Volume", sfxVolume); writeBool("Enable Music", useMusic); + section("Game Files"); + foreach(int i, ref s; gameFiles) + writeString(format("GameFile[%d]",i), s[esmDir.length..$]); + close(); } } diff --git a/core/filefinder.d b/core/filefinder.d index ec57e84665..91901b546c 100644 --- a/core/filefinder.d +++ b/core/filefinder.d @@ -153,6 +153,11 @@ class FileFinder return 0; } + bool has(char[] file) + { + return lookup.inList(file); + } + int opApply(int delegate(ref char[]) del) { int res = 0; diff --git a/openmw.d b/openmw.d index 1c6b1d5a85..10af5ab1b0 100644 --- a/openmw.d +++ b/openmw.d @@ -140,25 +140,8 @@ void main(char[][] args) initializeSound(); resources.initResources(); - // Files to load - /* - const char[][] files = ["Morrowind.esm", - "Tribunal.esm", - "Bloodmoon.esm"]; - /*/ - const char[][] files = ["Morrowind.esm"]; - //*/ - - // Add the path to the file name. The path is read from the config - // file. - char[][] esmFiles; - esmFiles.length = files.length; - foreach(int i, char[] ef; files) - // TODO: Quick hack, use FileFinder instead. - esmFiles[i] = config.esmDir ~ ef; - - // Load all data from the ESM files - loadTESFiles(esmFiles); + // Load all ESM and ESP files + loadTESFiles(config.gameFiles); CellData cd = cellList.get();