Posting parts of my code which is mostly similar to the mirror.c
example:
---------------------------------------------------------------------------------------------------------
static int __stdcall MirrorMoveFile(LPCWSTR FileName, LPCWSTR
NewFileName, BOOL ReplaceIfExisting,PDOKAN_FILE_INFO DokanFileInfo)
{
BOOL status;
char* dest = GetFilePath(FileName);
size_t s = sizeof(wchar_t)*(strlen(dest)+1);
wchar_t *filepath = (wchar_t*)_malloca(s);
memset(filepath,0,s);
mbstowcs(filepath,dest,s);
char* newdest = GetFilePath(NewFileName);
size_t ns = sizeof(wchar_t)*(strlen(newdest)+1);
wchar_t *newfilepath = (wchar_t*)_malloca(ns);
memset(newfilepath,0,ns);
mbstowcs(newfilepath,newdest,ns);
log("MoveFile:");
log(newdest);
if (DokanFileInfo->Context) {
// should close? or rename at closing?
CloseHandle((HANDLE)DokanFileInfo->Context);
DokanFileInfo->Context = 0;
}
if (ReplaceIfExisting)
status = MoveFileEx(filepath, newfilepath,
MOVEFILE_REPLACE_EXISTING);
else
status = MoveFile(filepath, newfilepath);
if (status == FALSE) {
DWORD error = GetLastError();
return -(int)error;
}
return 0;
}
static int __stdcall MirrorFindFiles(LPCWSTR FileName,PFillFindData
FillFindData, PDOKAN_FILE_INFO DokanFileInfo)
{
HANDLE hFind;
WIN32_FIND_DATAW findData;
DWORD error;
wchar_t* yenStar = L"\*";
int count = 0;
char* dest = GetFilePath(FileName);
size_t s = sizeof(wchar_t)*(strlen(dest)+1);
wchar_t *filepath = (wchar_t*)_malloca(s);
memset(filepath,0,s);
mbstowcs(filepath,dest,s);
wcsncat(filepath, yenStar, wcslen(yenStar));
hFind = FindFirstFile(filepath, &findData);
log("FindFiles:");
log(dest);
if (hFind == INVALID_HANDLE_VALUE) {
log("invalid handle");
return -1;
}
FillFindData(&findData, DokanFileInfo);
count++;
while (FindNextFile(hFind, &findData) != 0) {
FillFindData(&findData, DokanFileInfo);
count++;
}
error = GetLastError();
FindClose(hFind);
if (error != ERROR_NO_MORE_FILES) {
log("no more files");
return -1;
}
log("ok");
return 0;