EldoS | Feel safer!

Software components for data protection, secure storage and transfer

OnCanFileBeDeleted for directories or even for files?

Also by EldoS: CallbackRegistry
A component to monitor and control Windows registry access and create virtual registry keys.
Posted: 12/14/2012 03:04:44
by Davide Baccaglini (Standard support level)
Joined: 11/19/2012
Posts: 48

Hello, i've a question about OnCanFileBeDeleted event.
This event is raised only for directories or even for files?

Thanks in advance,
Posted: 12/14/2012 03:24:57
by  Eugene Kozarovitsky

OnCanFileBeDeleted event is raised both for directories and for files (as most of CBFS events).

Eugene Kozarovitsky
Posted: 12/14/2012 07:51:47
by Davide Baccaglini (Standard support level)
Joined: 11/19/2012
Posts: 48

I've tested it on my project and when i try to delete a file OnCanFileBeDeleted and OnDeleteFile are raised but if i try to delete a folder events aren't raised.
Posted: 12/14/2012 08:10:39
by  Eugene Kozarovitsky
What version of Callback File System do you use?
Have you checked the issue with the Mapper sample?
Posted: 12/14/2012 08:56:29
by Davide Baccaglini (Standard support level)
Joined: 11/19/2012
Posts: 48

Callback File System 3.0.

I tested it with Mapper sample and it works, but the problem is in another project.
Posted: 12/14/2012 09:08:20
by  Eugene Kozarovitsky
Could you post here your code snippet that creates and mounts the storage and assign callbacks and also the snippet that performs the deletion?
Posted: 12/14/2012 10:57:32
by Davide Baccaglini (Standard support level)
Joined: 11/19/2012
Posts: 48

Assign callbacks :
callback = new CallbackFileSystem();

      // CallbackFileSystem Events - DIRECTORY
      callback.OnIsDirectoryEmpty = new CbFsIsDirectoryEmptyEvent(OnIsDirectoryEmpty);
      callback.OnEnumerateDirectory = new CbFsEnumerateDirectoryEvent(OnEnumerateDirectory);
      callback.OnCloseEnumeration = new CbFsCloseEnumerationEvent(OnCloseEnumeration);

      // CallbackFileSystem Events - FILE
      callback.OnCreateFile = new CbFsCreateFileEvent(OnCreateFile);
      callback.OnOpenFile = new CbFsOpenFileEvent(OnOpenFile);
      callback.OnCloseFile = new CbFsCloseFileEvent(OnCloseFile);
      callback.OnGetFileInfo = new CbFsGetFileInfoEvent(OnGetFileInfo);
      callback.OnSetAllocationSize = new CbFsSetAllocationSizeEvent(OnSetAllocationSize);
      callback.OnSetEndOfFile = new CbFsSetEndOfFileEvent(OnSetEndOfFile);
      callback.OnSetFileAttributes = new CbFsSetFileAttributesEvent(OnSetFileAttributes);
      callback.OnCanFileBeDeleted = new CbFsCanFileBeDeletedEvent(OnCanFileBeDeleted);
      callback.OnDeleteFile = new CbFsDeleteFileEvent(OnDeleteFile);
      callback.OnRenameOrMoveFile = new CbFsRenameOrMoveFileEvent(OnRenameOrMoveFile);
      callback.OnReadFile = new CbFsReadFileEvent(OnReadFile);
      callback.OnWriteFile = new CbFsWriteFileEvent(OnWriteFile);
      callback.OnEnumerateNamedStreams = new CbFsEnumerateNamedStreamsEvent(OnEnumerateNamedStreams);
      callback.OnGetFileNameByFileId = new CbFsGetFileNameByFileIdEvent(OnGetFileNameByFileId);
      callback.OnGetFileSecurity = new CbFsGetFileSecurityEvent(OnGetFileSecurity);
      callback.OnSetFileSecurity = new CbFsSetFileSecurityEvent(OnSetFileSecurity);
      // CallbackFileSystem Events - VOLUME
      callback.OnMount = new CbFsMountEvent(OnMount);
      callback.OnUnmount = new CbFsUnmountEvent(OnUnmount);
      callback.OnGetVolumeSize = new CbFsGetVolumeSizeEvent(OnGetVolumeSize);
      callback.OnGetVolumeLabel = new CbFsGetVolumeLabelEvent(OnGetVolumeLabel);
      callback.OnSetVolumeLabel = new CbFsSetVolumeLabelEvent(OnSetVolumeLabel);
      callback.OnGetVolumeId = new CbFsGetVolumeIdEvent(OnGetVolumeId);
      callback.OnOpenVolume = new CbFsOpenVolumeEvent(OnOpenVolume);
      callback.OnCloseVolume = new CbFsCloseVolumeEvent(OnCloseVolume);
      callback.OnStorageEjected = new CbFsStorageEjectedEvent(OnStorageEjected);

Create storage :
// 1. CallbackFileSystem License Key

        // 2. CreateStorage and set Icon

        // 3. MountMedia
        rootVirtualStorage = new VirtualFileCBFS(@"\");
        rootVirtualStorageHandle = GCHandle.Alloc(rootVirtualStorage);

        // 3. AddMountingPoint

Deletion :
private void OnCanFileBeDeleted(object sender, CbFsFileInfo FileInfo, ref Boolean CanBeDeleted)
   if (folderNotDeleted.ToList().Find(k => k.Equals(FileInfo.FileName)) != null)
      CanBeDeleted = false;
      CanBeDeleted = true;   
Posted: 12/15/2012 04:10:29
by Volodymyr Zinin (EldoS Corp.)

Davide Baccaglini wrote:
Callback File System 3.0.

It is already the versions 3.2 and 4.0. Please use one of them.

Davide Baccaglini wrote:
I tested it with Mapper sample and it works, but the problem is in another project.

Most probable something is wrong in your callback implementation associated with this directory handling. Perhaps your code returned that the directory doesn't exist already or something else.
Take Process Monitor from sysinternals.com, mark the menu item "Filter"->"Enable advanced output", and set some filters ("Path"->"begins with"->"X:", "Path"->"contains"->"directory name", etc), and reproduce the problem with the Mapper sample as well as with your app. Then compare the logs. Find a place there where the logs start to be different and look for the difference in the operations above.
Posted: 01/15/2013 05:06:47
by Davide Baccaglini (Standard support level)
Joined: 11/19/2012
Posts: 48

Hello Vladimir!

I've tested it and no problem on other events are occurs.

I also updated CBFS from 3.2.116 to 4.0.123 and these are the results of the new tests :

    1. delete a single file [OK]
    2. delete a folder that contain one or more files [OK]
    3. delete an empty folder [no result]

In case 3 OnCanFileBeDeleted and OnDeleteFile aren't fired.

Can you help me?
Posted: 01/15/2013 06:31:13
by Volodymyr Zinin (EldoS Corp.)

Is the problem reproducible with the Mapper sample? If so please specify how to do it, including version of Windows and type of CallbackFS API (.NET, C++, Java, or Delphi) you are using.

Davide Baccaglini wrote:
I also updated CBFS from 3.2.116 to 4.0.123

It would be nice if you took the latest CallbackFS build.
Also by EldoS: CallbackProcess
A component to control process creation and termination in Windows and .NET applications.



Topic viewed 2259 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!