Beispiel #1
0
def _rightPythonVersion():
    sysVersion = sys.version_info[:3]
    if sysVersion < (2, 7) or sysVersion >= (3,):
        balt.showError(None, _(u"Only Python 2.7 and newer is supported "
            u"(%s.%s.%s detected). If you know what you're doing install the "
            u"WB python version and edit this warning out. "
            u"Wrye Bash will exit.") % sysVersion,
            title=_(u"Incompatible Python version detected"))
        return False
    return True
Beispiel #2
0
 def ErrorConflict(self):
     #returns True if the data format doesn't match
     if self.CmpDataVersion() > 0:
         showError(self.parent,
               _(u'The data format of the selected backup file is newer than the current Bash version!')+u'\n' +
               _(u'Backup v%s is not compatible with v%s') % (self.verApp, basher.settings['bash.version']) + u'\n' +
               u'\n' +
               _(u'You cannot use this backup with this version of Bash.'),
               _(u'Error: Version Conflict!'))
         return True
     #end if
     return False
Beispiel #3
0
def _rightPythonVersion():
    sysVersion = sys.version_info[:3]
    if sysVersion < (2, 7) or sysVersion >= (3, ):
        balt.showError(
            None,
            _(u"Only Python 2.7 and newer is supported "
              u"(%s.%s.%s detected). If you know what you're doing install the "
              u"WB python version and edit this warning out. "
              u"Wrye Bash will exit.") % sysVersion,
            title=_(u"Incompatible Python version detected"))
        return False
    return True
Beispiel #4
0
 def ErrorConflict(self):
     #returns True if the data format doesn't match
     if self.CmpDataVersion() > 0:
         showError(
             self.parent,
             _('The data format of the selected backup file is newer than the current Bash version!\n'
               ) + _('Backup v%s is not compatible with v%s\n') %
             (self.verApp, basher.settings['bash.readme'][1]) + _('\n') +
             _('You cannot use this backup with this version of Bash.'),
             _('Error: Version Conflict!'))
         return True
     #end if
     return False
Beispiel #5
0
def _showErrorInGui(e):
    """Try really hard to be able to show the error in the GUI."""
    o = StringIO.StringIO()
    traceback.print_exc(file=o)
    msg = o.getvalue()
    o.close()
    title = _(u'Error! Unable to start Wrye Bash.')
    msg = _(
        u'Please ensure Wrye Bash is correctly installed.') + u'\n\n\n%s' % msg
    try:  # raise ImportError("TEST _showErrorInAnyGui")
        global basher, balt, barb
        if not basher:
            # we get here if initBosh threw
            import basher
            import barb
            import balt
        bolt.deprintOn = bool(opts.debug)
        app = basher.BashApp(
            redirect=bolt.deprintOn and not hasattr(sys, 'frozen'))
        balt.showError(None, msg, title=title)
        app.MainLoop()
    except:
        traceback.print_exc()  # print current exception then
        # try really hard to be able to show the error in any GUI
        try:
            _showErrorInAnyGui(title + u'\n\n' + msg)
        except StandardError:
            print 'An error has occurred with Wrye Bash, and could not be ' \
                  'displayed.'
            print 'The following is the error that occurred while trying to ' \
                  'display the first error:'
            try:
                traceback.print_exc()
            except:
                print '  An error occurred while trying to display the' \
                      ' second error.'
            print 'The following is the error that could not be displayed:'
    raise e, None, sys.exc_info()[2]
Beispiel #6
0
def _showErrorInGui(e):
    """Try really hard to be able to show the error in the GUI."""
    o = StringIO.StringIO()
    traceback.print_exc(file=o)
    msg = o.getvalue()
    o.close()
    title = _(u'Error! Unable to start Wrye Bash.')
    msg = _(
        u'Please ensure Wrye Bash is correctly installed.') + u'\n\n\n%s' % msg
    try: # raise ImportError("TEST _showErrorInAnyGui")
        global basher, balt, barb
        if not basher:
            # we get here if initBosh threw
            import basher
            import barb
            import balt
        bolt.deprintOn = bool(opts.debug)
        app = basher.BashApp(redirect=bolt.deprintOn and not hasattr(sys, 'frozen'))
        balt.showError(None, msg, title=title)
        app.MainLoop()
    except:
        traceback.print_exc() # print current exception then
        # try really hard to be able to show the error in any GUI
        try:
            _showErrorInAnyGui(title + u'\n\n' + msg)
        except StandardError:
            print 'An error has occurred with Wrye Bash, and could not be ' \
                  'displayed.'
            print 'The following is the error that occurred while trying to ' \
                  'display the first error:'
            try:
                traceback.print_exc()
            except:
                print '  An error occurred while trying to display the' \
                      ' second error.'
            print 'The following is the error that could not be displayed:'
    raise e, None, sys.exc_info()[2]
