home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_2440 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  3.1 KB  |  73 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import win32file
  5. import win32api
  6. import win32con
  7. from win32com import storagecon
  8. import pythoncom
  9. import pywintypes
  10. import struct
  11. import traceback
  12. stream_types = {
  13.     win32con.BACKUP_DATA: 'Standard data',
  14.     win32con.BACKUP_EA_DATA: 'Extended attribute data',
  15.     win32con.BACKUP_SECURITY_DATA: 'Security descriptor data',
  16.     win32con.BACKUP_ALTERNATE_DATA: 'Alternative data streams',
  17.     win32con.BACKUP_LINK: 'Hard link information',
  18.     win32con.BACKUP_PROPERTY_DATA: 'Property data',
  19.     win32con.BACKUP_OBJECT_ID: 'Objects identifiers',
  20.     win32con.BACKUP_REPARSE_DATA: 'Reparse points',
  21.     win32con.BACKUP_SPARSE_BLOCK: 'Sparse file' }
  22. tempdir = win32api.GetTempPath()
  23. tempfile = win32api.GetTempFileName(tempdir, 'bkr')[0]
  24. print 'Filename:', tempfile
  25. f = open(tempfile, 'w')
  26. f.write('some random junk' + 'x' * 100)
  27. f.close()
  28. f = open(tempfile + ':streamdata', 'w')
  29. f.write('data written to alternate stream' + 'y' * 100)
  30. f.close()
  31. f = open(tempfile + ':anotherstream', 'w')
  32. f.write('z' * 200)
  33. f.close()
  34. m = storagecon.STGM_READWRITE | storagecon.STGM_SHARE_EXCLUSIVE | storagecon.STGM_DIRECT
  35. pss = pythoncom.StgOpenStorageEx(tempfile, m, storagecon.STGFMT_FILE, 0, pythoncom.IID_IPropertySetStorage, None)
  36. ps = pss.Create(pythoncom.FMTID_SummaryInformation, pythoncom.IID_IPropertyStorage, 0, storagecon.STGM_READWRITE | storagecon.STGM_SHARE_EXCLUSIVE)
  37. ps.WriteMultiple((storagecon.PIDSI_KEYWORDS, storagecon.PIDSI_COMMENTS), ('keywords', 'comments'))
  38. ps = None
  39. pss = None
  40. sa = pywintypes.SECURITY_ATTRIBUTES()
  41. sa.bInheritHandle = False
  42. h = win32file.CreateFile(tempfile, win32con.GENERIC_ALL, win32con.FILE_SHARE_READ, sa, win32con.OPEN_EXISTING, win32file.FILE_FLAG_BACKUP_SEMANTICS, None)
  43. win32_stream_id_format = 'LLQL'
  44. win32_stream_id_size = struct.calcsize(win32_stream_id_format)
  45.  
  46. def parse_stream_header(h, ctxt, data):
  47.     (stream_type, stream_attributes, stream_size, stream_name_size) = struct.unpack(win32_stream_id_format, data)
  48.     print '\nType:', stream_type, stream_types[stream_type], 'Attributes:', stream_attributes, 'Size:', stream_size, 'Name len:', stream_name_size
  49.     if stream_name_size > 0:
  50.         (bytes_read, stream_name_buf, ctxt) = win32file.BackupRead(h, stream_name_size, None, False, True, ctxt)
  51.         stream_name = pywintypes.UnicodeFromRaw(stream_name_buf[:])
  52.     else:
  53.         stream_name = 'Unnamed'
  54.     print 'Name:' + stream_name
  55.     return (ctxt, stream_type, stream_attributes, stream_size, stream_name_size, stream_name)
  56.  
  57. ctxt = 0
  58. win32_stream_id_buf = None
  59. while None:
  60.     (bytes_read, win32_stream_id_buf, ctxt) = win32file.BackupRead(h, win32_stream_id_size, win32_stream_id_buf, False, True, ctxt)
  61.     if bytes_read == 0:
  62.         break
  63.     
  64.     (ctxt, stream_type, stream_attributes, stream_size, stream_name_size, stream_name) = parse_stream_header(h, ctxt, win32_stream_id_buf[:])
  65.     if stream_size > 0:
  66.         bytes_moved = win32file.BackupSeek(h, stream_size, ctxt)
  67.         print 'Moved: ', bytes_moved
  68.         continue
  69.     continue
  70.     win32file.BackupRead(h, win32_stream_id_size, win32_stream_id_buf, True, True, ctxt)
  71.     win32file.CloseHandle(h)
  72.     return None
  73.