将Google Drive映射到Network Drive或Local Drive

Map Google Drive to Network Drive or Local Drive
2020-10-17
  •  译文(汉语)
  •  原文(英语)

我尝试使用C#和Google Drive API连接到我的Google Drive,然后将其映射为网络或本地驱动器.我知道还有其他类似NetDrive的程序(它非常有用且健壮),但是我希望自己创建一些东西.我已经在开发人员控制台中创建了一个项目,并且能够使用我的应用程序连接到云端硬盘并执行各种读取和上传操作,因此我知道特定的部分是可以的.访问和权限似乎都已设置.我只是不知道将存储映射为Windows中的可用驱动器时该从哪里开始.任何建议将是最有帮助的,非常感谢!

速聊1:
尚未完全解决此问题,但我正在研究Dokan库以尝试完成此任务.它具有功能,我只需要弄清楚如何使用它.
解决过程1

有两个用于实现NetDrive / WebDrive类型解决方案的基本组件.您正在寻找的是可安装文件系统和网络提供程序的创建.

网络提供商(NP)是处理网络层的用户模式组件,包括驱动器号的映射和取消映射以及许多其他相当复杂的UNC /网络内容.要了解您的用途,请查看Win32 WNET *()API.您将需要实现所有专门用于IFS和"网络"的WNet()调用.

完成后,您可能将能够在DOS中执行"net use \ MyWebDrive \"并在Windows资源管理器中执行"映射网络驱动器".您也许还可以使用Windows资源管理器枚举远程文件系统的内容.

但是,现在您需要确保所有第三方应用程序都可以访问您的网络驱动器...为此,您想实现Win32 File System API,例如CreateFile,Read(),Write(),CloseHandle() ,FindFirst()等.

为此,您可以编写一个可安装文件系统驱动程序FSD,以处理来自希望读取/写入该映射网络驱动器上文件的用户模式应用程序的所有I / O调用.这很可能是一个内核模式应用程序……一个经过签名/认证的文件系统设备驱动程序……可能是用老式的C语言编写的,甚至可能取决于您想做网络IO的方式使用TDI.

Microsoft在安装第三方内核模式驱动程序和网络提供商方面变得越来越严格.现在,使用基于Microsoft的TLS证书对WebDrive文件系统驱动程序进行了安全签名,并且我们的网络提供商已在Microsoft Windows SDK团队中注册为Windows平台的合法网络提供商.

一旦完成这些步骤,就需要考虑缓存.通过NP / FSD通过导线直接I / O到Google是不现实的,因此您需要在本地驱动器上使用一个中间缓存系统.有很多方法可以做到这一点,太多了.但是,请记住,您可能有多个用户模式应用程序同时读写网络驱动器(或一个WinWord之类的应用程序会打开多个文件句柄),并且您将需要能够正确处理所有这些请求.锁定和ACL,然后将这些更改和访问规则映射到远程服务器.

不要失去信心...正如WebDrive和NetDrive所展示的,您正在寻找要做的事情,但这并不是一个可以在几个周末结束的项目.我不确定NetDrive的作者,但自1997年以来我们就一直在全职开发WebDrive.似乎每个Windows Patch都会更改某些内容,而每个新版本的Adobe / Office / XYZ都会通过IO调用来做一些古怪的事情,这使我们拉我们的头发.

注意:还有另一种方法可以实现FSD周围的野兽,这是DropBox策略.使用本地硬盘驱动器上的临时文件夹,利用用户模式应用程序中的目录更改通知来监视文件夹中的文件更改,并将更改动态同步到远程端.GoogleDrive和许多其他在线存储公司都这样做,因为它既快捷又容易;但是,如果在短时间内发生许多更改,则Windows消息系统中的更改通知可能会丢失,并且数据可能会被破坏.

我意识到要消化的东西很多,但这是可行的.祝好运!

速聊1:
确实需要消化很多东西,但是非常有帮助,并且是一个很好的高级概述.非常感谢您的回复.我可能还会在某个时候提出一些后续问题.再次感谢!
解决过程2

我建议您在开始编码之前,需要花一些时间来全面了解Google云端硬盘并将其功能映射到Windows.一些阻抗采样点:

  • 云端硬盘中的文件夹根本不是文件夹
  • 云端硬盘中的文件=元数据,内容是可选的
  • 云端硬盘具有很多无法映射到NTFS的元数据(例如属性)
  • 适用文件会转换为Google文档还是原样存储
  • 您将如何映射修订
  • 权限

几乎可以肯定还有更多,这简直就是我的头上.您的应用需要就所有这些方面做出决策.通常,云端硬盘比NTFS提供更多的功能,因此只要将其用作备份存储库,就可以了.

速聊1:
100%同意,而我实际上已经在这样做.大约一周前,我以身份验证和基本文件操作这一部分开始了我的第一个测试,只是为了获得一些基础并获得开发控制台的经验,并且我一直在研究驱动器的内部工作原理并提出想法.我可以做什么以及最终想要做什么.当然还有更多的东西要学习.我确实知道我将需要驱动器映射功能,因此我想早点而不是晚点开始收集建议(因此我不会在需要的时候停滞不前).感谢您的意见!
速聊2:
实际上,还有两点要考虑.1 /哑剧类型.驱动器使用mime-type就像Windows使用文件扩展名一样.2 /在Window中,文件由其路径/文件名标识;在云端硬盘中,文件由唯一的ID标识,其推论是文件名可以重复.
速聊3:
有趣的是,与传统的Windows文件系统相比,它似乎更像是在处理数据库条目/对象.这可以清除我在修改API时注意到的一些事情.
速聊4:
要考虑的另一个差异是如何处理NTFS文件快捷方式.

