Exemple #1
0
 def __init__(self, settings_file, fsName):
     self._backup_dest_file = settings_file  # absolute path to dest 7z file
     self.files = {}
     for (bash_dir, tmpdir), setting_files in \
             _init_settings_files(fsName).iteritems():
         if not setting_files:  # we have to backup everything in there
             setting_files = bash_dir.list()
         tmp_dir = GPath(tmpdir)
         for name in setting_files:
             fpath = bash_dir.join(name)
             if fpath.exists():
                 self.files[tmp_dir.join(name)] = fpath
     # backup save profile settings
     savedir = GPath(u'My Games').join(fsName)
     profiles = [u''] + initialization.getLocalSaveDirs()
     for profile in profiles:
         pluginsTxt = (u'Saves', profile, u'plugins.txt')
         loadorderTxt = (u'Saves', profile, u'loadorder.txt')
         for txt in (pluginsTxt, loadorderTxt):
             tpath = savedir.join(*txt)
             fpath = dirs['saveBase'].join(*txt)
             if fpath.exists(): self.files[tpath] = fpath
         table = (u'Saves', profile, u'Bash', u'Table.dat')
         tpath = savedir.join(*table)
         fpath = dirs['saveBase'].join(*table)
         if fpath.exists(): self.files[tpath] = fpath
         if fpath.backup.exists(): self.files[tpath.backup] = fpath.backup
Exemple #2
0
def getJava():
    """Locate javaw.exe to launch jars from Bash."""
    if _os.name == 'posix':
        import subprocess
        java_bin_path = ''
        try:
            java_bin_path = subprocess.check_output('command -v java',
                                                    shell=True).rstrip('\n')
        except subprocess.CalledProcessError:
            pass  # what happens when java doesn't exist?
        return GPath(java_bin_path)
    try:
        java_home = GPath(_os.environ['JAVA_HOME'])
        java = java_home.join('bin', u'javaw.exe')
        if java.exists(): return java
    except KeyError:  # no JAVA_HOME
        pass
    win = GPath(_os.environ['SYSTEMROOT'])
    # Default location: Windows\System32\javaw.exe
    java = win.join(u'system32', u'javaw.exe')
    if not java.exists():
        # 1st possibility:
        #  - Bash is running as 32-bit
        #  - The only Java installed is 64-bit
        # Because Bash is 32-bit, Windows\System32 redirects to
        # Windows\SysWOW64.  So look in the ACTUAL System32 folder
        # by using Windows\SysNative
        java = win.join(u'sysnative', u'javaw.exe')
    if not java.exists():
        # 2nd possibility
        #  - Bash is running as 64-bit
        #  - The only Java installed is 32-bit
        # So javaw.exe would actually be in Windows\SysWOW64
        java = win.join(u'syswow64', u'javaw.exe')
    return java
Exemple #3
0
def ripAppearance(srcName,
                  destName,
                  srcForm='player',
                  destForm='player',
                  flags=unicode(0x2 | 0x4 | 0x8 | 0x10)):
    """Rips a face from one save game and pastes it into another."""
    flags = intArg(flags)
    srcName = GPath(srcName)
    destName = GPath(destName)
    #--Get source face
    srcFile = data.getSaveFile(srcName)
    if srcForm == 'player':
        face = PCFaces.save_getPlayerFace(srcFile)
    else:
        srcForm = intArg(srcForm)
        face = PCFaces.save_getCreatedFace(srcFile, srcForm)
    #printFace(face)
    #--Set destination face
    if srcName == destName:
        destFile = srcFile
    else:
        destFile = data.getSaveFile(destName)
    if destForm == 'player':
        PCFaces.save_setPlayerFace(destFile, face,
                                   flags)  #--Race, gender, hair, eyes
    else:
        destForm = intArg(destForm)
        PCFaces.save_setCreatedFace(destFile, destForm, face)
        if not face.gender: data.shapeIsMale.touch()
    if destName not in data.saves:
        destFile.safeSave()
    #--Done
    print face.pcName, u'...',
