def _apply_update_stage1_windows(): """Apply the Windows specific part of stage 1. On Windows files that are currently in use (``source-python.dll``) can't be replaced. Thus, this function checks if ``source-python.vdf`` exists. If it does, the new ``source-python.dll`` is copied to the addons directory with a new name (``source-python2.dll``). After that the VDF entry is modified to point to the new loader. If ``source-python.vdf`` does not exist, manual action is required. """ if not VDF_FILE.isfile(): update_logger.log_message( f'Stage 1 has been applied. Please shutdown your server and move ' f'(do not copy) {LOADER_UPDATE_FILE} to {LOADER_FILE}. After that ' f'start your server to apply stage 2.') else: update_logger.log_debug('Determining current VDF entry...') kv = KeyValues.from_file(VDF_FILE) # Get the current and new entry for the VDF file current_entry = kv.get_string('file') if current_entry == SP_VDF2: new_entry = SP_VDF1 elif current_entry == SP_VDF1: new_entry = SP_VDF2 else: raise ValueError(f'Unexpected entry in VDF: {current_entry}') update_logger.log_debug(f'Current VDF entry: {current_entry}') update_logger.log_debug(f'New VDF entry: {new_entry}') update_logger.log_debug( 'Moving new loader binary to game directory...') LOADER_UPDATE_FILE.move(GAME_PATH / f'{new_entry}.{BINARY_EXT}') kv.set_string('file', new_entry) kv.save_to_file(VDF_FILE) update_logger.log_message( 'Stage 1 has been applied. Restart your server to apply stage 2.')