CvPath.py + Civ Complete Edition

zappara

Mod Designer
Joined
Dec 19, 2003
Messages
2,781
Location
Finland
I've got a problem with missing UI elements when people try to play my mod on Complete Edition and this is known to be caused by missing windows reg key which is in Beyond the Sword but not in Complete Edition. This got me thinking that my problem might be solved with modified CvPath.py file which is used to find different assets folders for mods. There's section:

Code:
def _getInstallDir():
        subkey = r"Software\Firaxis Games\Sid Meier's Civilization 4 - Beyond the Sword"
	return __getRegValue(_winreg.HKEY_LOCAL_MACHINE, subkey, "INSTALLDIR")

but I think this doesn't work if player has Civ 4 Complete Edition. So could any python guru provide me code how to set subkey value correctly if player has just normal BtS or if he has Complete Edition. Sseems simple, I just don't know what to check and I don't know what the correct path name would be for Complete Edition.

Code:
def _getInstallDir():
  if ( normal BtS == true )
      subkey = x
      return...
  else if ( complete edition == true )
      subkey = y
      return...

This CvPath.py file is used on other mods too and those have had same problem. People have modified their windows registry to solve this problem but that's dangerous if you don't know what you're doing. So with fixed CvPath.py file we might get a easy fix for them for this problem.
 
Not sure that will help since i don't understand why you need to get the path with the registry key . Why don't you get the path with "os.getcwd()" ... if you play with warlords or BtS , you just have to split the path to get the install dir .

Tcho !
 
Not sure that will help since i don't understand why you need to get the path with the registry key . Why don't you get the path with "os.getcwd()" ... if you play with warlords or BtS , you just have to split the path to get the install dir .
My mod needs to know if player is playing my mod on BtS or on Complete edition (Warlords is irrelevant since mod works only on BtS version) and only way to check that (I think) is to check which registry key exists (BtS or Complete Edition) or check which install dir path exists (again BtS or Complete Edition). Because players can give custom path for game install folder, that leaves only registry key value that can be used for check. CvPath.py was originally made by Gillmer J. Derge for Civ4lerts mod.

I only understand some really basic python functions, not this complex code:

Code:
if (sys.platform == 'darwin'):
	""" Mac OS X """
	def _getUserDir():
		return os.path.join(os.environ['HOME'], "Documents", "Civilization IV")

	def _getInstallDir():
		import commands
		civ4name = "Civilization IV.app/Contents/MacOS/Civilization IV"
		str = commands.getoutput("ps -xo 'command' | grep " + "'" + civ4name + "'")
		m = str.find(civ4name)
		if (m >= 0):
			installDir = str[0:m]
		return installDir
else:
	import _winreg
	""" Windows """
	def __getRegValue(root, subkey, name):
		key = _winreg.OpenKey(root, subkey)
		try:
			value = _winreg.QueryValueEx(key, name)
			return value[0]
		finally:
			key.Close()
	
	def _getUserDir():
		myDocuments = __getRegValue(_winreg.HKEY_CURRENT_USER, 
				r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders",
				"Personal")
		civ4Dir = os.path.basename(_getInstallDir())
		return os.path.join(myDocuments, "My Games", civ4Dir)
	
	def _getInstallDir():
		subkey = r"Software\Firaxis Games\Sid Meier's Civilization 4 - Beyond the Sword"
		return __getRegValue(_winreg.HKEY_LOCAL_MACHINE, subkey, "INSTALLDIR")
If you can provide me a code block for this which works correctly in both BtS and in Complete Edition (ie. sets correct subkey based on which version player has) I would appreciate it :)
 
You can try That :

Code:
def _getInstallDir():
        return CvUtil.convertToUnicode(os.getcwd())

But i don't know if that will work . If Gillmer J. Derge use the registry key , there is perhaps a reason . But On initialization and in game this return the same unicode string . os.getcwd() return the python working directory , this is the current install directory of the civ version you play (install dir + Beyond the Sword) . Like _getInstallDir() originaly return an unicode string , i've converted the path to unicode .

Tell me if this work .

Tcho !
 
I have done alots of work with the CvPath module and there is no inherent need to use the reg key to get the install dir. It should work just fine using os.getcwd().
 
Back
Top Bottom