I need to create a virtual file system that syncs files from my Azure app service to local drive and backward. I need only some files and folders to be synchronized to my local file system and be available offline. The files/folders should synchronize during first access or when the user selects the "Always keep on this device" menu. Similar to how OneDrive is doing. I found the Microsoft CloudMirror C++ sample which has some basic OneDrive functionality, but it syncs all files one time during start and no listing/loading on first access.
Is it possible to build virtual file system with above functionality completely in .NET?
Right-click on the file or folder and select "Make available offline." Alternately, you can select "Make available online-only" for local files and move then to the OneDrive servers in the cloud, saving some space on your hard drive.
If you have a OneDrive file or folder and need to make it available on your computer whilst offline, right-click on the file or folder and select 'Always keep on this device. ' The file or folder will now display a dark green tick.
To build an OneDrive-like client you need to create the Sync Provider using cloud filter API, which is mostly programmable via Win32 (with some exceptions, see below), but you can build a complete OneDrive analog in .NET, including "Always keep on this device" menu and on-demand loading.
Here is the functionality that is available via .NET, so you do not need to PInvoke it:
Here is functionality available via Win32 functions only, you will need to call it via PInvoke:
Here is what you can do to write all code in .NET:
One option is to import all required Win32 functions using extern to .NET, for example:
[DllImport("cldapi.dll", SetLastError = true, ExactSpelling = true)]
public static extern int CfGetPlaceholderStateFromFileInfo(IntPtr infoBuffer, FILE_INFO_BY_HANDLE_CLASS infoClass);
[DllImport("cldapi.dll", SetLastError = true, ExactSpelling = true)]
public static extern HRESULT CfSetPinState(IntPtr fileHandle, int pinState, int pinFlags, IntPtr overlapped);
Another option could be using this sample.
Some more notes on building an OneDrive-like file system:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With