Exemple #4
0
def getOblivionModsPath(bash_ini_, game_info):
    ob_mods_path = get_path_from_ini(bash_ini_, u'sOblivionMods')
    if ob_mods_path:
        src = [u'[General]', u'sOblivionMods']
    else:
        ob_mods_path = GPath(GPath(u'..').join(u'%s Mods' % game_info.fsName))
        src = u'Relative Path'
    if not ob_mods_path.isabs(): ob_mods_path = dirs['app'].join(ob_mods_path)
    return ob_mods_path, src
Exemple #5
0
def moveSave(oldSave,newSave):
    """Temporarilty moves quicksave.ess to quicktemp.ess."""
    #--Use path.tail to prevent access outside of saves directory
    oldPath = data.savesDir.join(GPath(oldSave).tail)
    newPath = data.savesDir.join(GPath(newSave).tail)
    if newPath.exists() and not newPath.isfile():
        raise bolt.BoltError(newPath+_(' exists and is not a save file.'))
    if oldPath.exists():
        if not oldPath.isfile(): raise bolt.BoltError(oldPath+_(' is not a save file.'))
        oldPath.moveTo(newPath)
        bosh.CoSaves(oldPath).move(newPath)
Exemple #6
0
def compressionSettings(archive_path, blockSize, isSolid):
    archiveType = writeExts.get(archive_path.cext)
    if not archiveType:
        #--Always fall back to using the defaultExt
        archive_path = GPath(archive_path.sbody + defaultExt).tail
        archiveType = writeExts.get(archive_path.cext)
    if archive_path.cext in noSolidExts:  # zip
        solid = u''
    else:
        if isSolid:
            if blockSize:
                solid = u'-ms=on -ms=%dm' % blockSize
            else:
                solid = u'-ms=on'
        else:
            solid = u'-ms=off'
    userArgs = bass.inisettings['7zExtraCompressionArguments']
    if userArgs:
        if reSolid.search(userArgs):
            if not solid:  # zip, will blow if ms=XXX is passed in
                old = userArgs
                userArgs = reSolid.sub(u'', userArgs).strip()
                if old != userArgs:
                    deprint(archive_path.s +
                            u': 7zExtraCompressionArguments ini option "' +
                            old + u'" -> "' + userArgs + u'"')
            solid = userArgs
        else:
            solid += userArgs
    return archive_path, archiveType, solid
Exemple #7
0
def BrowseToMWDir():
    """Dialog to select Morrowind installation directory. Called by OnInit()."""
    # --Ask user through dialog.
    while True:
        mwDirDialog = wx.DirDialog(
            None, _(u"Select your Morrowind installation directory."))
        result = mwDirDialog.ShowModal()
        mwDir = mwDirDialog.GetPath()
        mwDirDialog.Destroy()
        # --User canceled?
        if result != wx.ID_OK:
            return False
        # --Valid Morrowind install directory?
        elif os.path.exists(os.path.join(mwDir, u'Morrowind.ini')):
            conf.settings['mwDir'] = mwDir
            conf.dirs['app'] = GPath(mwDir)
            return True
        # --Retry?
        retryDialog = wx.MessageDialog(
            None,
            _(u"Can't find Morrowind.ini in {!s}! Try again?".format(mwDir)),
            _(u'Morrowind Install Directory'), wx.YES_NO | wx.ICON_EXCLAMATION)
        result = retryDialog.ShowModal()
        retryDialog.Destroy()
        if result != wx.ID_YES:
            return False
Exemple #8
0
def swapPlayer(saveName,
               oldForm,
               newForm,
               flags=0x1 | 0x2 | 0x4 | 0x8 | 0x10 | 0x20 | 0x40):
    """Swaps the player between old and new forms.
    Archives player's current form/stats to oldForm, then changes player into new form."""
    oldForm = intArg(oldForm)
    newForm = intArg(newForm)
    flags = intArg(flags)
    #--Open Save file
    saveName = GPath(saveName)
    saveFile = data.getSaveFile(saveName)
    #--player >> oldForm
    oldFace = PCFaces.save_getPlayerFace(saveFile)
    PCFaces.save_setCreatedFace(saveFile, oldForm, oldFace)
    if not oldFace.gender: data.shapeIsMale.touch()
    #--newForm >> player
    newFace = PCFaces.save_getCreatedFace(saveFile, newForm)
    PCFaces.save_setPlayerFace(saveFile, newFace, flags)
    #--Checking
    #printFace(oldFace)
    #printFace(PCFaces.save_getCreatedFace(saveFile,oldForm))
    #printFace(newFace)
    #printFace(PCFaces.save_getPlayerFace(saveFile))
    #--Save and done
    if saveName not in data.saves:
        saveFile.safeSave()
    print u'  %s >> %s...' % (oldFace.pcName, newFace.pcName)
