home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 October / maximum-cd-2011-10.iso / DiscContents / digsby_setup.exe / lib / py2exe / resources / VersionInfo.pyo (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2011-06-22  |  8.4 KB  |  230 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. import struct
  5. VOS_NT_WINDOWS32 = 262148
  6. VFT_APP = 1
  7. RT_VERSION = 16
  8.  
  9. class VersionError(Exception):
  10.     pass
  11.  
  12.  
  13. def w32_uc(text):
  14.     if type(text) is str:
  15.         return unicode(text, 'unicode-escape').encode('utf-16-le')
  16.     return unicode(text).encode('utf-16-le')
  17.  
  18.  
  19. class VS_FIXEDFILEINFO:
  20.     dwSignature = 0xFEEF04BDL
  21.     dwStrucVersion = 65536
  22.     dwFileVersionMS = 65536
  23.     dwFileVersionLS = 1
  24.     dwProductVersionMS = 65536
  25.     dwProductVersionLS = 1
  26.     dwFileFlagsMask = 63
  27.     dwFileFlags = 0
  28.     dwFileOS = VOS_NT_WINDOWS32
  29.     dwFileType = VFT_APP
  30.     dwFileSubtype = 0
  31.     dwFileDateMS = 0
  32.     dwFileDateLS = 0
  33.     fmt = '13L'
  34.     
  35.     def __init__(self, version):
  36.         import string
  37.         version = string.replace(version, ',', '.')
  38.         fields = string.split(version + '.0.0.0.0', '.')[:4]
  39.         fields = map(string.strip, fields)
  40.         
  41.         try:
  42.             self.dwFileVersionMS = int(fields[0]) * 65536 + int(fields[1])
  43.             self.dwFileVersionLS = int(fields[2]) * 65536 + int(fields[3])
  44.         except ValueError:
  45.             raise VersionError, "could not parse version number '%s'" % version
  46.  
  47.  
  48.     
  49.     def __str__(self):
  50.         return struct.pack(self.fmt, self.dwSignature, self.dwStrucVersion, self.dwFileVersionMS, self.dwFileVersionLS, self.dwProductVersionMS, self.dwProductVersionLS, self.dwFileFlagsMask, self.dwFileFlags, self.dwFileOS, self.dwFileType, self.dwFileSubtype, self.dwFileDateMS, self.dwFileDateLS)
  51.  
  52.  
  53.  
  54. def align(data):
  55.     pad = -len(data) % 4
  56.     return data + '\x00' * pad
  57.  
  58.  
  59. class VS_STRUCT:
  60.     items = ()
  61.     
  62.     def __str__(self):
  63.         szKey = w32_uc(self.name)
  64.         ulen = len(szKey) + 2
  65.         value = self.get_value()
  66.         data = struct.pack('h%ss0i' % ulen, self.wType, szKey) + value
  67.         data = align(data)
  68.         for item in self.items:
  69.             data = data + str(item)
  70.         
  71.         wLength = len(data) + 4
  72.         wValueLength = len(value)
  73.         return self.pack('hh', wLength, wValueLength, data)
  74.  
  75.     
  76.     def pack(self, fmt, len, vlen, data):
  77.         return struct.pack(fmt, len, vlen) + data
  78.  
  79.     
  80.     def get_value(self):
  81.         return ''
  82.  
  83.  
  84.  
  85. class String(VS_STRUCT):
  86.     wType = 1
  87.     items = ()
  88.     
  89.     def __init__(self, .1):
  90.         (name, value) = .1
  91.         self.name = name
  92.         if value:
  93.             self.value = value + '\x00'
  94.         else:
  95.             self.value = value
  96.  
  97.     
  98.     def pack(self, fmt, len, vlen, data):
  99.         return struct.pack(fmt, len, vlen / 2) + data
  100.  
  101.     
  102.     def get_value(self):
  103.         return w32_uc(self.value)
  104.  
  105.  
  106.  
  107. class StringTable(VS_STRUCT):
  108.     wType = 1
  109.     
  110.     def __init__(self, name, strings):
  111.         self.name = name
  112.         self.items = map(String, strings)
  113.  
  114.  
  115.  
  116. class StringFileInfo(VS_STRUCT):
  117.     wType = 1
  118.     name = 'StringFileInfo'
  119.     
  120.     def __init__(self, name, strings):
  121.         self.items = [
  122.             StringTable(name, strings)]
  123.  
  124.  
  125.  
  126. class Var(VS_STRUCT):
  127.     wType = 0
  128.     name = 'Translation'
  129.     
  130.     def __init__(self, value):
  131.         self.value = value
  132.  
  133.     
  134.     def get_value(self):
  135.         return struct.pack('l', self.value)
  136.  
  137.  
  138.  
  139. class VarFileInfo(VS_STRUCT):
  140.     wType = 1
  141.     name = 'VarFileInfo'
  142.     
  143.     def __init__(self, *names):
  144.         self.items = map(Var, names)
  145.  
  146.     
  147.     def get_value(self):
  148.         return ''
  149.  
  150.  
  151.  
  152. class VS_VERSIONINFO(VS_STRUCT):
  153.     wType = 0
  154.     name = 'VS_VERSION_INFO'
  155.     
  156.     def __init__(self, version, items):
  157.         self.value = VS_FIXEDFILEINFO(version)
  158.         self.items = items
  159.  
  160.     
  161.     def get_value(self):
  162.         return str(self.value)
  163.  
  164.  
  165.  
  166. class Version(object):
  167.     
  168.     def __init__(self, version, comments = None, company_name = None, file_description = None, internal_name = None, legal_copyright = None, legal_trademarks = None, original_filename = None, private_build = None, product_name = None, product_version = None, special_build = None):
  169.         self.version = version
  170.         strings = []
  171.         if comments is not None:
  172.             strings.append(('Comments', comments))
  173.         
  174.         if company_name is not None:
  175.             strings.append(('CompanyName', company_name))
  176.         
  177.         if file_description is not None:
  178.             strings.append(('FileDescription', file_description))
  179.         
  180.         strings.append(('FileVersion', version))
  181.         if internal_name is not None:
  182.             strings.append(('InternalName', internal_name))
  183.         
  184.         if legal_copyright is not None:
  185.             strings.append(('LegalCopyright', legal_copyright))
  186.         
  187.         if legal_trademarks is not None:
  188.             strings.append(('LegalTrademarks', legal_trademarks))
  189.         
  190.         if original_filename is not None:
  191.             strings.append(('OriginalFilename', original_filename))
  192.         
  193.         if private_build is not None:
  194.             strings.append(('PrivateBuild', private_build))
  195.         
  196.         if product_name is not None:
  197.             strings.append(('ProductName', product_name))
  198.         
  199.         if not product_version:
  200.             pass
  201.         strings.append(('ProductVersion', version))
  202.         if special_build is not None:
  203.             strings.append(('SpecialBuild', special_build))
  204.         
  205.         self.strings = strings
  206.  
  207.     
  208.     def resource_bytes(self):
  209.         vs = VS_VERSIONINFO(self.version, [
  210.             StringFileInfo('040904B0', self.strings),
  211.             VarFileInfo(78644233)])
  212.         return str(vs)
  213.  
  214.  
  215.  
  216. def test():
  217.     import sys
  218.     sys.path.append('c:/tmp')
  219.     hexdump = hexdump
  220.     import hexdump
  221.     version = Version('1, 0, 0, 1', comments = '\xfcml\xe4ut comments', company_name = 'No Company', file_description = 'silly application', internal_name = 'silly', legal_copyright = u'Copyright ┬⌐ 2003', original_filename = 'silly.exe', private_build = 'test build', product_name = 'silly product', product_version = None)
  222.     hexdump(version.resource_bytes())
  223.  
  224. if __name__ == '__main__':
  225.     import sys
  226.     sys.path.append('d:/nbalt/tmp')
  227.     from hexdump import hexdump
  228.     test()
  229.  
  230.