diff --git a/Sunfish/ShareWeb/$sunfish/$index.html b/Sunfish/ShareWeb/$sunfish/$index.html
index 6938d26..89bda8f 100644
--- a/Sunfish/ShareWeb/$sunfish/$index.html
+++ b/Sunfish/ShareWeb/$sunfish/$index.html
@@ -24,7 +24,7 @@
-
+
{Name}
{Description}
diff --git a/Sunfish/Sunfish/Middleware/HttpServer.cs b/Sunfish/Sunfish/Middleware/HttpServer.cs
index 4f2040a..f619e33 100644
--- a/Sunfish/Sunfish/Middleware/HttpServer.cs
+++ b/Sunfish/Sunfish/Middleware/HttpServer.cs
@@ -381,13 +381,19 @@
Response.Headers["Location"] = to;
}
- public void Forbidden()
+ public void HTTPBadRequest()
+ {
+ Response.StatusCode = 400;
+ Response.StatusDescription = "Bad Request";
+ }
+
+ public void HTTPForbidden()
{
Response.StatusCode = 402;
Response.StatusDescription = "Forbidden";
}
- public void NotFound()
+ public void HTTPNotFound()
{
Response.StatusCode = 404;
Response.StatusDescription = "Not found";
@@ -423,16 +429,6 @@
GetOut().BaseStream.TransferFrom(s);
}
- public void Write(Icon image)
- {
- using (MemoryStream ms = new MemoryStream())
- {
- image.Save(ms);
- ms.Position = 0;
- Write(ms);
- }
- }
-
public void Close()
{
if (swout == null)
diff --git a/Sunfish/Sunfish/Middleware/VFSFolderFileSystem.cs b/Sunfish/Sunfish/Middleware/VFSFolderFileSystem.cs
index 505893c..7b46287 100644
--- a/Sunfish/Sunfish/Middleware/VFSFolderFileSystem.cs
+++ b/Sunfish/Sunfish/Middleware/VFSFolderFileSystem.cs
@@ -8,7 +8,7 @@
namespace DolphinWebXplorer2.Middleware
{
- public class VFSFolderFileSystem:VFSFolder
+ public class VFSFolderFileSystem : VFSFolder
{
private string basePath;
@@ -26,7 +26,8 @@
try
{
return File.OpenRead(path);
- }catch { };
+ }
+ catch { };
return null;
}
@@ -37,12 +38,14 @@
public override VFSItem GetItem(string path)
{
+ if (Path.DirectorySeparatorChar != '/')
+ path = path.Replace('/', Path.DirectorySeparatorChar);
string fpath = Path.Combine(basePath, path);
FileInfo fi = new FileInfo(fpath);
DirectoryInfo di = new DirectoryInfo(fpath);
if (!fi.Exists && !di.Exists)
return null;
- return new VFSItem(this,path,di.Exists);
+ return new VFSItem(this, path, di.Exists, fi.Exists ? fi.Length : 0);
}
public override string[] ListDirectories(string path)
@@ -50,7 +53,7 @@
string fpath = Path.Combine(basePath, path);
List
lst = new List();
foreach (string d in Directory.GetDirectories(fpath))
- lst.Add(d.Substring(fpath.Length+1));
+ lst.Add(d.Substring(fpath.Length + 1));
lst.Sort();
return lst.ToArray();
}
@@ -65,5 +68,9 @@
return lst.ToArray();
}
+ public string GetFSPath(string path)
+ {
+ return Path.Combine(basePath, path);
+ }
}
}
diff --git a/Sunfish/Sunfish/Middleware/VFSItem.cs b/Sunfish/Sunfish/Middleware/VFSItem.cs
index b95cb86..ed05419 100644
--- a/Sunfish/Sunfish/Middleware/VFSItem.cs
+++ b/Sunfish/Sunfish/Middleware/VFSItem.cs
@@ -9,38 +9,41 @@
{
public class VFSItem
{
- private VFSFolder vfolder;
-
- public VFSItem(VFSFolder vfolder, string path, bool isFolder)
+
+ public VFSItem(VFSFolder vfolder, string path, bool isFolder, long length)
{
- this.vfolder = vfolder;
- this.Path = path;
- this.Folder = isFolder;
+ Folder = vfolder;
+ Path = path;
+ Directory = isFolder;
Name = System.IO.Path.GetFileName(Path);
+ Length = length;
}
public Stream OpenRead()
{
- return vfolder.OpenRead(Path);
+ return Folder.OpenRead(Path);
}
public Stream OpenWrite()
{
- return vfolder.OpenWrite(Path);
+ return Folder.OpenWrite(Path);
}
public string[] ListDirectories()
{
- return vfolder.ListDirectories(Path);
+ return Folder.ListDirectories(Path);
}
public string[] ListFiles()
{
- return vfolder.ListFiles(Path);
+ return Folder.ListFiles(Path);
}
public string Path { get; }
public string Name { get; }
- public bool Folder { get; }
+ public bool Directory { get; }
+ public long Length { get; }
+
+ public VFSFolder Folder { get; }
}
}
diff --git a/Sunfish/Sunfish/Middleware/WebUI.cs b/Sunfish/Sunfish/Middleware/WebUI.cs
index 41858fa..97f44e3 100644
--- a/Sunfish/Sunfish/Middleware/WebUI.cs
+++ b/Sunfish/Sunfish/Middleware/WebUI.cs
@@ -94,6 +94,7 @@
public string Name { get; set; }
public string Description { get; set; }
public string Link { get; set; }
+ public string Icon { get; set; }
public string Styles { get; set; }
}
diff --git a/Sunfish/Sunfish/Program.cs b/Sunfish/Sunfish/Program.cs
index a1b397a..bbf0cdb 100644
--- a/Sunfish/Sunfish/Program.cs
+++ b/Sunfish/Sunfish/Program.cs
@@ -7,7 +7,7 @@
{
static class Program
{
- public static string VERSION = "2.0(alpha3)";
+ public static string VERSION = "2.0(alpha5)";
private static Form1 mainform;
///
/// Punto de entrada principal para la aplicación.
diff --git a/Sunfish/Sunfish/Services/RootService.cs b/Sunfish/Sunfish/Services/RootService.cs
index 13ca342..9dc0efa 100644
--- a/Sunfish/Sunfish/Services/RootService.cs
+++ b/Sunfish/Sunfish/Services/RootService.cs
@@ -35,6 +35,7 @@
continue;
WebUI.WriteItem(new WebUIListItem()
{
+ Icon= "/$sunfish/folder.png",
Name = s.Configuration.Name,
Description = s.Configuration.Location,
Link = s.Configuration.Location,
@@ -66,7 +67,7 @@
}
}
else
- call.NotFound();
+ call.HTTPNotFound();
}
protected override void Start()
diff --git a/Sunfish/Sunfish/Services/WebService.cs b/Sunfish/Sunfish/Services/WebService.cs
index 8502c31..b709a1a 100644
--- a/Sunfish/Sunfish/Services/WebService.cs
+++ b/Sunfish/Sunfish/Services/WebService.cs
@@ -1,6 +1,9 @@
using DolphinWebXplorer2.Middleware;
using Json.Net;
+using System;
using System.Collections.Generic;
+using System.Drawing;
+using System.Drawing.Imaging;
using System.IO;
using System.Runtime.CompilerServices;
@@ -61,13 +64,34 @@
public override void Process(string path, HttpCall call)
{
+ string meta;
+ if (!call.Parameters.TryGetValue("meta", out meta))
+ meta = null;
+ else if (string.IsNullOrEmpty(meta))
+ meta = null;
+ switch (meta)
+ {
+ case null:
+ ProcessGET(path, call);
+ break;
+ case "icon":
+ ProcessIcon(path, call);
+ break;
+ default:
+ call.HTTPBadRequest();
+ break;
+ }
+ }
+
+ private void ProcessGET(string path, HttpCall call)
+ {
if (path.EndsWith("/"))
{
VFSItem idx = vfs.GetItem(path + index);
//Directory entry, go for index file or navigation
if (index != null)
{
- if (idx != null && !idx.Folder)
+ if (idx != null && !idx.Directory)
{
DownloadAt(idx, call);
return;
@@ -76,26 +100,86 @@
if (allowNavigation)
{
idx = vfs.GetItem(path);
- if (idx != null && idx.Folder)
+ if (idx != null && idx.Directory)
WriteIndex(idx, call);
else
- call.NotFound();
+ call.HTTPNotFound();
}
else
- call.Forbidden();
+ call.HTTPForbidden();
}
else
{
VFSItem idx = vfs.GetItem(path);
if (idx != null)
{
- if (idx.Folder)
+ if (idx.Directory)
call.Redirect(call.Request.Url.LocalPath + "/");
else
DownloadAt(idx, call);
}
else
- call.NotFound();
+ call.HTTPNotFound();
+ }
+ }
+
+ private void ProcessIcon(string path, HttpCall call)
+ {
+ if (path.EndsWith("/"))
+ {
+ call.HTTPForbidden();
+ }
+ else
+ {
+ VFSItem fil = vfs.GetItem(path);
+ VFSFolder fold = fil.Folder;
+
+ try
+ {
+ if (fil.Length < 10485760) //10Mb
+ using (Stream fstream = fil.OpenRead())
+ using (Image i = Image.FromStream(fstream))
+ using (Image t = i.GetThumbnailImage(32, 32, null, IntPtr.Zero))
+ {
+ WritePNG((Bitmap)t, call);
+ return;
+ }
+ }
+ catch { };
+
+ if (fold is VFSFolderFileSystem)
+ {
+ string realpath = ((VFSFolderFileSystem)fold).GetFSPath(fil.Path);
+ using (ShellIcon i = new ShellIcon(realpath))
+ WritePNG(i.Image, call);
+ }
+ else
+ {
+ using (ShellIcon i = new ShellIcon(path))
+ WritePNG(i.Image, call);
+ }
+ }
+ }
+
+ public void WriteIcon(Icon image, HttpCall call)
+ {
+ call.Response.ContentType = "image/vnd.microsoft.icon";
+ using (MemoryStream ms = new MemoryStream())
+ {
+ image.Save(ms);
+ ms.Position = 0;
+ call.Write(ms);
+ }
+ }
+
+ public void WritePNG(Image image, HttpCall call)
+ {
+ call.Response.ContentType = "image/png";
+ using (MemoryStream ms = new MemoryStream())
+ {
+ image.Save(ms, ImageFormat.Png);
+ ms.Position = 0;
+ call.Write(ms);
}
}
@@ -113,6 +197,7 @@
{
WebUI.WriteItem(new WebUIListItem()
{
+ Icon = "/$sunfish/folder.png",
Name = d,
Description = "Directory",
Link = d + "/"
@@ -127,6 +212,7 @@
{
WebUI.WriteItem(new WebUIListItem()
{
+ Icon = d + "?meta=icon",
Name = d,
Description = "File",
Link = d