Exemple #9
0
def extract7z(src_archive, extract_dir, progress=None, readExtensions=None,
              recursive=False, filelist_to_extract=None):
    command = _extract_command(src_archive, extract_dir, recursive,
                               filelist_to_extract)
    proc = subprocess.Popen(command, stdout=subprocess.PIPE, bufsize=1,
                            stdin=subprocess.PIPE, startupinfo=startupinfo)
    # Error checking, progress feedback and subArchives for recursive unpacking
    index, errorLine, subArchives = 0, u'', []
    source_archive = src_archive.tail.s
    with proc.stdout as out:
        for line in iter(out.readline, b''):
            line = unicode(line, 'utf8')
            if regErrMatch(line):
                errorLine = line + u''.join(out)
                break
            maExtracting = regExtractMatch(line)
            if maExtracting:
                extracted = GPath(maExtracting.group(1).strip())
                if readExtensions and extracted.cext in readExtensions:
                    subArchives.append(extracted)
                if not progress: continue
                progress(index, source_archive + u'\n' + _(
                    u'Extracting files...') + u'\n' + extracted.s)
                index += 1
    returncode = proc.wait()
    if returncode or errorLine:
        raise StateError(u'%s: Extraction failed:\n7z.exe return value: %s\n%s'
                         % (source_archive, str(returncode), errorLine))
    return subArchives
Exemple #10
0
 def __init__(self, settings_file):
     self._settings_file = GPath(settings_file)
     self._saved_settings_version = self._settings_saved_with = None
     # bash.ini handling
     self._timestamped_old = self.__unset
     self._bash_ini_path = self.__unset
     # extract folder
     self._extract_dir = self.__unset
Exemple #11
0
def get_personal_path():
    if shell and shellcon:
        path = _getShellPath(shellcon.CSIDL_PERSONAL)
        sErrorInfo = _(u"Folder path extracted from win32com.shell.")
    else:
        path = _getShellPath('Personal')
        sErrorInfo = __get_error_info()
    return GPath(path), sErrorInfo
Exemple #12
0
def get_local_app_data_path():
    if shell and shellcon:
        path = _getShellPath(shellcon.CSIDL_LOCAL_APPDATA)
        sErrorInfo = _(u"Folder path extracted from win32com.shell.")
    else:
        path = _getShellPath('Local AppData')
        sErrorInfo = __get_error_info()
    return GPath(path), sErrorInfo
Exemple #13
0
 def restore_ini(self):
     if self._timestamped_old is self.__unset:
         return  # we did not move bash.ini
     if self._timestamped_old is not None:
         bolt.deprint(u'Restoring bash.ini')
         GPath(self._timestamped_old).copyTo(u'bash.ini')
     elif self._bash_ini_path:
         # remove bash.ini as it is the one from the backup
         bolt.GPath(u'bash.ini').remove()
 def keepRecords(self, keepIds):
     """Keeps records with fid in set keepIds. Discards the rest."""
     self.records = [
         record for record in self.records
         if (record.fid ==
             (record.isKeyedByEid and GPath(bosh.modInfos.masterName),
              0) and record.eid in keepIds) or record.fid in keepIds
     ]
     self.id_records.clear()
     self.setChanged()
