|
| 1 | +import os, sys, shutil |
| 2 | +from win32api import GetFileVersionInfo |
| 3 | +from json import load |
| 4 | +from re import fullmatch, IGNORECASE |
| 5 | + |
| 6 | + |
| 7 | +def getPEVersion(fname): |
| 8 | + try: |
| 9 | + fileInfo = GetFileVersionInfo(fname, '\\') |
| 10 | + version = "V%d.%d.%d" % (fileInfo['FileVersionMS'] / 65536, |
| 11 | + fileInfo['FileVersionMS'] % 65536, |
| 12 | + fileInfo['FileVersionLS'] / 65536) |
| 13 | + except Exception: |
| 14 | + print("Cannot get version number of", fname) |
| 15 | + return version |
| 16 | + |
| 17 | + |
| 18 | +os.chdir(sys.path[0]) |
| 19 | +print("Current Directory:", os.getcwd()) |
| 20 | +targetName = os.path.abspath(os.getcwd()).split('\\')[-2] |
| 21 | +print("Target Name", targetName) |
| 22 | + |
| 23 | +src32Dir = "" |
| 24 | +src64Dir = "" |
| 25 | +dirList = os.listdir("../") |
| 26 | + |
| 27 | +for i in dirList: |
| 28 | + if not os.path.isdir("../" + i): |
| 29 | + continue |
| 30 | + if not i.startswith("build"): |
| 31 | + continue |
| 32 | + |
| 33 | + if i.endswith("32_bit-Release"): |
| 34 | + src32Dir = "../" + i |
| 35 | + elif i.endswith("64_bit-Release"): |
| 36 | + src64Dir = "../" + i |
| 37 | + |
| 38 | +src32Path = src32Dir + "/release/" + targetName + ".exe" |
| 39 | +src64Path = src64Dir + "/release/" + targetName + ".exe" |
| 40 | +print("Target Files:") |
| 41 | +print(src32Path) |
| 42 | +print(src64Path) |
| 43 | + |
| 44 | +ver32 = getPEVersion(src32Path) |
| 45 | +ver64 = getPEVersion(src64Path) |
| 46 | +print("Versions:") |
| 47 | +print("win32:", ver32) |
| 48 | +print("win64:", ver64) |
| 49 | +if ver32 != ver64: |
| 50 | + print("WARNING!") |
| 51 | + print("Version names are not the same!") |
| 52 | +dst32Dir = "./" + ver32 + "-win32" |
| 53 | +dst64Dir = "./" + ver64 + "-win64" |
| 54 | +dst32Path = dst32Dir + "/" + targetName + ".exe" |
| 55 | +dst64Path = dst64Dir + "/" + targetName + ".exe" |
| 56 | + |
| 57 | +if os.path.exists(dst32Dir) and os.path.exists(dst32Path): |
| 58 | + print(dst32Path, "exists, replacing...") |
| 59 | + os.remove(dst32Path) |
| 60 | +elif not os.path.exists(dst32Dir): |
| 61 | + print(dst32Dir, "doesn't exist, creating...") |
| 62 | + shutil.copytree("./32", dst32Dir) |
| 63 | +shutil.copyfile(src32Path, dst32Path) |
| 64 | +configPath = dst32Dir + "/config" |
| 65 | +if os.path.exists(configPath): |
| 66 | + print(configPath, "exists, replacing...") |
| 67 | + shutil.rmtree(configPath) |
| 68 | +shutil.copytree("../config", configPath) |
| 69 | + |
| 70 | +if os.path.exists(dst64Dir) and os.path.exists(dst64Path): |
| 71 | + print(dst64Path, "exists, replacing...") |
| 72 | + os.remove(dst64Path) |
| 73 | +elif not os.path.exists(dst64Dir): |
| 74 | + print(dst64Dir, "doesn't exist, creating...") |
| 75 | + shutil.copytree("./64", dst64Dir) |
| 76 | +shutil.copyfile(src64Path, dst64Path) |
| 77 | +configPath = dst64Dir + "/config" |
| 78 | +if os.path.exists(configPath): |
| 79 | + print(configPath, "exists, replacing...") |
| 80 | + shutil.rmtree(configPath) |
| 81 | +shutil.copytree("../config", configPath) |
| 82 | + |
| 83 | +# TODO: GUI+client |
| 84 | + |
| 85 | +use7z = input("Compress?(y/N)") |
| 86 | +if fullmatch("yes|y", use7z, IGNORECASE): |
| 87 | + archive32Path = dst32Dir + ".7z" |
| 88 | + archive64Path = dst64Dir + ".7z" |
| 89 | + |
| 90 | + if os.path.exists(archive32Path): |
| 91 | + print(archive32Path, "exists, replacing...") |
| 92 | + os.remove(archive32Path) |
| 93 | + os.system("7z a -t7z -mmt8 -mx9 " + archive32Path + " " + dst32Dir) |
| 94 | + |
| 95 | + if os.path.exists(archive64Path): |
| 96 | + print(archive64Path, "exists, replacing...") |
| 97 | + os.remove(archive64Path) |
| 98 | + os.system("7z a -t7z -mmt8 -mx9 " + archive64Path + " " + dst64Dir) |
0 commit comments