2015-02-13 15:25:13 +01:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
from __future__ import with_statement
|
|
|
|
|
2015-02-21 03:27:13 +01:00
|
|
|
import re
|
|
|
|
import sys
|
2015-02-13 15:25:13 +01:00
|
|
|
|
|
|
|
|
2015-02-21 03:27:13 +01:00
|
|
|
def parse_args():
|
|
|
|
def usage():
|
2015-03-26 09:20:27 +01:00
|
|
|
sys.stderr.write('Usage: verinfo.py [-b mame|mess|ume|ldplayer] [-r|-p] [-o <outfile>] <srcfile>\n')
|
2015-02-21 03:27:13 +01:00
|
|
|
sys.exit(1)
|
2015-02-13 15:25:13 +01:00
|
|
|
|
2015-02-21 03:27:13 +01:00
|
|
|
flags = True
|
|
|
|
target = 'mame'
|
2015-02-22 00:37:25 +01:00
|
|
|
format = 'rc'
|
2015-02-21 03:27:13 +01:00
|
|
|
input = None
|
2015-02-22 00:37:25 +01:00
|
|
|
output = None
|
2015-02-21 03:27:13 +01:00
|
|
|
i = 1
|
|
|
|
while i < len(sys.argv):
|
|
|
|
if flags and (sys.argv[i] == '-r'):
|
2015-02-22 00:37:25 +01:00
|
|
|
format = 'rc'
|
2015-02-21 03:27:13 +01:00
|
|
|
elif flags and (sys.argv[i] == '-p'):
|
2015-02-22 00:37:25 +01:00
|
|
|
format = 'plist'
|
2015-02-21 03:27:13 +01:00
|
|
|
elif flags and (sys.argv[i] == '-b'):
|
2015-03-05 16:24:05 +01:00
|
|
|
i += 1
|
2015-03-26 09:20:27 +01:00
|
|
|
if (i >= len(sys.argv)) or (sys.argv[i] not in ('mame', 'mess', 'ume', 'ldplayer')):
|
2015-02-21 03:27:13 +01:00
|
|
|
usage()
|
|
|
|
else:
|
|
|
|
target = sys.argv[i]
|
2015-02-22 00:37:25 +01:00
|
|
|
elif flags and (sys.argv[i] == '-o'):
|
2015-03-05 16:24:05 +01:00
|
|
|
i += 1
|
2015-02-22 00:37:25 +01:00
|
|
|
if (i >= len(sys.argv)) or (output is not None):
|
|
|
|
usage()
|
|
|
|
else:
|
|
|
|
output = sys.argv[i]
|
2015-02-21 03:27:13 +01:00
|
|
|
elif flags and (sys.argv[i] == '--'):
|
|
|
|
flags = False
|
|
|
|
elif flags and sys.argv[i].startswith('-'):
|
|
|
|
usage()
|
|
|
|
elif input is not None:
|
|
|
|
usage()
|
|
|
|
else:
|
|
|
|
input = sys.argv[i]
|
|
|
|
i += 1
|
|
|
|
if input is None:
|
|
|
|
usage()
|
2015-02-22 00:37:25 +01:00
|
|
|
return target, format, input, output
|
2015-02-21 03:27:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
def extract_version(input):
|
|
|
|
pattern = re.compile('\s+BARE_BUILD_VERSION\s+"(([^."]+)\.([^."]+))"')
|
|
|
|
for line in input.readlines():
|
|
|
|
match = pattern.search(line)
|
|
|
|
if match:
|
|
|
|
return match.group(1), match.group(2), match.group(3)
|
|
|
|
return None, None, None
|
|
|
|
|
|
|
|
|
2015-02-22 00:37:25 +01:00
|
|
|
build, outfmt, srcfile, dstfile = parse_args()
|
2015-02-13 15:25:13 +01:00
|
|
|
|
|
|
|
try:
|
2015-02-22 00:37:25 +01:00
|
|
|
fp = open(srcfile, 'rU')
|
2015-02-13 15:25:13 +01:00
|
|
|
except IOError:
|
2015-02-21 03:27:13 +01:00
|
|
|
sys.stderr.write("Unable to open source file '%s'\n" % srcfile)
|
|
|
|
sys.exit(1)
|
2015-02-13 15:25:13 +01:00
|
|
|
|
2015-02-21 03:27:13 +01:00
|
|
|
version_string, version_major, version_minor = extract_version(fp)
|
2015-02-13 15:25:13 +01:00
|
|
|
version_build = "0"
|
|
|
|
version_subbuild = "0"
|
2015-02-21 03:27:13 +01:00
|
|
|
if not version_string:
|
|
|
|
sys.stderr.write("Unable to extract version from source file '%s'\n" % srcfile)
|
|
|
|
sys.exit(1)
|
2015-02-22 00:37:25 +01:00
|
|
|
fp.close()
|
|
|
|
|
|
|
|
if dstfile is not None:
|
|
|
|
try:
|
|
|
|
fp = open(dstfile, 'w')
|
|
|
|
except IOError:
|
|
|
|
sys.stderr.write("Unable to open output file '%s'\n" % dstfile)
|
|
|
|
sys.exit(1)
|
|
|
|
else:
|
|
|
|
fp = sys.stdout
|
2015-02-21 03:27:13 +01:00
|
|
|
|
|
|
|
if build == "mess":
|
2015-02-13 15:25:13 +01:00
|
|
|
# MESS
|
2015-02-27 04:16:59 +01:00
|
|
|
author = "MESS Team"
|
|
|
|
comments = "Multi Emulation Super System"
|
|
|
|
company_name = "MESS Team"
|
|
|
|
file_description = "Multi Emulation Super System"
|
|
|
|
internal_name = "MESS"
|
|
|
|
original_filename = "MESS"
|
|
|
|
product_name = "MESS"
|
2015-02-21 03:27:13 +01:00
|
|
|
bundle_identifier = "org.mamedev.mess"
|
|
|
|
elif build == "ume":
|
2015-02-13 15:25:13 +01:00
|
|
|
# UME
|
|
|
|
author = "MAME and MESS Team"
|
|
|
|
comments = "Universal Machine Emulator"
|
|
|
|
company_name = "MAME and MESS Team"
|
|
|
|
file_description = "Universal Machine Emulator"
|
|
|
|
internal_name = "UME"
|
|
|
|
original_filename = "UME"
|
|
|
|
product_name = "UME"
|
2015-02-21 03:27:13 +01:00
|
|
|
bundle_identifier = "org.mamedev.ume"
|
|
|
|
else:
|
2015-02-13 15:25:13 +01:00
|
|
|
# MAME
|
|
|
|
author = "Nicola Salmoria and the MAME Team"
|
|
|
|
comments = "Multiple Arcade Machine Emulator"
|
|
|
|
company_name = "MAME Team"
|
|
|
|
file_description = "Multiple Arcade Machine Emulator"
|
|
|
|
internal_name = "MAME"
|
|
|
|
original_filename = "MAME"
|
|
|
|
product_name = "MAME"
|
2015-02-21 03:27:13 +01:00
|
|
|
bundle_identifier = "org.mamedev.mame"
|
2015-02-13 15:25:13 +01:00
|
|
|
|
|
|
|
legal_copyright = "Copyright Nicola Salmoria and the MAME team"
|
|
|
|
|
2015-02-21 03:27:13 +01:00
|
|
|
if outfmt == 'rc':
|
2015-02-22 00:37:25 +01:00
|
|
|
fp.write('VS_VERSION_INFO VERSIONINFO\n')
|
|
|
|
fp.write('\tFILEVERSION %s,%s,%s,%s\n' % (version_major, version_minor, version_build, version_subbuild))
|
|
|
|
fp.write('\tPRODUCTVERSION %s,%s,%s,%s\n' % (version_major, version_minor, version_build, version_subbuild))
|
|
|
|
fp.write('\tFILEFLAGSMASK 0x3fL\n')
|
2015-03-05 16:38:07 +01:00
|
|
|
if version_build == 0:
|
2015-02-22 00:37:25 +01:00
|
|
|
fp.write('\tFILEFLAGS 0x0L\n')
|
|
|
|
else:
|
|
|
|
fp.write('\tFILEFLAGS VS_FF_PRERELEASE\n')
|
|
|
|
fp.write('\tFILEOS VOS_NT_WINDOWS32\n')
|
|
|
|
fp.write('\tFILETYPE VFT_APP\n')
|
|
|
|
fp.write('\tFILESUBTYPE VFT2_UNKNOWN\n')
|
|
|
|
fp.write('BEGIN\n')
|
|
|
|
fp.write('\tBLOCK "StringFileInfo"\n')
|
|
|
|
fp.write('\tBEGIN\n')
|
|
|
|
fp.write('#ifdef UNICODE\n')
|
|
|
|
fp.write('\t\tBLOCK "040904b0"\n')
|
|
|
|
fp.write('#else\n')
|
|
|
|
fp.write('\t\tBLOCK "040904E4"\n')
|
|
|
|
fp.write('#endif\n')
|
|
|
|
fp.write('\t\tBEGIN\n')
|
|
|
|
fp.write('\t\t\tVALUE "Author", "%s\\0"\n' % author)
|
|
|
|
fp.write('\t\t\tVALUE "Comments", "%s\\0"\n' % comments)
|
|
|
|
fp.write('\t\t\tVALUE "CompanyName", "%s\\0"\n' % company_name)
|
|
|
|
fp.write('\t\t\tVALUE "FileDescription", "%s\\0"\n' % file_description)
|
|
|
|
fp.write('\t\t\tVALUE "FileVersion", "%s, %s, %s, %s\\0"\n' % (version_major, version_minor, version_build, version_subbuild))
|
|
|
|
fp.write('\t\t\tVALUE "InternalName", "%s\\0"\n' % internal_name)
|
|
|
|
fp.write('\t\t\tVALUE "LegalCopyright", "%s\\0"\n' % legal_copyright)
|
|
|
|
fp.write('\t\t\tVALUE "OriginalFilename", "%s\\0"\n' % original_filename)
|
|
|
|
fp.write('\t\t\tVALUE "ProductName", "%s\\0"\n' % product_name)
|
|
|
|
fp.write('\t\t\tVALUE "ProductVersion", "%s\\0"\n' % version_string)
|
|
|
|
fp.write('\t\tEND\n')
|
|
|
|
fp.write('\tEND\n')
|
|
|
|
fp.write('\tBLOCK "VarFileInfo"\n')
|
|
|
|
fp.write('\tBEGIN\n')
|
|
|
|
fp.write('#ifdef UNICODE\n')
|
|
|
|
fp.write('\t\tVALUE "Translation", 0x409, 1200\n')
|
|
|
|
fp.write('#else\n')
|
|
|
|
fp.write('\t\tVALUE "Translation", 0x409, 1252\n')
|
|
|
|
fp.write('#endif\n')
|
|
|
|
fp.write('\tEND\n')
|
|
|
|
fp.write('END\n')
|
2015-02-21 03:27:13 +01:00
|
|
|
elif outfmt == 'plist':
|
2015-02-22 00:37:25 +01:00
|
|
|
fp.write('<?xml version="1.0" encoding="UTF-8"?>\n')
|
|
|
|
fp.write('<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n')
|
|
|
|
fp.write('<plist version="1.0">\n')
|
|
|
|
fp.write('<dict>\n')
|
|
|
|
fp.write('\t<key>CFBundleDisplayName</key>\n')
|
|
|
|
fp.write('\t<string>%s</string>\n' % product_name)
|
|
|
|
fp.write('\t<key>CFBundleIdentifier</key>\n')
|
|
|
|
fp.write('\t<string>%s</string>\n' % bundle_identifier)
|
|
|
|
fp.write('\t<key>CFBundleInfoDictionaryVersion</key>\n')
|
|
|
|
fp.write('\t<string>6.0</string>\n')
|
|
|
|
fp.write('\t<key>CFBundleName</key>\n')
|
|
|
|
fp.write('\t<string>%s</string>\n' % product_name)
|
|
|
|
fp.write('\t<key>CFBundleShortVersionString</key>\n')
|
|
|
|
fp.write('\t<string>%s.%s.%s</string>\n' % (version_major, version_minor, version_build))
|
|
|
|
fp.write('</dict>\n')
|
|
|
|
fp.write('</plist>\n')
|
|
|
|
fp.flush()
|