Exemple #15
0
def unpack7z(srcFile, dstDir, progress=None):
    # extract srcFile to dstDir
    progress = progress or Progress()

    # count the files in the archive
    length = 0
    reList = re.compile(u'Path = (.*?)(?:\r\n|\n)', re.U)
    command = ur'"%s" l -slt "%s"' % (dirs['compiled'].join(u'7z.exe').s,
                                      srcFile.s)
    ins, err = Popen(command, stdout=PIPE, stdin=PIPE,
                     startupinfo=startupinfo).communicate()
    ins = StringIO.StringIO(ins)
    for line in ins:
        length += 1
    ins.close()

    if progress:
        progress(0, srcFile.s + u'\n' + _(u'Extracting files...'))
        progress.setFull(1 + length)
    #end if

    app7z = dirs['compiled'].join(u'7z.exe').s
    command = u'"%s" x "%s" -y -o"%s"' % (app7z, srcFile.s, dstDir.s)

    #--Extract files
    ins = Popen(command, stdout=PIPE, stdin=PIPE,
                startupinfo=startupinfo).stdout
    #--Error Checking, and progress feedback
    #--Note subArchives for recursive unpacking
    reExtracting = re.compile(u'Extracting\s+(.+)', re.U)
    regMatch = reExtracting.match
    reError = re.compile(u'Error: (.*)', re.U)
    regErrMatch = reError.match
    errorLine = []
    index = 0
    for line in ins:
        line = unicode(line, 'utf8')
        maExtracting = regMatch(line)
        if len(errorLine) or regErrMatch(line):
            errorLine.append(line)
        if maExtracting:
            extracted = GPath(maExtracting.group(1).strip())
            if progress:
                progress(
                    index, srcFile.s + u'\n' + _(u'Extracting files...') +
                    u'\n' + extracted.s)
            #end if
            index += 1
        #end if
    #end for
    result = ins.close()
    if result:
        raise StateError(srcFile.s + u': Extraction failed:\n' +
                         u'\n'.join(errorLine))
Exemple #16
0
 def GetActivePlugins(self):
     plugins = c_uint8_p_p()
     num = c_size_t()
     try:
         _CGetActivePlugins(self._DB, byref(plugins), byref(num))
     except BossError as e:
         if e.code == BOSS_API_ERROR_FILE_NOT_FOUND:
             self.SetActivePlugins([])
             _CGetActivePlugins(self._DB, byref(plugins), byref(num))
         else:
             raise
     return [GPath(_uni(plugins[i])) for i in xrange(num.value)]
Exemple #17
0
def init_app_links(apps_dir, badIcons, iconList):
    init_params = []
    for path, (target, icon,
               description) in _get_app_links(apps_dir).iteritems():
        if target.lower().find(
                ur'installer\{') != -1:  # msi shortcuts: dc0c8de
            target = path
        else:
            target = GPath(target)
        if not target.exists(): continue
        # Target exists - extract path, icon and description
        # First try a custom icon #TODO(ut) docs - also comments methods here!
        fileName = u'%s%%i.png' % path.sbody
        customIcons = [apps_dir.join(fileName % x) for x in (16, 24, 32)]
        if customIcons[0].exists():
            icon = customIcons
        # Next try the shortcut specified icon
        else:
            icon, idex = icon.split(u',')
            if icon == u'':
                if target.cext == u'.exe':
                    if win32gui and win32gui.ExtractIconEx(target.s, -1):
                        # -1 queries num of icons embedded in the exe
                        icon = target
                    else:  # generic exe icon, hardcoded and good to go
                        icon, idex = _os.path.expandvars(
                            u'%SystemRoot%\\System32\\shell32.dll'), u'2'
                else:
                    icon, idex = _get_default_app_icon(idex, target)
            icon = GPath(icon)
            if icon.exists():
                fileName = u';'.join((icon.s, idex))
                icon = iconList(fileName)
                # Last, use the 'x' icon
            else:
                icon = badIcons
        init_params.append((path, icon, description))
