EldoS | Feel safer!

Software components for data protection, secure storage and transfer

onOpenFile how to check is directory opening or file

Also by EldoS: CallbackFilter
A component to monitor and control disk activity, track file and directory operations (create, read, write, rename etc.), alter file data, encrypt files, create virtual files.
Posted: 05/05/2012 12:37:42
by szagriichuk  (Basic support level)
Joined: 03/28/2012
Posts: 51

How to check is opening directory or file without fileAttributes parameter in method onOpenFile ?
Posted: 05/05/2012 23:13:29
by Eaton Zveare (Standard support level)
Joined: 11/28/2011
Posts: 20

Here is something I do on Windows.

        private object GetPCItemInfo(string ItemPath)
            var fileInfo = new FileInfo(ItemPath);
            if (fileInfo.Exists) return fileInfo;
            var dirInfo = new DirectoryInfo(ItemPath);
            if (dirInfo.Exists) return dirInfo;
            return null;

For example, when you use that method, you would use it like this:
var fileObject = GetPCItemInfo("C:\\testFileOrFolder");
bool isFile = fileObject is FileInfo;
bool isFolder = fileObject is DirectoryInfo;
bool nonExistentItem = fileObject is null;

One, and only one, of those booleans will always be true. In your CBFS implementation, you should replace the Directory/File Info with your classes/methods that grab the appropriate objects.

This is my implementation. GetItemFromPath returns the item (file or folder) that resides at the path given, or null if nothing is there.
var item = Device.GetItemFromPath(FileName);
if (item == null) return;
FileHandleContext = GCHandle.ToIntPtr(GCHandle.Alloc(item));
Posted: 05/05/2012 23:43:28
by Eugene Mayevski (EldoS Corp.)

In OnOpenFile you are asked to open an existing entity. The OS knows which of them exists since you reported this in OnEnumerateDirectory/OnGetFileInfo. If the type of the entity has changed externally since the last OnEnumerateDirectory/OnGetFileInfo operation, then you need to report the change back to the OS (using NotifyDirectoryChange) so that it could re-read the necessary data.

Consequently in OnOpenFile you open what you have.

Sincerely yours
Eugene Mayevski



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