可以定义在系统范围内使用的自定义URI方案
Is possible to define custom URI scheme used system-wide?
我一直在想是否有可能在Windows中创建一个库作为文件提供程序。
例如,如果您尝试使用标准的打开文件对话框打开ftp://example.com/touch.txt
文件,它(以某种方式神奇地)工作。是否有一种方法可以为我自己的URI方案实现我自己的提供者?
Asynchronous Pluggable Protocol
可能是一个解决方案吗?我无法找到一个关于如何使其工作的工作代码示例。
要理解:我需要这个在系统范围内工作。这是没有连接到互联网浏览器。
如果我需要这个File.Open("my://test.txt")
工作呢?
做File.ReadAllBytes("ftp://example.com/touch.txt");
不工作,如果你尝试它,你会得到一个异常,如
System.NotSupportedException was unhandled
Message=The given path's format is not supported.
Source=mscorlib
StackTrace:
at System.Security.Util.StringExpressionSet.CanonicalizePath(String path, Boolean needFullPath)
at System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath)
at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)
at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, AccessControlActions control, String[] pathList, Boolean checkForDuplicates, Boolean needFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at System.IO.File.ReadAllBytes(String path)
at WindowsFormsApplication1.Form1.button1_Click(Object sender, EventArgs e) in D:CodeWindowsFormsApplication1WindowsFormsApplication1Form1.cs:line 25
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at WindowsFormsApplication1.Program.Main() in D:CodeWindowsFormsApplication1WindowsFormsApplication1Program.cs:line 17
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
它工作的原因,当你做一个OpenFileDialog是windows欺骗,并将下载文件到本地临时文件夹首先。它只对ftp:
和http:
这样做,因为OpenFileDialog是由windows shell处理的,shell是使用URI方案的。
我相信HKCRftp
下的Source Filter
键指向一个注册的COM对象,该对象处理进行本地复制的逻辑。
如果你只是想让你的应用程序通过一个URL打开,就像steam对它的steam://rungameid/382110
一样,你只需要遵循这个MSDN页面中的说明。
如果你想要你的文件是"可打开的"通过shell像http:
或ftp:
与打开文件对话框,你需要写一个COM对象作为"源过滤器",我不知道有任何地方可以找到文档。
Update:阅读更多,它看起来像异步可插拔协议,就像你提到的是你如何制作那些源过滤器。我从来没有尝试过制作一个,所以我不能帮助你超越。
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- 如何将点击的信号和插槽添加到qt中的自定义按钮中
- C++自定义比较函数
- 如何比较自定义类的std::变体
- std::设置自定义比较器
- 如何正确实现和访问运算符的各种自定义枚举器
- flutter:即使shouldRepaint()返回true,自定义画家也不会重新绘制
- 自定义先决条件对移动分配运算符有效吗
- 使用VS Code和CMake Tools运行自定义命令
- 如何创建从Maya(或类似程序)到虚幻引擎的自定义数据导出插件
- std::ranges::elements_view,用于自定义类似元组的数据
- 跟随整数索引列表的自定义类迭代器
- 参数化自定义CMake工具链
- 使用自定义比较函数使用std::sort()对矢量字符串进行排序时出现问题
- 如何在自定义类中启用'auto loops'?
- 使用QJsEngine在Qt中注册自定义类型
- Qt自定义QPush按钮未显示在布局上
- 自定义对象的dlib序列化在gcc中失败
- 自定义创建QFuture
- 可以定义在系统范围内使用的自定义URI方案