Exemple #18
0
 def _restore_settings(self, fsName):
     deprint(u'')
     deprint(_(u'RESTORE BASH SETTINGS: ') + self._settings_file.s)
     # backup previous Bash ini if it exists
     old_bash_ini = dirs['mopy'].join(u'bash.ini')
     self._timestamped_old = u''.join(
         [old_bash_ini.root.s, u'(',
          bolt.timestamp(), u').ini'])
     try:
         old_bash_ini.moveTo(self._timestamped_old)
         deprint(u'Existing bash.ini moved to %s' % self._timestamped_old)
     except StateError:  # does not exist
         self._timestamped_old = None
     # restore all the settings files
     restore_paths = _init_settings_files(fsName).keys()
     for dest_dir, back_path in restore_paths:
         full_back_path = self._extract_dir.join(back_path)
         for name in full_back_path.list():
             if full_back_path.join(name).isfile():
                 deprint(
                     GPath(back_path).join(name).s + u' --> ' +
                     dest_dir.join(name).s)
                 full_back_path.join(name).copyTo(dest_dir.join(name))
     # restore savegame profile settings
     back_path = GPath(u'My Games').join(fsName, u'Saves')
     saves_dir = dirs['saveBase'].join(u'Saves')
     full_back_path = self._extract_dir.join(back_path)
     if full_back_path.exists():
         for root_dir, folders, files_ in full_back_path.walk(
                 True, None, True):
             root_dir = GPath(u'.' + root_dir.s)
             for name in files_:
                 deprint(
                     back_path.join(root_dir, name).s + u' --> ' +
                     saves_dir.join(root_dir, name).s)
                 full_back_path.join(root_dir, name).copyTo(
                     saves_dir.join(root_dir, name))
 def setRecord(self, record):
     """Adds record to record list and indexed."""
     if self.records and not self.id_records:
         self.indexRecords()
     record_id = record.fid
     if record.isKeyedByEid:
         if record_id == (GPath(bosh.modInfos.masterName), 0):
             record_id = record.eid
     if record_id in self.id_records:
         oldRecord = self.id_records[record_id]
         index = self.records.index(oldRecord)
         self.records[index] = record
     else:
         self.records.append(record)
     self.id_records[record_id] = record
Exemple #20
0
def cmdRestore():
    # restore settings on user request
    if not basherImported: import basher, barb
    backup = None
    path = None
    quit = opts.restore and opts.quietquit
    if opts.restore: path = GPath(opts.filename)
    if opts.restore:
        try:
            backup = barb.RestoreSettings(basher.bashFrame, path, quit,
                                          opts.backup_images)
            backup.Apply()
        except barb.BackupCancelled:
            pass
    del backup
    return quit
Exemple #21
0
def get_registry_path(subkey, entry, exe):
    """Check registry for a path to a program."""
    if not winreg: return None
    for hkey in (winreg.HKEY_LOCAL_MACHINE, winreg.HKEY_CURRENT_USER):
        for wow6432 in (u'', u'Wow6432Node\\'):
            try:
                key = winreg.OpenKey(hkey,
                                     u'Software\\%s%s' % (wow6432, subkey))
                value = winreg.QueryValueEx(key, entry)
            except OSError:
                continue
            if value[1] != winreg.REG_SZ: continue
            installPath = GPath(value[0])
            if not installPath.exists(): continue
            exePath = installPath.join(exe)
            if not exePath.exists(): continue
            return installPath
    return None
Exemple #22
0
def cmdBackup():
    # backup settings if app version has changed or on user request
    global basher, balt, barb
    if not basher: import basher, balt, barb
    path = None
    quit = opts.backup and opts.quietquit
    if opts.backup: path = GPath(opts.filename)
    if barb.BackupSettings.PromptMismatch() or opts.backup:
        backup = barb.BackupSettings(balt.Link.Frame, path, quit,
                                     opts.backup_images)
        try:
            backup.Apply()
        except bolt.StateError:
            if backup.SameAppVersion():
                backup.WarnFailed()
            elif backup.PromptQuit():
                return False
        except barb.BackupCancelled:
            if not backup.SameAppVersion() and not backup.PromptContinue():
                return False
        del backup
    return quit