Beispiel #7
0
def main():
    global opts, extra

    parser = optparse.OptionParser()
    pathGroup = optparse.OptionGroup(parser, "Path Arguments",
                         r"All path arguments must be absolute paths and use either forward slashes (/) or two backward slashes (\\). All of these can also be set in the ini (where  you can also use relative paths) and if set in both cmd line takes precedence.")
    pathGroup.add_option('-o', '--falloutPath',
                        action='store',
                        type='string',
                        default='',
                        dest='falloutPath',
                        help='Specifies the Fallout3 directory (the one containing Fallout3.exe). Use this argument if Bash is located outside of the Fallout3 directory.')
    userPathGroup = optparse.OptionGroup(parser, "'User Directory Arguments",
                        'These arguments allow you to specify your user directories in several ways.'
                        ' These are only useful if the regular procedure for getting the user directory fails.'
                        ' And even in that case, the user is probably better off installing win32com.')
    userPathGroup.add_option('-p', '--personalPath',
                        action='store',
                        type='string',
                        default='',
                        dest='personalPath',
                        help='Specify the user\'s personal directory. (Like "C:\\\\Documents and Settings\\\\Wrye\\\\My Documents\") '
                             'If you need to set this then you probably need to set -l too')
    userPathGroup.add_option('-u', '--userPath',
                        action='store',
                        type='string',
                        default='',
                        dest='userPath',
                        help='Specify the user profile path. May help if HOMEDRIVE and/or HOMEPATH'
                             ' are missing from the user\'s environment')
    userPathGroup.add_option('-l', '--localAppDataPath',
                        action='store',
                        type='string',
                        default='',
                        dest='localAppDataPath',
                        help='Specify the user\'s local application data directory.'
                             'If you need to set this then you probably need to set -p too.')
    backupGroup = optparse.OptionGroup(parser, "'Backup and Restore Arguments",
                        'These arguments allow you to do backup and restore settings operations.')
    backupGroup.add_option('-b', '--backup',
                        action='store_true',
                        default=False,
                        dest='backup',
                        help='Backup all Bash settings to an archive file before the app launches. Either specify the filepath with  the -f/--filename options or Wrye Bash will prompt the user for the backup file path.')
    backupGroup.add_option('-r', '--restore',
                        action='store_true',
                        default=False,
                        dest='restore',
                        help='Backup all Bash settings to an archive file before the app launches. Either specify the filepath with  the -f/--filename options or Wrye Bash will prompt the user for the backup file path.')
    backupGroup.add_option('-f', '--filename',
                        action='store',
                        default='',
                        dest='filename',
                        help='The file to use with the -r or -b options. Must end in \'.7z\' and be a valid path and for -r exist and for -b not already exist.')
    backupGroup.add_option('-q', '--quiet-quit',
                        action='store_true',
                        default=False,
                        dest='quietquit',
                        help='Close Bash after creating or restoring backup and do not display any prompts or message dialogs.')
    parser.set_defaults(backup_images=0)                    
    backupGroup.add_option('-i', '--include-changed-images',
                        action='store_const',
                        const=1,
                        dest='backup_images',
                        help='Include changed images from mopy/bash/images in the backup. Include any image(s) from backup file in restore.')
    backupGroup.add_option('-I', '--include-all-images',
                        action='store_const',
                        const=2,
                        dest='backup_images',
                        help='Include all images from mopy/bash/images in the backup/restore (if present in backup file).')
    parser.add_option('-d', '--debug',
                        action='store_true',
                        default=False,
                        dest='debug',
                        help='Useful if bash is crashing on startup or if you want to print a lot of '
                             'information (e.g. while developing or debugging).')
    parser.add_option('--no-psyco',
                        action='store_false',
                        default=True,
                        dest='Psyco',
                        help='Disables import of Psyco')
    parser.set_defaults(mode=0)
    parser.add_option('-C', '--Cbash-mode',
                        action='store_const',
                        const=2,
                        dest='mode',
                        help='enables CBash and uses CBash to build bashed patch.')
    parser.add_option('-P', '--Python-mode',
                        action='store_const',
                        const=1,
                        dest='mode',
                        help='disables CBash and uses python code to build bashed patch.')
    parser.set_defaults(unicode='')
    parser.add_option('-U', '--Unicode',
                        action='store_true',
                        dest='unicode',
                        help='enables Unicode mode, overriding the ini if it exists.')
    parser.add_option('-A', '--Ansi',
                        action='store_false',
                        dest='unicode',
                        help='disables Unicode mode, overriding the ini if it exists.')
    parser.add_option('--restarting',
                        action='store_true',
                        default=False,
                        dest='restarting',
                        help=optparse.SUPPRESS_HELP)
    parser.add_option('--genHtml',
                        default=None,
                        help=optparse.SUPPRESS_HELP)
    
    parser.add_option_group(pathGroup)
    parser.add_option_group(userPathGroup)
    parser.add_option_group(backupGroup)

    opts,extra = parser.parse_args()
    if len(extra) > 0:
        parser.print_help()
        return
    
    bolt.deprintOn = opts.debug
    
    if opts.Psyco:
        try:
            import psyco
            psyco.full()
        except:
            pass
    if opts.unicode != '':
        bolt.bUseUnicode = int(opts.unicode)
    #--Initialize Directories and some settings
    #  required before the rest has imported
    SetUserPath('bash.ini',opts.userPath)

    try:
        bolt.CBash = opts.mode
        import bosh
        bosh.initBosh(opts.personalPath,opts.localAppDataPath,opts.falloutPath)
        bosh.exe7z = bosh.dirs['compiled'].join(bosh.exe7z).s

        # if HTML file generation was requested, just do it and quit
        if opts.genHtml is not None:
            print "generating HTML file from: '%s'" % opts.genHtml
            import belt
            bolt.WryeText.genHtml(opts.genHtml)
            print "done"
            return

        import basher
        import barb
        import balt
    except bolt.PermissionError, e:
        if opts.debug:
            if hasattr(sys,'frozen'):
                app = basher.BashApp()
            else:
                app = basher.BashApp(False)
            bolt.deprintOn = True
        else:
            app = basher.BashApp()
        balt.showError(None,str(e))
        app.MainLoop()
        raise
