Browse Source

Merge branch 'master' of http://git.ius.plus:88/Project-Wing/fis

loki.wu 2 years ago
parent
commit
b6b71e7d79
3 changed files with 91 additions and 12 deletions
  1. 0 12
      fis/Handlers/DynamicResourceHandler.cs
  2. 77 0
      fis/Handlers/ZipHandler.cs
  3. 14 0
      fis/Managers/BrowserManager.cs

+ 0 - 12
fis/Handlers/DynamicResourceHandler.cs

@@ -1,12 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace fis.Handlers
-{
-    class DynamicResourceHandler
-    {
-    }
-}

+ 77 - 0
fis/Handlers/ZipHandler.cs

@@ -0,0 +1,77 @@
+using System;
+using System.IO;
+using System.IO.Compression;
+using System.Linq;
+using Xilium.CefGlue.Common.Handlers;
+
+namespace fis.Win.Handlers
+{
+    internal class ZipHandler : IHostHandler, IDisposable
+    {
+        private readonly ZipArchive _archive;
+        private bool _disposed;
+
+        public string Host { get; }
+
+        public ZipHandler(string host, string zipFile)
+        {
+            Host = host;
+            _archive = ZipFile.Open(zipFile, ZipArchiveMode.Read);
+        }
+
+        ~ZipHandler()
+        {
+            Dispose();
+        }
+
+        public HandleResult Handle(string path, byte[] postData = null)
+        {
+            try
+            {
+                string text = path;
+                if (text.StartsWith("/"))
+                {
+                    text = text.Substring(1);
+                }
+                string path2 = "flyinsono/" +  text;
+                var entry = _archive.Entries.FirstOrDefault(x => x.FullName == path2);
+                if(entry != null)
+                {
+                    string mimeType = MimeTypeMap.GetMimeType(Path.GetExtension(path2)!.ToLower());
+                    using (var entryStream = entry.Open())
+                    {
+                        var ms = new MemoryStream();
+                        entryStream.CopyTo(ms);
+                        return new HandleResult(ms, mimeType);
+                    }
+
+                }
+                if (File.Exists(path2))
+                {
+                    
+                }
+            }
+            catch
+            {
+            }
+
+            return null;
+        }
+
+        private void DoDispose()
+        {
+            if (!_disposed)
+            {
+                _archive.Dispose();
+                _disposed = true;
+            }
+        }
+
+        public void Dispose()
+        {
+            // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
+            DoDispose();
+            GC.SuppressFinalize(this);
+        }
+    }
+}

+ 14 - 0
fis/Managers/BrowserManager.cs

@@ -1,8 +1,10 @@
 using fis.Mac;
 using fis.Utilities;
 using fis.Win;
+using fis.Win.Handlers;
 using System;
 using System.Collections.Generic;
+using System.IO;
 using System.Runtime.InteropServices;
 using Xilium.CefGlue;
 using Xilium.CefGlue.Avalonia;
@@ -83,6 +85,18 @@ namespace fis.Managers
             }
             _requestHandler = new HostRequestHandler();
             var appHandler = new FileSystemHostHandler(ShellConfig.Instance.AppHost, ShellConfig.Instance.AppResourcePath);
+            //从Zip创建Handler
+            //Zip路径:ShellConfig.Instance.AppResourcePath + "flyinsono.zip", 即 软件目录\App\flyinsono\flyinsono.zip
+            //Zip包内容结构:
+            //flyinosno.zip
+            //  -flyinsono
+            //      -canvicekit
+            //          -canvaskit.js
+            //          -...
+            //      -index.html
+            //      -flutter.js
+            //      -.....
+            //var appHandler = new ZipHandler(ShellConfig.Instance.AppHost, Path.Combine(ShellConfig.Instance.AppResourcePath, "flyinsono.zip"));
             var resourceHandler = new FileSystemHostHandler(ShellConfig.Instance.LocalResourceHost, ShellConfig.Instance.LocalResourcePath);
             var platformHandler = new JsonRpcHandler<IPlatformService>(ShellConfig.Instance.LocalApiHost, _platformService);
             _requestHandler.RegisterHostHandler(appHandler);