|
@@ -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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|