- Introduction
- Developer’s Guide
- Samples
- Reference
Google Drive Folder sample
Source repository: https://github.com/aelyo-softworks/ShellBoost-Samples
A Winforms application that is an equivalent of One Drive for Google Drive. It demonstrates the File On-Demand ShellBoost feature. It’s not currently exposing a Shell Namespace Extension, but the sample could be modified to integrate the code that can be found in the Physical Overview sample.
The sample only run on Windows 10 version 1709 (or “Fall Creators Update”) or higher because the “Files On-Demand” Windows NTFS technology only runs on this version of Windows or higher.
Note: This is only a sample code, provided as is. Data loss may arise, so we recommend you use a Google Drive account where data is not important when testing this sample.
Steps to run the sample
1) Since the sample connects to Google Drive, it needs API credentials. There are many ways to integrate with Google Drive, but the sample uses OAuth 2. So, it needs a Google Drive Secrets .json file. The easiest way is to go to the https://developers.google.com/drive/api/v3/quickstart/dotnet page and Enable the Drive API, as shown here below. We recommend you to choose “ShellBoost Drive Sample” as the name of the app and “Desktop” for the type of clients:
2) Once you have downloaded a Secrets .json file (often named “credentials.json”), compile and run the sample. By default, it should show you this:
3) This
is normal. Now, use the File / Configure Secrets File menu item and choose the
.json file you have downloaded from the Google developers’ site. You should now
see this:
4) The
Secrets .json file has been configured ok, so the sample can now connect to the
Google Drive API, on behalf of a Google Drive account / user. There is no account
synchronized yet, so use the File / Add Account menu item. This should open a
new browser (note embedded browser usage is now unsupported by Google sign in
so it’s been removed from the sample) and guide you to sign. Once you have
signed in, you may see a warning screen like this:
This warning is normal. It’s shown by Google because the app requests access to a sensitive/restricted authorization scope (Google Drive) and the application has not been verified by Google. If you don’t even see this warning, depending on the Google account you use and how it’s configured, you also may have to enable “Less Secured Apps” access, using a Google’s UI linked to your account, that should look like this:
Once you have done that, you can retry to add an account to get to the “This app isn’t verified” warning.
If you do see the warning, click on the “Hide Advanced” link located at the bottom left, it will open another warning text and a new “Go to ShellBoost Drive Sample (unsafe)” link (or the name you used when you created the app) that you can click. Now you should see the user Content Screen, something like this:
Select « Allow », and you should see another consent screen, like this:
5) Select
“Allow” again, the dialog box should close itself and now, you should see
something like this:
This log shows the sample is synchronizing the files and folders it has found on the Google Drive of the added account, with the local drive, using Files On-Demand technology.
Once the program is started, it will, by default, synchronize files automatically:
from Google Drive to the local drive every 300 seconds. This value is configurable via the File / Preferences menu item.
from the local drive to Google Drive automatically (it can take a few seconds due to how the whole synchronization process work, check remarks in the File Systems Synchronization chapter for more on this.
Here is the Google Drive view of our account (it has 3 files and 2 folders):
And here is our local drive after the first synchronization:
As you can see all files are created, but they don’t take any space on the physical disk (beyond the metadata like its name and size), just like with Microsoft’s OneDrive. If you open a file (right click, context menu, open, or double-click), Windows will automatically require the sample to download the file. The sample will download it from Google Drive and the application associated with this file will open. Now the explorer view will show this:
Note that if you had exited the sample and opened the file, Windows would have told you it cannot do this, as it needs the sample app, which is mentioned as a " cloud provider" to the end-user, to run to fetch data.
You can observe the icon has changed. It means the file has now been downloaded and its content is physically stored on the disk. Now, even if the sample application is closed or does not run, the file can still be opened, like any other file on the disk.
Synchronization works the other way around. If you create a file in the local folder, it will be uploaded to the Google Drive, as soon as possible. Here is the view of the account Google Drive after a Word document has been created in the local folder:
Remarks
“Google Docs” (Document, Spreadsheet, Presentation, etc.) in Google Drive are special type of items (not files) as they don’t use end-user quota. Because of this, their size cannot be determined by the Google Drive API, because they just don’t have a size. So, the application synchronizes these items from Google Drive to the local folder in a special way: it creates a .url file (an “Internet Shortcut”) that points to the Google Doc link on the internet, not the file with its content.
Errors (such as Sharing Violation errors) are often encountered in the application log. This is a sample that demonstrates a feature and it makes apparent the issues it encounters during the normal course of its operations. So, these errors are, in general, more informative.
The sample supports multiple Google Drive accounts.
The sample currently only synchronizes owned (by the current logged in account) and non-Trashed (removed) items from Google Drive.
If there is more than one file with a given name in a given folder (Google Drive supports that), than the EndPointSynchronizer will consider all files with that name, in that folder, don’t exist.
The sample automatically creates a “ShellBoostTemp” folder, at Google Drive’s root, that’s used for temporary file content moving. You can check the remarks in the File Systems Synchronization chapter for more on this.