#include <GUIConstants.au3>
#include <GuiListView.au3>
#include <File.au3>
Global $sFile
$hGUI = GUICreate('Demo File Restore', 1110, 600)
GUISetBkColor(0xB1B1B1)
$hLabelRecyCler = GUICtrlCreateLabel('Папка корзины', 5, 5, 100, 20)
$sStyle = BitOR($LVS_REPORT, $LVS_ShowSELALWAYS)
$sExStyle = BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)
$hListViewRecycler = GUICtrlCreateListView("", 5, 30, 800, 520, $sStyle, $sExStyle)
GUICtrlSetBkColor(-1, 0xDBDB00)
_GUICtrlListView_InsertColumn($hListViewRecycler, 0, 'Original name', 160)
_GUICtrlListView_InsertColumn($hListViewRecycler, 1, 'Original Patch', 300)
_GUICtrlListView_InsertColumn($hListViewRecycler, 2, 'Deleted Data', 100)
_GUICtrlListView_InsertColumn($hListViewRecycler, 3, 'Size', 50)
_GUICtrlListView_InsertColumn($hListViewRecycler, 4, 'Atributes', 40)
_GUICtrlListView_InsertColumn($hListViewRecycler, 5, 'Recycle name', 300)
$hLabelTempFolder = GUICtrlCreateLabel('Папка : Temp Folder', 810, 5, 300, 20)
$hListView = GUICtrlCreateListView("", 810, 30, 300, 520, $sStyle, $sExStyle)
GUICtrlSetBkColor(-1, 0xDBDBDB)
_GUICtrlListView_InsertColumn($hListView, 0, 'FileName', 160)
_GUICtrlListView_InsertColumn($hListView, 1, 'FileFullName', 700)
$hBtRestore = GUICtrlCreateButton("Restore", 10, 570, 70, 20)
$hBtClearRecycler = GUICtrlCreateButton("Clear Recycler", 90, 570, 110, 20)
$hBtTestFileCreate = GUICtrlCreateButton("TestFile Create", 610, -1, 100, '')
$hBtDelete = GUICtrlCreateButton("Delete", 850, -1, 70, '')
$hBtBack = GUICtrlCreateButton("Back", 1030, -1, '', '')
GUISetState()
; Создаем в рабочей папке скрипта Папку : " Temp Folder "
DirCreate(@ScriptDir & '\Temp Folder')
Update_RecyclerFolderLV($hListViewRecycler)
Update_TempFolderLV($hListView)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
DirRemove(@ScriptDir & '\Temp Folder')
Exit
Case $hBtClearRecycler
If MsgBox(36, 'Attention', 'Are you sure, clear the recycle bin?', 0, $hGUI) = 6 Then FileRecycleEmpty()
Case $hBtTestFileCreate
; Создаем в папке : "Temp Folder " файлы\папки для тестирования
For $i = 1 To 3
DirCreate(@ScriptDir & '\Temp Folder\TestFolder ' & $i)
FileClose(FileOpen(@ScriptDir & '\Temp Folder\TestFile ' & $i & '.txt', 2))
Next
Case $hBtDelete
$aItems = _GUICtrlListView_GetSelectedIndices($hListView, 1)
For $i = 1 To $aItems[0]
$sFile = _GUICtrlListView_GetItemText($hListView, $aItems[$i], 1)
FileRecycle($sFile)
Next
Case $hBtBack
_FileRecycleBinFileRestore($sFile)
Case $hBtRestore
$aItems = _GUICtrlListView_GetSelectedIndices($hListViewRecycler, True)
If $aItems[0] = 0 Then ContinueLoop
For $i = 1 To $aItems[0]
$sFile = _GUICtrlListView_GetItemText($hListViewRecycler, $aItems[$i], 5)
_FileRecycleBinFileRestore($sFile, 1)
Next
Case Else
ContinueLoop
EndSwitch
Update_RecyclerFolderLV($hListViewRecycler)
Update_TempFolderLV($hListView)
WEnd
Func _FileRecycleBinEnumItems($sRoot = '')
Local $oShellApp, $oRecycleBin, $oFolderItems, $oItem
$oShellApp = ObjCreate('Shell.Application')
$oRecycleBin = $oShellApp.NameSpace(10)
If Not IsObj($oRecycleBin) Then
Return SetError(1, 0, 0)
EndIf
Local $Ret, $Result[101][6] = [[0]]
$sRoot = StringStripWS($sRoot, 3)
If $sRoot > '' Then
If StringInStr($sRoot, ':') Then
$sRoot = StringRegExpReplace($sRoot, ':.*', '')
Else
$sRoot = ''
EndIf
If Not FileExists($sRoot & ':') Then
Return SetError(1, 0, 0)
EndIf
EndIf
$Ret = DllCall('shell32.dll', 'none', 'SHGetSettings', 'uint*', 0, 'dword', 2)
If @error Then
Return SetError(1, 0, 0)
EndIf
$oFolderItems = $oRecycleBin.Items()
For $oItem In $oFolderItems
If ($sRoot > '') And ($sRoot <> StringLeft($oItem.Path, 1)) Then
ContinueLoop
EndIf
$Result[0][0] += 1
If $Result[0][0] > UBound($Result) - 1 Then
ReDim $Result[$Result[0][0] + 100][UBound($Result, 2)]
EndIf
$Result[$Result[0][0]][0] = $oRecycleBin.GetDetailsOf($oItem, 0) ; Original name
$Result[$Result[0][0]][1] = $oRecycleBin.GetDetailsOf($oItem, 1) ; Original path
$Result[$Result[0][0]][2] = $oRecycleBin.GetDetailsOf($oItem, 2) ; Deleted date
$Result[$Result[0][0]][3] = $oItem.Size ; Size
$Result[$Result[0][0]][4] = FileGetAttrib($oItem.Path) ; Attributes
$Result[$Result[0][0]][5] = $oItem.Path ; Recycle name
If (Not $Ret[1]) And (Not StringInStr($Result[$Result[0][0]][4], 'D')) Then
If StringInStr($Result[$Result[0][0]][5], '.') Then
$Result[$Result[0][0]][0] &= StringRegExpReplace($Result[$Result[0][0]][5], '^.*\.', '.')
EndIf
EndIf
Next
ReDim $Result[$Result[0][0] + 1][UBound($Result, 2)]
Return $Result
EndFunc
Func _FileRecycleBinFileRestore($sFile, $iFlag = 0, $iReplace = 0)
Local $aData = _FileRecycleBinEnumItems()
For $i = 1 To UBound($aData, 1) - 1
$sOriginalFullName = $aData[$i][1] & '\' & $aData[$i][0]
$sRecyclerFullName = $aData[$i][5]
$sAtributes = $aData[$i][4]
$sCompare = $sOriginalFullName
If $iFlag <> 0 Then $sCompare = $sRecyclerFullName
If $sCompare = $sFile Then
If $sAtributes = 'D' Then
DirMove($sRecyclerFullName, $sOriginalFullName, $iReplace)
Else
FileMove($sRecyclerFullName, $sOriginalFullName, $iReplace)
EndIf
ExitLoop
EndIf
Next
EndFunc
Func Update_RecyclerFolderLV($hLV)
$aData = _FileRecycleBinEnumItems()
_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($hLV))
For $i = 1 To UBound($aData, 1) - 1
_GUICtrlListView_AddItem($hLV, $aData[$i][0])
For $j = 1 To UBound($aData, 2) - 1
_GUICtrlListView_AddSubItem($hLV, $i - 1, $aData[$i][$j], $j)
Next
Next
EndFunc
Func Update_TempFolderLV($hLV)
$aArray = _FileListToArray(@ScriptDir & '\Temp Folder', '*.*', 0)
_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($hLV))
For $i = 1 To UBound($aArray, 1) - 1
_GUICtrlListView_AddItem($hLV, $aArray[$i])
_GUICtrlListView_AddSubItem($hLV, $i - 1, @ScriptDir & '\Temp Folder\' & $aArray[$i], 1)
Next
EndFunc