I am attempting to connect to my Google Drive using C# and the Google Drive API and then map that as a network or local drive. There are other programs I know that do this like NetDrive (which is extremely useful and robust), but I am looking to create something on my own. I have created a project in the developer console and have been able to connect to Drive using my application and do various read and upload operations, so I know that particular portion is ok. Access and permissions all seem to be set. I just have no idea where to start when it comes to mapping that storage as a usable drive in Windows. Any advice would be most helpful, thank you very much!

Talk1:
Haven't fully solved this quite yet, but I am looking into the Dokan libraries to try to accomplish this. It has the capabilities, I just need to figure out how to use it.
Solutions1

There are two basic components for implementing a NetDrive/WebDrive type of solution. What you are looking at is the creation of an Installable File System and Network Provider.

The Network Provider, or NP, is the user mode component that handles the Network layers, including the mapping and unmapping of the drive letter, along with lots of other fairly complicated UNC/Network stuff. To get an idea of what you are in for, check out the Win32 WNET*() API; you will need to implement all of the WNet() calls specifically for your IFS and 'network'.

When you are done, you'll probably have the ability to to do a "net use \MyWebDrive\" in DOS and Map Network Drive in Windows Explorer. You might also be able to use Windows Explorer to enum the contents of the remote file system.

However, now you need to make sure that all third party applications can access your network drive...to do that, you want to implement the Win32 File System API, such as CreateFile, Read(), Write(), CloseHandle(), FindFirst(), etc.

To do this, you can write an Installable File System Driver, FSD, to handle all I/O calls from User mode applications wanting to read/write to the files on that mapped network drive. This will most likely be a Kernel Mode application...a signed/certified file system device driver....probably written in old-school C and maybe even utilizing TDI depending on how you want to do your network IO.

Microsoft is becoming much more strict about installing 3rd party kernel mode drivers and network providers. The WebDrive file system driver is now securely signed using a Microsoft based TLS certificate and our Network Provider has been registered with the Microsoft Windows SDK team as a legitimate Network Provider for the Windows platform.

Once you get these pieces in place, you'll then want to think about Caching. Direct I/O through your NP/FSD over the wire to Google is not practical, so you'll need an intermediate caching system on your local drive. There are lots of ways to do that, too many to go into here. However, just keep in mind that you may have multiple user mode applications reading and writing to your network drive simultaneously (or one app like WinWord which opens multiple file handles), and you'll need to be able to handle all those requests with proper locking and ACLs, and then map those changes and access rules to the remote server.

Don't lose faith...what you are looking to do is possible as WebDrive and NetDrive have shown, but it's not really a project that can be knocked out in a few weekends. I'm not sure about the author of NetDrive, but we've been developing WebDrive full time since 1997. It seems that every Windows Patch changes something and every new version of Adobe/Office/XYZ does something quirky with IO calls that makes us pull our hair out.

Note: There's also another way to implement this beast which may get around the FSD, it's the DropBox strategy. Using a temporary folder on your local hard drive, leverage Directory Change Notifications in a User Mode application to monitor file changes in the folder and dynamically synchronize the changes to the remote end. GoogleDrive and a lot of the other online storage companies do it this way because it's quick-&-easy; however, if many changes occur in a short period, a Change Notification could get lost in Windows Messaging and data might get trashed.

I realize this is a lot to digest, but it's doable...it's cool stuff; good luck!

Talk1:
A lot to digest indeed, but very helpful and a really good high-level overview. I really appreciate your response. I'll probably have some follow-up questions at some point too. Thanks again!
Solutions2

I suggest that before you start coding, you take time to thoroughly understand Google Drive and map its capabilities to/from Windows. Some sample points of impedance:-

  • folders in Drive aren't folders at all
  • A file in Drive = the metadata, content is optional
  • Drive has a lot of metadata that doesn't map to NTFS (eg. properties)
  • Will applicable files be converted to Google Docs, or stored as is
  • How will you map revisions
  • Permissions

There are almost certainly more, this is just off the top of my head. Your app needs to make decisions regarding all of these aspects. Generally, Drive offers more capabilities than NTFS, so provided you are simply using it as a backup repository, you should be OK.

Talk1:
100% agree, and I'm actually already in the processes of doing just that. I started my first tests with the authentication and basic file operations piece about week ago just to get a bit of a base and to get some experience with the dev console, and I've been studying up on the inner workings of drive and giving thoughts to what I can do and what I ultimately want to do. Still have more to learn of course. I do know that I'll want the drive map feature, so I wanted to start gathering advice sooner rather than later (so I don't stall out when it's time). Thank you for your advice!
Talk2:
actually, another couple of points to consider. 1/ mime-type. Drive uses mime-type in the same was Windows uses file extension. 2/ In Window, a file is identified by its path/filename; in Drive a file is identified by a unique ID, with the corollary that file-names can be duplicated.
Talk3:
Interesting - it almost seems more like working with database entries/objects than a traditional Windows file system. That makes kind of clears up some things I was noticing when tinkering with the API.
Talk4:
Another discrepancy to consider is how you will deal with NTFS file shortcuts.
转载于:https://stackoverflow.com/questions/30859190/map-google-drive-to-network-drive-or-local-drive

本人是.net程序员,因为英语不行,使用工具翻译,希望对有需要的人有所帮助
如果本文质量不好,还请谅解,毕竟这些操作还是比较费时的,英语较好的可以看原文

留言回复
我们只提供高质量资源,素材,源码,坚持 下了就能用 原则,让客户花了钱觉得值
上班时间 : 周一至周五9:00-17:30 期待您的加入