Dr Elmer Jiggle
Jan 24, 2006, 11:52 PM
I'd like to allow configuration of a mod I'm working on via an .ini file. Python includes support for .ini parsing via the ConfigParser module, so this should theoretically be very easy. Presumably if the mod is installed in CustomAssets, it should load CustomAssets/<modname>.ini. If it's installed in Mods it should load Mods/<modname>/<modname>.ini.
I can get the CustomAssets directory and the top level Mods directory without too much difficulty.
userDirectory = os.path.expanduser("~")
civ4Directory = os.path.join(userDirectory,
"My Documents\\My Games\\Sid Meier's Civilization 4")
customAssetsDirectory = os.path.join(civ4Directory, "CustomAssets")
modsDirectory = os.path.join(civ4Directory, "Mods")
The active mod directory, on the other hand, isn't so easy. I can't figure out how to determine the active mod name. I've tried looking at sys.argv and quite a variety of other places, but it doesn't appear to be available. The game plays some weird tricks with the module loader, so you can't use sys.path to find the directory either.
Has anyone figured out how to do this, or are they any bright ideas on another approach? The Hall of Fame mod uses an .ini file, but he just hardcoded the path, and ideally I'd like to avoid that. You never know when some genius is going to decide he wants to use a different directory name for your mod, and then suddenly everything breaks and you've got tons of bug reports.
Thanks.
I can get the CustomAssets directory and the top level Mods directory without too much difficulty.
userDirectory = os.path.expanduser("~")
civ4Directory = os.path.join(userDirectory,
"My Documents\\My Games\\Sid Meier's Civilization 4")
customAssetsDirectory = os.path.join(civ4Directory, "CustomAssets")
modsDirectory = os.path.join(civ4Directory, "Mods")
The active mod directory, on the other hand, isn't so easy. I can't figure out how to determine the active mod name. I've tried looking at sys.argv and quite a variety of other places, but it doesn't appear to be available. The game plays some weird tricks with the module loader, so you can't use sys.path to find the directory either.
Has anyone figured out how to do this, or are they any bright ideas on another approach? The Hall of Fame mod uses an .ini file, but he just hardcoded the path, and ideally I'd like to avoid that. You never know when some genius is going to decide he wants to use a different directory name for your mod, and then suddenly everything breaks and you've got tons of bug reports.
Thanks.