# This file contains the code needed to build a Ren'Py distribution. label distribute: python hide: import zipfile import tarfile import os import os.path import time import sys store.progress_time = 0 def progress(tit, n, m, time=time): if time.time() < store.progress_time + .1: return title(tit) mid(message) ui.bar(m, n, xmaximum=200, xalign=0.5) ui.close() ui.pausebehavior(0) interact() lint() store.message = "" title(u"生成发布") mid() text(u"刚才运行了语法检查, 如果有错误, 你应该选No, 然后修正错误\n\n要继续吗?") ui.close() bottom() button("Yes", clicked=ui.returns(True)) button("No", clicked=ui.returns(False)) ui.close() if not interact(): renpy.jump("tools") if os.path.exists(config.renpy_base + "/renpy.exe"): windows = True else: windows = False if os.path.exists(config.renpy_base + "/lib/linux-x86"): linux = True else: linux = False if os.path.exists(config.renpy_base + "/renpy.app"): mac = True else: mac = False if not windows or not mac or not linux: store.message = u"完整版的Ren'Py能生成Windows, Mac, 及Linux三个版本. 请到www.renpy.org下载完整版." title(u"生成发布") mid() text(u"将生成下面几种平台的发布形式:") spacer() if windows: text("Windows 98+", color="#000") if linux: text("Linux x86", color="#000") if mac: text("Mac OS X 10.3+", color="#000") spacer() # TODO: If missing platforms, prompt for a DL. text(u"是否同意?") ui.close() bottom() button("Yes", clicked=ui.returns(True)) button("No", clicked=ui.returns(False)) ui.close() if not interact(): renpy.jump("tools") default_name = project.name if persistent.build_project == project.name: default_name = persistent.build_name name = prompt(u"生成发布", u"请输入生成发布的目录名", "tools", default_name, u"通常是名称和版本号, 例如 'moonlight_walks-1.0'.") name = name.strip() if not name: store.error("Error", u"名称不能为空", "tools_menu") try: name = name.encode("ascii") except: store.error("Error", "名称必须是ASCII码.", "tools_menu") persistent.build_project = project.name persistent.build_name = name # Figure out the files that will make up the distribution. multi_dirs = [ ] multi_files = [ ] def ignored(f): if f[0] == '.' or f.endswith(".bak") or f[-1] == '~': return True if f == "launcherinfo.py": return True return False # Ren'Py Source. for dirname, dirs, files in os.walk(config.renpy_base + "/renpy"): shortdir = dirname[len(config.renpy_base)+1:] dirs[:] = [ i for i in dirs if not i[0] == '.' ] for d in dirs: multi_dirs.append((dirname + "/" + d, shortdir + "/" + d)) for f in files: if ignored(f): continue if f.endswith(".pyc") or f.endswith(".pyo"): continue multi_files.append((dirname + "/" + f, shortdir + "/" + f)) multi_files.append((config.renpy_base + "/LICENSE.txt", "renpy/LICENSE.txt")) # Project files. for dirname, dirs, files in os.walk(project.path): shortdir = dirname[len(project.path)+1:] dirs[:] = [ i for i in dirs if not i[0] == '.' ] if dirname == project.path: if "archived" in dirs: dirs.remove("archived") if dirname == project.gamedir: if "saves" in dirs: dirs.remove("saves") for d in dirs: multi_dirs.append((dirname + "/" + d, shortdir + "/" + d)) for f in files: if ignored(f): continue multi_files.append((dirname + "/" + f, shortdir + "/" + f)) # Common directory... doesn't include subdirs. multi_dirs.append((config.commondir, "common")) for i in os.listdir(config.commondir): if ignored(i): continue multi_files.append((config.commondir + "/" + i, "common/" + i)) shortgamedir = project.gamedir[len(project.path)+1:] # Script version. multi_files.append((config.gamedir + "/script_version.rpy", shortgamedir + "/script_version.rpy")) multi_files.append((config.gamedir + "/script_version.rpyc", shortgamedir + "/script_version.rpyc")) # renpy.py multi_files.append((config.renpy_base + "/renpy.py", project.name + ".py")) multi_dirs.sort() multi_files.sort() # Windows Zip if windows: win_files = [ ( config.renpy_base + "/renpy.exe", project.name + ".exe"), ( config.renpy_base + "/renpy.code", "renpy.code" ), ( config.renpy_base + "/python23.dll", "python23.dll" ), ] zf = zipfile.ZipFile(name + ".zip", "w", zipfile.ZIP_DEFLATED) progress_len = len(multi_files) + len(win_files) store.message = u"务必在Lemma Soft Forums通告你发布的工程." for i, (fn, an) in enumerate(multi_files + win_files): progress("Building Windows", i, progress_len) zi = zipfile.ZipInfo(name + "/" + an) s = os.stat(fn) zi.date_time = time.gmtime(s.st_mtime)[:6] zi.compress_type = zipfile.ZIP_DEFLATED zi.create_system = 3 zi.external_attr = long(0100666) << 16 data = file(fn, "rb").read() zf.writestr(zi, data) zf.close() # Linux Tar Bz2 if linux: linux_dirs = [ (config.renpy_base + "/lib", "lib"), ] linux_files = [ (config.renpy_base + "/renpy.sh", project.name + ".sh"), (config.renpy_base + "/lib/python", "lib/python"), ] linux_base = config.renpy_base + "/lib/linux-x86" for dirname, dirs, files in os.walk(linux_base): dirs[:] = [ i for i in dirs if not i[0] == '.' ] shortname = dirname[len(config.renpy_base)+1:] for d in dirs: linux_dirs.append((dirname + "/" + d, shortname + "/" + d)) for f in files: if f.endswith(".pyc") or f.endswith(".pyo"): continue linux_files.append((dirname + "/" + f, shortname + "/" + f)) linux_dirs.sort() linux_files.sort() tf = tarfile.open(name + "-linux-x86.tar.bz2", "w:bz2") tf.dereference = True progress_len = len(multi_dirs) + len(linux_dirs) + len(multi_files) + len(linux_files) store.message = u"如果可以, 请将你的游戏递交到 www.renai.us." for j, i in enumerate(multi_dirs + linux_dirs + multi_files + linux_files): progress("Building Linux", j, progress_len) fn, an = i info = tf.gettarinfo(fn, name + "-linux-x86/" + an) if info.isdir(): perms = 0777 elif info.name.endswith(".sh"): perms = 0777 elif info.name.endswith(".so"): perms = 0777 elif info.name.endswith("python"): perms = 0777 elif info.name.endswith("python.real"): perms = 0777 else: perms = 0666 info.mode = perms info.uid = 1000 info.gid = 1000 info.uname = "renpy" info.gname = "renpy" if info.isreg(): tf.addfile(info, file(fn, "rb")) else: tf.addfile(info) tf.close() if mac: mac_files = [ ] for dirname, dirs, files in os.walk(config.renpy_base + "/renpy.app"): shortname = project.name + ".app/" + dirname[len(config.renpy_base + "/renpy.app")+1:] if ".svn" in dirs: dirs.remove(".svn") for f in files: mac_files.append((dirname + "/" + f, shortname + "/" + f)) zf = zipfile.ZipFile(name + "-mac.zip", "w", zipfile.ZIP_DEFLATED) progress_len = len(multi_files) + len(mac_files) store.message = u"感谢你选择了Ren'Py." for i, (fn, an) in enumerate(multi_files + mac_files): progress("Building Mac OS X", i, progress_len) zi = zipfile.ZipInfo(name + "-mac/" + an) s = os.stat(fn) zi.date_time = time.gmtime(s.st_mtime)[:6] zi.compress_type = zipfile.ZIP_DEFLATED zi.create_system = 3 if os.path.dirname(fn).endswith("MacOS") or fn.endswith(".so") or fn.endswith(".dylib"): zi.external_attr = long(0100777) << 16 data = file(fn, "rb").read() else: zi.external_attr = long(0100666) << 16 data = file(fn, "rb").read() zf.writestr(zi, data) # Announce Success store.message = "" title("Success") mid() text(u"发布已生成. 在放出前务必要测试.") spacer() if mac: text(u"注意: windows不支持Mac zip的解包和重新打包.", size=16) ui.close() bottom() button("Return", clicked=ui.returns(True)) ui.close() interact() jump tools