11import os , sys , shutil
22from win32api import GetFileVersionInfo
33from json import load
4- from re import fullmatch , IGNORECASE
4+ from re import fullmatch , sub , IGNORECASE
55
66compressDirList = []
77
88
99def getPEVersion (fname ):
1010 try :
11- fileInfo = GetFileVersionInfo (fname , '\\ ' )
12- version = "V%d.%d.%d" % (fileInfo ['FileVersionMS' ] / 65536 ,
13- fileInfo ['FileVersionMS' ] % 65536 ,
14- fileInfo ['FileVersionLS' ] / 65536 )
11+ fileInfo = GetFileVersionInfo (fname , "\\ " )
12+ version = "V%d.%d.%d" % (
13+ fileInfo ["FileVersionMS" ] / 65536 ,
14+ fileInfo ["FileVersionMS" ] % 65536 ,
15+ fileInfo ["FileVersionLS" ] / 65536 ,
16+ )
1517 except Exception :
1618 print ("Cannot get version number of" , fname )
1719 return version
1820
1921
2022os .chdir (sys .path [0 ])
2123print ("Current Directory:" , os .getcwd ())
22- targetName = os .path .abspath (os .getcwd ()).split (' \\ ' )[- 2 ]
24+ targetName = os .path .abspath (os .getcwd ()).split (" \\ " )[- 2 ]
2325print ("Target Name" , targetName )
2426
2527src32Dir = ""
@@ -63,11 +65,6 @@ def getPEVersion(fname):
6365 print (dst32Dir , "doesn't exist, creating..." )
6466 shutil .copytree ("./32" , dst32Dir )
6567shutil .copyfile (src32Path , dst32Path )
66- configPath = dst32Dir + "/config"
67- if os .path .exists (configPath ):
68- print (configPath , "exists, replacing..." )
69- shutil .rmtree (configPath )
70- shutil .copytree ("../config" , configPath )
7168compressDirList .append (dst32Dir )
7269
7370if os .path .exists (dst64Dir ) and os .path .exists (dst64Path ):
@@ -77,19 +74,23 @@ def getPEVersion(fname):
7774 print (dst64Dir , "doesn't exist, creating..." )
7875 shutil .copytree ("./64" , dst64Dir )
7976shutil .copyfile (src64Path , dst64Path )
80- configPath = dst64Dir + "/config"
81- if os .path .exists (configPath ):
82- print (configPath , "exists, replacing..." )
83- shutil .rmtree (configPath )
84- shutil .copytree ("../config" , configPath )
8577compressDirList .append (dst64Dir )
8678
8779# TODO: GUI+client
8880clientList = [
89- "official-v3.1.0" , "rrg_other-v4.13441" , "rrg_other-v4.14434" ,
90- "rrg_other-v4.14831"
81+ "official-v3.1.0" ,
82+ "rrg_other-v4.13441" ,
83+ "rrg_other-v4.14434" ,
84+ "rrg_other-v4.14831" ,
85+ "rrg_other-v4.15864" ,
9186]
9287
88+ configList = []
89+ for config in os .listdir ("../config" ):
90+ configPath = os .path .join ("../config" , config )
91+ if os .path .isfile (configPath ) and config .endswith (".json" ):
92+ configList .append (config )
93+
9394
9495def generateClient (clientName ):
9596 global compressDirList
@@ -105,12 +106,34 @@ def generateClient(clientName):
105106 shutil .copytree (clientSrcDir , clientDstDir )
106107 shutil .copytree (dst64Dir , clientDstGUIDir )
107108 if "official" in clientName :
108- shutil .copyfile ("./client/GUIsettings_Official.ini" ,
109- clientDstGUIDir + "/GUIsettings.ini" )
109+ shutil .copyfile (
110+ "./client/GUIsettings_Official.ini" , clientDstGUIDir + "/GUIsettings.ini"
111+ )
110112 elif "rrg" in clientName :
111- shutil .copyfile ("./client/GUIsettings_RRG.ini" ,
112- clientDstGUIDir + "/GUIsettings.ini" )
113+ shutil .copyfile (
114+ "./client/GUIsettings_RRG.ini" , clientDstGUIDir + "/GUIsettings.ini"
115+ )
116+ # Use exactly matched configFile if possible
117+ version = clientName [clientName .find ("v" ) :]
118+ for config in configList :
119+ if version in config :
120+ print ("Find matched config file" , config )
121+ with open (
122+ clientDstGUIDir + "/GUIsettings.ini" , "r" , encoding = "utf-8"
123+ ) as f :
124+ data = f .read ()
125+ data = sub (
126+ "configFile=:/config/.+\\ .json" ,
127+ "configFile=:/config/" + config ,
128+ data ,
129+ )
130+ with open (
131+ clientDstGUIDir + "/GUIsettings.ini" , "w" , encoding = "utf-8"
132+ ) as f :
133+ f .write (data )
134+
113135 compressDirList .append (clientDstDir )
136+ return clientDstDir
114137
115138
116139for cl in clientList :
0 commit comments