EldoS | Feel safer!

Software components for data protection, secure storage and transfer

NotifyDirectoryChange in root, unsolvable answer

Also by EldoS: RawDisk
Access locked and protected files in Windows, read and write disks and partitions and more.
#21061
Posted: 08/20/2012 06:13:34
by ttran Tran (Priority Standard support level)
Joined: 08/20/2012
Posts: 35

Hello,
When I delete a folder in my driver (e.g. R:), I want "R:" to refresh by calling
NotifyDirectoryChange("\\", CallbackFS.CbFsNotifyFileAction.fanRemoved , true);

Anyway, nothing happen. The question is how can I refresh the root folder from the program ? This question is not new, but as I see, NotifyDirectoryChange works well with sub-folder, but not root folder.

Thanks
Tran
#21062
Posted: 08/20/2012 06:21:19
by Volodymyr Zinin (EldoS Corp.)

As I understand you deleted not the root folder, but a subfolder inside the root. So call NotifyDirectoryChange with the deleted folder name. For example:
NotifyDirectoryChange("\\qwerty", CallbackFS.CbFsNotifyFileAction.fanRemoved , true);
#21063
Posted: 08/20/2012 06:45:13
by ttran Tran (Priority Standard support level)
Joined: 08/20/2012
Posts: 35

Hello,
What you say is what I did, but then the content of the root is NOT refreshed at all. My solution is after deleting a sub-folder of the root, I have to write my own code to refresh Windows Explorer.

However, if I delete the sub-sub-folder of a sub-folder of a root, your technique works well. The content of the sub-folder is refreshed.
#21064
Posted: 08/20/2012 07:34:22
by Volodymyr Zinin (EldoS Corp.)

Hm. The code is the same for the root and non-root folder deletion, and finally calls the system kernel API in order to notify the system about folder deletion. We will check it. Please specify what version of Windows and type of CallbackFS API (C++, Delphi, or .NET) you are using.
Thanks.
#21065
Posted: 08/20/2012 07:43:48
by ttran Tran (Priority Standard support level)
Joined: 08/20/2012
Posts: 35

Hi,
Win 7, C#, .Net 4, Your CBFS we just download for about 2 months to use.
To Delete a Folder we put the code inside
private void CbFsIsDirectoryEmpty(
object sender,
string FileName,
ref Boolean IsEmpty)

We have seen that sometimes, even the specific folder is not empty, the event CbFsIsDirectoryEmpty still happens. So whenever this event is called, we always check the remote server if the folder exactly contains no file or not. In case the folder is empty, we delete the folder, then call NotifyDirectoryChange.

Again, we emphasize: all codes are written inside the
private void CbFsIsDirectoryEmpty(
object sender,
string FileName,
ref Boolean IsEmpty)


To delete a file, of course, we use
private void CbFsDeleteFile(
object sender,
CbFsFileInfo FileInfo)
#21066
Posted: 08/20/2012 07:58:31
by Volodymyr Zinin (EldoS Corp.)

You shouldn't use NotifyDirectoryChange in the case a file or directory is deleted via CallbackFS (i.e. when someone deletes it via the CallbackFS virtual disk). Its usage is necessary only if a file's or directory's representation has been deleted or modified on the remote server (in your case).

CallbackFS uses the CbFsIsDirectoryEmpty callback in order to obtain information whether the specified directory is empty or not. You shouldn't delete the directory in this case. For deletion files as well as directories there is another callback - CbFsDeleteFile. And this last one is not always called after the CbFsIsDirectoryEmpty callback.
#21067
Posted: 08/20/2012 09:04:19
by ttran Tran (Priority Standard support level)
Joined: 08/20/2012
Posts: 35

Hello,
I re-write my code in the following way:
1. In
private void CbFsIsDirectoryEmpty(
object sender,
string FileName,
ref Boolean IsEmpty)

if I see that the folder is empty (in remote server) then I set IsEmpty = true;
I put this "candidate folder for delete" in a Hashmap, for example named: cadidatesToDelete.

2. In
private void CbFsDeleteFile(
object sender,
CbFsFileInfo FileInfo)

if FileInfo is a Folder, and it is also inside the cadidatesToDelete Hashmap, I delete this folder.

3. When I do this, I totally do not need NotifyDirectoryChange.


Is that the reasonable way when working with your CBFS ? I got all directories refreshed automatically.

Thanks,
Tran
#21068
Posted: 08/20/2012 09:17:09
by Volodymyr Zinin (EldoS Corp.)

Exactly. But CbFsDeleteFile isn't always called after CbFsIsDirectoryEmpty. So you need to support your cadidatesToDelete Hashmap in the actual state.
#21069
Posted: 08/20/2012 09:22:41
by ttran Tran (Priority Standard support level)
Joined: 08/20/2012
Posts: 35

You means CbFsDeleteFile isn't always called IMMEDIATELY after CbFsIsDirectoryEmpty, but SURELY CbFsDeleteFile will be called in a moment in future for the candidated Folder? Or NOT Surely ?
#21070
Posted: 08/20/2012 09:45:05
by Volodymyr Zinin (EldoS Corp.)

No. For example in some case CbFsIsDirectoryEmpty is called when Windows wants to move a folder to recycle bin and so it checks if the disrectory is empty or not. In this case after the CbFsIsDirectoryEmpty call there will be the OnFileRename callback.
I think it's better not to bind CbFsIsDirectoryEmpty with CbFsDeleteFile. Just perform necessary checking inside CbFsIsDirectoryEmpty and try to delete the folder inside CbFsDeleteFile. If for some reason it won't be deleted by your code (for example the remote connection lost or server denies it) then do nothing extra. It isn't a fatal error.
Also by EldoS: CallbackRegistry
A component to monitor and control Windows registry access and create virtual registry keys.

Reply

Statistics

Topic viewed 1197 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!