コード例 #1
0
 def start(self):
     # Check if headless mode was requested
     if len(sys.argv) == 2 and sys.argv[1].lower() == 'headless':
         self.headless = True
     self.setup_console()
     self.print_header()
     # Check if executable is in good location
     if not glob.glob('World*.app') and not glob.glob('Wow*.exe') or \
             not os.path.isdir(Path('Interface/AddOns')) or not os.path.isdir('WTF'):
         self.console.print(
             '[bold red]This executable should be placed in the same directory where Wow.exe, '
             'WowClassic.exe or World of Warcraft.app is located.[/bold red]\n\n'
         )
         pause(self.headless)
         sys.exit(1)
     # Detect Classic client
     if os.path.basename(os.getcwd()) == '_classic_':
         self.core.clientType = 'wow_classic'
         set_terminal_title(f'CurseBreaker v{__version__} - Classic')
     # Check if client have write access
     try:
         with open('PermissionTest', 'w') as _:
             pass
         os.remove('PermissionTest')
     except IOError:
         self.console.print(
             '[bold red]CurseBreaker doesn\'t have write rights for the current directory.\n'
             'Try starting it with administrative privileges.[/bold red]\n\n'
         )
         pause(self.headless)
         sys.exit(1)
     self.auto_update()
     self.core.init_config()
     self.setup_table()
     # Curse URI Support
     if len(sys.argv) == 2 and 'twitch://' in sys.argv[1]:
         try:
             self.c_install(sys.argv[1].strip())
         except Exception as e:
             self.handle_exception(e)
         timeout(self.headless)
         sys.exit(0)
     if len(sys.argv) == 2 and '.ccip' in sys.argv[1]:
         try:
             path = sys.argv[1].strip()
             self.c_install(self.core.parse_cf_xml(path))
             if os.path.exists(path):
                 os.remove(path)
         except Exception as e:
             self.handle_exception(e)
         timeout(self.headless)
         sys.exit(0)
     # CLI command
     if len(sys.argv) >= 2:
         command = ' '.join(sys.argv[1:]).split(' ', 1)
         if command[0].lower() == 'headless':
             pass
         elif getattr(self, f'c_{command[0].lower()}', False):
             try:
                 getattr(self, f'c_{command[0].lower()}')(
                     command[1].strip() if len(command) > 1 else False)
             except Exception as e:
                 self.handle_exception(e)
             sys.exit(0)
         else:
             self.console.print('Command not found.')
             sys.exit(0)
     # Addons auto update
     if len(self.core.config['Addons']) > 0:
         if not self.headless:
             self.console.print(
                 'Automatic update of all addons will start in 5 seconds.\n'
                 'Press any button to enter interactive mode.',
                 highlight=False)
         starttime = time.time()
         keypress = None
         while True:
             if self.headless:
                 break
             elif kbhit():
                 keypress = getch()
                 break
             elif time.time() - starttime > 5:
                 break
         if not keypress:
             if not self.headless:
                 self.print_header()
             try:
                 self.c_update(None, True)
                 if self.core.backup_check():
                     self.setup_table()
                     self.console.print(
                         f'\n[green]Backing up WTF directory{"!" if self.headless else ":"}[/green]'
                     )
                     self.core.backup_wtf(
                         None if self.headless else self.console)
                 if self.core.config['WAUsername'] != 'DISABLED':
                     self.setup_table()
                     self.c_wa_update(None, False)
             except Exception as e:
                 self.handle_exception(e)
             self.console.print('')
             self.print_log()
             pause(self.headless)
             sys.exit(0)
     if self.headless:
         sys.exit(1)
     self.setup_completer()
     self.print_header()
     self.console.print(
         'Use command [green]help[/green] or press [green]TAB[/green] to see a list of available comm'
         'ands.\nCommand [green]exit[/green] or pressing [green]CTRL+D[/green] will close the applica'
         'tion.\n\n')
     if len(self.core.config['Addons']) == 0:
         self.console.print(
             'Command [green]import[/green] might be used to detect already installed addons.\n\n'
         )
     # Prompt session
     while True:
         try:
             command = self.session.prompt(
                 HTML('<ansibrightgreen>CB></ansibrightgreen> '),
                 completer=self.completer)
         except KeyboardInterrupt:
             continue
         except EOFError:
             break
         else:
             command = command.split(' ', 1)
             if getattr(self, f'c_{command[0].lower()}', False):
                 try:
                     self.setup_table()
                     getattr(self, f'c_{command[0].lower()}')(
                         command[1].strip() if len(command) > 1 else False)
                     self.setup_completer()
                 except Exception as e:
                     self.handle_exception(e)
             else:
                 self.console.print('Command not found.')
コード例 #2
0
            '[green]toggle_wa [Username][/green]\n\tEnables/disables automatic WeakAuras updates.\n\tI'
            'f a username is provided check will start to ignore the specified author.\n'
            '[green]set_wa_api [API key][/green]\n\tSets Wago API key required to access private auras'
            '.\n\tIt can be procured here: [link=https://wago.io/account]https://wago.io/account[/link]'
            '\n[green]set_wa_wow_account [Account name][/green]\n\tSets WoW account used by WeakAuras up'
            'dater.\n\tNeeded only if WeakAuras are used on more than one WoW account.\n'
            '[green]uri_integration[/green]\n\tEnables integration with CurseForge page.\n\t[i]"Install"'
            '[/i] button will now start this application.\n'
            '\n[bold green]Supported URL:[/bold green]\n\thttps://www.curseforge.com/wow/addons/[[addon_'
            'name]] [bold white]|[/bold white] cf:[[addon_name]]\n\thttps://www.wowinterface.com/downloa'
            'ds/[[addon_name]] [bold white]|[/bold white] wowi:[[addon_id]]\n\thttps://www.tukui.org/add'
            'ons.php?id=[[addon_id]] [bold white]|[/bold white] tu:[[addon_id]]\n\thttps://www.tukui.org'
            '/classic-addons.php?id=[[addon_id]] [bold white]|[/bold white] tuc:[[addon_id]]\n\tElvUI [b'
            'old white]|[/bold white] ElvUI:Dev\n\tTukui\n\tSLE:Dev',
            highlight=False)

    def c_exit(self, _):
        sys.exit(0)


if __name__ == '__main__':
    freeze_support()
    clientpath = os.environ.get('CURSEBREAKER_PATH')
    if clientpath:
        os.chdir(clientpath)
    elif getattr(sys, 'frozen', False):
        os.chdir(os.path.dirname(os.path.abspath(sys.executable)))
    set_terminal_title(f'CurseBreaker v{__version__}')
    app = TUI()
    app.start()