Exemple #23
0
def getPersonalPath(bash_ini_, my_docs_path):
    #--Determine User folders from Personal and Local Application Data directories
    #  Attempt to pull from, in order: Command Line, Ini, win32com, Registry
    if my_docs_path:
        my_docs_path = GPath(my_docs_path)
        sErrorInfo = _(u"Folder path specified on command line (-p)")
    else:
        my_docs_path = get_path_from_ini(bash_ini_, 'sPersonalPath')
        if my_docs_path:
            sErrorInfo = _(
                u"Folder path specified in bash.ini (%s)") % u'sPersonalPath'
        else:
            my_docs_path, sErrorInfo = get_personal_path()
    #  If path is relative, make absolute
    if not my_docs_path.isabs():
        my_docs_path = dirs['app'].join(my_docs_path)
    #  Error check
    if not my_docs_path.exists():
        raise BoltError(u"Personal folder does not exist.\n"
                        u"Personal folder: %s\nAdditional info:\n%s" %
                        (my_docs_path.s, sErrorInfo))
    return my_docs_path
Exemple #24
0
    def __init__(self, parent=None, path=None, quit=False, backup_images=None):
        BaseBackupSettings.__init__(self, parent, path, quit)
        for path, name, tmpdir in (
            (dirs['mopy'], 'Bash.ini', 'Fallout New Vegas\\Mopy'),
            (dirs['mods'].join('Bash'), 'Table',
             'Fallout New Vegas\\Data\\Bash'),
            (dirs['mods'].join('Docs'), 'Bash Readme Template',
             'Fallout New Vegas\\Data\\Docs'),
            (dirs['mods'].join('Docs'), 'Bashed Lists',
             'Fallout New Vegas\\Data\\Docs'),
            (dirs['mods'].join('Docs'), 'wtxt_sand_small.css',
             'Fallout New Vegas\\Data\\Docs'),
            (dirs['mods'].join('Docs'), 'wtxt_teal.css',
             'Fallout New Vegas\\Data\\Docs'),
            (dirs['modsBash'], 'Table',
             'Fallout New Vegas Mods\\Bash Mod Data'),
            (dirs['modsBash'].join('INI Data'), 'Table',
             'Fallout New Vegas Mods\\Bash Mod Data\\INI Data'),
            (dirs['installers'].join('Bash'), 'Converters',
             'Fallout New Vegas Mods\\Bash Installers\\Bash'),
            (dirs['installers'].join('Bash'), 'Installers',
             'Fallout New Vegas Mods\\Bash Installers\\Bash'),
            (dirs['userApp'], 'Profiles', 'LocalAppData\\FalloutNV'),
            (dirs['userApp'], 'bash config', 'LocalAppData\\FalloutNV'),
            (dirs['saveBase'], 'BashProfiles', 'My Games\\FalloutNV'),
            (dirs['saveBase'], 'BashSettings', 'My Games\\FalloutNV'),
            (dirs['saveBase'], 'Messages', 'My Games\\FalloutNV'),
            (dirs['saveBase'], 'ModeBase', 'My Games\\FalloutNV'),
            (dirs['saveBase'], 'People', 'My Games\\FalloutNV'),
        ):
            tmpdir = GPath(tmpdir)
            for ext in (
                    '', '.dat', '.pkl', '.html', '.txt'
            ):  # hack so the above file list can be shorter, could include rogue files but not very likely
                tpath = tmpdir.join(name + ext)
                fpath = path.join(name + ext)
                if fpath.exists(): self.files[tpath] = fpath
                if fpath.backup.exists():
                    self.files[tpath.backup] = fpath.backup
            #end for
        #end for

        #backup all files in Mopy\Data, Data\Bash Patches and Data\INI Tweaks
        for path, tmpdir in (
            (dirs['l10n'], 'Fallout New Vegas\\Mopy\\bash\\l10n'),
            (dirs['mods'].join('Bash Patches'),
             'Fallout New Vegas\\Data\\Bash Patches'),
            (dirs['mods'].join('INI Tweaks'),
             'Fallout New Vegas\\Data\\INI Tweaks'),
        ):
            tmpdir = GPath(tmpdir)
            for name in path.list():
                if path.join(name).isfile():
                    self.files[tmpdir.join(name)] = path.join(name)

        #backup image files if told to
        if backup_images == 1:  #changed images only
            tmpdir = GPath('Fallout New Vegas\\Mopy\\bash\\images')
            path = dirs['images']
            for name in path.list():
                fullname = path.join(name)
                if fullname.isfile():
                    changed = True
                    for ver_list in bolt.images_list:
                        if name.s in bolt.images_list[
                                ver_list] and bolt.images_list[ver_list][
                                    name.s] == fullname.size:
                            changed = False
                    if changed and not name.s.lower() == 'thumbs.db':
                        self.files[tmpdir.join(name)] = fullname
        elif backup_images == 2:  #all images
            tmpdir = GPath('Fallout New Vegas\\Mopy\\bash\\images')
            path = dirs['images']
            for name in path.list():
                if path.join(
                        name).isfile() and not name.s.lower() == 'thumbs.db':
                    self.files[tmpdir.join(name)] = path.join(name)

        #backup save profile settings
        savedir = GPath('My Games\\FalloutNV')
        profiles = [''] + [
            x
            for x in dirs['saveBase'].join('Saves').list() if dirs['saveBase'].
            join('Saves', x).isdir() and str(x).lower() != 'bash'
        ]
        for profile in profiles:
            tpath = savedir.join('Saves', profile, 'plugins.txt')
            fpath = dirs['saveBase'].join('Saves', profile, 'plugins.txt')
            if fpath.exists(): self.files[tpath] = fpath
            for ext in ('.dat', '.pkl'):
                tpath = savedir.join('Saves', profile, 'Bash', 'Table' + ext)
                fpath = dirs['saveBase'].join('Saves', profile, 'Bash',
                                              'Table' + ext)
                if fpath.exists(): self.files[tpath] = fpath
                if fpath.backup.exists():
                    self.files[tpath.backup] = fpath.backup
