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_require (args): registry= cryregistry.load() project= cryproject.load (args.project_file) plugin_dependencies= {} require_getall (registry, cryproject.require_list(project), plugin_dependencies) plugin_list= require_sortedlist (plugin_dependencies) plugin_list= cryregistry.filter_plugin (registry, plugin_list) project_path= os.path.dirname (args.project_file) plugin_path= os.path.join (project_path, 'cryext.txt') if os.path.isfile (plugin_path): os.remove (plugin_path) plugin_file= open (plugin_path, 'w') for k in plugin_list: project_file= cryregistry.project_file (registry, k) project_path= os.path.dirname (project_file) project= cryproject.load (project_file) (m_extensionName, shared_path)= cryproject.shared_tuple (project, args.platform, args.config) asset_dir= cryproject.asset_dir (project) m_extensionBinaryPath= os.path.normpath (os.path.join (project_path, shared_path)) m_extensionAssetDirectory= asset_dir and os.path.normpath (os.path.join (project_path, asset_dir)) or '' m_extensionClassName= 'EngineExtension_%s' % os.path.splitext (os.path.basename (m_extensionBinaryPath))[0] line= ';'.join ((m_extensionName, m_extensionClassName, m_extensionBinaryPath, m_extensionAssetDirectory)) plugin_file.write (line + os.linesep) plugin_file.close()
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 add_engines(*engine_files, silent): """ Adds the collection of engines to the registered engines. """ engine_registry = cryregistry.load_engines() added = [] for engine_file in engine_files: if os.path.splitext(engine_file)[1] != cryregistry.ENGINE_EXTENSION: continue engine = cryproject.load(engine_file) if not engine: error_engine_json_decode(engine_file, silent) info = engine['info'] engine_id = info['id'] engine_data = {'uri': os.path.abspath(engine_file), 'info': info} prev = engine_registry.setdefault(engine_id, engine_data) if prev is engine_data or prev != engine_data: engine_registry[engine_id] = engine_data added.append(engine_id) if added: return cryregistry.save_engines(engine_registry, register_action=True, silent=silent) return 0
def cmd_edit(argv): if not os.path.isfile (args.project_file): error_project_not_found (args.project_file) project= cryproject.load (args.project_file) if project is None: error_project_json_decode (args.project_file) tool_path= os.path.join (get_engine_path(), 'bin', args.platform, 'Sandbox.exe') if not os.path.isfile (tool_path): error_engine_tool_not_found (tool_path) #--- csharp= project.get ("csharp") if csharp: csharp_copylinks (args) subcmd= ( tool_path, '-project', os.path.abspath (args.project_file) ) print_subprocess (subcmd) subprocess.Popen(subcmd)
def cmd_projgen(args, open_cmake=False): if not os.path.isfile(args.project_file): error_project_not_found(args.project_file) project = cryproject.load(args.project_file) if project is None: error_project_json_decode(args.project_file) project_path = os.path.abspath(os.path.dirname(args.project_file)) engine_path = get_engine_path() cmakelists_dir = cryproject.cmakelists_dir(project) if not cmakelists_dir: error_code_folder_not_specified() code_directory = os.path.join(project_path, cmakelists_dir) # Generate solutions crysolutiongenerator.generate_solution(args.project_file, code_directory, engine_path) # Skip on Crytek build agents if args.buildmachine: return cmakelists_path = os.path.join(os.path.join(project_path, cmakelists_dir), 'CMakeLists.txt') # Generate the Solution if code_directory is not None and os.path.isfile(cmakelists_path): generate_project_solution(project_path, code_directory, open_cmake)
def cmd_build(args): if not os.path.isfile (args.project_file): error_project_not_found (args.project_file) project= cryproject.load (args.project_file) if project is None: error_project_json_decode (args.project_file) cmake_path= get_cmake_path() if cmake_path is None: error_cmake_not_found() #--- cmake if cryproject.cmakelists_dir(project) is not None: project_path= os.path.dirname (os.path.abspath (args.project_file)) solution_dir= get_solution_dir (args) subcmd= ( cmake_path, '--build', solution_dir, '--config', args.config ) print_subprocess (subcmd) errcode= subprocess.call(subcmd, cwd= project_path) if errcode != 0: sys.exit (errcode)
def cmd_monodev(args): if not os.path.isfile(args.project_file): error_project_not_found(args.project_file) project = cryproject.load(args.project_file) if project is None: error_project_json_decode(args.project_file) csharp = project.get("csharp", {}) mono_solution = csharp.get('monodev', {}).get('solution') if mono_solution is None: error_mono_not_set(args.project_file) dirname = os.path.dirname(args.project_file) mono_solution = os.path.abspath(os.path.join(dirname, mono_solution)) if not os.path.isfile(mono_solution): error_mono_not_found(mono_solution) engine_path = get_engine_path() tool_path = os.path.join(engine_path, 'Tools', 'MonoDevelop', 'bin', 'MonoDevelop.exe') if not os.path.isfile(tool_path): error_engine_tool_not_found(tool_path) #--- launch monodev subcmd = (tool_path, mono_solution) print_subprocess(subcmd) subprocess.Popen(subcmd, env=dict(os.environ, CRYENGINEROOT=engine_path))
def run(project_file): # Path to the project file as created by the launcher - engine and project path are derivable from this. project = cryproject.load(project_file) project_path = os.path.dirname(project_file) engine_path = cryrun.get_engine_path() # Path to which the game is to be exported. export_path = os.path.join(project_path, '{}_package'.format(project['info']['name'])) # Ensure that only the current data are exported, making sure that errors are reported. if os.path.exists(export_path): shutil.rmtree(export_path) # Copy engine (common) files. copy_engine_assets(engine_path, export_path) copy_engine_binaries(engine_path, export_path, os.path.join('bin', 'win_x64')) if 'csharp' in project: copy_mono_files(engine_path, export_path) # Copy project-specific files. copy_game_dll(project_path, export_path) package_assets(project, project_path, export_path) copy_levels(project, project_path, export_path) create_config(project, export_path)
def cmd_metagen(argv): if not os.path.isfile (args.project_file): error_project_not_found (args.project_file) project= cryproject.load (args.project_file) if project is None: error_project_json_decode (args.project_file) tool_path= os.path.join (get_engine_path(), 'Tools/rc/rc.exe') if not os.path.isfile (tool_path): error_engine_tool_not_found (tool_path) job_path= os.path.join (get_engine_path(), 'Tools/cryassets/rcjob_cryassets.xml') if not os.path.isfile (job_path): error_engine_tool_not_found (job_path) project_path= os.path.dirname (os.path.abspath (args.project_file)) asset_dir = cryproject.asset_dir(project) asset_path = os.path.normpath (os.path.join (project_path, asset_dir)) subcmd= ( tool_path, ('/job=' + job_path), ('/src=' + asset_path) ) print_subprocess (subcmd) subprocess.Popen(subcmd)
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 require_getall (registry, require_list, result): for k in require_list: if k in result: continue project_file= cryregistry.project_file (registry, k) project= cryproject.load (project_file) result[k]= cryproject.require_list (project)
def cmd_projgen(args): if not os.path.isfile(args.project_file): error_project_not_found(args.project_file) project = cryproject.load(args.project_file) if project is None: error_project_json_decode(args.project_file) cmake_path = get_cmake_path() if cmake_path is None: error_cmake_not_found() #--- csharp = project.get("csharp") if csharp: csharp_copylinks(args) csharp_userfile(args, csharp) #--- project_path = os.path.abspath(os.path.dirname(args.project_file)) solution_path = os.path.join(project_path, get_solution_dir(args)) engine_path = get_engine_path() subcmd = ( cmake_path, '-Wno-dev', { 'win_x86': '-AWin32', 'win_x64': '-Ax64' }[args.platform], '-DPROJECT_FILE:FILEPATH=%s' % os.path.abspath(args.project_file), '-DCryEngine_DIR:PATH=%s' % engine_path, '-DCMAKE_PREFIX_PATH:PATH=%s' % os.path.join(engine_path, 'Tools', 'CMake', 'modules'), '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG:PATH=%s' % os.path.join(project_path, cryproject.shared_dir(project, args.platform, 'Debug')), '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE:PATH=%s' % os.path.join(project_path, cryproject.shared_dir(project, args.platform, 'Release')), '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL:PATH=%s' % os.path.join( project_path, cryproject.shared_dir(project, args.platform, 'MinSizeRel')), '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO:PATH=%s' % os.path.join( project_path, cryproject.shared_dir(project, args.platform, 'RelWithDebInfo')), os.path.join(project_path, cryproject.cmakelists_dir(project))) if not os.path.isdir(solution_path): os.makedirs(solution_path) os.chdir(solution_path) print_subprocess(subcmd) sys.exit(subprocess.call(subcmd))
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 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 command_ok(self): """ Called when the Ok button is pressed. """ 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: if HAS_WIN_MODULES: 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'] # When using the switch engine UI we don't need to be silent anymore. error_code = add_engines(engine_path, silent=False) if error_code != 0: self.close() return error_code self.close() return switch_engine(self.project_file, engine_id, False)
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_remove(args): engine_registry = cryregistry.load_engines() removed = [] for engine_file in args.project_files: engine = cryproject.load(engine_file) engine_id = engine['info']['id'] if engine_id in engine_registry: del engine_registry[engine_id] removed.append(engine_id) if removed: cryregistry.save_engines(engine_registry)
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 cmd_build(args): if not os.path.isfile (args.project_file): error_project_not_found (args.project_file) project= cryproject.load (args.project_file) if project is None: error_project_json_decode (args.project_file) cmake_path= get_cmake_path() if cmake_path is None: error_cmake_not_found() #--- mono csharp= project.get ("csharp", {}) mono_solution= csharp.get ("monodev", {}).get ("solution") if mono_solution is not None: engine_path= get_engine_path() tool_path= os.path.join (engine_path, 'Tools', 'MonoDevelop', 'bin', 'mdtool.exe') if not os.path.isfile (tool_path): error_engine_tool_not_found (tool_path) subcmd= ( tool_path, 'build', os.path.join (os.path.dirname (args.project_file), mono_solution) ) print_subprocess (subcmd) errcode= subprocess.call(subcmd) if errcode != 0: sys.exit (errcode) #--- cmake if cryproject.cmakelists_dir(project) is not None: project_path= os.path.dirname (os.path.abspath (args.project_file)) solution_dir= get_solution_dir (args) subcmd= ( cmake_path, '--build', solution_dir, '--config', args.config ) print_subprocess (subcmd) errcode= subprocess.call(subcmd, cwd= project_path) if errcode != 0: sys.exit (errcode)
def cmd_devenv(args): if not os.path.isfile(args.project_file): error_project_not_found(args.project_file) project = cryproject.load(args.project_file) if project is None: error_project_json_decode(args.project_file) #--- csharp = project.get("csharp", {}) mono_solution = csharp.get('monodev', {}).get('solution') if mono_solution: # launch monodev dirname = os.path.dirname(args.project_file) mono_solution = os.path.abspath(os.path.join(dirname, mono_solution)) if not os.path.isfile(mono_solution): error_mono_not_found(mono_solution) engine_path = get_engine_path() tool_path = os.path.join(engine_path, 'Tools', 'MonoDevelop', 'bin', 'MonoDevelop.exe') if not os.path.isfile(tool_path): error_engine_tool_not_found(tool_path) subcmd = (tool_path, mono_solution) print_subprocess(subcmd) subprocess.Popen(subcmd, env=dict(os.environ, CRYENGINEROOT=engine_path)) else: # launch msdev cmakelists_dir = cryproject.cmakelists_dir(project) if cmakelists_dir is not None: project_path = os.path.abspath(os.path.dirname(args.project_file)) solution_path = os.path.join(project_path, get_solution_dir(args)) solutions = glob.glob(os.path.join(solution_path, '*.sln')) if not solutions: error_solution_not_found(solution_path) solutions.sort() subcmd = ('cmd', '/C', 'start', '', solutions[0]) print_subprocess(subcmd) engine_path = get_engine_path() subprocess.Popen(subcmd, env=dict(os.environ, CRYENGINEROOT=engine_path)) else: error_mono_not_set(args.project_file)
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_remove(args): """ Removes the engine from the registery-file. """ engine_registry = cryregistry.load_engines() removed = [] for engine_file in args.engine_files: engine = cryproject.load(engine_file) engine_id = engine['info']['id'] if engine_id in engine_registry: del engine_registry[engine_id] removed.append(engine_id) if removed: sys.exit( cryregistry.save_engines(engine_registry, register_action=False, silent=args.silent))
def cmd_launch_dedicated_server(args): if not os.path.isfile(args.project_file): error_project_not_found(args.project_file) project = cryproject.load(args.project_file) if project is None: error_project_json_decode(args.project_file) tool_path = os.path.join(get_engine_path(), 'bin', args.platform, 'Game_Server.exe') if not os.path.isfile(tool_path): error_engine_tool_not_found(tool_path) #--- subcmd = (tool_path, '-project', os.path.abspath(args.project_file)) print_subprocess(subcmd) subprocess.Popen(subcmd)
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 cmd_cmake_gui(args): if not os.path.isfile(args.project_file): error_project_not_found(args.project_file) project = cryproject.load(args.project_file) if project is None: error_project_json_decode(args.project_file) dirname = os.path.dirname(os.path.abspath(args.project_file)) #--- cpp cmakelists_dir = cryproject.cmakelists_dir(project) if cmakelists_dir is not None: project_path = os.path.abspath(os.path.dirname(args.project_file)) source_path = os.path.join(project_path, cmakelists_dir) solution_dir = get_project_solution_dir(project_path) if solution_dir == None: error_solution_not_found(project_path) return solution_path = os.path.join(project_path, solution_dir) open_cmake_gui(source_path, solution_path)
def add_engines(*engine_files): engine_registry = cryregistry.load_engines() added = [] for engine_file in engine_files: if os.path.splitext(engine_file)[1] != cryregistry.ENGINE_EXTENSION: continue engine = cryproject.load(engine_file) info = engine['info'] engine_id = info['id'] engine_data = {'uri': os.path.abspath(engine_file), 'info': info} prev = engine_registry.setdefault(engine_id, engine_data) if prev is engine_data or prev != engine_data: engine_registry[engine_id] = engine_data added.append(engine_id) if added: cryregistry.save_engines(engine_registry)
def cmd_projgen(args): if not os.path.isfile (args.project_file): error_project_not_found (args.project_file) project= cryproject.load (args.project_file) if project is None: error_project_json_decode (args.project_file) project_path= os.path.abspath (os.path.dirname (args.project_file)) engine_path= get_engine_path() cmakelists_dir= cryproject.cmakelists_dir(project) code_directory = os.path.join (project_path, cmakelists_dir) # Generate solutions crysolutiongenerator.generate_solution(args.project_file, code_directory, engine_path) cmakelists_path = os.path.join(os.path.join (project_path, cmakelists_dir), 'CMakeLists.txt') # Generate the Solution, skip on Crytek build agents if cmakelists_dir is not None and os.path.exists(cmakelists_path) and not args.buildmachine: cmake_path= get_cmake_path() if cmake_path is None: error_cmake_not_found() solution_path= os.path.join (project_path, get_solution_dir (args)) subcmd= ( cmake_path, {'win_x86': '-AWin32', 'win_x64': '-Ax64'}[args.platform], '-DCMAKE_TOOLCHAIN_FILE=%s' % os.path.join (engine_path, 'Tools', 'CMake', 'toolchain', 'windows', 'WindowsPC-MSVC.cmake'), os.path.join (project_path, cmakelists_dir) ) if not os.path.isdir (solution_path): os.makedirs (solution_path) print_subprocess (subcmd) errcode= subprocess.call(subcmd, cwd= solution_path) if errcode != 0: sys.exit (errcode)
def cmd_cmake_gui(args): if not os.path.isfile (args.project_file): error_project_not_found (args.project_file) project= cryproject.load (args.project_file) if project is None: error_project_json_decode (args.project_file) dirname= os.path.dirname (os.path.abspath (args.project_file)) #--- cpp cmakelists_dir= cryproject.cmakelists_dir(project) if cmakelists_dir is not None: cmake_path= get_cmake_path() if cmake_path is None: error_cmake_not_found() project_path= os.path.abspath (os.path.dirname (args.project_file)) solution_path= os.path.join (project_path, get_solution_dir (args)) cmake_gui_path = cmake_path.replace('cmake.exe','cmake-gui.exe') subcmd= (cmake_gui_path) pid = subprocess.Popen([cmake_gui_path],cwd= solution_path)
def run(project_file): """ Entry point for setting up the process to release a packaged build. """ # Path to the project file as created by the launcher - engine and project path are derivable from this. project = cryproject.load(project_file) project_title = project['info']['name'] # The path the folder that contains the .cryproject file. project_path = os.path.normpath(os.path.dirname(project_file)) project_path_long = LONG_PATH_PREFIX + project_path # The path to the engine that is being used by the project. engine_path = os.path.normpath(get_engine_path()) engine_path_long = LONG_PATH_PREFIX + engine_path # Path to which the game is to be exported. export_path = os.path.join(project_path, '{}_package'.format(project_title)) configurations = get_available_configurations(engine_path) if not configurations: print( "Unable to find a valid engine configuration. Make sure to build your engine to the following locations." ) for key, value in DEFAULT_CONFIGURATIONS: print("Configuration: {} \n Location: {}".format(key, value)) print("Press Enter to exit") input() return # configuration is returned as (export_path, config_name, config_bin_folder, include_symbols) configuration = release_project_gui.configure_build( export_path, configurations) if not configuration: # No configuration selected. # Most likely because the user closed the window, so close this as well. return export_path = os.path.normpath(configuration[0]) export_path_long = LONG_PATH_PREFIX + export_path config_type = configuration[1] bin_path = os.path.normpath(configuration[2]) include_symbols = configuration[3] print("Packaging project {}".format(project_title)) print("Configuration: {}".format(config_type)) print("Debug symbols are {}".format( "included" if include_symbols else "excluded")) print("Building to: {}".format(export_path)) task_list = [] if os.path.exists(export_path_long): task_list.append(("Deleting previous build...", delete_previous_build, export_path_long)) task_list.append(("Packaging custom engine assets...", package_engine_assets, engine_path, export_path)) task_list.append(("Copying default engine assets...", copy_engine_assets, engine_path_long, export_path_long)) task_list.append( ("Copying engine binaries...", copy_engine_binaries, engine_path_long, export_path_long, bin_path, include_symbols)) if requires_mono(project, project_path_long): task_list.append(("Copying mono files...", copy_mono_files, engine_path_long, export_path_long)) task_list.append( ("Copying game binaries...", copy_project_plugins, project, project_path, export_path, bin_path, config_type, include_symbols)) task_list.append(("Copying shared libraries...", copy_libs, project, project_path, export_path, include_symbols)) task_list.append(("Copying existing game asset packages...", copy_assets, project, project_path_long, export_path_long)) task_list.append(("Packaging game assets...", package_assets, project, engine_path, project_path, export_path)) task_list.append(("Cleaning up temp folders...", delete_temp_folders, engine_path_long, project_path_long)) task_list.append( ("Creating config files...", create_config, project_file, export_path)) i = 0 count = len(task_list) for task in task_list: description = task[0] print(description) set_title("{}% {}".format(int(get_percentage(i, count)), description)) task[1](*task[2:]) i += 1 set_title("100% Build packaged successfully") print("Build packaged successfully") print("Press Enter to exit") input()