Beispiel #1
0
 def _validate_entry(entry):
     name = app.EntryGetName(entry)
     if not case_sensitive:
         name = name.upper()
     for mask in masks:
         if mask == "*.*":
             mask = "*"
         if not app.FileNameMatches(name, unicode(mask)):
             continue
         if not ((search_files and app.EntryIsFile(entry)) or
                 (search_folders and app.EntryIsDirectory(entry))):
             continue
         if not (
             (search_deleted and app.EntryIsDeleted(entry)) or
             (search_non_deleted and not app.EntryIsDeleted(entry))):
             continue
         if use_modify_filter:
             MD = app.EntryGetModifyDate(entry)
             if not ((MD >= modify_from) and (MD < modify_to + 1)):
                 continue
         if use_create_filter:
             CD = app.EntryGetCreateDate(entry)
             if not ((CD >= created_from) and (CD < created_to + 1)):
                 continue
         if size_from is not None and app.EntryIsFile(entry):
             if not (app.EntryGetDataSize(entry) >= size_from):
                 continue
         if size_to is not None and app.EntryIsFile(entry):
             if not (app.EntryGetDataSize(entry) <= size_to):
                 continue
         mft_ref = app.EntryGetMFTRef(entry)
         if not _entries.has_key(mft_ref):
             app.AddSearchResult(entry)
             _entries[mft_ref] = entry
         break
Beispiel #2
0
def update_quickview():
    app.SetQVCaption(STR_NOT_AVAIL)
    FF = app.GetFocusedFile()
    if FF:
        try:
            mft_ref = app.EntryGetMFTRef(FF)
            Volume = app.VolumeForEntry(FF)
            CurrentQVFile = Volume.open_file(mft_ref)
        except Exception, Value:
            traceback.print_exc()
            CurrentQVFile = None
        if CurrentQVFile:
            RC = CurrentQVFile.default_data_stream_size >> 4
            if CurrentQVFile.default_data_stream_size & 3:
                RC += 1
            if RC > 4096:
                RC = 4095
            app.SetQVCaption(CurrentQVFile.win32_file_names.keys()[0])
            C = RC * 16
            if C > CurrentQVFile.default_data_stream_size:
                C = CurrentQVFile.default_data_stream_size
            if C > 0:
                try:
                    data = CurrentQVFile.data_streams[""].read_data(0, C)
                    app.SetQVData(data)
                    app.SetQVRowCount(RC)
                except Exception, Value:
                    traceback.print_exc()
            else:
                app.SetQVRowCount(0)
            return
Beispiel #3
0
 def _search_from(entry):
     while entry and SearchActive:
         _validate_entry(entry)
         if app.EntryIsContainer(entry):
             if skip_unk_entry and app.EntryIsDirectory(
                     entry) and app.EntryGetMFTRef(entry) == -7:
                 entry = app.EntryGetNext(entry)
                 continue
             _search_from(app.EntryGetFirstChild(entry))
         entry = app.EntryGetNext(entry)
Beispiel #4
0
 def _do_save_as():
     global progress_dlg_cancel
     progress_dlg_cancel = False
     ff = app.GetFocusedFile()
     if ff:
         file_name = app.SaveDlgQuery(app.EntryGetName(ff))
         if not file_name:
             return
         file_name = os.path.abspath(file_name)
         if file_name[:2].upper() == app.EntryGetPath(ff)[:2].upper():
             if app.ShowYesNoDlg(
                     u"It is not safe to recover the file to destination you specified, recovered files can be corrupted. Do you want to proceed anyway?"
             ) == 7:
                 return
         if file_name:
             BULK = 256 * 1024
             app.ShowProgressDlg(
                 u"Copy...",
                 u"Copy file " + app.EntryGetName(ff) + u" to " + file_name)
             entry = ff
             target_path = file_name
             try:
                 volume = app.VolumeForEntry(entry)
                 mft_ref = app.EntryGetMFTRef(entry)
                 if volume and mft_ref >= 0:
                     file = volume.open_file(mft_ref)
                     total_size = reduce(lambda x, y: y.size + x,
                                         file.data_streams.values(), 0L)
                     processed_size = 0L
                     for data_stream_name, data_stream in file.data_streams.items(
                     ):
                         is_alter_stream = len(data_stream_name) > 0
                         file_name = target_path
                         if data_stream_name:
                             file_name += u"_" + data_stream_name
                         f = open(file_name, "wb")
                         pos = 0L
                         count = data_stream.size
                         while count > 0:
                             if progress_dlg_cancel:
                                 raise Exception(STR_USER_CANCELLED)
                             C = BULK
                             if C > count:
                                 C = count
                             data = data_stream.read_data(pos, C)
                             pos += C
                             count -= C
                             processed_size += C
                             f.write(data)
                             perc = int(pos * 100.0 / data_stream.size)
                             app.NotifyProgressDlg(perc)
                         f.close()
             except:
                 traceback.print_exc()
             app.HideProgressDlg()