Beispiel #8
0
def main():
    bolt.deprintOn = opts.debug
    if len(extra) > 0:
        return

    # useful for understanding context of bug reports
    if opts.debug or hasattr(sys, 'frozen'):
        # 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
        errLog = open(os.path.join(os.getcwdu(), u'BashBugDump.log'), 'w')
        sys.stdout = errLog
        sys.stderr = errLog
        old_stderr = errLog

    if opts.debug:
        dump_environment()

    if opts.Psyco:
        try:
            import psyco
            psyco.full()
        except:
            pass

    # ensure we are in the correct directory so relative paths will work properly
    if hasattr(sys, "frozen"):
        pathToProg = os.path.dirname(
            unicode(sys.executable, sys.getfilesystemencoding()))
    else:
        pathToProg = os.path.dirname(
            unicode(sys.argv[0], sys.getfilesystemencoding()))
    if pathToProg:
        os.chdir(pathToProg)
    del pathToProg

    # Detect the game we're running for
    import bush
    if opts.debug:
        print u'Searching for game to manage:'
    ret = bush.setGame(opts.gameName, opts.oblivionPath)
    if ret != False:  # False == success
        if len(ret) != 1:
            if len(ret) == 0:
                msgtext = _(
                    u"Wrye Bash could not find a game to manage. Please use -o command line argument to specify the game path"
                )
            else:
                msgtext = _(
                    u"Wrye Bash could not determine which game to manage.  The following games have been detected, please select one to manage."
                )
                msgtext += u'\n\n'
                msgtext += _(
                    u'To prevent this message in the future, use the -g command line argument to specify the game'
                )
            try:
                # First try using wxPython
                import wx

                class AppReturnCode(object):
                    def __init__(self, default=None):
                        self.value = default

                    def get(self):
                        return self.value

                    def set(self, value):
                        self.value = value

                class GameSelect(wx.Frame):
                    def __init__(self, gameNames, callback):
                        wx.Frame.__init__(self, None, wx.ID_ANY, u'Wrye Bash')
                        self.callback = callback
                        self.panel = panel = wx.Panel(self, wx.ID_ANY)
                        sizer = wx.BoxSizer(wx.VERTICAL)
                        sizer.Add(
                            wx.TextCtrl(panel,
                                        wx.ID_ANY,
                                        msgtext,
                                        style=wx.TE_MULTILINE | wx.TE_READONLY
                                        | wx.TE_BESTWRAP), 1, wx.GROW | wx.ALL,
                            5)
                        for gameName in gameNames:
                            gameName = gameName[0].upper() + gameName[1:]
                            sizer.Add(wx.Button(panel, wx.ID_ANY, gameName), 0,
                                      wx.GROW | wx.ALL ^ wx.TOP, 5)
                        button = wx.Button(panel, wx.ID_CANCEL, _(u'Quit'))
                        button.SetDefault()
                        sizer.Add(button, 0, wx.GROW | wx.ALL ^ wx.TOP, 5)
                        self.Bind(wx.EVT_BUTTON, self.OnButton)
                        panel.SetSizer(sizer)

                    def OnButton(self, event):
                        if event.GetId() != wx.ID_CANCEL:
                            self.callback(
                                self.FindWindowById(event.GetId()).GetLabel())
                        self.Close(True)

                _app = wx.App(False)
                retCode = AppReturnCode()
                frame = GameSelect(ret, retCode.set)
                frame.Show()
                frame.Center()
                _app.MainLoop()
                del _app
                retCode = retCode.get()
                if retCode is None: return
                # Add the game to the command line, so restarting uses it
                sys.argv = sys.argv + ['-g', retCode]
                bush.setGame(retCode, opts.oblivionPath)
            except:
                # No good with wxPython, use Tkinter instead
                # Python mode, use Tkinter here, since we don't know for sure if wx is present
                import Tkinter
                root = Tkinter.Tk()
                frame = Tkinter.Frame(root)
                frame.pack()

                class onQuit(object):
                    def __init__(self):
                        self.canceled = False

                    def onClick(self):
                        self.canceled = True
                        root.destroy()

                quit = onQuit()

                button = Tkinter.Button(frame,
                                        text=_(u'Quit'),
                                        fg='red',
                                        command=quit.onClick,
                                        pady=15,
                                        borderwidth=5,
                                        relief=Tkinter.GROOVE)
                button.pack(fill=Tkinter.BOTH, expand=1, side=Tkinter.BOTTOM)

                class onClick(object):
                    def __init__(self, gameName):
                        self.gameName = gameName

                    def onClick(self):
                        sys.argv = sys.argv + ['-g', self.gameName]
                        bush.setGame(self.gameName, opts.oblivionPath)
                        root.destroy()

                for gameName in ret:
                    text = gameName[0].upper() + gameName[1:]
                    command = onClick(gameName).onClick
                    button = Tkinter.Button(frame,
                                            text=text,
                                            command=command,
                                            pady=15,
                                            borderwidth=5,
                                            relief=Tkinter.GROOVE)
                    button.pack(fill=Tkinter.BOTH,
                                expand=1,
                                side=Tkinter.BOTTOM)
                w = Tkinter.Text(frame)

                w.insert(Tkinter.END, msgtext)
                w.config(state=Tkinter.DISABLED)
                w.pack()
                root.mainloop()
                if quit.canceled:
                    return
                del Tkinter  # Unload TKinter, it's not needed anymore
        else:
            bush.setGame(ret[0], opts.oblivionPath)

    if opts.bashmon:
        # ensure the console is set up properly
        import ctypes
        ctypes.windll.kernel32.AllocConsole()
        sys.stdin = open('CONIN$', 'r')
        sys.stdout = open('CONOUT$', 'w', 0)
        sys.stderr = open('CONOUT$', 'w', 0)
        # run bashmon and exit
        import bashmon
        bashmon.monitor(0.25)  #--Call monitor with specified sleep interval
        return

    #--Initialize Directories and some settings
    #  required before the rest has imported
    SetUserPath(u'bash.ini', opts.userPath)

    isUAC = False
    try:
        # Force Python mode if CBash can't work with this game
        bolt.CBash = opts.mode if bush.game.esp.canCBash else 1
        import bosh
        isUAC = bosh.testUAC(opts.oblivionPath)
        bosh.initBosh(opts.personalPath, opts.localAppDataPath,
                      opts.oblivionPath)
        bosh.exe7z = bosh.dirs['compiled'].join(bosh.exe7z).s

        # 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('mbcs')
            import belt
            bolt.WryeText.genHtml(opts.genHtml)
            try:
                print msg2
            except UnicodeError:
                print msg2.encode('mbcs')
            return

        import basher
        import barb
        import balt
    except (bolt.PermissionError, bolt.BoltError) as e:
        # try really hard to be able to show the error in the GUI
        try:
            if 'basher' not in locals():
                # we get here if initBosh threw
                import basher
                import barb
                import balt
        except:
            raise e
        if opts.debug:
            if hasattr(sys, 'frozen'):
                app = basher.BashApp()
            else:
                app = basher.BashApp(False)
            bolt.deprintOn = True
        else:
            app = basher.BashApp()
        balt.showError(None, u'%s' % e)
        app.MainLoop()
        raise e
    except (ImportError, StandardError) as e:
        # try really hard to be able to show the error in any GUI
        try:
            o = StringIO.StringIO()
            traceback.print_exc(file=o)
            msg = o.getvalue()
            o.close()
            msg = (_(u'Error! Unable to start Wrye Bash.') + u'\n\n' +
                   _(u'Please ensure Wrye Bash is correctly installed.') +
                   u'\n\n\n%s') % msg
            print msg

            if hasattr(sys, 'frozen'):
                # WBSA we've disabled TKinter, since it's not required, use wx
                # here instead
                import wx

                class ErrorMessage(wx.Frame):
                    def __init__(self):
                        wx.Frame.__init__(self, None, wx.ID_ANY, u'Wrye Bash')
                        self.panel = panel = wx.Panel(self, wx.ID_ANY)
                        sizer = wx.BoxSizer(wx.VERTICAL)
                        sizer.Add(
                            wx.TextCtrl(panel,
                                        wx.ID_ANY,
                                        msg,
                                        style=wx.TE_MULTILINE | wx.TE_READONLY
                                        | wx.TE_BESTWRAP), 1, wx.GROW | wx.ALL,
                            5)
                        button = wx.Button(panel, wx.ID_CANCEL, _(u'Quit'))
                        button.SetDefault()
                        sizer.Add(button, 0, wx.GROW | wx.ALL ^ wx.TOP, 5)
                        self.Bind(wx.EVT_BUTTON, self.OnButton)
                        panel.SetSizer(sizer)

                    def OnButton(self, event):
                        self.Close(True)

                _app = wx.App(False)
                frame = ErrorMessage()
                frame.Show()
                frame.Center()
                _app.MainLoop()
                del _app
                return
            else:
                # Python mode, use Tkinter
                import Tkinter
                root = Tkinter.Tk()
                frame = Tkinter.Frame(root)
                frame.pack()

                button = Tkinter.Button(frame,
                                        text=_(u"QUIT"),
                                        fg="red",
                                        command=root.destroy,
                                        pady=15,
                                        borderwidth=5,
                                        relief=Tkinter.GROOVE)
                button.pack(fill=Tkinter.BOTH, expand=1, side=Tkinter.BOTTOM)

                w = Tkinter.Text(frame)
                w.insert(Tkinter.END, msg)
                w.config(state=Tkinter.DISABLED)
                w.pack()
                root.mainloop()
                return
        except StandardError as y:
            print 'An error has occured with Wrye Bash, and could not be displayed.'
            print 'The following is the error that occured while trying to display the first error:'
            try:
                print y
                traceback.format_exc()
            except:
                print '  An error occured while trying to display the second error.'
            print 'The following is the error that could not be displayed:'
            raise e

    if not oneInstanceChecker(): return
    atexit.register(exit)
    basher.InitSettings()
    basher.InitLinks()
    basher.InitImages()
    #--Start application
    if opts.debug:
        if hasattr(sys, 'frozen'):
            # 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()

    import wx
    wxver = wx.version()
    if not u'unicode' in wxver.lower() and not u'2.9' in wxver:
        # Can't use translatable strings, because they'd most likely end up being in unicode!
        if not balt.askYes(
                None,
                'Warning: you appear to be using a non-unicode version of wxPython (%s).  This will cause problems!  It is highly recommended you use a unicode version of wxPython instead.  Do you still want to run Wrye Bash?'
                % wxver,
                'Warning: Non-Unicode wxPython detected',
        ):
            return
    sysVersion = (sys.version_info[0], sys.version_info[1],
                  sys.version_info[2])
    if sysVersion < (
            2, 6
    ):  #nasty, may cause failure in oneInstanceChecker but better than bash failing to open things for no (user) apparent reason such as in 2.5.2 and under.
        bolt.close_fds = False
        if sysVersion[:2] == (2, 5):
            run = balt.askYes(
                None,
                _(u"Warning: You are using a python version prior to 2.6 and there may be some instances that failures will occur.  Updating to Python 2.7x is recommended but not imperative.  Do you still want to run Wrye Bash right now?"
                  ), _(u"Warning OLD Python version detected"))
        else:
            run = balt.askYes(
                None,
                _(u"Warning: You are using a Python version prior to 2.5x which is totally out of date and ancient and Bash will likely not like it and may totally refuse to work.  Please update to a more recent version of Python(2.7x is preferred).  Do you still want to run Wrye Bash?"
                  ), _(u"Warning OLD Python version detected"))
        if not run:
            return

    # process backup/restore options
    # quit if either is true, but only after calling both
    quit = cmdBackup()
    quit = cmdRestore() or quit
    if quit: return

    global basherImported
    basherImported = True

    basher.isUAC = isUAC
    if isUAC:
        uacRestart = False
        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 to the %(gameName)s directory.  If you do not start Wrye Bash with elevated privileges, you will be prompted at each operation that requires elevated privileges."
            ) % {
                'gameName': bush.game.name
            }
            title = _(u'UAC Protection')
            if balt.canVista:
                admin = _(u'Run with Administrator Privileges')
                readme = bosh.dirs['mopy'].join(
                    u'Docs', u'Wrye Bash General Readme.html')
                if readme.exists():
                    readme = u'file:///' + readme.s.replace(
                        u'\\', u'/').replace(u' ', u'%20')
                else:
                    # Fallback to SVN repository
                    readme = u"http://wrye-bash.github.io/docs/Wrye%20Bash%20General%20Readme.html"
                readme += '#trouble-permissions'
                uacRestart = balt.vistaDialog(
                    None,
                    message=message,
                    buttons=[
                        (True, u'+' + admin),
                        (False, _(u'Run normally')),
                    ],
                    title=title,
                    expander=[
                        _(u'How to avoid this message in the future'),
                        _(u'Less information'),
                        (_(u'Use one of the following command line switches:')
                         + u'\n\n' + _(u'--no-uac: always run normally') +
                         u'\n' +
                         _(u'--uac: always run with Admin Privileges') +
                         u'\n\n' +
                         _(u'See the <A href="%(readmePath)s">readme</A> for more information.'
                           ) % {
                               'readmePath': readme
                           })
                    ],
                )
            else:
                uacRestart = balt.askYes(
                    None, message + u'\n\n' +
                    _(u'Start Wrye Bash with Administrator Privileges?'),
                    title)
        elif opts.uac:
            uacRestart = True
        if uacRestart:
            basher.appRestart = True
            basher.uacRestart = True
            return

    app.Init()
    app.MainLoop()
