我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用win32api.BeginUpdateResource()。
def SetVersion(exenm, versionfile): if isinstance(versionfile, VSVersionInfo): vs = versionfile else: fp = codecs.open(versionfile, 'rU', 'utf-8') txt = fp.read() fp.close() vs = eval(txt) hdst = win32api.BeginUpdateResource(exenm, 0) win32api.UpdateResource(hdst, pefile.RESOURCE_TYPE['RT_VERSION'], 1, vs.toRaw()) win32api.EndUpdateResource (hdst, 0)
def UpdateResources(dstpath, data, type_, names=None, languages=None): """ Update or add resource data in dll/exe file dstpath. type_ = resource type to update names = a list of resource names to update (None = all) languages = a list of resource languages to update (None = all) """ # Look for existing resources. res = GetResources(dstpath, [type_], names, languages) # add type_, names and languages not already present in existing resources if not type_ in res and type_ != "*": res[type_] = {} if names: for name in names: if not name in res[type_] and name != "*": res[type_][name] = [] if languages: for language in languages: if not language in res[type_][name] and language != "*": res[type_][name].append(language) # add resource to destination, overwriting existing resources hdst = win32api.BeginUpdateResource(dstpath, 0) for type_ in res: for name in res[type_]: for language in res[type_][name]: logger.info("Updating resource type %s name %s language %s", type_, name, language) win32api.UpdateResource(hdst, type_, name, data.encode('UTF-8'), language) win32api.EndUpdateResource(hdst, 0)
def stamp(pathname, options): # For some reason, the API functions report success if the file is open # but doesnt work! Try and open the file for writing, just to see if it is # likely the stamp will work! try: f = open(pathname, "a+b") f.close() except IOError, why: print "WARNING: File %s could not be opened - %s" % (pathname, why) ver = options.version try: bits = [int(i) for i in ver.split(".")] vmaj, vmin, vsub, vbuild = bits except (IndexError, TypeError, ValueError): raise ValueError("--version must be a.b.c.d (all integers) - got %r" % ver) ifn = options.internal_name if not ifn: ifn = os.path.basename(pathname) ofn = options.original_filename if not ofn: ofn = os.path.basename(pathname) sdata = { 'Comments' : options.comments, 'CompanyName' : options.company, 'FileDescription' : options.description, 'FileVersion' : ver, 'InternalName' : ifn, 'LegalCopyright' : options.copyright, 'LegalTrademarks' : options.trademarks, 'OriginalFilename' : ofn, 'ProductName' : options.product, 'ProductVersion' : ver, } vdata = { 'Translation' : struct.pack('hh', 0x409,1252), } is_dll = options.dll if is_dll is None: is_dll = os.path.splitext(pathname)[1].lower() in '.dll .pyd'.split() is_debug = options.debug if is_debug is None: is_debug = os.path.splitext(pathname)[0].lower().endswith("_d") # convert None to blank strings for k, v in sdata.items(): if v is None: sdata[k] = "" vs = VS_VERSION_INFO(vmaj, vmin, vsub, vbuild, sdata, vdata, is_debug, is_dll) h = BeginUpdateResource(pathname, 0) UpdateResource(h, 16, 1, vs) EndUpdateResource(h, 0) if options.verbose: print "Stamped:", pathname
def stamp(pathname, options): # For some reason, the API functions report success if the file is open # but doesnt work! Try and open the file for writing, just to see if it is # likely the stamp will work! try: f = open(pathname, "a+b") f.close() except IOError, why: print "WARNING: File %s could not be opened - %s" % (pathname, why) ver = options.version try: bits = [int(i) for i in ver.split(".")] vmaj, vmin, vsub, vbuild = bits except (IndexError, TypeError, ValueError): raise ValueError("--version must be a.b.c.d (all integers) - got %r" % ver) ifn = options.internal_name if not ifn: ifn = os.path.basename(pathname) ofn = options.original_filename if ofn is None: ofn = os.path.basename(pathname) sdata = { 'Comments' : options.comments, 'CompanyName' : options.company, 'FileDescription' : options.description, 'FileVersion' : ver, 'InternalName' : ifn, 'LegalCopyright' : options.copyright, 'LegalTrademarks' : options.trademarks, 'OriginalFilename' : ofn, 'ProductName' : options.product, 'ProductVersion' : ver, } vdata = { 'Translation' : struct.pack('hh', 0x409,1252), } is_dll = options.dll if is_dll is None: is_dll = os.path.splitext(pathname)[1].lower() in '.dll .pyd'.split() is_debug = options.debug if is_debug is None: is_debug = os.path.splitext(pathname)[0].lower().endswith("_d") # convert None to blank strings for k, v in sdata.items(): if v is None: sdata[k] = "" vs = VS_VERSION_INFO(vmaj, vmin, vsub, vbuild, sdata, vdata, is_debug, is_dll) h = BeginUpdateResource(pathname, 0) UpdateResource(h, 16, 1, vs) EndUpdateResource(h, 0) if options.verbose: print "Stamped:", pathname
def stamp(pathname, options): # For some reason, the API functions report success if the file is open # but doesnt work! Try and open the file for writing, just to see if it is # likely the stamp will work! try: f = open(pathname, "a+b") f.close() except IOError as why: print("WARNING: File %s could not be opened - %s" % (pathname, why)) ver = options.version try: bits = [int(i) for i in ver.split(".")] vmaj, vmin, vsub, vbuild = bits except (IndexError, TypeError, ValueError): raise ValueError("--version must be a.b.c.d (all integers) - got %r" % ver) ifn = options.internal_name if not ifn: ifn = os.path.basename(pathname) ofn = options.original_filename if ofn is None: ofn = os.path.basename(pathname) sdata = { 'Comments' : options.comments, 'CompanyName' : options.company, 'FileDescription' : options.description, 'FileVersion' : ver, 'InternalName' : ifn, 'LegalCopyright' : options.copyright, 'LegalTrademarks' : options.trademarks, 'OriginalFilename' : ofn, 'ProductName' : options.product, 'ProductVersion' : ver, } vdata = { 'Translation' : struct.pack('hh', 0x409,1252), } is_dll = options.dll if is_dll is None: is_dll = os.path.splitext(pathname)[1].lower() in '.dll .pyd'.split() is_debug = options.debug if is_debug is None: is_debug = os.path.splitext(pathname)[0].lower().endswith("_d") # convert None to blank strings for k, v in list(sdata.items()): if v is None: sdata[k] = "" vs = VS_VERSION_INFO(vmaj, vmin, vsub, vbuild, sdata, vdata, is_debug, is_dll) h = BeginUpdateResource(pathname, 0) UpdateResource(h, 16, 1, vs) EndUpdateResource(h, 0) if options.verbose: print("Stamped:", pathname)