def switch_engine(project_file, engine_id): project = cryproject.load (project_file) if cryproject.engine_id (project) != engine_id: if has_win_modules: message = 'Changing the version of the engine can cause the project to become unstable. Make sure to make a backup of your project before changing the version!' if MessageBox (None, message, 'Changing engine version', win32con.MB_OKCANCEL | win32con.MB_ICONWARNING) == win32con.IDCANCEL: return 1 # Return 1 to indicate that changing the engine is canceled by the user. try: project['require']['engine'] = engine_id cryproject.save (project, project_file) except: # Catch every exception and print it to the console. # This way the command can be debugged in the console but the normal user will not be overwhelmed with technical stuff. e = sys.exc_info()[0] print(repr(e)) message = 'An error occurred while changing the engine version. Is the project file read-only?' if has_win_modules: MessageBox (None, message, 'An error occurred', win32con.MB_OK | win32con.MB_ICONERROR) else: sys.stderr.write (message) return 1 if has_win_modules: message = 'The engine version has changed and this has caused the code to become incompatible. Please generate the solution, fix any errors in the code and rebuild the project before launching it.' MessageBox (None, message, 'Rebuild required', win32con.MB_OK | win32con.MB_ICONWARNING) return 0
def command_ok(self): i= self.combo.current() (engine_id, name)= self.engine_list[i] if engine_id is None: engine_dirname= name listdir= os.listdir (engine_dirname) engine_files= list (filter (lambda filename: os.path.isfile (os.path.join (engine_dirname, filename)) and os.path.splitext(filename)[1] == cryregistry.ENGINE_EXTENSION, listdir)) engine_files.sort() if not engine_files: message= 'Folder is not a previously registered CRYENGINE folder. Would you like to add the folder as a custom engine?' if MessageBox (None, message, 'Switch engine version', win32con.MB_OKCANCEL | win32con.MB_ICONWARNING) == win32con.IDCANCEL: return engine_id= "{%s}" % uuid.uuid4() engine_path= os.path.join (engine_dirname, os.path.basename (engine_dirname) + cryregistry.ENGINE_EXTENSION) file= open (engine_path, 'w') file.write (json.dumps ({'info': {'id': engine_id}}, indent=4, sort_keys=True)) file.close() else: engine_path= os.path.join (engine_dirname, engine_files[0]) engine= cryproject.load (engine_path) engine_id= engine['info']['id'] add_engines (engine_path) project= cryproject.load (self.project_file) if cryproject.engine_id (project) != engine_id: project['require']['engine']= engine_id cryproject.save (project, self.project_file) cmd_run (args, ('projgen', self.project_file)) self.close()
def cmd_run_project (args, sys_argv=sys.argv[1:]): if not os.path.isfile (args.project_file): error_project_not_found (args) project = cryproject.load (args.project_file) if project is None: error_project_json_decode (args) engine_id = cryproject.engine_id(project) engine_path = "" # Start by checking for the ability to specifying use of the local engine if engine_id is '.': engine_path = os.path.dirname(args.project_file) else: # Now check the registry engine_registry = cryregistry.load_engines() engine_path = cryregistry.engine_path (engine_registry, engine_id) if engine_path is None: error_engine_path_not_found (args, engine_id) #--- if getattr( sys, 'frozen', False ): subcmd = [ os.path.join (engine_path, 'Tools', 'CryVersionSelector', 'cryrun.exe') ] else: subcmd = [ python_path(), os.path.join (engine_path, 'Tools', 'CryVersionSelector', 'cryrun.py') ] if not os.path.isfile (subcmd[-1]): error_engine_tool_not_found (args, subcmd[-1]) sys_argv = [x for x in sys_argv if x not in ('--silent', )] subcmd.extend (sys_argv) print_subprocess (subcmd) p = subprocess.Popen(subcmd, stderr=subprocess.PIPE) returncode = p.wait() if not args.silent and returncode != 0: title = command_title (args) text = p.stderr.read().strip().decode() if not text: text = SUBPROCESS_NO_STDERR if has_win_modules: result = MessageBox (None, text, title, win32con.MB_OKCANCEL | win32con.MB_ICONERROR) if result == win32con.IDOK: input() # Keeps the window from closing else: sys.stderr.write (text) if returncode != 0: sys.exit (returncode)
def cmd_run (args, sys_argv= sys.argv[1:]): if not os.path.isfile (args.project_file): error_project_not_found (args) project= cryproject.load (args.project_file) if project is None: error_project_json_decode (args) engine_id= cryproject.engine_id(project) engine_registry= cryregistry.load_engines() engine_path= cryregistry.engine_path (engine_registry, engine_id) if engine_path is None: error_engine_path_not_found (args, engine_id) #--- if getattr( sys, 'frozen', False ): subcmd= [ os.path.join (engine_path, 'Tools', 'CryVersionSelector', 'cryrun.exe') ] else: subcmd= [ python3_path(), os.path.join (engine_path, 'Tools', 'CryVersionSelector', 'cryrun.py') ] if not os.path.isfile (subcmd[-1]): error_engine_tool_not_found (args, subcmd[-1]) sys_argv= [x for x in sys_argv if x not in ('--silent', )] subcmd.extend (sys_argv) (temp_fd, temp_path)= tempfile.mkstemp(suffix='.out', prefix=args.command + '_', text=True) temp_file= os.fdopen(temp_fd, 'w') print_subprocess (subcmd) p= subprocess.Popen(subcmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) for line in p.stdout: temp_file.write (line) sys.stdout.write (line) returncode= p.wait() temp_file.close() if not args.silent and returncode != 0: title= command_title (args) text= p.stderr.read().strip() if not text: text= SUBPROCESS_NO_STDERR result= MessageBox (None, text, title, win32con.MB_OKCANCEL | win32con.MB_ICONERROR) if result == win32con.IDOK: subprocess.call(('notepad.exe', temp_path)) os.remove (temp_path) sys.exit (returncode)
def cmd_switch(args): title = 'Switch CRYENGINE version' if not os.path.isfile(args.project_file): error_project_not_found(args) project = cryproject.load(args.project_file) if project is None: error_project_json_decode(args) #--- If the engine version is already specified than set it and return early. if args.engine_version != None: target_version = args.engine_version sys.exit(switch_engine(args.project_file, target_version)) #--- engine_list = [] engine_version = [] engines = cryregistry.load_engines() for (engine_id, engine_data) in engines.items(): engine_file = engine_data['uri'] info = engine_data.get('info', {}) name = info.get('name', os.path.dirname(engine_file)) version = info.get('version') if version is not None: engine_version.append((version, name, engine_id)) else: engine_list.append((name, engine_id)) engine_version.sort() engine_version.reverse() engine_list.sort() engine_list = list(map(lambda a: (a[2], a[1]), engine_version)) + list( map(lambda a: (a[1], a[0]), engine_list)) #--- engine_id = cryproject.engine_id(project) found = 0 for i in range(len(engine_list)): (id_, name) = engine_list[i] if id_ == engine_id: found = i break #--- app = CrySwitch(args.project_file, engine_list, found) app.mainloop()
def cmd_switch(args): """ Command to switch the project to another engine. By specifying an engine version the project will instantly switch to that engine. Otherwise a GUI is shown where the user can select the engine version. """ if not os.path.isfile(args.project_file): error_project_not_found(args) project = cryproject.load(args.project_file) if project is None: error_project_json_decode(args) #--- If the engine version is already specified than set it and return early. if args.engine_version != None: sys.exit( switch_engine(args.project_file, args.engine_version, args.silent)) engine_list = [] engine_version = [] engines = cryregistry.load_engines() for (engine_id, engine_data) in engines.items(): engine_file = engine_data['uri'] info = engine_data.get('info', {}) name = info.get('name', os.path.dirname(engine_file)) version = info.get('version') if version is not None: engine_version.append((version, name, engine_id)) else: engine_list.append((name, engine_id)) engine_version.sort() engine_version.reverse() engine_list.sort() engine_list = list(map(lambda a: (a[2], a[1]), engine_version)) + list( map(lambda a: (a[1], a[0]), engine_list)) engine_id = cryproject.engine_id(project) found = 0 for i in range(len(engine_list)): (id_, name) = engine_list[i] if id_ == engine_id: found = i break app = CrySwitch(args.project_file, engine_list, found) app.mainloop()
def switch_engine(project_file, engine_id, silent): """ Switch the engine of the selected project to the specified engine. By setting silent to True, no permissions will be asked from the user and warnings are not given. """ project = cryproject.load(project_file) if cryproject.engine_id(project) != engine_id: if not silent and HAS_WIN_MODULES: message = ( 'Changing the version of the engine can cause the project to become unstable. ' 'Do you want to create a backup before switching the engine?') result = MESSAGEBOX( None, message, 'Changing engine version', win32con.MB_YESNOCANCEL | win32con.MB_ICONWARNING) if result == win32con.IDCANCEL: return 1 # Return 1 to indicate that changing the engine is canceled by the user. if result == win32con.IDYES: create_backup(project_file) try: project['require']['engine'] = engine_id cryproject.save(project, project_file) except: # Catch every exception and print it to the console. # This way the command can be debugged in the console but the normal user will not be overwhelmed with technical stuff. exception_info = sys.exc_info()[0] print(repr(exception_info)) message = 'An error occurred while changing the engine version. Is the project file read-only?' if not silent and HAS_WIN_MODULES: MESSAGEBOX(None, message, 'An error occurred', win32con.MB_OK | win32con.MB_ICONERROR) else: sys.stderr.write(message) return 1 if not silent and HAS_WIN_MODULES: message = ( 'The engine version has changed and this has caused the code to become incompatible. ' 'Please generate the solution, fix any errors in the code and rebuild the project before launching it.' ) MESSAGEBOX(None, message, 'Rebuild required', win32con.MB_OK | win32con.MB_ICONWARNING) return 0
def cmd_switch(args): title = 'Switch CRYENGINE version' if not os.path.isfile(args.project_file): error_project_not_found(args) project = cryproject.load(args.project_file) if project is None: error_project_json_decode(args) #--- engine_list = [] engines = cryregistry.load_engines() for (engine_id, engine_data) in engines.items(): engine_file = engine_data['uri'] info = engine_data.get('info', {}) version = info.get('version', 0) name = info.get('name', os.path.dirname(engine_file)) engine_list.append((version, name, engine_id)) engine_list.sort() engine_list.reverse() engine_list = list(map(lambda a: (a[2], a[1]), engine_list)) #--- engine_id = cryproject.engine_id(project) found = 0 for i in range(len(engine_list)): (id_, name) = engine_list[i] if id_ == engine_id: found = i break #--- app = CrySwitch(args.project_file, engine_list, found) app.mainloop()
def command_ok(self): i = self.combo.current() (engine_id, name) = self.engine_list[i] if engine_id is None: engine_dirname = name listdir = os.listdir(engine_dirname) engine_files = list( filter( lambda filename: os.path.isfile( os.path.join(engine_dirname, filename)) and os.path. splitext(filename)[1] == cryregistry.ENGINE_EXTENSION, listdir)) engine_files.sort() if not engine_files: engine_id = "{%s}" % uuid.uuid4() engine_path = os.path.join( engine_dirname, os.path.basename(engine_dirname) + cryregistry.ENGINE_EXTENSION) file = open(engine_path, 'w') file.write( json.dumps({'info': { 'id': engine_id }}, indent=4, sort_keys=True)) file.close() else: engine_path = os.path.join(engine_dirname, engine_files[0]) engine = cryproject.load(engine_path) engine_id = engine['info']['id'] add_engines(engine_path) project = cryproject.load(self.project_file) if cryproject.engine_id(project) != engine_id: project['require']['engine'] = engine_id cryproject.save(project, self.project_file) self.close()
def cmd_deploy(args): if not os.path.isfile(args.project_file): error_project_not_found(args) project = cryproject.load(args.project_file) if project is None: error_project_json_decode(args) project_dir = os.path.dirname(args.project_file) engine_id = cryproject.engine_id(project) engines = cryregistry.load_engines() engine_data = engines.get(engine_id) engine_file = engine_data['uri'] engine_dir = os.path.dirname(engine_file) deployment_dir = os.path.join(project_dir, 'Build') rc_path = os.path.join(engine_dir, "Tools/rc/rc.exe") source_asset_dir = os.path.join(project_dir, cryproject.asset_dir(project)) target_asset_dir = os.path.normcase( os.path.join(deployment_dir, cryproject.asset_dir(project))) if not os.path.exists(target_asset_dir): os.makedirs(target_asset_dir) # Copy plugin list copy_file(project_dir, deployment_dir, "cryplugin.csv") # Copy game binaries copy_file_formats_in_dir(os.path.join(project_dir, "bin"), os.path.join(deployment_dir, "bin"), ['*.dll', '*.exe']) # Start copying assets copy_file_formats_in_dir(source_asset_dir, target_asset_dir, ['*.xml', '*.pak', '*.cgf', '*.mtl', '*.cfg']) # Convert textures in assets dir subprocess.check_call([ rc_path, "*.tif", "/p=PC", "/sourceroot=" + source_asset_dir, "/targetroot=" + target_asset_dir, "refresh" ]) # Convert animations in assets dir subprocess.check_call([ rc_path, "*.i_caf", "/animConfigFolder=Animations", "/p=PC", "/sourceroot=" + source_asset_dir, "/targetroot=" + target_asset_dir, "refresh" ]) # Copy engine directory source_engine_assets_dir = os.path.join(engine_dir, "Engine") target_engine_assets_dir = os.path.join(deployment_dir, "Engine") copy_file_formats_in_dir( source_engine_assets_dir, target_engine_assets_dir, [ '*.cfg', '*.xml', '*.txt', '*.thread_config', '*.ttf', '*.dds', '*.mtl', '*.abc', '*.cbc', '*.cgf', '*.pfxp', '*.lut', '*.dat', '*.ext', '*.cfi', '*.cfx' ]) # Convert textures in engine dir subprocess.check_call([ rc_path, "*.tif", "/p=PC", "/sourceroot=" + source_engine_assets_dir, "/targetroot=" + target_engine_assets_dir, "refresh" ]) # Copy engine binaries copy_file_formats_in_dir(os.path.join(engine_dir, "bin"), os.path.join(deployment_dir, "bin"), ['*.dll', '*.exe', '*.py', '*.pyc']) # Create system cfg system_cfg_file = open(os.path.join(deployment_dir, "system.cfg"), "w") system_cfg_file.write("sys_game_folder=" + cryproject.asset_dir(project) + "\n") system_cfg_file.write("sys_dll_game=\"\"\n") system_cfg_file.close()