def initReg(): reg = Reg() if "vkparser" in reg.read_key(r'HKEY_CURRENT_USER\SOFTWARE')['keys']: writeReg("none") return reg.create_key(r'HKEY_CURRENT_USER\SOFTWARE\vkparser') writeReg("none")
def register_project_engine(config, prompt_path=True): """ Register the projects engine :return: True on success """ reg = Reg() try: registered_engines = reg.read_key(config.UE4EngineBuildsReg)['values'] for engine in registered_engines: eng_val = engine['value'] # type:str if eng_val.startswith('{') and eng_val.endswith('}'): click.secho("Removing arbitrary Engine Association {0}".format( eng_val)) reg.delete_value(config.UE4EngineBuildsReg, engine['value']) except Exception: # No entries yet, all good! pass if check_engine_dir_valid(config.UE4EnginePath): click.secho('Setting engine registry key {0} to {1}'.format( config.UE4EngineKeyName, config.UE4EnginePath)) try: reg.create_key(config.UE4EngineBuildsReg) except Exception: pass reg.write_value(config.UE4EngineBuildsReg, config.UE4EngineKeyName, config.UE4EnginePath, 'REG_SZ') elif prompt_path: my_engine_path = input('Enter Engine Path: ') if check_engine_dir_valid(my_engine_path): click.secho('Setting engine registry key {0} to {1}'.format( config.UE4EngineKeyName, my_engine_path)) reg.write_value(config.UE4EngineBuildsReg, config.UE4EngineKeyName, my_engine_path, 'REG_SZ') else: print_error( "Could not find engine path, make sure you type the full path!" ) return False else: print_error("Could not find engine path!") return False return True
class Keywords(object): def __init__(self, host=None): self.reg = Reg(host) def read_registry_key(self, key, key_wow64_32key=False): """ Reading registry key """ resp = self.reg.read_key(key, key_wow64_32key) return resp def create_registry_key(self, key, key_wow64_32key=False): """ Creating registry key """ self.reg.create_key(key, key_wow64_32key) def delete_registry_key(self, key, key_wow64_32key=False): """ Deleting registry key """ self.reg.delete_key(key, key_wow64_32key) def read_registry_value(self, key, value, key_wow64_32key=False): """ Reading value from registry """ return self.reg.read_value(key, value, key_wow64_32key) def write_registry_value(self, key, value, data=None, reg_type='REG_SZ', key_wow64_32key=False): """ Writing (or creating) data in value """ self.reg.write_value(key, value, data, reg_type, key_wow64_32key) def delete_registry_value(self, key, value, key_wow64_32key=False): """ Deleting value from registry """ self.reg.delete_value(key, value, key_wow64_32key)
def register_project_engine(config, prompt_path=True): """ Register the projects engine :return: True on success """ reg = Reg() # try: # registered_engines = reg.read_key(config.UE4EngineBuildsReg)['values'] # for engine in registered_engines: # eng_val = engine['value'] # type:str # if eng_val.startswith('{') and eng_val.endswith('}'): # click.secho("Removing arbitrary Engine Association {0}".format(eng_val)) # reg.delete_value(config.UE4EngineBuildsReg, engine['value']) # except Exception: # # No entries yet, all good! # pass if check_engine_dir_valid(config.UE4EnginePath): # Check if the engine is already registered try: registered_engines = reg.read_key(config.UE4EngineBuildsReg)['values'] for engine in registered_engines: if engine['value'] == config.UE4EngineKeyName: # Check if the data matches the engine path, if not, update the key if engine['data'] != config.UE4EnginePath: click.secho('Updating engine registry key {0}:{1} to {2}'.format(config.UE4EngineKeyName, engine['data'], config.UE4EnginePath)) click.secho('This is probably because the engine has been moved.') reg.write_value(config.UE4EngineBuildsReg, config.UE4EngineKeyName, config.UE4EnginePath, 'REG_SZ') return True except Exception: pass click.secho('Setting engine registry key {0} to {1}'.format(config.UE4EngineKeyName, config.UE4EnginePath)) try: reg.create_key(config.UE4EngineBuildsReg) except Exception: pass reg.write_value(config.UE4EngineBuildsReg, config.UE4EngineKeyName, config.UE4EnginePath, 'REG_SZ') elif prompt_path: my_engine_path = input('Enter Engine Path: ') if check_engine_dir_valid(my_engine_path): click.secho('Setting engine registry key {0} to {1}'.format(config.UE4EngineKeyName, my_engine_path)) reg.write_value(config.UE4EngineBuildsReg, config.UE4EngineKeyName, my_engine_path, 'REG_SZ') else: print_error("Could not find engine path, make sure you type the full path!") return False else: print_error("Could not find engine path to register!") return False return True
import os import sys from winregistry import WinRegistry as Reg absPath = os.path.abspath(__file__) print('current file path', absPath) dirPath = os.path.dirname(absPath) print('computed file path', dirPath) filePath = os.path.join(dirPath, 'main.py') print('target file path', filePath) print('python location', sys.executable) reg = Reg() regPath = 'HKEY_CLASSES_ROOT\\*\\shell' videoViewerPath = regPath + '\\VideoViewer' reg.create_key(videoViewerPath) reg.write_value(videoViewerPath, '', data='Open by Video Viewer') commandPath = videoViewerPath + '\\command' reg.create_key(commandPath) reg.write_value(commandPath, '', data='"%s" "%s" "%s"' % (sys.executable, filePath, '%1'))