예제 #1
0
def initDataFolder():
    """
	Finds the first directory that contains a folder named SETTINGS_FOLDER.
	"""
    global _dataFolderInitDone
    if _dataFolderInitDone:
        return
    BugUtil.debug("BugPath - initializing data folder")

    # K-Mod. If it doesn't already exist, create the folder in the user directory.
    dir = join(getRootDir(), getModName(), SETTINGS_FOLDER)
    if dir != None:
        if not isdir(dir):
            # copy the default settings from the K-Mod folder.
            default_dir = join(getModDir(), SETTINGS_FOLDER)
            if isdir(default_dir):
                try:
                    safeInfoPath("BugPath - copying settings to '%s'", dir)
                    # copytree is suppose to create the missing parent directores, but apparently it doesn't work. So I need to do this:
                    try:
                        os.makedirs(join(getRootDir(), getModName()))
                    except OSError:
                        pass
                    # sucks.
                    shutil.copytree(default_dir, dir)
                except:
                    BugUtil.trace("Failed to copy settings")
        if not isdir(dir):
            # Second attempt: create the directory manually
            try:
                safeInfoPath("BugPath - creating '%s'", dir)
                os.makedirs(dir)
            except OSError:
                BugUtil.trace("Failed to create directory '%s'", dir)
    # K-Mod end

    dataDirs = (
        join(getRootDir(), getModName()),  # My Games\BTS\BUG Mod
        join(getUserDir(), getModName()),  # My Games\BUG Mod
        join(getAppDir(), getModName()),  # Civ4\BTS\BUG Mod
        join(getModDir(), DATA_FOLDER),  # Civ4\BTS\Mods\BUG Mod 3.6\Data
        join(getModDir()),  # Civ4\BTS\Mods\BUG Mod 3.6
    )
    for dir in dataDirs:
        if setDataDir(dir):
            break
    else:
        BugUtil.error("No valid data directory containing %s found",
                      SETTINGS_FOLDER)
    _dataFolderInitDone = True
    # <advc.009> setDataDir tries to locate INFO_FOLDER in the same place
    # as SETTINGS_FOLDER, but settings need to be in \My Games\, whereas
    # info is in the program folder. I don't see how this can work in standalone
    # BUG (same code there) either - perhaps it doesn't; haven't tried it.
    global _infoDir
    for dir in dataDirs:
        _infoDir = join(dir, INFO_FOLDER)
        if isdir(_infoDir):  # Show the troublesome path in the System tab too
            BugConfigTracker.add("Info_Directory", _infoDir)
            break
예제 #2
0
 def openSDFile(self):
     szPath = BugAutolog.getFilePath()
     if (not szPath or szPath == "Default"):
         szPath = SP.joinModDir("Autolog")
     if (not os.path.isdir(szPath)):
         os.makedirs(szPath)
     szFile = os.path.join(szPath, self.FileName)
     self.SDFile = codecs.open(szFile, 'a', 'utf-8')
     BugConfigTracker.add("SDFile_Log", szFile)
예제 #3
0
def setRootDir(dir):
    safeDebugPath("BugPath - Checking root dir '%s'", dir)
    if isdir(dir) and isfile(join(dir, "CivilizationIV.ini")):
        global _rootDir
        _rootDir = dir
        safeInfoPath("BugPath - root dir is '%s'", dir)
        BugConfigTracker.add("Root_Directory", _rootDir)
        return True
    return False
예제 #4
0
파일: StatusDump.py 프로젝트: AP-ML/DTM
	def openSDFile(self):
		szPath = BugAutolog.getFilePath()
		if (not szPath or szPath == "Default"):
			szPath = BugPath.findOrMakeDir("Autolog")
		if (not os.path.isdir(szPath)):
			os.makedirs(szPath)
		szFile = os.path.join(szPath, self.FileName)
		self.SDFile = codecs.open(szFile, 'a', 'utf-8')
		BugConfigTracker.add("SDFile_Log", szFile)
예제 #5
0
def setRootDir(dir):
    safeDebugPath("BugPath - Checking root dir '%s'", dir)
    if isdir(dir) and isfile(join(dir, "CivilizationIV.ini")):
        global _rootDir
        _rootDir = dir
        safeInfoPath("BugPath - root dir is '%s'", dir)
        BugConfigTracker.add("Root_Directory", _rootDir)
        return True
    return False
예제 #6
0
def setModDir(dir):
    safeDebugPath("BugPath - checking mod dir '%s'", dir)
    if isdir(dir):
        global _isMod, _modDir, _modFolder
        _isMod = True
        _modDir = dir
        _modFolder = basename(dir)
        safeInfoPath("BugPath - mod dir is '%s'", dir)
        safeDebugPath("BugPath - mod folder is '%s'", _modFolder)
        BugConfigTracker.add("Mod_Directory", _modDir)
        return True
    return False
예제 #7
0
def setModDir(dir):
    safeDebugPath("BugPath - checking mod dir '%s'", dir)
    if isdir(dir):
        global _isMod, _modDir, _modFolder
        _isMod = True
        _modDir = dir
        _modFolder = basename(dir)
        safeInfoPath("BugPath - mod dir is '%s'", dir)
        safeDebugPath("BugPath - mod folder is '%s'", _modFolder)
        BugConfigTracker.add("Mod_Directory", _modDir)
        return True
    return False
