示例#1
0
 def auto_update(self):
     if getattr(sys, 'frozen',
                False) and 'CURSEBREAKER_VARDEXMODE' not in os.environ:
         try:
             if os.path.isfile(sys.executable + '.old'):
                 try:
                     os.remove(sys.executable + '.old')
                 except PermissionError:
                     pass
             payload = requests.get(
                 'https://api.github.com/repos/AcidWeb/CurseBreaker/releases/latest',
                 headers=HEADERS).json()
             if 'name' in payload and 'body' in payload and 'assets' in payload:
                 remoteversion = payload['name']
                 changelog = payload['body']
                 url = None
                 for binary in payload['assets']:
                     if (self.os == 'Windows' and '.exe' in binary['name'])\
                             or (self.os == 'Darwin' and '.zip' in binary['name'])\
                             or (self.os == 'Linux' and '.gz' in binary['name']):
                         url = binary['browser_download_url']
                         break
                 if url and StrictVersion(
                         remoteversion[1:]) > StrictVersion(__version__):
                     self.console.print(
                         '[green]Updating CurseBreaker...[/green]')
                     shutil.move(sys.executable, sys.executable + '.old')
                     payload = requests.get(url, headers=HEADERS)
                     if self.os == 'Darwin':
                         zipfile.ZipFile(io.BytesIO(
                             payload.content)).extractall(
                                 path=os.path.dirname(
                                     os.path.abspath(sys.executable)))
                     else:
                         with open(sys.executable, 'wb') as f:
                             if self.os == 'Windows':
                                 f.write(payload.content)
                             elif self.os == 'Linux':
                                 f.write(gzip.decompress(payload.content))
                     os.chmod(sys.executable, 0o775)
                     self.console.print(
                         f'[bold green]Update complete! The application will be restarted now.'
                         f'[/bold green]\n\n[green]Changelog:[/green]\n{changelog}\n'
                     )
                     self.print_log()
                     pause(self.headless)
                     subprocess.call([sys.executable] + sys.argv[1:])
                     sys.exit(0)
         except Exception as e:
             self.console.print(
                 f'[bold red]Update failed!\n\nReason: {str(e)}[/bold red]\n'
             )
             self.print_log()
             pause(self.headless)
             sys.exit(1)
示例#2
0
 def auto_update(self):
     if getattr(sys, 'frozen', False):
         try:
             if os.path.isfile(sys.executable + '.old'):
                 try:
                     os.remove(sys.executable + '.old')
                 except PermissionError:
                     pass
             payload = requests.get(
                 'https://api.github.com/repos/AcidWeb/CurseBreaker/releases/latest',
                 headers=HEADERS).json()
             if 'name' in payload and 'body' in payload and 'assets' in payload:
                 remoteversion = payload['name']
                 changelog = payload['body']
                 url = None
                 for binary in payload['assets']:
                     if (self.os == 'Windows' and '.exe' in binary['name'])\
                             or (self.os == 'Darwin' and '.zip' in binary['name'])\
                             or (self.os == 'Linux' and '.gz' in binary['name']):
                         url = binary['browser_download_url']
                         break
                 if url and StrictVersion(
                         remoteversion[1:]) > StrictVersion(__version__):
                     printft(
                         HTML(
                             '<ansigreen>Updating CurseBreaker...</ansigreen>'
                         ))
                     shutil.move(sys.executable, sys.executable + '.old')
                     payload = requests.get(url, headers=HEADERS)
                     if self.os == 'Darwin':
                         zipfile.ZipFile(io.BytesIO(
                             payload.content)).extractall()
                     else:
                         with open(sys.executable, 'wb') as f:
                             if self.os == 'Windows':
                                 f.write(payload.content)
                             elif self.os == 'Linux':
                                 f.write(gzip.decompress(payload.content))
                     os.chmod(sys.executable, 0o775)
                     printft(
                         HTML(
                             f'<ansibrightgreen>Update complete! Please restart the application.</ansibrightgre'
                             f'en>\n\n<ansigreen>Changelog:</ansigreen>\n{changelog}\n'
                         ))
                     pause()
                     sys.exit(0)
         except Exception as e:
             printft(
                 HTML(
                     f'<ansibrightred>Update failed!\n\nReason: {str(e)}</ansibrightred>\n'
                 ))
             pause()
             sys.exit(1)
示例#3
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.')