def main(mcp_dir, patch_dir="patches", orig_dir=".minecraft_orig"): new_src_dir = os.path.join(base_dir, "src") patch_base_dir = os.path.join(base_dir, patch_dir) patchsrc_base_dir = os.path.join(base_dir, "patchsrc") resources_base_dir = os.path.join(base_dir, "resources") try: shutil.rmtree(new_src_dir, onerror=pythonisdumb, ignore_errors=True) shutil.rmtree(patch_base_dir, onerror=pythonisdumb, ignore_errors=True) shutil.rmtree(patchsrc_base_dir, onerror=pythonisdumb, ignore_errors=True) shutil.rmtree(resources_base_dir, onerror=pythonisdumb, ignore_errors=True) if not os.path.exists(new_src_dir): os.mkdir(new_src_dir) if not os.path.exists(patch_base_dir): os.mkdir(patch_base_dir) if not os.path.exists(patchsrc_base_dir): os.mkdir(patchsrc_base_dir) if not os.path.exists(resources_base_dir): os.makedirs(resources_base_dir) except OSError as e: quit mod_src_dir = os.path.join(mcp_dir, "src", "minecraft") resources_src_dir = os.path.join(mcp_dir, "src", "resources") org_src_dir = os.path.join(mcp_dir, "src", orig_dir) for src_dir, dirs, files in os.walk(mod_src_dir): pkg = os.path.relpath(src_dir, mod_src_dir) new_dir = os.path.join(new_src_dir, pkg) mod_dir = os.path.join(org_src_dir, pkg) patch_dir = os.path.join(patch_base_dir, pkg) patchsrc_dir = os.path.join(patchsrc_base_dir, pkg) try: if not os.path.exists(new_dir): os.mkdir(new_dir) if not os.path.exists(patch_dir): os.mkdir(patch_dir) if not os.path.exists(patchsrc_dir): os.mkdir(patchsrc_dir) except OSerror as e: quit for file_ in files: mod_file = os.path.join(src_dir, file_) org_file = os.path.join(mod_dir, file_) if mod_file[-4:] != "java": continue if file_ == "Minecraft.java": # Update Minecrift version print "Updating Minecraft.java Minecrift version: [Minecrift %s %s] %s" % ( minecrift_version_num, minecrift_build, org_file) replacelineinfile( mod_file, "public final String minecriftVerString", " public final String minecriftVerString = \"Vivecraft %s %s\";\n" % (minecrift_version_num, minecrift_build)) if os.path.exists(org_file): patch_file = os.path.join(patch_dir, file_ + ".patch") label = pkg.replace( "\\", "/") + "/" + file_ #patch label always has "/" create_patch(mcp_dir, org_file, mod_file, label, patch_file) if os.path.exists(patch_file): shutil.copy(mod_file, patchsrc_dir) else: new_file = os.path.join(new_dir, file_) #new class file, just replace if os.path.exists(new_file): os.remove(new_file) shutil.copy(mod_file, new_dir) for resource_dir, dirs, files in os.walk(resources_src_dir): pkg = os.path.relpath(resource_dir, resources_src_dir) new_dir = os.path.join(resources_base_dir, pkg) if not os.path.exists(new_dir): os.mkdir(new_dir) for file_ in files: new_file = os.path.join(new_dir, file_) mod_file = os.path.join(resource_dir, file_) print "Copy resource %s" % (mod_file) #new class file, just replace if os.path.exists(new_file): os.remove(new_file) shutil.copy(mod_file, new_dir) removeEmptyFolders(patch_base_dir) removeEmptyFolders(new_src_dir) removeEmptyFolders(patchsrc_base_dir) removeEmptyFolders(resources_base_dir)
def main(mcp_dir, patch_dir = "patches", orig_dir = ".minecraft_orig"): new_src_dir = os.path.join( base_dir , "src" ) patch_base_dir = os.path.join( base_dir , patch_dir ) patchsrc_base_dir = os.path.join( base_dir , "patchsrc" ) try: shutil.rmtree( new_src_dir ) shutil.rmtree( patch_base_dir ) shutil.rmtree( patchsrc_base_dir ) except OSError as e: pass if not os.path.exists( new_src_dir ): os.mkdir( new_src_dir ) if not os.path.exists( patch_base_dir ): os.mkdir( patch_base_dir ) if not os.path.exists( patchsrc_base_dir ): os.mkdir( patchsrc_base_dir ) mod_src_dir = os.path.join( mcp_dir , "src", "minecraft" ) org_src_dir = os.path.join( mcp_dir , "src", orig_dir ) for src_dir, dirs, files in os.walk(mod_src_dir): pkg = os.path.relpath(src_dir,mod_src_dir) new_dir = os.path.join( new_src_dir, pkg ) mod_dir = os.path.join( org_src_dir, pkg ) patch_dir = os.path.join( patch_base_dir, pkg ) patchsrc_dir = os.path.join( patchsrc_base_dir, pkg ) if not os.path.exists(new_dir): os.mkdir(new_dir) if not os.path.exists(patch_dir): os.mkdir(patch_dir) if not os.path.exists(patchsrc_dir): os.mkdir(patchsrc_dir) for file_ in files: mod_file = os.path.join(src_dir, file_) org_file = os.path.join(mod_dir, file_) if mod_file[-4:]!="java": continue if file_ == "Minecraft.java": # Update Minecrift version print "Updating Minecraft.java Minecrift version: [Minecrift %s %s] %s" % ( minecrift_version_num, minecrift_build, org_file ) replacelineinfile( mod_file, "public final String minecriftVerString", " public final String minecriftVerString = \"Vivecraft %s %s\";\n" % (minecrift_version_num, minecrift_build) ); if os.path.exists(org_file): patch_file = os.path.join(patch_dir,file_+".patch") label = pkg.replace("\\","/") + "/" + file_ #patch label always has "/" create_patch( mcp_dir, org_file, mod_file, label, patch_file ) if os.path.exists( patch_file ): shutil.copy(mod_file, patchsrc_dir) else: new_file = os.path.join(new_dir, file_) #new class file, just replace if os.path.exists( new_file ): os.remove( new_file ) shutil.copy(mod_file, new_dir) removeEmptyFolders(patch_base_dir) removeEmptyFolders(new_src_dir) removeEmptyFolders(patchsrc_base_dir)