Beispiel #5
0
 def copy_file(entry, target_path, context, rparams):
     global RecoverySkip
     recover_all_data_strems = rparams['recover_all_data_strems']
     delete_unsuccessful = rparams['delete_unsuccessful']
     naming = rparams['naming']
     unchecking = rparams['unchecking']
     context.current_file_progress = 0
     RecoverySkip = False
     BULK = 256 * 1024
     processed_size = 0L
     total_size = 0L
     file_name = None
     has_errors = False
     f = None
     try:
         volume = app.VolumeForEntry(entry)
         mft_ref = app.EntryGetMFTRef(entry)
         if volume and mft_ref >= 0:
             file = volume.open_file(mft_ref)
             if len(file.data_streams) > 1:
                 emit(
                     rmtMessage, STR_KNOWN_DATA_STREAMS +
                     unicode(str(file.data_streams.keys())))
             total_size = reduce(lambda x, y: y.size + x,
                                 file.data_streams.values(), 0L)
             for data_stream_name, data_stream in file.data_streams.items():
                 is_alter_stream = len(data_stream_name) > 0
                 if is_alter_stream and not recover_all_data_strems:
                     continue
                 if data_stream_name:
                     context.current_file_name = app.EntryGetName(
                         entry) + u" stream: " + data_stream_name
                 else:
                     context.current_file_name = app.EntryGetName(entry)
                 file_name = target_path
                 if data_stream_name:
                     file_name += u"_" + data_stream_name
                 if os.path.exists(file_name):
                     if naming == 0:
                         file_name = generate_autoname(file_name)
                     elif naming == 1:
                         file_name = app.SaveDlgQuery(file_name)
                         if not file_name:
                             raise Exception(STR_USER_SKIPPED)
                     elif naming == 2:
                         continue
                 f = open(file_name, "wb")
                 pos = 0L
                 count = data_stream.size
                 while count > 0:
                     if not RecoveryRunning:
                         raise Exception(STR_USER_CANCELLED)
                     if RecoverySkip:
                         if not is_alter_stream:
                             context.processed_size += count
                         raise Exception(STR_USER_SKIPPED)
                     C = BULK
                     if C > count:
                         C = count
                     try:
                         data = data_stream.read_data(pos, C)
                         pos += C
                         count -= C
                         processed_size += C
                         context.current_file_progress = int(
                             processed_size * 100.0 / total_size)
                         f.write(data)
                     finally:
                         if not is_alter_stream:
                             context.processed_size += C
                 f.close()
                 f = None
                 if is_alter_stream:
                     emit(
                         rmtSuccess,
                         u"Recovered ok - " + app.EntryGetPath(entry) +
                         u" stream " + data_stream_name)
                 else:
                     emit(rmtSuccess,
                          u"Recovered ok - " + app.EntryGetPath(entry))
         else:
             raise Exception(STR_CANNOT_OPEN_FILE % (mft_ref, str(volume)))
     except Exception, Value:
         has_errors = True
         emit(rmtError, STR_ERROR_ON % (target_path, str(Value)))
         if f:
             f.close()
         if file_name and delete_unsuccessful:
             try:
                 os.remove(file_name)
             except Exception, Value:
                 pass