Exemple #25
0
    def Apply(self):
        if self.ErrorConflict():
            self.WarnFailed()
            return
        elif not self.PromptMismatch():
            raise BackupCancelled()
            return

        deprint('')
        deprint('RESTORE BASH SETTINGS: ' + self.dir.join(self.archive).s)

        # reinitialize bosh.dirs using the backup copy of bash.ini if it exists
        tmpBash = self.tmp.join('Fallout New Vegas\\Mopy\\bash.ini')
        opts, args = bash.opts, bash.extra

        bash.SetUserPath(tmpBash.s, opts.userPath)

        bashIni = bash.GetBashIni(tmpBash.s)
        bosh.initBosh(opts.personalPath, opts.localAppDataPath,
                      opts.falloutPath)

        # restore all the settings files
        restore_paths = (
            (dirs['mopy'], 'Fallout New Vegas\\Mopy'),
            (dirs['mods'].join('Bash'), 'Fallout New Vegas\\Data\\Bash'),
            (dirs['mods'].join('Bash Patches'),
             'Fallout New Vegas\\Data\\Bash Patches'),
            (dirs['mods'].join('Docs'), 'Fallout New Vegas\\Data\\Docs'),
            (dirs['mods'].join('INI Tweaks'),
             'Fallout New Vegas\\Data\\INI Tweaks'),
            (dirs['modsBash'], 'Fallout New Vegas Mods\\Bash Mod Data'),
            (dirs['modsBash'].join('INI Data'),
             'Fallout New Vegas Mods\\Bash Mod Data\\INI Data'),
            (dirs['installers'].join('Bash'),
             'Fallout New Vegas Mods\\Bash Installers\\Bash'),
            (dirs['userApp'], 'LocalAppData\\FalloutNV'),
            (dirs['saveBase'], 'My Games\\FalloutNV'),
        )
        if 14 >= self.verApp:
            # restore from old data paths
            restore_paths += ((dirs['l10n'], 'Fallout New Vegas\\Data'), )
            if self.restore_images:
                restore_paths += ((dirs['images'],
                                   'Fallout New Vegas\\Mopy\\images'), )
        else:
            restore_paths += ((dirs['l10n'],
                               'Fallout New Vegas\\bash\\l10n'), )
            if self.restore_images:
                restore_paths += ((dirs['images'],
                                   'Fallout New Vegas\\Mopy\\bash\\images'), )
        for fpath, tpath in restore_paths:
            path = self.tmp.join(tpath)
            if path.exists():
                for name in path.list():
                    if path.join(name).isfile():
                        deprint(
                            GPath(tpath).join(name).s + ' --> ' +
                            fpath.join(name).s)
                        path.join(name).copyTo(fpath.join(name))

        #restore savegame profile settings
        tpath = GPath('My Games\\FalloutNV\\Saves')
        fpath = dirs['saveBase'].join('Saves')
        path = self.tmp.join(tpath)
        if path.exists():
            for root, folders, files in path.walk(True, None, True):
                root = GPath('.' + root.s)
                for name in files:
                    deprint(
                        tpath.join(root, name).s + ' --> ' +
                        fpath.join(root, name).s)
                    path.join(root, name).copyTo(fpath.join(root, name))

        # tell the user the restore is compete and warn about restart
        self.WarnRestart()
        if basher.bashFrame:  # should always exist
            basher.bashFrame.Destroy()
