1
1
import os , sys , shutil
2
2
from win32api import GetFileVersionInfo
3
3
from json import load
4
- from re import fullmatch , IGNORECASE
4
+ from re import fullmatch , sub , IGNORECASE
5
5
6
6
compressDirList = []
7
7
8
8
9
9
def getPEVersion (fname ):
10
10
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
+ )
15
17
except Exception :
16
18
print ("Cannot get version number of" , fname )
17
19
return version
18
20
19
21
20
22
os .chdir (sys .path [0 ])
21
23
print ("Current Directory:" , os .getcwd ())
22
- targetName = os .path .abspath (os .getcwd ()).split (' \\ ' )[- 2 ]
24
+ targetName = os .path .abspath (os .getcwd ()).split (" \\ " )[- 2 ]
23
25
print ("Target Name" , targetName )
24
26
25
27
src32Dir = ""
@@ -63,11 +65,6 @@ def getPEVersion(fname):
63
65
print (dst32Dir , "doesn't exist, creating..." )
64
66
shutil .copytree ("./32" , dst32Dir )
65
67
shutil .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 )
71
68
compressDirList .append (dst32Dir )
72
69
73
70
if os .path .exists (dst64Dir ) and os .path .exists (dst64Path ):
@@ -77,19 +74,23 @@ def getPEVersion(fname):
77
74
print (dst64Dir , "doesn't exist, creating..." )
78
75
shutil .copytree ("./64" , dst64Dir )
79
76
shutil .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 )
85
77
compressDirList .append (dst64Dir )
86
78
87
79
# TODO: GUI+client
88
80
clientList = [
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" ,
91
86
]
92
87
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
+
93
94
94
95
def generateClient (clientName ):
95
96
global compressDirList
@@ -105,12 +106,34 @@ def generateClient(clientName):
105
106
shutil .copytree (clientSrcDir , clientDstDir )
106
107
shutil .copytree (dst64Dir , clientDstGUIDir )
107
108
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
+ )
110
112
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
+
113
135
compressDirList .append (clientDstDir )
136
+ return clientDstDir
114
137
115
138
116
139
for cl in clientList :
0 commit comments