Beispiel #9
0
            if 'basher' not in locals():
                # we get here if initBosh threw
                import basher
                import barb
                import balt
        except:
            raise e
        if opts.debug:
            if hasattr(sys,'frozen'):
                app = basher.BashApp()
            else:
                app = basher.BashApp(False)
            bolt.deprintOn = True
        else:
            app = basher.BashApp()
        balt.showError(None,u'%s'%e)
        app.MainLoop()
        raise e
    except (ImportError, StandardError) as e:
        # try really hard to be able to show the error in any GUI
        try:
            o = StringIO.StringIO()
            traceback.print_exc(file=o)
            msg = o.getvalue()
            o.close()
            msg = (_(u'Error! Unable to start Wrye Bash.')
                   + u'\n\n' +
                   _(u'Please ensure Wrye Bash is correctly installed.')
                   + u'\n\n\n%s') % msg
            print msg
Beispiel #10
0
            if 'basher' not in locals():
                # we get here if initBosh threw
                import basher
                import barb
                import balt
        except:
            raise e
        if opts.debug:
            if hasattr(sys,'frozen'):
                app = basher.BashApp()
            else:
                app = basher.BashApp(False)
            bolt.deprintOn = True
        else:
            app = basher.BashApp()
        balt.showError(None,u'%s'%e)
        app.MainLoop()
        raise e
    except (ImportError, StandardError) as e:
        # try really hard to be able to show the error in any GUI
        try:
            o = StringIO.StringIO()
            traceback.print_exc(file=o)
            msg = o.getvalue()
            o.close()
            msg = (_(u'Error! Unable to start Wrye Bash.')
                   + u'\n\n' +
                   _(u'Please ensure Wrye Bash is correctly installed.')
                   + u'\n\n\n%s') % msg
            print msg
