def add_to_startup(Add): """ Add to startup. Returns error string or None.""" if not isWindows() and Add: return 'Not a Windows-type OS. Not adding to the startup!' if not getattr(sys, 'frozen', False) and Add: return 'App is not packaged. Not adding to the startup!' if not isWindows(): return try: key = 'StarCraft Co-op Overlay' path = truePath('SCO.exe') if Add: logger.info(f'Adding {path} to registry as {key}') reg_add_to_startup(key, path) elif reg_get_startup_field_value(key) != None: logger.info(f'Removing {path} from registry as {key}') reg_delete_startup_field(key) except: logger.error(f'Failed to edit registry.\n{traceback.format_exc()}') return 'Error when adding the app to registry!' finally: return None
def write_permission_granted(): """ Returns True if the app can write into its directory """ permission_granted = True tfile = truePath('test_permission_file') try: with open(tfile, 'a') as f: f.write('.') os.remove(tfile) except: permission_granted = False logger.info(f'Permission error:\n{traceback.format_exc()}') return permission_granted
def __init__(self, ACCOUNTDIR): names, handles = find_names_and_handles(ACCOUNTDIR) self.main_names = names self.main_handles = handles self.parsed_replays = set() self.ReplayData = list() self.ReplayDataAll = list() self.cachefile = truePath('cache_overall_stats') self.winrate_data = dict() self.current_replays = find_replays(ACCOUNTDIR) self.closing = False self.full_analysis_finished = False self.name_handle_dict = dict()
def __init__(self, twdict): self.channel = twdict['channel_name'] self.bot_name = twdict['bot_name'] self.bot_oauth = twdict['bot_oauth'] self.host = twdict['host'] self.port = int(twdict['port']) self.banks = twdict['bank_locations'] self.responses = twdict['responses'] self.greetings = twdict['greetings'] self.banned_mutators = {m.lower() for m in twdict['banned_mutators']} self.banned_units = {u.lower() for u in twdict['banned_units']} if len(self.banks) > 0: self.bank = self.banks.get('Default', list(self.banks.values())[0]) self.commandNumber = random.randint(1, 1000000) self.UnconfirmedCommands = dict() self.chat_log = truePath('ChatLog.txt') self.RUNNING = False
import requests import asyncio import keyboard import websockets from SCOFunctions.MFilePath import truePath from SCOFunctions.MLogging import logclass from SCOFunctions.ReplayAnalysis import analyse_replay OverlayMessages = [] # Storage for all messages globalOverlayMessagesSent = 0 # Global variable to keep track of messages sent. Useful when opening new overlay instances later. lock = threading.Lock() logger = logclass('MAIN','INFO') initMessage = {'initEvent':True,'colors':['null','null','null','null'],'duration':60} analysis_log_file = truePath('cache_replay_analysis.txt') ReplayPosition = 0 AllReplays = dict() player_winrate_data = dict() PLAYER_HANDLES = set() # Set of handles of the main player PLAYER_NAMES = set() # Set of names of the main player generated from handles and used in winrate notification most_recent_playerdata = None SETTINGS = dict() CAnalysis = None APP_CLOSING = False session_games = {'Victory':0,'Defeat':0} WEBPAGE = None RNG_COMMANDER = dict() def stop_threads():
def randomize_commander(self): """ Randomizes commander based on current selection """ # Get values mastery_all_in = True if self.CB_RNG_Mastery.currentText( ) == 'All points into one' else False commander_dict = dict() found = False for co in prestige_names: commander_dict[co] = set() for prest in {0, 1, 2, 3}: if self.RNG_co_dict[(co, prest)].isChecked(): commander_dict[co].add(prest) found = True # Check if there are any prestiges selected if not found: logger.error('No commanders to randomize') return # Randomize commander, prestige, mastery, mmap, race = randomize( commander_dict, mastery_all_in=mastery_all_in) # Update image self.FR_RNG_Result_BG.setStyleSheet(f'background-color: black;') image_file = truePath(f'Layouts/Commanders/{commander}.png') if os.path.isfile(image_file): pixmap = QtGui.QPixmap(image_file) pixmap = pixmap.scaled(self.FR_RNG_Result_BG.width(), self.FR_RNG_Result_BG.height(), QtCore.Qt.KeepAspectRatio, QtCore.Qt.FastTransformation) self.FR_RNG_Result_BG.setPixmap(pixmap) # Commander and prestige self.FR_RNG_Result_CO.setText(commander) self.FR_RNG_Result_Prestige.setText( f"{prestige_names[commander][prestige]} (P{prestige})") # Mastery mastery = mastery if self.CB_RNG_Mastery.currentText( ) != 'No mastery generated' else [0, 0, 0, 0, 0, 0] mtext = '' for idx, m in enumerate(CommanderMastery[commander]): fill = '' if mastery[idx] > 9 else ' ' style = ' style="color: #aaa"' if mastery[idx] == 0 else '' mtext += f"<span{style}>{fill}<b>{mastery[idx]}</b> {m}</span><br>" self.FR_RNG_Result_Mastery.setText(mtext) # Map and race if self.CB_RNG_Map.isChecked() and self.CB_RNG_Race.isChecked(): self.FR_RNG_Result_MapRace.setText(f"{mmap} | {race}") elif self.CB_RNG_Map.isChecked(): self.FR_RNG_Result_MapRace.setText(mmap) elif self.CB_RNG_Race.isChecked(): self.FR_RNG_Result_MapRace.setText(race) else: self.FR_RNG_Result_MapRace.setText('') MF.RNG_COMMANDER = { 'Commander': commander, 'Prestige': prestige_names[commander][prestige] }