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:
- The "Always keep on this device"/"Free up space" shows automatically on sync root registration. But it only sets Pinned and Unpinned file attributes. You need to monitor the file system, examine the pinned/unpinned attributes, and hydrate/dehydrate each file.
- The on-demand folders listing is done inside the CF_CALLBACK_TYPE_FETCH_PLACEHOLDERS callback. You need to register callback using CfConnectSyncRoot() and listen to it in .NET code.
- The on-demand file content download (hydration) is done inside the CF_CALLBACK_TYPE_FETCH_DATA callback. You need to register and listen to it in .NET code.