Beispiel #11
0
def main():
    global opts, extra

    parser = optparse.OptionParser()
    pathGroup = optparse.OptionGroup(
        parser, "Path Arguments",
        r"All path arguments must be absolute paths and use either forward slashes (/) or two backward slashes (\\). All of these can also be set in the ini (where  you can also use relative paths) and if set in both cmd line takes precedence."
    )
    pathGroup.add_option(
        '-o',
        '--falloutPath',
        action='store',
        type='string',
        default='',
        dest='falloutPath',
        help=
        'Specifies the FalloutNV directory (the one containing FalloutNV.exe). Use this argument if Bash is located outside of the FalloutNV directory.'
    )
    userPathGroup = optparse.OptionGroup(
        parser, "'User Directory Arguments",
        'These arguments allow you to specify your user directories in several ways.'
        ' These are only useful if the regular procedure for getting the user directory fails.'
        ' And even in that case, the user is probably better off installing win32com.'
    )
    userPathGroup.add_option(
        '-p',
        '--personalPath',
        action='store',
        type='string',
        default='',
        dest='personalPath',
        help=
        'Specify the user\'s personal directory. (Like "C:\\\\Documents and Settings\\\\Wrye\\\\My Documents\") '
        'If you need to set this then you probably need to set -l too')
    userPathGroup.add_option(
        '-u',
        '--userPath',
        action='store',
        type='string',
        default='',
        dest='userPath',
        help=
        'Specify the user profile path. May help if HOMEDRIVE and/or HOMEPATH'
        ' are missing from the user\'s environment')
    userPathGroup.add_option(
        '-l',
        '--localAppDataPath',
        action='store',
        type='string',
        default='',
        dest='localAppDataPath',
        help='Specify the user\'s local application data directory.'
        'If you need to set this then you probably need to set -p too.')
    backupGroup = optparse.OptionGroup(
        parser, "'Backup and Restore Arguments",
        'These arguments allow you to do backup and restore settings operations.'
    )
    backupGroup.add_option(
        '-b',
        '--backup',
        action='store_true',
        default=False,
        dest='backup',
        help=
        'Backup all Bash settings to an archive file before the app launches. Either specify the filepath with  the -f/--filename options or Wrye Bash will prompt the user for the backup file path.'
    )
    backupGroup.add_option(
        '-r',
        '--restore',
        action='store_true',
        default=False,
        dest='restore',
        help=
        'Backup all Bash settings to an archive file before the app launches. Either specify the filepath with  the -f/--filename options or Wrye Bash will prompt the user for the backup file path.'
    )
    backupGroup.add_option(
        '-f',
        '--filename',
        action='store',
        default='',
        dest='filename',
        help=
        'The file to use with the -r or -b options. Must end in \'.7z\' and be a valid path and for -r exist and for -b not already exist.'
    )
    backupGroup.add_option(
        '-q',
        '--quiet-quit',
        action='store_true',
        default=False,
        dest='quietquit',
        help=
        'Close Bash after creating or restoring backup and do not display any prompts or message dialogs.'
    )
    parser.set_defaults(backup_images=0)
    backupGroup.add_option(
        '-i',
        '--include-changed-images',
        action='store_const',
        const=1,
        dest='backup_images',
        help=
        'Include changed images from mopy/bash/images in the backup. Include any image(s) from backup file in restore.'
    )
    backupGroup.add_option(
        '-I',
        '--include-all-images',
        action='store_const',
        const=2,
        dest='backup_images',
        help=
        'Include all images from mopy/bash/images in the backup/restore (if present in backup file).'
    )
    parser.add_option(
        '-d',
        '--debug',
        action='store_true',
        default=False,
        dest='debug',
        help=
        'Useful if bash is crashing on startup or if you want to print a lot of '
        'information (e.g. while developing or debugging).')
    parser.add_option('--no-psyco',
                      action='store_false',
                      default=True,
                      dest='Psyco',
                      help='Disables import of Psyco')
    parser.set_defaults(mode=0)
    parser.add_option(
        '-C',
        '--Cbash-mode',
        action='store_const',
        const=2,
        dest='mode',
        help='enables CBash and uses CBash to build bashed patch.')
    parser.add_option(
        '-P',
        '--Python-mode',
        action='store_const',
        const=1,
        dest='mode',
        help='disables CBash and uses python code to build bashed patch.')
    parser.set_defaults(unicode='')
    parser.add_option(
        '-U',
        '--Unicode',
        action='store_true',
        dest='unicode',
        help='enables Unicode mode, overriding the ini if it exists.')
    parser.add_option(
        '-A',
        '--Ansi',
        action='store_false',
        dest='unicode',
        help='disables Unicode mode, overriding the ini if it exists.')
    parser.add_option('--restarting',
                      action='store_true',
                      default=False,
                      dest='restarting',
                      help=optparse.SUPPRESS_HELP)
    parser.add_option('--genHtml', default=None, help=optparse.SUPPRESS_HELP)

    parser.add_option_group(pathGroup)
    parser.add_option_group(userPathGroup)
    parser.add_option_group(backupGroup)

    opts, extra = parser.parse_args()
    if len(extra) > 0:
        parser.print_help()
        return

    bolt.deprintOn = opts.debug

    if opts.Psyco:
        try:
            import psyco
            psyco.full()
        except:
            pass
    if opts.unicode != '':
        bolt.bUseUnicode = int(opts.unicode)
    #--Initialize Directories and some settings
    #  required before the rest has imported
    SetUserPath('bash.ini', opts.userPath)

    try:
        bolt.CBash = opts.mode
        import bosh
        bosh.initBosh(opts.personalPath, opts.localAppDataPath,
                      opts.falloutPath)
        bosh.exe7z = bosh.dirs['compiled'].join(bosh.exe7z).s

        # if HTML file generation was requested, just do it and quit
        if opts.genHtml is not None:
            print "generating HTML file from: '%s'" % opts.genHtml
            import belt
            bolt.WryeText.genHtml(opts.genHtml)
            print "done"
            return

        import basher
        import barb
        import balt
    except bolt.PermissionError, e:
        if opts.debug:
            if hasattr(sys, 'frozen'):
                app = basher.BashApp()
            else:
                app = basher.BashApp(False)
            bolt.deprintOn = True
        else:
            app = basher.BashApp()
        balt.showError(None, str(e))
        app.MainLoop()
        raise