Skip to content

Commit 2798b44

Browse files
committed
Move GSLocalization.h parsing regex pattern to FillLocalizationMappingTable
1 parent 8931e31 commit 2798b44

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

BuildAddOn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def GetProjectGenerationParams (args, workspaceRootFolder, buildPath, platformNa
215215
'-G', GetInstalledVisualStudioGenerator (),
216216
'-T', GetToolset (int (version)),
217217
])
218-
localizationMappingTable = FillLocalizationMappingTable (devkitDir, r'#define\s+VERSION_APPENDIX\s+"([A-Z]+)"[\s\S]*?#define\s+WIN_LANGCHARSET_STR\s+"([^"]+)"')
218+
localizationMappingTable = FillLocalizationMappingTable (devkitDir)
219219
winLangCharsetStr = '040904b0'
220220
if languageCode != 'INT':
221221
winLangCharsetStr = localizationMappingTable.get (languageCode, winLangCharsetStr)

CompileResources.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
class ResourceCompiler (object):
1818
def __init__ (self, devKitPath: Path, acVersion: str, buildNum: str, addonName: str, languageCode: str, defaultLanguageCode: str,
19-
pattern: str, sourcesPath: Path, resourcesPath: Path, resourceObjectsPath: Path, permissiveLocalization: bool):
19+
sourcesPath: Path, resourcesPath: Path, resourceObjectsPath: Path, permissiveLocalization: bool):
2020
self.devKitPath = devKitPath
2121
self.acVersion = acVersion
2222
self.buildNum = buildNum
@@ -29,7 +29,7 @@ def __init__ (self, devKitPath: Path, acVersion: str, buildNum: str, addonName:
2929
self.permissiveLocalization = permissiveLocalization
3030
self.resConvPath = None
3131
self.nativeResourceFileExtension = None
32-
self.localizationMappingTable = FillLocalizationMappingTable (devKitPath, pattern)
32+
self.localizationMappingTable = FillLocalizationMappingTable (devKitPath)
3333

3434
def GetPlatformDevKitLinkKey (self) -> str:
3535
return ""
@@ -259,7 +259,7 @@ def RunResConv (self, platformSign: str, codepage: str, inputFilePath: Path) ->
259259
class WinResourceCompiler (ResourceCompiler):
260260
def __init__ (self, devKitPath: Path, acVersion: str, buildNum: str, addonName: str, languageCode: str, defaultLanguageCode: str, sourcesPath: Path, resourcesPath: Path, resourceObjectsPath: Path, permissiveLocalization: bool):
261261
super (WinResourceCompiler, self).__init__ (devKitPath, acVersion, buildNum, addonName, languageCode, defaultLanguageCode,
262-
r'#define\s+VERSION_APPENDIX\s+"([A-Z]+)"[\s\S]*?#define\s+WIN_LANGCHARSET_STR\s+"([^"]+)"', sourcesPath, resourcesPath, resourceObjectsPath, permissiveLocalization)
262+
sourcesPath, resourcesPath, resourceObjectsPath, permissiveLocalization)
263263
self.resConvPath = devKitPath / 'Tools' / 'Win' / 'ResConv.exe'
264264
self.nativeResourceFileExtension = '.rc2'
265265

@@ -332,7 +332,7 @@ def CompileNativeResource (self, resultResourcePath: Path) -> None:
332332
class MacResourceCompiler (ResourceCompiler):
333333
def __init__ (self, devKitPath: Path, acVersion: str, buildNum: str, addonName: str, languageCode: str, defaultLanguageCode: str, sourcesPath: Path, resourcesPath: Path, resourceObjectsPath: Path, permissiveLocalization: bool):
334334
super (MacResourceCompiler, self).__init__ (devKitPath, acVersion, buildNum, addonName, languageCode, defaultLanguageCode,
335-
r'#define\s+VERSION_APPENDIX\s+"([A-Z]+)"[\s\S]*?#define\s+MAC_REGION_NAME\s+"([^"]+)"', sourcesPath, resourcesPath, resourceObjectsPath, permissiveLocalization)
335+
sourcesPath, resourcesPath, resourceObjectsPath, permissiveLocalization)
336336
self.resConvPath = devKitPath / 'Tools' / 'OSX' / 'ResConv'
337337
self.nativeResourceFileExtension = '.ro'
338338

LocalizationMappingTable.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1+
import platform
12
import re
23

3-
def FillLocalizationMappingTable (devKitPath, pattern: str) -> str:
4+
5+
def FillLocalizationMappingTable (devKitPath) -> str:
46
# Dynamically generate a mapping table from GSLocalization.h
7+
pattern = None
8+
system = platform.system ()
9+
if system == 'Windows':
10+
pattern = r'#define\s+VERSION_APPENDIX\s+"([A-Z]+)"[\s\S]*?#define\s+WIN_LANGCHARSET_STR\s+"([^"]+)"'
11+
elif system == 'Darwin':
12+
pattern = r'#define\s+VERSION_APPENDIX\s+"([A-Z]+)"[\s\S]*?#define\s+MAC_REGION_NAME\s+"([^"]+)"'
13+
14+
assert pattern, 'Platform is not supported'
15+
516
gsLocalizationPath = devKitPath / 'Inc' / 'GSLocalization.h'
617
with open(gsLocalizationPath, 'r', encoding='utf-8') as f:
718
gsLocalizationContent = f.read ()

0 commit comments

Comments
 (0)