|
| 1 | +# Created with python 3.11.4 |
| 2 | + |
| 3 | +import glob |
| 4 | +import os |
| 5 | + |
| 6 | + |
| 7 | +def modifyLine(line: str) -> str: |
| 8 | + searchWords = [ |
| 9 | + "DEBUG_LOG", |
| 10 | + "DEBUG_LOG_LEVEL", |
| 11 | + "DEBUG_CRASH", |
| 12 | + "DEBUG_ASSERTLOG", |
| 13 | + "DEBUG_ASSERTCRASH", |
| 14 | + "RELEASE_CRASH", |
| 15 | + "RELEASE_CRASHLOCALIZED", |
| 16 | + "WWDEBUG_SAY", |
| 17 | + "WWDEBUG_WARNING", |
| 18 | + "WWRELEASE_SAY", |
| 19 | + "WWRELEASE_WARNING", |
| 20 | + "WWRELEASE_ERROR", |
| 21 | + "WWASSERT_PRINT", |
| 22 | + "WWDEBUG_ERROR", |
| 23 | + "SNAPSHOT_SAY", |
| 24 | + "SHATTER_DEBUG_SAY", |
| 25 | + "DBGMSG", |
| 26 | + "REALLY_VERBOSE_LOG", |
| 27 | + "DOUBLE_DEBUG", |
| 28 | + "PERF_LOG", |
| 29 | + "CRCGEN_LOG", |
| 30 | + "STATECHANGED_LOG", |
| 31 | + "PING_LOG", |
| 32 | + "BONEPOS_LOG", |
| 33 | + ] |
| 34 | + |
| 35 | + SEARCH_PATTERNS = [ |
| 36 | + r'\r\n"', |
| 37 | + r'\n"', |
| 38 | + ] |
| 39 | + |
| 40 | + for searchWord in searchWords: |
| 41 | + wordBegin = line.find(searchWord) |
| 42 | + wordEnd = wordBegin + len(searchWord) |
| 43 | + |
| 44 | + if wordBegin >= 0: |
| 45 | + for searchPattern in SEARCH_PATTERNS: |
| 46 | + searchPatternLen = len(searchPattern) |
| 47 | + i = wordEnd |
| 48 | + lookEnd = len(line) - searchPatternLen |
| 49 | + |
| 50 | + while i < lookEnd: |
| 51 | + pattern = line[i:i+searchPatternLen] |
| 52 | + if pattern == searchPattern: |
| 53 | + lineCopy = line[:i] + '"' + line[i+searchPatternLen:] |
| 54 | + return lineCopy |
| 55 | + i += 1 |
| 56 | + |
| 57 | + break |
| 58 | + |
| 59 | + return line |
| 60 | + |
| 61 | + |
| 62 | +def main(): |
| 63 | + current_dir = os.path.dirname(os.path.abspath(__file__)) |
| 64 | + root_dir = os.path.join(current_dir, "..", "..") |
| 65 | + root_dir = os.path.normpath(root_dir) |
| 66 | + core_dir = os.path.join(root_dir, "Core") |
| 67 | + generals_dir = os.path.join(root_dir, "Generals") |
| 68 | + generalsmd_dir = os.path.join(root_dir, "GeneralsMD") |
| 69 | + fileNames = [] |
| 70 | + fileNames.extend(glob.glob(os.path.join(core_dir, '**', '*.h'), recursive=True)) |
| 71 | + fileNames.extend(glob.glob(os.path.join(core_dir, '**', '*.cpp'), recursive=True)) |
| 72 | + fileNames.extend(glob.glob(os.path.join(core_dir, '**', '*.inl'), recursive=True)) |
| 73 | + fileNames.extend(glob.glob(os.path.join(generals_dir, '**', '*.h'), recursive=True)) |
| 74 | + fileNames.extend(glob.glob(os.path.join(generals_dir, '**', '*.cpp'), recursive=True)) |
| 75 | + fileNames.extend(glob.glob(os.path.join(generals_dir, '**', '*.inl'), recursive=True)) |
| 76 | + fileNames.extend(glob.glob(os.path.join(generalsmd_dir, '**', '*.h'), recursive=True)) |
| 77 | + fileNames.extend(glob.glob(os.path.join(generalsmd_dir, '**', '*.cpp'), recursive=True)) |
| 78 | + fileNames.extend(glob.glob(os.path.join(generalsmd_dir, '**', '*.inl'), recursive=True)) |
| 79 | + |
| 80 | + for fileName in fileNames: |
| 81 | + with open(fileName, 'r', encoding="cp1252") as file: |
| 82 | + try: |
| 83 | + lines = file.readlines() |
| 84 | + except UnicodeDecodeError: |
| 85 | + continue # Not good. |
| 86 | + with open(fileName, 'w', encoding="cp1252") as file: |
| 87 | + for line in lines: |
| 88 | + line = modifyLine(line) |
| 89 | + file.write(line) |
| 90 | + |
| 91 | + return |
| 92 | + |
| 93 | + |
| 94 | +if __name__ == "__main__": |
| 95 | + main() |
0 commit comments