Linux multi-monitor fullscreen support
[ryzomcore.git] / nel / tools / build_gamedata / d1_client_patch.py
blob5237542f6ee77e3c7075157f99e40837995e1177
1 #!/usr/bin/python
2 #
3 # \file d1_client_patch.py
4 # \brief Install to client patch
5 # \date 2009-02-18 16:19GMT
6 # \author Jan Boon (Kaetemi)
7 # Python port of game data build pipeline.
8 # Install to client patch
9 #
10 # NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
11 # Copyright (C) 2009-2014 by authors
13 # This program is free software: you can redistribute it and/or modify
14 # it under the terms of the GNU Affero General Public License as
15 # published by the Free Software Foundation, either version 3 of the
16 # License, or (at your option) any later version.
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU Affero General Public License for more details.
23 # You should have received a copy of the GNU Affero General Public License
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
27 import time, sys, os, shutil, subprocess, distutils.dir_util, argparse
28 sys.path.append("configuration")
30 parser = argparse.ArgumentParser(description='Ryzom Core - Build Gamedata - Client Patch')
31 parser.add_argument('--bnponly', '-bo', action='store_true')
32 args = parser.parse_args()
34 if os.path.isfile("log.log"):
35 os.remove("log.log")
36 log = open("log.log", "w")
37 from scripts import *
38 from buildsite import *
39 from tools import *
41 sys.path.append(WorkspaceDirectory)
42 from projects import *
44 # Log error
45 printLog(log, "")
46 printLog(log, "-------")
47 printLog(log, "--- Install to client patch")
48 printLog(log, "-------")
49 printLog(log, time.strftime("%Y-%m-%d %H:%MGMT", time.gmtime(time.time())))
50 printLog(log, "")
52 # Find tools
53 BnpMake = findTool(log, ToolDirectories, BnpMakeTool, ToolSuffix)
54 SnpMake = findTool(log, ToolDirectories, SnpMakeTool, ToolSuffix);
55 PatchGen = findTool(log, ToolDirectories, PatchGenTool, ToolSuffix)
56 printLog(log, "")
58 # Find **** HARDCODED **** WINDOWS **** tools ... TODO: fix patch_gen tool !!!
59 Lzma = findFileMultiDir(log, ToolDirectories + WindowsExeDllCfgDirectories, "lzma.exe")
60 printLog(log, "LZMA " + Lzma)
61 XDelta = findFileMultiDir(log, ToolDirectories + WindowsExeDllCfgDirectories, "xdelta.exe")
62 printLog(log, "XDELTA " + XDelta)
63 printLog(log, "")
65 if BnpMake == "":
66 toolLogFail(log, BnpMakeTool, ToolSuffix)
67 elif PatchGen == "" and not args.bnponly:
68 toolLogFail(log, PatchGenTool, ToolSuffix)
69 elif Lzma == "" and not args.bnponly:
70 toolLogFail(log, "LZMA", ToolSuffix)
71 elif XDelta == "" and not args.bnponly:
72 toolLogFail(log, "XDELTA", ToolSuffix)
73 elif os.path.dirname(Lzma) != os.path.dirname(XDelta):
74 printLog(log, "FAIL lzma.exe and xdelta.exe must be in the same directory")
75 else:
76 mkPath(log, ClientPatchDirectory)
77 if not args.bnponly:
78 productXml = ClientPatchDirectory + "/" + ProductName + ".xml"
79 if not os.path.isfile(productXml):
80 printLog(log, ">>> Create new product <<<")
81 subprocess.call([ PatchGen, "createNewProduct", productXml ])
82 printLog(log, "")
83 printLog(log, ">>> Rewrite " + ProductName + ".xml <<<") # because we know better.
84 shutil.move(productXml, productXml + ".old")
85 oldCfg = open(productXml + ".old", "r")
86 cfg = open(productXml, "w")
87 inCategories = 0
88 for line in oldCfg:
89 if not inCategories:
90 if line.strip() == "<_Categories>":
91 inCategories = 1
92 cfg.write("\t<_Categories>\n")
93 for category in InstallClientData:
94 packExt = ".bnp"
95 if (category["StreamedPackages"]):
96 packExt = ".snp"
97 cfg.write("\t\t<_Category>\n")
98 cfg.write("\t\t\t<_Name type=\"STRING\" value=\"" + category["Name"] + "\"/>\n")
99 if category["UnpackTo"] != None:
100 if category["UnpackTo"] != "":
101 cfg.write("\t\t\t<_UnpackTo type=\"STRING\" value=\"./" + category["UnpackTo"] + "/\"/>\n")
102 else:
103 cfg.write("\t\t\t<_UnpackTo type=\"STRING\" value=\"./\"/>\n")
104 cfg.write("\t\t\t<_IsOptional type=\"SINT32\" value=\"" + str(category["IsOptional"]) + "\"/>\n")
105 cfg.write("\t\t\t<_IsIncremental type=\"SINT32\" value=\"" + str(category["IsIncremental"]) + "\"/>\n")
106 for package in category["Packages"]:
107 if (len(package[1]) > 0):
108 cfg.write("\t\t\t<_Files type=\"STRING\" value=\"" + package[1][0] + "\"/>\n")
109 else:
110 cfg.write("\t\t\t<_Files type=\"STRING\" value=\"" + package[0] + packExt + "\"/>\n")
111 for ref in category["Refs"]:
112 cfg.write("\t\t\t<_Files type=\"STRING\" value=\"" + ref + "_.ref\"/>\n")
113 cfg.write("\t\t</_Category>\n")
114 cfg.write("\t</_Categories>\n")
115 else:
116 cfg.write(line)
117 else:
118 if line.strip() == "</_Categories>":
119 inCategories = 0
120 oldCfg.close()
121 cfg.close()
122 os.remove(productXml + ".old")
123 printLog(log, "")
124 printLog(log, ">>> Make bnp <<<")
125 targetPath = ClientPatchDirectory + "/bnp"
126 tagPath = ClientPatchDirectory + "/bnp_tag"
127 mkPath(log, targetPath)
128 mkPath(log, tagPath)
129 for category in InstallClientData:
130 packExt = ".bnp"
131 if (category["StreamedPackages"]):
132 packExt = ".snp"
133 for package in category["Packages"]:
134 printLog(log, "PACKAGE " + package[0])
135 sourcePath = InstallDirectory + "/" + package[0]
136 mkPath(log, sourcePath)
137 targetBnp = targetPath + "/" + package[0] + packExt
138 tagBnp = tagPath + "/" + package[0] + packExt + ".tag"
139 if (len(package[1]) > 0):
140 targetBnp = targetPath + "/" + package[1][0]
141 tagBnp = tagPath + "/" + package[1][0] + ".tag"
142 printLog(log, "TARGET " + package[1][0])
143 needUpdateBnp = 1
144 if (len(package) > 2):
145 needUpdateBnp = needUpdate(log, sourcePath + "/" + package[2], tagBnp)
146 else:
147 needUpdateBnp = needUpdateDirNoSubdirFile(log, sourcePath, tagBnp)
148 if (needUpdateBnp):
149 subRet = 0
150 open(tagBnp, 'a').close()
151 os.utime(tagBnp, None)
152 if (category["StreamedPackages"]):
153 printLog(log, "SNP " + targetBnp)
154 # cwDir = os.getcwd().replace("\\", "/")
155 # toolDir = os.path.dirname(Lzma).replace("\\", "/")
156 # os.chdir(toolDir)
157 subRet = subprocess.call([ SnpMake, "-p", sourcePath, targetBnp, ClientPatchDirectory + "/stream" ] + package[1][1:])
158 # os.chdir(cwDir)
159 else:
160 printLog(log, "BNP " + targetBnp)
161 subRet = subprocess.call([ BnpMake, "-p", sourcePath, "-o", targetBnp ] + package[1][1:])
162 if (subRet != 0):
163 os.remove(tagBnp)
164 else:
165 printLog(log, "SKIP " + targetBnp)
166 printLog(log, "")
167 if not args.bnponly:
168 printLog(log, ">>> Update product <<<")
169 cwDir = os.getcwd().replace("\\", "/")
170 toolDir = os.path.dirname(Lzma).replace("\\", "/")
171 os.chdir(toolDir)
172 subprocess.call([ PatchGen, "updateProduct", productXml ])
173 os.chdir(cwDir)
174 printLog(log, "")
177 log.close()
178 if os.path.isfile("d1_client_patch.log"):
179 os.remove("d1_client_patch.log")
180 shutil.copy("log.log", time.strftime("%Y-%m-%d-%H-%M-GMT", time.gmtime(time.time())) + "_client_patch.log")
181 shutil.move("log.log", "d1_client_patch.log")