def PromptFile(self): #prompt for backup filename #returns False if user cancels if self.archive == None or self.dir.join(self.archive).exists(): dt = datetime.datetime.now() file = u'Backup Bash Settings %s (%s) v%s-%s.7z' % (bush.game.name,dt.strftime(u'%Y-%m-%d %H.%M.%S'),self.verDat,self.verApp) if not self.quit: path = askSave(self.parent,_(u'Backup Bash Settings'),self.dir,file,u'*.7z') if not path: return False self.dir = path.head self.archive = path.tail elif not self.archive: self.archive = file #end if self.maketmp() return True
def PromptFile(self): #prompt for backup filename #returns False if user cancels if self.archive == None or self.dir.join(self.archive).exists(): dt = datetime.datetime.now() file = 'Backup Bash Settings v%s (%s).7z' % (self.verApp,dt.strftime('%d-%m-%Y %H%M.%S')) if not self.quit: path = askSave(self.parent,_('Backup Bash Settings'),self.dir,file,'*.7z') if not path: return False self.dir = path.head self.archive = path.tail elif not self.archive: self.archive = file #end if self.maketmp() return True
def PromptFile(self): #prompt for backup filename #returns False if user cancels if self.archive == None or self.dir.join(self.archive).exists(): dt = datetime.datetime.now() file = 'Backup Bash Settings v%s (%s).7z' % ( self.verApp, dt.strftime('%d-%m-%Y %H%M.%S')) if not self.quit: path = askSave(self.parent, _('Backup Bash Settings'), self.dir, file, '*.7z') if not path: return False self.dir = path.head self.archive = path.tail elif not self.archive: self.archive = file #end if self.maketmp() return True
def PromptFile(self): #prompt for backup filename #returns False if user cancels if self.archive == None or self.dir.join(self.archive).exists(): dt = datetime.datetime.now() file = u'Backup Bash Settings %s (%s) v%s-%s.7z' % ( bush.game.name, dt.strftime(u'%Y-%m-%d %H.%M.%S'), self.verDat, self.verApp) if not self.quit: path = askSave(self.parent, _(u'Backup Bash Settings'), self.dir, file, u'*.7z') if not path: return False self.dir = path.head self.archive = path.tail elif not self.archive: self.archive = file #end if self.maketmp() return True
def _main(opts): """Run the Wrye Bash main loop. This function is marked private because it should be inside a try-except block. Call main() from the outside. :param opts: command line arguments """ import barg bass.sys_argv = barg.convert_to_long_options(sys.argv) import env # env imports bolt (this needs fixing) bolt.deprintOn = opts.debug # useful for understanding context of bug reports if opts.debug or is_standalone: # Standalone stdout is NUL no matter what. Redirect it to stderr. # Also, setup stdout/stderr to the debug log if debug mode / # standalone before wxPython is up global _bugdump_handle # _bugdump_handle = io.open(os.path.join(os.getcwdu(),u'BashBugDump.log'),'w',encoding='utf-8') _bugdump_handle = codecs.getwriter('utf-8')(open( os.path.join(os.getcwdu(), u'BashBugDump.log'), 'w')) sys.stdout = _bugdump_handle sys.stderr = _bugdump_handle old_stderr = _bugdump_handle if opts.debug: dump_environment() # Check if there are other instances of Wrye Bash running instance = _wx.SingleInstanceChecker('Wrye Bash') # must stay alive ! assure_single_instance(instance) global initialization import initialization #--Bash installation directories, set on boot, not likely to change initialization.init_dirs_mopy_and_cd(is_standalone) # if HTML file generation was requested, just do it and quit if opts.genHtml is not None: msg1 = _(u"generating HTML file from: '%s'") % opts.genHtml msg2 = _(u'done') try: print msg1 except UnicodeError: print msg1.encode(bolt.Path.sys_fs_enc) import belt # this imports bosh which imports wx (DUH) bolt.WryeText.genHtml(opts.genHtml) try: print msg2 except UnicodeError: print msg2.encode(bolt.Path.sys_fs_enc) return # We need the Mopy dirs to initialize restore settings instance bash_ini_path, restore_ = u'bash.ini', None # import barb that does not import from bosh/balt/bush import barb if opts.restore: try: restore_ = barb.RestoreSettings(opts.filename) restore_.extract_backup() # get the bash.ini from the backup, or None - use in _detect_game bash_ini_path = restore_.backup_ini_path() except (exception.BoltError, exception.StateError, OSError, IOError): bolt.deprint(u'Failed to restore backup', traceback=True) restore_ = None # The rest of backup/restore functionality depends on setting the game try: bashIni, bush_game, game_ini_path = _detect_game(opts, bash_ini_path) if not bush_game: return if restore_: try: # TODO(ut) error checks - limit except Exception below restore_.restore_settings(bush_game.fsName) # we currently disallow backup and restore on the same boot if opts.quietquit: return except Exception: bolt.deprint(u'Failed to restore backup', traceback=True) restore_.restore_ini() # reset the game and ini import bush bush.reset_bush_globals() bashIni, bush_game, game_ini_path = _detect_game( opts, u'bash.ini') import bosh # this imports balt (DUH) which imports wx bosh.initBosh(bashIni, game_ini_path) env.isUAC = env.testUAC(bush_game.gamePath.join(u'Data')) global basher, balt import basher, balt except (exception.PermissionError, exception.BoltError, ImportError, OSError, IOError) as e: msg = u'\n'.join([ _(u'Error! Unable to start Wrye Bash.'), u'\n', _(u'Please ensure Wrye Bash is correctly installed.'), u'\n', traceback.format_exc(e) ]) _close_dialog_windows() _show_wx_error(msg) return atexit.register(exit_cleanup) basher.InitSettings() basher.InitLinks() basher.InitImages() #--Start application if opts.debug: if is_standalone: # Special case for py2exe version app = basher.BashApp() # Regain control of stdout/stderr from wxPython sys.stdout = old_stderr sys.stderr = old_stderr else: app = basher.BashApp(False) else: app = basher.BashApp() if not is_standalone and (not _rightWxVersion() or not _rightPythonVersion()): return if env.isUAC: uacRestart = opts.uac if not opts.noUac and not opts.uac: # Show a prompt asking if we should restart in Admin Mode message = _( u"Wrye Bash needs Administrator Privileges to make changes " u"to the %(gameName)s directory. If you do not start Wrye " u"Bash with elevated privileges, you will be prompted at " u"each operation that requires elevated privileges.") % { 'gameName': bush_game.displayName } uacRestart = balt.ask_uac_restart(message, title=_(u'UAC Protection'), mopy=bass.dirs['mopy']) if uacRestart: bass.update_sys_argv(['--uac']) if uacRestart: bass.is_restarting = True return # Backup the Bash settings - we need settings being initialized to get # the previous version - we should read this from a file so we can move # backup higher up in the boot sequence. previous_bash_version = bass.settings['bash.version'] # backup settings if app version has changed or on user request if opts.backup or barb.BackupSettings.new_bash_version_prompt_backup( balt, previous_bash_version): frame = None # balt.Link.Frame, not defined yet, no harm done base_dir = bass.settings['bash.backupPath'] or bass.dirs['modsBash'] settings_file = (opts.backup and opts.filename) or None if not settings_file: settings_file = balt.askSave( frame, title=_(u'Backup Bash Settings'), defaultDir=base_dir, wildcard=u'*.7z', defaultFile=barb.BackupSettings.backup_filename( bush_game.fsName)) if settings_file: with balt.BusyCursor(): backup = barb.BackupSettings(settings_file, bush_game.fsName) try: with balt.BusyCursor(): backup.backup_settings(balt) except exception.StateError: if balt.askYes( frame, u'\n'.join([ _(u'There was an error while trying to backup the ' u'Bash settings!'), _(u'If you continue, your current settings may be ' u'overwritten.'), _(u'Do you want to quit Wrye Bash now?') ]), title=_(u'Unable to create backup!')): return # Quit app.Init() # Link.Frame is set here ! app.MainLoop()