예제 #8
0
def setDataDir(dir):
    if isdir(dir):
        safeDebugPath("BugPath - Checking data dir '%s'", dir)
        settingsDir = join(dir, SETTINGS_FOLDER)
        if isdir(settingsDir):
            safeInfoPath("BugPath - data dir is '%s'", dir)
            global _dataDir, _settingsDir, _infoDir
            _dataDir = dir
            _settingsDir = settingsDir
            _infoDir = join(dir, INFO_FOLDER)
            BugConfigTracker.add("Settings_Directory", _settingsDir)
            return True
    return False
예제 #9
0
	def openFile(self, bForce=False, sWrite='a'):
		if (self.HoldOpen and not bForce):
			return

		szPath = BugFile.getFilePath()
		if (not szPath or szPath == "Default"):
			szPath = BugPath.findOrMakeDir("Autolog")
		if (not os.path.isdir(szPath)):
			os.makedirs(szPath)

		szFile = os.path.join(szPath, self.FileName)
		self.File = codecs.open(szFile, sWrite, 'utf-8')
		BugConfigTracker.add("Autolog_Log", szFile)
예제 #10
0
def setDataDir(dir):
    if isdir(dir):
        safeDebugPath("BugPath - Checking data dir '%s'", dir)
        settingsDir = join(dir, SETTINGS_FOLDER)
        if isdir(settingsDir):
            safeInfoPath("BugPath - data dir is '%s'", dir)
            global _dataDir, _settingsDir, _infoDir
            _dataDir = dir
            _settingsDir = settingsDir
            _infoDir = join(dir, INFO_FOLDER)
            BugConfigTracker.add("Settings_Directory", _settingsDir)
            return True
    return False
예제 #11
0
파일: BugFile.py 프로젝트: AP-ML/DTM
	def openFile(self, bForce=False, sWrite='a'):
		if (self.HoldOpen and not bForce):
			return

		szPath = BugFile.getFilePath()
		if (not szPath or szPath == "Default"):
			szPath = BugPath.findOrMakeDir("Autolog")
		if (not os.path.isdir(szPath)):
			os.makedirs(szPath)

		szFile = os.path.join(szPath, self.FileName)
		self.File = codecs.open(szFile, sWrite, 'utf-8')
		BugConfigTracker.add("Autolog_Log", szFile)
예제 #12
0
def initSearchPaths():
    """
	Adds the CustomAssets, mod Assets and BTS Assets directories to a list of search paths.
	"""
    global _searchPathsInitDone
    if _searchPathsInitDone:
        return
    BugUtil.debug("BugPath - initializing asset search paths")

    assetDirs = [join(getModDir(), ASSETS_FOLDER), join(getAppDir(), ASSETS_FOLDER)]
    # EF: Mod's no longer access CustomAssets folder; too many issues
    if not isNoCustomAssets() and not isMod():
        assetDirs.insert(0, join(getRootDir(), CUSTOM_ASSETS_FOLDER))
    for dir in assetDirs:
        addAssetFileSearchPath(dir)

    if _assetFileSearchPaths:
        BugConfigTracker.add("Asset_Search_Paths", _assetFileSearchPaths)
    else:
        BugUtil.error("No asset directories found")
    _searchPathsInitDone = True
예제 #13
0
def initSearchPaths():
    """
	Adds the CustomAssets, mod Assets and BTS Assets directories to a list of search paths.
	"""
    global _searchPathsInitDone
    if _searchPathsInitDone:
        return
    BugUtil.debug("BugPath - initializing asset search paths")

    assetDirs = [
        join(getModDir(), ASSETS_FOLDER),
        join(getAppDir(), ASSETS_FOLDER),
    ]
    # EF: Mod's no longer access CustomAssets folder; too many issues
    if not isNoCustomAssets() and not isMod():
        assetDirs.insert(0, join(getRootDir(), CUSTOM_ASSETS_FOLDER))
    for dir in assetDirs:
        addAssetFileSearchPath(dir)

    if _assetFileSearchPaths:
        BugConfigTracker.add("Asset_Search_Paths", _assetFileSearchPaths)
    else:
        BugUtil.error("No asset directories found")
    _searchPathsInitDone = True
예제 #14
0
def init():
    print "[BugPath] initializing..."
    import SystemPaths as SP
    import BugConfigTracker

    global _modDir, _settingsDir
    _modDir = SP.modDir
    _settingsDir = SP.userSettingsDir
    BugConfigTracker.add("Mod_Directory", _modDir)
    BugConfigTracker.add("Settings_Directory", _settingsDir)

    global _assetFileSearchPaths
    _assetFileSearchPaths = _modDir + "\Assets"
    BugConfigTracker.add("Asset_Search_Paths", _assetFileSearchPaths)

    print "[BugPath] initialized."
예제 #15
0
	def updateLogFile(self):
		if self.LogFileName and self.LogFilePath:
			self.bStarted = False
			self.RealLogFile = os.path.join(self.LogFilePath, self.LogFileName)
			BugConfigTracker.add("Autolog_Log", self.RealLogFile)
예제 #16
0
 def updateLogFile(self):
     if self.LogFileName and self.LogFilePath:
         self.bStarted = False
         self.RealLogFile = os.path.join(self.LogFilePath, self.LogFileName)
         BugConfigTracker.add("Autolog_Log", self.RealLogFile)