Exemple #26
0
 def GetIndexedPlugin(self, index):
     plugin = c_uint8_p()
     _CGetIndexedPlugin(self._DB, index, byref(plugin))
     return GPath(_uni(plugin.value))
Exemple #27
0
 def GetAssets(self, contentPath):
     assets = c_char_p_p()
     num = c_size_t()
     _Cbsa_get_assets(self._handle, _enc(contentPath), byref(assets), byref(num))
     return [GPath(_uni(assets[i])) for i in xrange(num.value)]
Exemple #28
0
 def ExtractAssets(self, contentPath, destPath):
     assets = c_char_p_p()
     num = c_size_t()
     _Cbsa_extract_assets(self._handle, _enc(contentPath), _enc(destPath), byref(assets), byref(num), True)
     return [GPath(_uni(assets[i])) for i in xrange(num.value)]
Exemple #29
0
def unpack7z(srcFile, dstDir, progress=None):
    # extract srcFile to dstDir
    progress = progress or Progress()

    # count the files in the archive
    length = 0
    reList = re.compile('Path = (.*?)(?:\r\n|\n)')
    if bosh.inisettings['EnableUnicode']:
        command = r'"%s" l -slt "%s"' % (
            dirs['compiled'].join('7zUnicode.exe').s, srcFile.s)
    else:
        command = r'"%s" l -slt "%s"' % (dirs['compiled'].join('7z.exe').s,
                                         srcFile.s)
    ins, err = Popen(command, stdout=PIPE,
                     startupinfo=startupinfo).communicate()
    ins = stringBuffer(ins)
    for line in ins:
        length += 1
    ins.close()

    if progress:
        progress(0, _("%s\nExtracting files...") % srcFile.s)
        progress.setFull(1 + length)
    #end if

    if bosh.inisettings['EnableUnicode']:
        app7z = dirs['compiled'].join('7zUnicode.exe').s
    else:
        app7z = dirs['compiled'].join('7z.exe').s
    command = '"%s" x "%s" -y -o"%s"' % (app7z, srcFile.s, dstDir.s)

    #--Extract files
    ins = Popen(command, stdout=PIPE, startupinfo=startupinfo).stdout
    #--Error Checking, and progress feedback
    #--Note subArchives for recursive unpacking
    reExtracting = re.compile('Extracting\s+(.+)')
    regMatch = reExtracting.match
    reError = re.compile('Error: (.*)')
    regErrMatch = reError.match
    errorLine = []
    index = 0
    for line in ins:
        maExtracting = regMatch(line)
        if len(errorLine) or regErrMatch(line):
            errorLine.append(line)
        if maExtracting:
            extracted = GPath(maExtracting.group(1).strip())
            if progress:
                progress(
                    index,
                    _("%s\nExtracting files...\n%s") %
                    (srcFile.s, extracted.s))
            #end if
            index += 1
        #end if
    #end for
    result = ins.close()
    if result:
        raise StateError(
            _("%s: Extraction failed:\n%s") %
            (srcFile.s, "\n".join(errorLine)))
Exemple #30
0
 def SortMods(self, trialOnly=False):
     plugins = c_uint8_p_p()
     num = c_size_t()
     lastRec = c_size_t()
     _CSortMods(self._DB, byref(plugins), byref(num), byref(lastRec))
     return [GPath(_uni(plugins[i])) for i in xrange(num.value)]