-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for IFileOperation interface (#5)
- Loading branch information
1 parent
c2ba062
commit 36d9568
Showing
4 changed files
with
313 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
#include <initguid.h> | ||
#include <shlobj.h> | ||
|
||
HRESULT STDMETHODCALLTYPE QueryInterface( | ||
IFileOperationProgressSink *this, | ||
REFIID riid, | ||
void **ppv | ||
) { | ||
if (riid == &IID_IUnknown || riid == &IID_IFileOperationProgressSink) { | ||
*ppv = this; | ||
|
||
return S_OK; | ||
} | ||
|
||
*ppv = NULL; | ||
|
||
return E_NOINTERFACE; | ||
} | ||
|
||
ULONG STDMETHODCALLTYPE AddRef(IFileOperationProgressSink *this) { | ||
return S_OK; | ||
} | ||
|
||
ULONG STDMETHODCALLTYPE Release(IFileOperationProgressSink *this) { | ||
return S_OK; | ||
} | ||
|
||
HRESULT STDMETHODCALLTYPE StartOperations(IFileOperationProgressSink *this) { | ||
return S_OK; | ||
} | ||
|
||
HRESULT STDMETHODCALLTYPE FinishOperations( | ||
IFileOperationProgressSink *this, | ||
HRESULT hrResult | ||
) { | ||
return S_OK; | ||
} | ||
|
||
HRESULT STDMETHODCALLTYPE PreRenameItem( | ||
IFileOperationProgressSink *this, | ||
DWORD dwFlags, | ||
IShellItem *psiItem, | ||
LPCWSTR pszNewName | ||
) { | ||
return S_OK; | ||
} | ||
|
||
HRESULT STDMETHODCALLTYPE PostRenameItem( | ||
IFileOperationProgressSink *this, | ||
DWORD dwFlags, | ||
IShellItem *psiItem, | ||
LPCWSTR pszNewName, | ||
HRESULT hrRename, | ||
IShellItem *psiNewlyCreated | ||
) { | ||
return S_OK; | ||
} | ||
|
||
HRESULT STDMETHODCALLTYPE PreMoveItem( | ||
IFileOperationProgressSink *this, | ||
DWORD dwFlags, | ||
IShellItem *psiItem, | ||
IShellItem *psiDestinationFolder, | ||
LPCWSTR pszNewNam | ||
) { | ||
return S_OK; | ||
} | ||
|
||
HRESULT STDMETHODCALLTYPE PostMoveItem( | ||
IFileOperationProgressSink *this, | ||
DWORD dwFlags, | ||
IShellItem *psiItem, | ||
IShellItem *psiDestinationFolder, | ||
LPCWSTR pszNewName, | ||
HRESULT hrMove, | ||
IShellItem *psiNewlyCreated | ||
) { | ||
return S_OK; | ||
} | ||
|
||
HRESULT STDMETHODCALLTYPE PreCopyItem( | ||
IFileOperationProgressSink *this, | ||
DWORD dwFlags, | ||
IShellItem *psiItem, | ||
IShellItem *psiDestinationFolder, | ||
LPCWSTR pszNewName | ||
) { | ||
return S_OK; | ||
} | ||
|
||
HRESULT STDMETHODCALLTYPE PostCopyItem( | ||
IFileOperationProgressSink *this, | ||
DWORD dwFlags, | ||
IShellItem *psiItem, | ||
IShellItem *psiDestinationFolder, | ||
LPCWSTR pszNewName, | ||
HRESULT hrCopy, | ||
IShellItem *psiNewlyCreated | ||
) { | ||
return S_OK; | ||
} | ||
|
||
HRESULT STDMETHODCALLTYPE PreDeleteItem( | ||
IFileOperationProgressSink *this, | ||
DWORD dwFlags, | ||
IShellItem *psiItem | ||
) { | ||
if (dwFlags & TSF_DELETE_RECYCLE_IF_POSSIBLE) { | ||
return S_OK; | ||
} | ||
|
||
return E_ABORT; | ||
} | ||
|
||
HRESULT STDMETHODCALLTYPE PostDeleteItem( | ||
IFileOperationProgressSink *this, | ||
DWORD dwFlags, | ||
IShellItem *psiItem, | ||
HRESULT hrDelete, | ||
IShellItem *psiNewlyCreated | ||
) { | ||
return S_OK; | ||
} | ||
|
||
HRESULT STDMETHODCALLTYPE PreNewItem( | ||
IFileOperationProgressSink *this, | ||
DWORD dwFlags, | ||
IShellItem *psiDestinationFolder, | ||
LPCWSTR pszNewName | ||
) { | ||
return S_OK; | ||
} | ||
|
||
HRESULT STDMETHODCALLTYPE PostNewItem( | ||
IFileOperationProgressSink *this, | ||
DWORD dwFlags, | ||
IShellItem *psiDestinationFolder, | ||
LPCWSTR pszNewName, | ||
LPCWSTR pszTemplateName, | ||
DWORD dwFileAttributes, | ||
HRESULT hrNew, | ||
IShellItem *psiNewItem | ||
) { | ||
return S_OK; | ||
} | ||
|
||
HRESULT STDMETHODCALLTYPE UpdateProgress( | ||
IFileOperationProgressSink *this, | ||
UINT iWorkTotal, | ||
UINT iWorkSoFar | ||
) { | ||
return S_OK; | ||
} | ||
|
||
HRESULT STDMETHODCALLTYPE ResetTimer(IFileOperationProgressSink *this) { | ||
return S_OK; | ||
} | ||
|
||
HRESULT STDMETHODCALLTYPE PauseTimer(IFileOperationProgressSink *this) { | ||
return S_OK; | ||
} | ||
|
||
HRESULT STDMETHODCALLTYPE ResumeTimer(IFileOperationProgressSink *this) { | ||
return S_OK; | ||
} | ||
|
||
static IFileOperationProgressSinkVtbl progressSinkVtbl = { | ||
QueryInterface, | ||
AddRef, | ||
Release, | ||
StartOperations, | ||
FinishOperations, | ||
PreRenameItem, | ||
PostRenameItem, | ||
PreMoveItem, | ||
PostMoveItem, | ||
PreCopyItem, | ||
PostCopyItem, | ||
PreDeleteItem, | ||
PostDeleteItem, | ||
PreNewItem, | ||
PostNewItem, | ||
UpdateProgress, | ||
ResetTimer, | ||
PauseTimer, | ||
ResumeTimer | ||
}; | ||
|
||
static IFileOperationProgressSink progressSink = { &progressSinkVtbl }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
@echo off | ||
|
||
setlocal enabledelayedexpansion | ||
|
||
:: Global settings | ||
set program=recycle-bin | ||
set dir=test | ||
set name=a | ||
|
||
:: Test cases | ||
<nul set /p="Test case #1: Long directory names: " | ||
call :test 100 5 | ||
|
||
<nul set /p="Test case #2: Deep folder hierarchy: " | ||
call :test 20 20 | ||
|
||
<nul set /p="Test case #3: Deep hierarchy with long paths: " | ||
call :test 200 20 | ||
|
||
exit /b | ||
|
||
:: Test case procedure | ||
:: Parameters: <filename-length> <hierarchy-depth> | ||
:test | ||
:: Repeat filename | ||
set file= | ||
for /l %%i in (1, 1, %~1) do set file=!file!%name% | ||
|
||
:: Create initial directory | ||
set target=%dir% | ||
mkdir %target% | ||
|
||
:: Create folder hierarchy | ||
for /l %%i in (1, 1, %~2) do ( | ||
set target=!target!\%file% | ||
mkdir %file% | ||
robocopy %file% !target! /MOVE >nul | ||
) | ||
|
||
:: Delete long path | ||
"%program%".exe !target! | ||
|
||
if %errorlevel% == 0 ( | ||
if exist !target! ( | ||
echo FAILED | ||
) else ( | ||
echo PASSED | ||
) | ||
) else ( | ||
echo FAILED | ||
) | ||
|
||
:: Clean up | ||
"%program%".exe %dir% | ||
goto :eof |