diff --git a/Sunfish/Sunfish/Form1.Designer.cs b/Sunfish/Sunfish/Form1.Designer.cs
index 77178ea..120b6c5 100644
--- a/Sunfish/Sunfish/Form1.Designer.cs
+++ b/Sunfish/Sunfish/Form1.Designer.cs
@@ -56,9 +56,10 @@
// button1
//
this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.button1.Location = new System.Drawing.Point(142, 334);
+ this.button1.Location = new System.Drawing.Point(213, 514);
+ this.button1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.button1.Name = "button1";
- this.button1.Size = new System.Drawing.Size(92, 23);
+ this.button1.Size = new System.Drawing.Size(138, 35);
this.button1.TabIndex = 1;
this.button1.Text = "Ok";
this.toolTip1.SetToolTip(this.button1, "Hide");
@@ -68,14 +69,15 @@
// nudPort
//
this.nudPort.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.nudPort.Location = new System.Drawing.Point(179, 6);
+ this.nudPort.Location = new System.Drawing.Point(268, 9);
+ this.nudPort.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.nudPort.Maximum = new decimal(new int[] {
64000,
0,
0,
0});
this.nudPort.Name = "nudPort";
- this.nudPort.Size = new System.Drawing.Size(55, 20);
+ this.nudPort.Size = new System.Drawing.Size(82, 26);
this.nudPort.TabIndex = 3;
this.toolTip1.SetToolTip(this.nudPort, "Listen port");
this.nudPort.Value = new decimal(new int[] {
@@ -89,9 +91,10 @@
//
this.cbActive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.cbActive.AutoSize = true;
- this.cbActive.Location = new System.Drawing.Point(77, 8);
+ this.cbActive.Location = new System.Drawing.Point(119, 12);
+ this.cbActive.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.cbActive.Name = "cbActive";
- this.cbActive.Size = new System.Drawing.Size(90, 17);
+ this.cbActive.Size = new System.Drawing.Size(132, 24);
this.cbActive.TabIndex = 4;
this.cbActive.Text = "Listen on port";
this.toolTip1.SetToolTip(this.cbActive, "Enable whole server");
@@ -104,9 +107,10 @@
this.btAdd.Font = new System.Drawing.Font("Lucida Console", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btAdd.ImageIndex = 0;
this.btAdd.ImageList = this.il16;
- this.btAdd.Location = new System.Drawing.Point(6, 334);
+ this.btAdd.Location = new System.Drawing.Point(9, 514);
+ this.btAdd.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.btAdd.Name = "btAdd";
- this.btAdd.Size = new System.Drawing.Size(23, 23);
+ this.btAdd.Size = new System.Drawing.Size(34, 35);
this.btAdd.TabIndex = 5;
this.toolTip1.SetToolTip(this.btAdd, "Add new access");
this.btAdd.UseVisualStyleBackColor = true;
@@ -126,9 +130,10 @@
this.btSub.Font = new System.Drawing.Font("Lucida Console", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btSub.ImageKey = "bt_minus.bmp";
this.btSub.ImageList = this.il16;
- this.btSub.Location = new System.Drawing.Point(35, 334);
+ this.btSub.Location = new System.Drawing.Point(52, 514);
+ this.btSub.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.btSub.Name = "btSub";
- this.btSub.Size = new System.Drawing.Size(23, 23);
+ this.btSub.Size = new System.Drawing.Size(34, 35);
this.btSub.TabIndex = 6;
this.toolTip1.SetToolTip(this.btSub, "Remove >selected access");
this.btSub.UseVisualStyleBackColor = true;
@@ -145,9 +150,10 @@
this.lbPaths.FormattingEnabled = true;
this.lbPaths.IntegralHeight = false;
this.lbPaths.ItemHeight = 28;
- this.lbPaths.Location = new System.Drawing.Point(0, 32);
+ this.lbPaths.Location = new System.Drawing.Point(0, 49);
+ this.lbPaths.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.lbPaths.Name = "lbPaths";
- this.lbPaths.Size = new System.Drawing.Size(240, 296);
+ this.lbPaths.Size = new System.Drawing.Size(358, 453);
this.lbPaths.TabIndex = 7;
this.lbPaths.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.lbPaths_DrawItem);
this.lbPaths.SelectedIndexChanged += new System.EventHandler(this.lbPaths_SelectedIndexChanged);
@@ -157,20 +163,21 @@
//
// cmsItem
//
+ this.cmsItem.ImageScalingSize = new System.Drawing.Size(24, 24);
this.cmsItem.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.añadirToolStripMenuItem,
this.editarToolStripMenuItem,
this.borrarToolStripMenuItem,
this.toolStripSeparator1});
this.cmsItem.Name = "cmsItem";
- this.cmsItem.Size = new System.Drawing.Size(132, 76);
+ this.cmsItem.Size = new System.Drawing.Size(193, 106);
this.cmsItem.Opening += new System.ComponentModel.CancelEventHandler(this.cmsItem_Opening);
//
// añadirToolStripMenuItem
//
this.añadirToolStripMenuItem.Name = "añadirToolStripMenuItem";
this.añadirToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.Insert;
- this.añadirToolStripMenuItem.Size = new System.Drawing.Size(131, 22);
+ this.añadirToolStripMenuItem.Size = new System.Drawing.Size(192, 32);
this.añadirToolStripMenuItem.Text = "Añadir";
this.añadirToolStripMenuItem.Click += new System.EventHandler(this.btAdd_Click);
//
@@ -178,30 +185,31 @@
//
this.editarToolStripMenuItem.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold);
this.editarToolStripMenuItem.Name = "editarToolStripMenuItem";
- this.editarToolStripMenuItem.Size = new System.Drawing.Size(131, 22);
+ this.editarToolStripMenuItem.Size = new System.Drawing.Size(192, 32);
this.editarToolStripMenuItem.Text = "Editar";
//
// borrarToolStripMenuItem
//
this.borrarToolStripMenuItem.Name = "borrarToolStripMenuItem";
this.borrarToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.Delete;
- this.borrarToolStripMenuItem.Size = new System.Drawing.Size(131, 22);
+ this.borrarToolStripMenuItem.Size = new System.Drawing.Size(192, 32);
this.borrarToolStripMenuItem.Text = "Borrar";
this.borrarToolStripMenuItem.Click += new System.EventHandler(this.btSub_Click);
//
// toolStripSeparator1
//
this.toolStripSeparator1.Name = "toolStripSeparator1";
- this.toolStripSeparator1.Size = new System.Drawing.Size(128, 6);
+ this.toolStripSeparator1.Size = new System.Drawing.Size(189, 6);
//
// btShowIp
//
this.btShowIp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btShowIp.Font = new System.Drawing.Font("Lucida Console", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btShowIp.Image = global::DolphinWebXplorer2.Properties.Resources.messagebox_info;
- this.btShowIp.Location = new System.Drawing.Point(113, 334);
+ this.btShowIp.Location = new System.Drawing.Point(170, 514);
+ this.btShowIp.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.btShowIp.Name = "btShowIp";
- this.btShowIp.Size = new System.Drawing.Size(23, 23);
+ this.btShowIp.Size = new System.Drawing.Size(34, 35);
this.btShowIp.TabIndex = 8;
this.toolTip1.SetToolTip(this.btShowIp, "Show network information");
this.btShowIp.UseVisualStyleBackColor = true;
@@ -212,9 +220,10 @@
this.btGeneralOptions.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btGeneralOptions.Font = new System.Drawing.Font("Lucida Console", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btGeneralOptions.Image = global::DolphinWebXplorer2.Properties.Resources.run;
- this.btGeneralOptions.Location = new System.Drawing.Point(84, 334);
+ this.btGeneralOptions.Location = new System.Drawing.Point(126, 514);
+ this.btGeneralOptions.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.btGeneralOptions.Name = "btGeneralOptions";
- this.btGeneralOptions.Size = new System.Drawing.Size(23, 23);
+ this.btGeneralOptions.Size = new System.Drawing.Size(34, 35);
this.btGeneralOptions.TabIndex = 9;
this.toolTip1.SetToolTip(this.btGeneralOptions, "General Options");
this.btGeneralOptions.UseVisualStyleBackColor = true;
@@ -222,33 +231,34 @@
//
// cmsGOptions
//
+ this.cmsGOptions.ImageScalingSize = new System.Drawing.Size(24, 24);
this.cmsGOptions.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.shareScreenToolStripMenuItem});
this.cmsGOptions.Name = "cmsGOptions";
- this.cmsGOptions.Size = new System.Drawing.Size(142, 26);
+ this.cmsGOptions.Size = new System.Drawing.Size(186, 36);
//
// shareScreenToolStripMenuItem
//
this.shareScreenToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.tstbPassword});
this.shareScreenToolStripMenuItem.Name = "shareScreenToolStripMenuItem";
- this.shareScreenToolStripMenuItem.Size = new System.Drawing.Size(141, 22);
+ this.shareScreenToolStripMenuItem.Size = new System.Drawing.Size(185, 32);
this.shareScreenToolStripMenuItem.Text = "Share Screen";
this.shareScreenToolStripMenuItem.Click += new System.EventHandler(this.shareScreenToolStripMenuItem_Click);
//
// tstbPassword
//
this.tstbPassword.Name = "tstbPassword";
- this.tstbPassword.Size = new System.Drawing.Size(100, 23);
+ this.tstbPassword.Size = new System.Drawing.Size(100, 31);
this.tstbPassword.ToolTipText = "Password";
this.tstbPassword.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.tstbPassword_KeyPress);
this.tstbPassword.TextChanged += new System.EventHandler(this.tstbPassword_TextChanged);
//
// Form1
//
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(240, 363);
+ this.ClientSize = new System.Drawing.Size(360, 558);
this.Controls.Add(this.btGeneralOptions);
this.Controls.Add(this.btShowIp);
this.Controls.Add(this.lbPaths);
@@ -257,6 +267,7 @@
this.Controls.Add(this.cbActive);
this.Controls.Add(this.nudPort);
this.Controls.Add(this.button1);
+ this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Sunfish";
diff --git a/Sunfish/Sunfish/Form1.cs b/Sunfish/Sunfish/Form1.cs
index 4678d8a..e42b13a 100644
--- a/Sunfish/Sunfish/Form1.cs
+++ b/Sunfish/Sunfish/Form1.cs
@@ -261,5 +261,9 @@
Activate();
}
}
+
+ private void button2_Click(object sender, EventArgs e)
+ {
+ }
}
}
diff --git a/Sunfish/Sunfish/Form1.resx b/Sunfish/Sunfish/Form1.resx
index 092f2db..012af4b 100644
--- a/Sunfish/Sunfish/Form1.resx
+++ b/Sunfish/Sunfish/Form1.resx
@@ -112,23 +112,23 @@
2.0
- System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
- System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
+
17, 17
-
+
114, 17
- AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj0yLjAuMC4w
+ AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAAq
- AQAAAk1TRnQBSQFMAgEBAgEAAVABAAFQAQABEAEAARABAAT/AQUBAAj/AUIBTQF2BwABdgMAASgDAAFA
+ AQAAAk1TRnQBSQFMAgEBAgEAAWABAAFgAQABEAEAARABAAT/AQUBAAj/AUIBTQF2BwABdgMAASgDAAFA
AwABEAMAAQEBAAEEBgABAhgAAYACAAGAAwACgAEAAYADAAGAAQABgAEAAoACAAPAAQADgAMAAf8CAAH/
AwAC/wEAAf8DAAH/AQAB/wEAAv8CAAP//wD/AAMAAUIBTQE+BwABPgMAASgDAAFAAwABEAMAAQEBAAEB
BQABgBcAA/8BAAT/BAAE/wQABP8EAAH8AT8C/wQAAfwBPwL/BAAB/AE/Av8EAAHgAQcB4AEHBAAB4AEH
@@ -136,13 +136,10 @@
BAAL
-
- 17, 17
-
-
+
185, 17
-
+
283, 17
\ No newline at end of file
diff --git a/Sunfish/Sunfish/HttpServer.cs b/Sunfish/Sunfish/HttpServer.cs
deleted file mode 100644
index 41c1f54..0000000
--- a/Sunfish/Sunfish/HttpServer.cs
+++ /dev/null
@@ -1,474 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.IO;
-using System.Net;
-using System.Web;
-using System.Threading;
-using DolphinWebXplorer2;
-
-namespace XWolf
-{
- public class HttpServer
- {
- private int port;
- private HttpListener lis = null;
- private Thread loop = null;
- private bool multiThread = true;
- private List processors = new List();
- private List errors = new List();
- private WindowsFirewallRule fwRule;
- public delegate void ErrorEventHandler(HttpServer server, Exception e);
- public delegate HttpServerProcessor CreateProcessorHandler(HttpServer server);
- public event ErrorEventHandler Error;
- public event CreateProcessorHandler CreateProcessor;
-
- public HttpServer(int port)
- {
- this.port = port;
- }
-
- public bool Start()
- {
- if (lis != null)
- return false;
- lis = new HttpListener();
- lis.Prefixes.Add("http://+:" + port + "/");
- try
- {
- lis.Start();
- }
- catch (HttpListenerException e)
- {
- lis = null;
- return false;
- }
- loop = new Thread(ServerLoop);
- loop.Start();
- return true;
- }
-
- private void ServerLoop()
- {
- for (; ; )
- {
- HttpListenerContext ctx = lis.GetContext();
- if (multiThread)
- {
- new Thread(new ParameterizedThreadStart(MultithreadCall)).Start(ctx);
- }
- else
- CallNewProcessor(ctx);
- }
- }
-
- private void MultithreadCall(object octx)
- {
- lock (processors)
- {
- processors.Add(Thread.CurrentThread);
- }
- CallNewProcessor((HttpListenerContext)octx);
- lock (processors)
- {
- processors.Remove(Thread.CurrentThread);
- }
- }
-
- private void CallNewProcessor(HttpListenerContext ctx)
- {
- HttpServerProcessor proc = CreateProcessor == null ? new HttpServerProcessor() : CreateProcessor(this);
- proc.server = this;
- proc.Process(ctx);
- }
-
- public bool Stop()
- {
- if (lis == null)
- return false;
- if (loop != null)
- {
- try { loop.Abort(); }
- catch { };
- loop = null;
- }
- try { lis.Stop(); }
- catch { };
- try { lis.Close(); }
- catch { };
- try
- {
- lis = null;
- foreach (Thread son in processors.ToArray())
- try { son.Abort(); }
- catch { };
- }
- finally
- {
- }
- return true;
- }
-
- internal void LogError(Exception e)
- {
- errors.Add(new LogError(e));
- if (Error != null)
- Error(this, e);
- }
-
- public bool Up { get { return lis != null; } }
- public int Port { get { return port; } set { port = value; } }
- public bool MultiThread { get { return multiThread; } set { multiThread = value; } }
- }
-
- public class HttpServerProcessor
- {
- protected HttpListenerRequest Request;
- protected HttpListenerResponse Response;
- protected System.Security.Principal.IPrincipal User;
- protected HttpPost Post;
- private StreamWriter swout;
- private string path;
- private Dictionary getArgs = new Dictionary();
- internal HttpServer server;
-
- internal void Process(HttpListenerContext ctx)
- {
- Exception error = null;
- try
- {
- Request = ctx.Request;
- Response = ctx.Response;
- User = ctx.User;
- System.Text.Encoding utf8EncoderNoBOM = new System.Text.UTF8Encoding(false);
- swout = new StreamWriter(Response.OutputStream, utf8EncoderNoBOM);
- Response.Headers[HttpResponseHeader.ContentType] = "text/html";
- Response.Headers[HttpResponseHeader.ContentEncoding] = "UTF-8";
- getArgs.Clear();
- if ("POST" == Request.HttpMethod)
- {
- Post = new HttpPost(this, Request.InputStream, Request.ContentType, Request.ContentEncoding);
- }
- GetHeaders();
- Process();
- Out.Close();
- }
- catch (Exception e)
- {
- error = e;
- try
- {
- Out.Close();
- }
- catch { };
- }
- try
- {
- ctx.Response.Close();
- }
- catch { };
- if (error != null && server != null)
- {
- server.LogError(error);
- }
- }
-
- private void GetHeaders()
- {
- path = Request.Url.LocalPath;
- string qs = Request.Url.Query;
- if (qs.StartsWith("?"))
- ReadEncodedArguments(qs.Substring(1));
- }
-
- internal void ReadEncodedArguments(string qs)
- {
- string[] args = qs.Split('&');
- foreach (string arg in args)
- {
- int ppos = arg.IndexOf('=');
- if (ppos == -1)
- getArgs[arg] = "true";
- else
- {
- string aname = arg.Substring(0, ppos);
- string aval = arg.Substring(ppos + 1);
- getArgs[aname] = HttpUtility.UrlDecode(aval);
- }
- }
- }
-
- internal void SetArgument(string name, string value)
- {
- getArgs[name] = value;
- }
-
- public HttpListenerResponse GetResponse() { return Response; }
-
- protected void Error404()
- {
- Response.StatusCode = 404;
- Response.StatusDescription = "Not found";
- }
-
- public void Write(String s)
- {
- if (s != null)
- swout.Write(s);
- }
-
- public void Write(object o)
- {
- if (o != null)
- swout.Write(o);
- }
-
- public void Write(byte[] data)
- {
- swout.Flush();
- OutStream.Write(data, 0, data.Length);
- }
-
- public void Write(byte[] data, int offset, int count)
- {
- swout.Flush();
- OutStream.Write(data, offset, count);
- }
-
- public string nl2br(string s)
- {
- return s.Replace("\r\n", "
").Replace("\n", "
").Replace("\r", "
");
- }
-
- public string UrlEncode(string url)
- {
- return HttpUtility.UrlEncode(url);
- }
-
- public string UrlDecode(string url)
- {
- return HttpUtility.UrlDecode(url);
- }
-
- virtual protected void Process()
- {
- Error404();
- }
-
- protected Stream OutStream { get { return Response.OutputStream; } }
- protected StreamWriter Out { get { return swout; } }
- public string Path { get { return path; } }
- public Dictionary GET { get { return getArgs; } }
- public Dictionary POST { get { return getArgs; } }
- }
-
- public class LogError
- {
- public LogError(Exception e)
- {
- Exception = e;
- }
-
- public DateTime Time { get; } = DateTime.Now;
- public Exception Exception { get; }
- }
-
- public class HttpPost
- {
- private string contentType;
- private Dictionary parms;
- private Dictionary files=new Dictionary();
- private HttpServerProcessor owner;
- private Encoding encoding;
- private static char[] CRLF = { '\r', '\n' };
- private string mimeBoundary;
- private char[] mimeBoundaryChr;
- private byte[] mimeBoundaryBytes;
-
- public HttpPost(HttpServerProcessor owner, Stream input, string contentType, Encoding enc)
- {
- this.owner = owner;
- this.encoding = enc;
- string[] cttp = contentType.Split(';');
- this.contentType = cttp[0];
- if (cttp.Length > 1)
- {
- parms = new Dictionary();
- for (int i = 1; i < cttp.Length; i++)
- {
- string[] s = cttp[i].Trim().Split('=');
- parms[s[0]] = s.Length > 1 ? s[1] : "X";
- }
- }
- if ("multipart/form-data".Equals(cttp[0], StringComparison.InvariantCultureIgnoreCase))
- ReadMultipart(input);
- else
- if ("application/x-www-form-urlencoded".Equals(cttp[0], StringComparison.InvariantCultureIgnoreCase))
- ReadPost(input);
- }
-
- private void ReadPost(Stream input)
- {
- MemoryStream ms = new MemoryStream();
- byte[] buf = new byte[10240];
- int readed = 0;
- while ((readed = input.Read(buf, 0, buf.Length)) > 0)
- {
- ms.Write(buf, 0, readed);
- if (ms.Length > 1024 * 1024)
- return;
- }
- ms.Close();
- string args = encoding.GetString(ms.ToArray());
- owner.ReadEncodedArguments(args);
- }
-
- private void ReadMultipart(Stream input)
- {
- mimeBoundary = "--"+parms["boundary"];
- BinaryReader br = new BinaryReader(input, encoding);
- string bnd = ReadLine(br);
- if (bnd == mimeBoundary + "--")
- return; //empty
- if (bnd != mimeBoundary)
- throw new Exception("form-data boundary error.");
- mimeBoundary = "\r\n" + mimeBoundary;
- mimeBoundaryChr = mimeBoundary.ToCharArray();
- mimeBoundaryBytes = Encoding.ASCII.GetBytes(mimeBoundary);
- while (ReadFormData(br)) ;
- }
-
- private string ReadLine(BinaryReader br)
- {
- return ReadUntil(br, CRLF);
- }
-
- private string ReadStringToBoundary(BinaryReader br)
- {
- return ReadUntil(br, mimeBoundaryChr);
- }
-
- private string ReadUntil(BinaryReader br, char[] signal)
- {
- List chars = new List();
- while (true)
- {
- char ch = br.ReadChar();
- chars.Add(ch);
- if (chars.Count >= signal.Length)
- {
- bool eq = true;
- for (int i = 0; i < signal.Length; i++)
- {
- if (signal[i]!=chars[(chars.Count-signal.Length)+i])
- {
- eq = false;
- break;
- }
- }
- if (eq)
- {
- char[] chs = chars.ToArray();
- return new string(chs,0,chs.Length-signal.Length);
- }
- }
- }
- }
-
- private byte[] ReadUntil(BinaryReader br, byte[] signal)
- {
- List bytes = new List();
- while (true)
- {
- byte by = br.ReadByte();
- bytes.Add(by);
- if (bytes.Count >= signal.Length)
- {
- bool eq = true;
- for (int i = 0; i < signal.Length; i++)
- {
- if (signal[i] != bytes[(bytes.Count - signal.Length) + i])
- {
- eq = false;
- break;
- }
- }
- if (eq)
- {
- return bytes.ToArray();
- }
- }
- }
- }
-
- private bool ReadFormData(BinaryReader br)
- {
- Dictionary hdrs = new Dictionary();
- while (true)
- {
- string line = ReadLine(br);
- if (line.Length == 0)
- break;
- int dp = line.IndexOf(':');
- if (dp < 0)
- throw new Exception("multipart form data error");
- hdrs[line.Substring(0, dp)] = line.Substring(dp + 1);
- }
- Dictionary cdisp = GetContentDisposition(hdrs);
- if (hdrs.ContainsKey("Content-Type") || cdisp.ContainsKey("filename"))
- {
- byte[] data = ReadUntil(br, mimeBoundaryBytes);
- string fname = cdisp["filename"];
- if (fname.Length>0)
- files[cdisp["name"]] = new HttpPostFile(fname, data);
- }
- else
- {
- string data = ReadStringToBoundary(br);
- owner.SetArgument(cdisp["name"], data);
- }
- char ch1 = br.ReadChar();
- char ch2 = br.ReadChar();
- if (ch1 == '\r' && ch2 == '\n')
- return true;
- if (ch1 == '-' && ch2 == '-')
- return false;
- throw new Exception("Error reading multipart (" + ch1 + ch2 + ")");
- }
-
- private Dictionary GetContentDisposition(Dictionary hdrs)
- {
- if (!hdrs.ContainsKey("Content-Disposition"))
- return null;
- Dictionary result = new Dictionary();
- foreach (string cd in hdrs["Content-Disposition"].Split(';')){
- int pos = cd.IndexOf("=");
- if (pos < 0)
- continue;
- string name = cd.Substring(1, pos-1);
- string var = cd.Substring(pos + 1);
- if (var.Length > 0 && var[0] == '"')
- var = var.Substring(1, var.Length - 2);
- result[name] = var;
- }
- return result;
- }
-
- public Dictionary File { get { return files; } }
- }
-
- public class HttpPostFile
- {
- private string filename;
- private byte[] data;
-
- internal HttpPostFile(string filename, byte[] data)
- {
- this.filename = filename;
- this.data = data;
- }
-
- public string Filename { get { return filename; } }
- public byte[] Data { get { return data; } }
- }
-}
diff --git a/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwAuthorizedApplication.cs b/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwAuthorizedApplication.cs
new file mode 100644
index 0000000..dfac91d
--- /dev/null
+++ b/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwAuthorizedApplication.cs
@@ -0,0 +1,77 @@
+using System;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+namespace NetFwTypeLib
+{
+ [Guid("B5E64FFA-C2C5-444E-A301-FB5E00018050"), TypeLibType(4160)]
+ [ComImport]
+ public interface INetFwAuthorizedApplication
+ {
+ [DispId(1)]
+ string Name
+ {
+ [DispId(1)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.BStr)]
+ get;
+ [DispId(1)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [param: MarshalAs(UnmanagedType.BStr)]
+ set;
+ }
+ [DispId(2)]
+ string ProcessImageFileName
+ {
+ [DispId(2)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.BStr)]
+ get;
+ [DispId(2)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [param: MarshalAs(UnmanagedType.BStr)]
+ set;
+ }
+ [DispId(3)]
+ NET_FW_IP_VERSION_ IpVersion
+ {
+ [DispId(3)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(3)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(4)]
+ NET_FW_SCOPE_ Scope
+ {
+ [DispId(4)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(4)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(5)]
+ string RemoteAddresses
+ {
+ [DispId(5)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.BStr)]
+ get;
+ [DispId(5)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [param: MarshalAs(UnmanagedType.BStr)]
+ set;
+ }
+ [DispId(6)]
+ bool Enabled
+ {
+ [DispId(6)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(6)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ }
+}
diff --git a/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwAuthorizedApplications.cs b/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwAuthorizedApplications.cs
new file mode 100644
index 0000000..95b3e92
--- /dev/null
+++ b/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwAuthorizedApplications.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Collections;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+namespace NetFwTypeLib
+{
+ [Guid("644EFD52-CCF9-486C-97A2-39F352570B30"), TypeLibType(4160)]
+ [ComImport]
+ public interface INetFwAuthorizedApplications : IEnumerable
+ {
+ [DispId(1)]
+ int Count
+ {
+ [DispId(1)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ }
+ [DispId(2)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ void Add([MarshalAs(UnmanagedType.Interface)] [In] INetFwAuthorizedApplication app);
+ [DispId(3)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ void Remove([MarshalAs(UnmanagedType.BStr)] [In] string imageFileName);
+ [DispId(4)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.Interface)]
+ INetFwAuthorizedApplication Item([MarshalAs(UnmanagedType.BStr)] [In] string imageFileName);
+ [DispId(-4), TypeLibFunc(1)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalType = "System.Runtime.InteropServices.CustomMarshalers.EnumeratorToEnumVariantMarshaler")]
+ IEnumerator GetEnumerator();
+ }
+}
diff --git a/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwIcmpSettings.cs b/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwIcmpSettings.cs
new file mode 100644
index 0000000..cbf0236
--- /dev/null
+++ b/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwIcmpSettings.cs
@@ -0,0 +1,111 @@
+using System;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+namespace NetFwTypeLib
+{
+ [Guid("A6207B2E-7CDD-426A-951E-5E1CBC5AFEAD"), TypeLibType(4160)]
+ [ComImport]
+ public interface INetFwIcmpSettings
+ {
+ [DispId(1)]
+ bool AllowOutboundDestinationUnreachable
+ {
+ [DispId(1)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(1)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(2)]
+ bool AllowRedirect
+ {
+ [DispId(2)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(2)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(3)]
+ bool AllowInboundEchoRequest
+ {
+ [DispId(3)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(3)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(4)]
+ bool AllowOutboundTimeExceeded
+ {
+ [DispId(4)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(4)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(5)]
+ bool AllowOutboundParameterProblem
+ {
+ [DispId(5)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(5)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(6)]
+ bool AllowOutboundSourceQuench
+ {
+ [DispId(6)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(6)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(7)]
+ bool AllowInboundRouterRequest
+ {
+ [DispId(7)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(7)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(8)]
+ bool AllowInboundTimestampRequest
+ {
+ [DispId(8)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(8)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(9)]
+ bool AllowInboundMaskRequest
+ {
+ [DispId(9)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(9)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(10)]
+ bool AllowOutboundPacketTooBig
+ {
+ [DispId(10)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(10)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ }
+}
diff --git a/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwMgr.cs b/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwMgr.cs
new file mode 100644
index 0000000..27b252a
--- /dev/null
+++ b/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwMgr.cs
@@ -0,0 +1,35 @@
+using System;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+namespace NetFwTypeLib
+{
+ [Guid("F7898AF5-CAC4-4632-A2EC-DA06E5111AF2"), TypeLibType(4160)]
+ [ComImport]
+ public interface INetFwMgr
+ {
+ [DispId(1)]
+ INetFwPolicy LocalPolicy
+ {
+ [DispId(1)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.Interface)]
+ get;
+ }
+ [DispId(2)]
+ NET_FW_PROFILE_TYPE_ CurrentProfileType
+ {
+ [DispId(2)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ }
+ [DispId(3)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ void RestoreDefaults();
+ [DispId(4)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ void IsPortAllowed([MarshalAs(UnmanagedType.BStr)] [In] string imageFileName, [In] NET_FW_IP_VERSION_ IpVersion, [In] int portNumber, [MarshalAs(UnmanagedType.BStr)] [In] string localAddress, [In] NET_FW_IP_PROTOCOL_ ipProtocol, [MarshalAs(UnmanagedType.Struct)] out object allowed, [MarshalAs(UnmanagedType.Struct)] out object restricted);
+ [DispId(5)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ void IsIcmpTypeAllowed([In] NET_FW_IP_VERSION_ IpVersion, [MarshalAs(UnmanagedType.BStr)] [In] string localAddress, [In] byte Type, [MarshalAs(UnmanagedType.Struct)] out object allowed, [MarshalAs(UnmanagedType.Struct)] out object restricted);
+ }
+}
diff --git a/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwOpenPort.cs b/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwOpenPort.cs
new file mode 100644
index 0000000..7a34295
--- /dev/null
+++ b/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwOpenPort.cs
@@ -0,0 +1,92 @@
+using System;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+namespace NetFwTypeLib
+{
+ [Guid("E0483BA0-47FF-4D9C-A6D6-7741D0B195F7"), TypeLibType(4160)]
+ [ComImport]
+ public interface INetFwOpenPort
+ {
+ [DispId(1)]
+ string Name
+ {
+ [DispId(1)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.BStr)]
+ get;
+ [DispId(1)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [param: MarshalAs(UnmanagedType.BStr)]
+ set;
+ }
+ [DispId(2)]
+ NET_FW_IP_VERSION_ IpVersion
+ {
+ [DispId(2)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(2)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(3)]
+ NET_FW_IP_PROTOCOL_ Protocol
+ {
+ [DispId(3)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(3)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(4)]
+ int Port
+ {
+ [DispId(4)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(4)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(5)]
+ NET_FW_SCOPE_ Scope
+ {
+ [DispId(5)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(5)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(6)]
+ string RemoteAddresses
+ {
+ [DispId(6)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.BStr)]
+ get;
+ [DispId(6)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [param: MarshalAs(UnmanagedType.BStr)]
+ set;
+ }
+ [DispId(7)]
+ bool Enabled
+ {
+ [DispId(7)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(7)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(8)]
+ bool BuiltIn
+ {
+ [DispId(8)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ }
+ }
+}
diff --git a/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwOpenPorts.cs b/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwOpenPorts.cs
new file mode 100644
index 0000000..abeaaed
--- /dev/null
+++ b/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwOpenPorts.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Collections;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+namespace NetFwTypeLib
+{
+ [Guid("C0E9D7FA-E07E-430A-B19A-090CE82D92E2"), TypeLibType(4160)]
+ [ComImport]
+ public interface INetFwOpenPorts : IEnumerable
+ {
+ [DispId(1)]
+ int Count
+ {
+ [DispId(1)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ }
+ [DispId(2)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ void Add([MarshalAs(UnmanagedType.Interface)] [In] INetFwOpenPort Port);
+ [DispId(3)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ void Remove([In] int portNumber, [In] NET_FW_IP_PROTOCOL_ ipProtocol);
+ [DispId(4)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.Interface)]
+ INetFwOpenPort Item([In] int portNumber, [In] NET_FW_IP_PROTOCOL_ ipProtocol);
+ [DispId(-4), TypeLibFunc(1)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalType = "System.Runtime.InteropServices.CustomMarshalers.EnumeratorToEnumVariantMarshaler")]
+ IEnumerator GetEnumerator();
+ }
+}
diff --git a/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwPolicy.cs b/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwPolicy.cs
new file mode 100644
index 0000000..5f108b0
--- /dev/null
+++ b/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwPolicy.cs
@@ -0,0 +1,23 @@
+using System;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+namespace NetFwTypeLib
+{
+ [Guid("D46D2478-9AC9-4008-9DC7-5563CE5536CC"), TypeLibType(4160)]
+ [ComImport]
+ public interface INetFwPolicy
+ {
+ [DispId(1)]
+ INetFwProfile CurrentProfile
+ {
+ [DispId(1)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.Interface)]
+ get;
+ }
+ [DispId(2)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.Interface)]
+ INetFwProfile GetProfileByType([In] NET_FW_PROFILE_TYPE_ profileType);
+ }
+}
diff --git a/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwPolicy2.cs b/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwPolicy2.cs
new file mode 100644
index 0000000..c08c9e0
--- /dev/null
+++ b/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwPolicy2.cs
@@ -0,0 +1,129 @@
+using System;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+namespace NetFwTypeLib
+{
+ [Guid("98325047-C671-4174-8D81-DEFCD3F03186"), TypeLibType(4160)]
+ [ComImport]
+ public interface INetFwPolicy2
+ {
+ [DispId(1)]
+ int CurrentProfileTypes
+ {
+ [DispId(1)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ }
+ [DispId(2)]
+ bool FirewallEnabled
+ {
+ [DispId(2)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(2)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(3)]
+ object ExcludedInterfaces
+ {
+ [DispId(3)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.Struct)]
+ get;
+ [DispId(3)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [param: MarshalAs(UnmanagedType.Struct)]
+ set;
+ }
+ [DispId(4)]
+ bool BlockAllInboundTraffic
+ {
+ [DispId(4)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(4)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(5)]
+ bool NotificationsDisabled
+ {
+ [DispId(5)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(5)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(6)]
+ bool UnicastResponsesToMulticastBroadcastDisabled
+ {
+ [DispId(6)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(6)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(7)]
+ INetFwRules Rules
+ {
+ [DispId(7)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.Interface)]
+ get;
+ }
+ [DispId(8)]
+ INetFwServiceRestriction ServiceRestriction
+ {
+ [DispId(8)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.Interface)]
+ get;
+ }
+ [DispId(12)]
+ NET_FW_ACTION_ DefaultInboundAction
+ {
+ [DispId(12)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(12)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(13)]
+ NET_FW_ACTION_ DefaultOutboundAction
+ {
+ [DispId(13)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(13)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(14)]
+ bool IsRuleGroupCurrentlyEnabled
+ {
+ [DispId(14)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ }
+ [DispId(15)]
+ NET_FW_MODIFY_STATE_ LocalPolicyModifyState
+ {
+ [DispId(15)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ }
+ [DispId(9)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ void EnableRuleGroup([In] int profileTypesBitmask, [MarshalAs(UnmanagedType.BStr)] [In] string group, [In] bool enable);
+ [DispId(10)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ bool IsRuleGroupEnabled([In] int profileTypesBitmask, [MarshalAs(UnmanagedType.BStr)] [In] string group);
+ [DispId(11)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ void RestoreLocalFirewallDefaults();
+ }
+}
diff --git a/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwProduct.cs b/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwProduct.cs
new file mode 100644
index 0000000..9ed2b89
--- /dev/null
+++ b/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwProduct.cs
@@ -0,0 +1,43 @@
+using System;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+namespace NetFwTypeLib
+{
+ [Guid("71881699-18F4-458B-B892-3FFCE5E07F75"), TypeLibType(4160)]
+ [ComImport]
+ public interface INetFwProduct
+ {
+ [DispId(1)]
+ object RuleCategories
+ {
+ [DispId(1)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.Struct)]
+ get;
+ [DispId(1)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [param: MarshalAs(UnmanagedType.Struct)]
+ set;
+ }
+ [DispId(2)]
+ string DisplayName
+ {
+ [DispId(2)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.BStr)]
+ get;
+ [DispId(2)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [param: MarshalAs(UnmanagedType.BStr)]
+ set;
+ }
+ [DispId(3)]
+ string PathToSignedProductExe
+ {
+ [DispId(3)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.BStr)]
+ get;
+ }
+ }
+}
diff --git a/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwProducts.cs b/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwProducts.cs
new file mode 100644
index 0000000..e39e815
--- /dev/null
+++ b/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwProducts.cs
@@ -0,0 +1,31 @@
+using System;
+using System.Collections;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+namespace NetFwTypeLib
+{
+ [Guid("39EB36E0-2097-40BD-8AF2-63A13B525362"), TypeLibType(4160)]
+ [ComImport]
+ public interface INetFwProducts : IEnumerable
+ {
+ [DispId(1)]
+ int Count
+ {
+ [DispId(1)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ }
+ [DispId(2)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.IUnknown)]
+ object Register([MarshalAs(UnmanagedType.Interface)] [In] INetFwProduct product);
+ [DispId(3)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.Interface)]
+ INetFwProduct Item([In] int index);
+ [DispId(-4), TypeLibFunc(1)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalType = "System.Runtime.InteropServices.CustomMarshalers.EnumeratorToEnumVariantMarshaler")]
+ IEnumerator GetEnumerator();
+ }
+}
diff --git a/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwProfile.cs b/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwProfile.cs
new file mode 100644
index 0000000..4a4b51b
--- /dev/null
+++ b/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwProfile.cs
@@ -0,0 +1,98 @@
+using System;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+namespace NetFwTypeLib
+{
+ [Guid("174A0DDA-E9F9-449D-993B-21AB667CA456"), TypeLibType(4160)]
+ [ComImport]
+ public interface INetFwProfile
+ {
+ [DispId(1)]
+ NET_FW_PROFILE_TYPE_ Type
+ {
+ [DispId(1)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ }
+ [DispId(2)]
+ bool FirewallEnabled
+ {
+ [DispId(2)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(2)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(3)]
+ bool ExceptionsNotAllowed
+ {
+ [DispId(3)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(3)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(4)]
+ bool NotificationsDisabled
+ {
+ [DispId(4)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(4)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(5)]
+ bool UnicastResponsesToMulticastBroadcastDisabled
+ {
+ [DispId(5)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(5)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(6)]
+ INetFwRemoteAdminSettings RemoteAdminSettings
+ {
+ [DispId(6)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.Interface)]
+ get;
+ }
+ [DispId(7)]
+ INetFwIcmpSettings IcmpSettings
+ {
+ [DispId(7)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.Interface)]
+ get;
+ }
+ [DispId(8)]
+ INetFwOpenPorts GloballyOpenPorts
+ {
+ [DispId(8)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.Interface)]
+ get;
+ }
+ [DispId(9)]
+ INetFwServices Services
+ {
+ [DispId(9)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.Interface)]
+ get;
+ }
+ [DispId(10)]
+ INetFwAuthorizedApplications AuthorizedApplications
+ {
+ [DispId(10)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.Interface)]
+ get;
+ }
+ }
+}
diff --git a/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwRemoteAdminSettings.cs b/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwRemoteAdminSettings.cs
new file mode 100644
index 0000000..351c499
--- /dev/null
+++ b/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwRemoteAdminSettings.cs
@@ -0,0 +1,53 @@
+using System;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+namespace NetFwTypeLib
+{
+ [Guid("D4BECDDF-6F73-4A83-B832-9C66874CD20E"), TypeLibType(4160)]
+ [ComImport]
+ public interface INetFwRemoteAdminSettings
+ {
+ [DispId(1)]
+ NET_FW_IP_VERSION_ IpVersion
+ {
+ [DispId(1)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(1)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(2)]
+ NET_FW_SCOPE_ Scope
+ {
+ [DispId(2)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(2)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(3)]
+ string RemoteAddresses
+ {
+ [DispId(3)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.BStr)]
+ get;
+ [DispId(3)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [param: MarshalAs(UnmanagedType.BStr)]
+ set;
+ }
+ [DispId(4)]
+ bool Enabled
+ {
+ [DispId(4)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(4)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ }
+}
diff --git a/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwRule.cs b/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwRule.cs
new file mode 100644
index 0000000..aeade53
--- /dev/null
+++ b/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwRule.cs
@@ -0,0 +1,215 @@
+using System;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+namespace NetFwTypeLib
+{
+ [Guid("AF230D27-BABA-4E42-ACED-F524F22CFCE2"), TypeLibType(4160)]
+ [ComImport]
+ public interface INetFwRule
+ {
+ [DispId(1)]
+ string Name
+ {
+ [DispId(1)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.BStr)]
+ get;
+ [DispId(1)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [param: MarshalAs(UnmanagedType.BStr)]
+ set;
+ }
+ [DispId(2)]
+ string Description
+ {
+ [DispId(2)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.BStr)]
+ get;
+ [DispId(2)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [param: MarshalAs(UnmanagedType.BStr)]
+ set;
+ }
+ [DispId(3)]
+ string ApplicationName
+ {
+ [DispId(3)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.BStr)]
+ get;
+ [DispId(3)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [param: MarshalAs(UnmanagedType.BStr)]
+ set;
+ }
+ [DispId(4)]
+ string serviceName
+ {
+ [DispId(4)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.BStr)]
+ get;
+ [DispId(4)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [param: MarshalAs(UnmanagedType.BStr)]
+ set;
+ }
+ [DispId(5)]
+ int Protocol
+ {
+ [DispId(5)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(5)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(6)]
+ string LocalPorts
+ {
+ [DispId(6)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.BStr)]
+ get;
+ [DispId(6)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [param: MarshalAs(UnmanagedType.BStr)]
+ set;
+ }
+ [DispId(7)]
+ string RemotePorts
+ {
+ [DispId(7)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.BStr)]
+ get;
+ [DispId(7)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [param: MarshalAs(UnmanagedType.BStr)]
+ set;
+ }
+ [DispId(8)]
+ string LocalAddresses
+ {
+ [DispId(8)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.BStr)]
+ get;
+ [DispId(8)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [param: MarshalAs(UnmanagedType.BStr)]
+ set;
+ }
+ [DispId(9)]
+ string RemoteAddresses
+ {
+ [DispId(9)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.BStr)]
+ get;
+ [DispId(9)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [param: MarshalAs(UnmanagedType.BStr)]
+ set;
+ }
+ [DispId(10)]
+ string IcmpTypesAndCodes
+ {
+ [DispId(10)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.BStr)]
+ get;
+ [DispId(10)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [param: MarshalAs(UnmanagedType.BStr)]
+ set;
+ }
+ [DispId(11)]
+ NET_FW_RULE_DIRECTION_ Direction
+ {
+ [DispId(11)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(11)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(12)]
+ object Interfaces
+ {
+ [DispId(12)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.Struct)]
+ get;
+ [DispId(12)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [param: MarshalAs(UnmanagedType.Struct)]
+ set;
+ }
+ [DispId(13)]
+ string InterfaceTypes
+ {
+ [DispId(13)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.BStr)]
+ get;
+ [DispId(13)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [param: MarshalAs(UnmanagedType.BStr)]
+ set;
+ }
+ [DispId(14)]
+ bool Enabled
+ {
+ [DispId(14)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(14)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(15)]
+ string Grouping
+ {
+ [DispId(15)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.BStr)]
+ get;
+ [DispId(15)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [param: MarshalAs(UnmanagedType.BStr)]
+ set;
+ }
+ [DispId(16)]
+ int Profiles
+ {
+ [DispId(16)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(16)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(17)]
+ bool EdgeTraversal
+ {
+ [DispId(17)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(17)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(18)]
+ NET_FW_ACTION_ Action
+ {
+ [DispId(18)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(18)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ }
+}
diff --git a/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwRule2.cs b/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwRule2.cs
new file mode 100644
index 0000000..cbd4456
--- /dev/null
+++ b/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwRule2.cs
@@ -0,0 +1,225 @@
+using System;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+namespace NetFwTypeLib
+{
+ [Guid("9C27C8DA-189B-4DDE-89F7-8B39A316782C"), TypeLibType(4160)]
+ [ComImport]
+ public interface INetFwRule2 : INetFwRule
+ {
+ [DispId(1)]
+ string Name
+ {
+ [DispId(1)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.BStr)]
+ get;
+ [DispId(1)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [param: MarshalAs(UnmanagedType.BStr)]
+ set;
+ }
+ [DispId(2)]
+ string Description
+ {
+ [DispId(2)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.BStr)]
+ get;
+ [DispId(2)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [param: MarshalAs(UnmanagedType.BStr)]
+ set;
+ }
+ [DispId(3)]
+ string ApplicationName
+ {
+ [DispId(3)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.BStr)]
+ get;
+ [DispId(3)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [param: MarshalAs(UnmanagedType.BStr)]
+ set;
+ }
+ [DispId(4)]
+ string serviceName
+ {
+ [DispId(4)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.BStr)]
+ get;
+ [DispId(4)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [param: MarshalAs(UnmanagedType.BStr)]
+ set;
+ }
+ [DispId(5)]
+ int Protocol
+ {
+ [DispId(5)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(5)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(6)]
+ string LocalPorts
+ {
+ [DispId(6)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.BStr)]
+ get;
+ [DispId(6)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [param: MarshalAs(UnmanagedType.BStr)]
+ set;
+ }
+ [DispId(7)]
+ string RemotePorts
+ {
+ [DispId(7)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.BStr)]
+ get;
+ [DispId(7)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [param: MarshalAs(UnmanagedType.BStr)]
+ set;
+ }
+ [DispId(8)]
+ string LocalAddresses
+ {
+ [DispId(8)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.BStr)]
+ get;
+ [DispId(8)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [param: MarshalAs(UnmanagedType.BStr)]
+ set;
+ }
+ [DispId(9)]
+ string RemoteAddresses
+ {
+ [DispId(9)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.BStr)]
+ get;
+ [DispId(9)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [param: MarshalAs(UnmanagedType.BStr)]
+ set;
+ }
+ [DispId(10)]
+ string IcmpTypesAndCodes
+ {
+ [DispId(10)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.BStr)]
+ get;
+ [DispId(10)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [param: MarshalAs(UnmanagedType.BStr)]
+ set;
+ }
+ [DispId(11)]
+ NET_FW_RULE_DIRECTION_ Direction
+ {
+ [DispId(11)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(11)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(12)]
+ object Interfaces
+ {
+ [DispId(12)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.Struct)]
+ get;
+ [DispId(12)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [param: MarshalAs(UnmanagedType.Struct)]
+ set;
+ }
+ [DispId(13)]
+ string InterfaceTypes
+ {
+ [DispId(13)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.BStr)]
+ get;
+ [DispId(13)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [param: MarshalAs(UnmanagedType.BStr)]
+ set;
+ }
+ [DispId(14)]
+ bool Enabled
+ {
+ [DispId(14)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(14)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(15)]
+ string Grouping
+ {
+ [DispId(15)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.BStr)]
+ get;
+ [DispId(15)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [param: MarshalAs(UnmanagedType.BStr)]
+ set;
+ }
+ [DispId(16)]
+ int Profiles
+ {
+ [DispId(16)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(16)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(17)]
+ bool EdgeTraversal
+ {
+ [DispId(17)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(17)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(18)]
+ NET_FW_ACTION_ Action
+ {
+ [DispId(18)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(18)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(19)]
+ int EdgeTraversalOptions
+ {
+ [DispId(19)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(19)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ }
+}
diff --git a/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwRules.cs b/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwRules.cs
new file mode 100644
index 0000000..63418b2
--- /dev/null
+++ b/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwRules.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Collections;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+namespace NetFwTypeLib
+{
+ [Guid("9C4C6277-5027-441E-AFAE-CA1F542DA009"), TypeLibType(4160)]
+ [ComImport]
+ public interface INetFwRules : IEnumerable
+ {
+ [DispId(1)]
+ int Count
+ {
+ [DispId(1)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ }
+ [DispId(2)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ void Add([MarshalAs(UnmanagedType.Interface)] [In] INetFwRule rule);
+ [DispId(3)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ void Remove([MarshalAs(UnmanagedType.BStr)] [In] string Name);
+ [DispId(4)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.Interface)]
+ INetFwRule Item([MarshalAs(UnmanagedType.BStr)] [In] string Name);
+ [DispId(-4), TypeLibFunc(1)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalType = "System.Runtime.InteropServices.CustomMarshalers.EnumeratorToEnumVariantMarshaler")]
+ IEnumerator GetEnumerator();
+ }
+}
diff --git a/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwService.cs b/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwService.cs
new file mode 100644
index 0000000..bd4bb3d
--- /dev/null
+++ b/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwService.cs
@@ -0,0 +1,83 @@
+using System;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+namespace NetFwTypeLib
+{
+ [Guid("79FD57C8-908E-4A36-9888-D5B3F0A444CF"), TypeLibType(4160)]
+ [ComImport]
+ public interface INetFwService
+ {
+ [DispId(1)]
+ string Name
+ {
+ [DispId(1)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.BStr)]
+ get;
+ }
+ [DispId(2)]
+ NET_FW_SERVICE_TYPE_ Type
+ {
+ [DispId(2)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ }
+ [DispId(3)]
+ bool Customized
+ {
+ [DispId(3)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ }
+ [DispId(4)]
+ NET_FW_IP_VERSION_ IpVersion
+ {
+ [DispId(4)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(4)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(5)]
+ NET_FW_SCOPE_ Scope
+ {
+ [DispId(5)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(5)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(6)]
+ string RemoteAddresses
+ {
+ [DispId(6)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.BStr)]
+ get;
+ [DispId(6)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [param: MarshalAs(UnmanagedType.BStr)]
+ set;
+ }
+ [DispId(7)]
+ bool Enabled
+ {
+ [DispId(7)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ [DispId(7)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ set;
+ }
+ [DispId(8)]
+ INetFwOpenPorts GloballyOpenPorts
+ {
+ [DispId(8)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.Interface)]
+ get;
+ }
+ }
+}
diff --git a/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwServiceRestriction.cs b/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwServiceRestriction.cs
new file mode 100644
index 0000000..cbb84b0
--- /dev/null
+++ b/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwServiceRestriction.cs
@@ -0,0 +1,25 @@
+using System;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+namespace NetFwTypeLib
+{
+ [Guid("8267BBE3-F890-491C-B7B6-2DB1EF0E5D2B"), TypeLibType(4160)]
+ [ComImport]
+ public interface INetFwServiceRestriction
+ {
+ [DispId(3)]
+ INetFwRules Rules
+ {
+ [DispId(3)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.Interface)]
+ get;
+ }
+ [DispId(1)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ void RestrictService([MarshalAs(UnmanagedType.BStr)] [In] string serviceName, [MarshalAs(UnmanagedType.BStr)] [In] string appName, [In] bool RestrictService, [In] bool serviceSidRestricted);
+ [DispId(2)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ bool ServiceRestricted([MarshalAs(UnmanagedType.BStr)] [In] string serviceName, [MarshalAs(UnmanagedType.BStr)] [In] string appName);
+ }
+}
diff --git a/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwServices.cs b/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwServices.cs
new file mode 100644
index 0000000..689e049
--- /dev/null
+++ b/Sunfish/Sunfish/Library/NetFwTypeLib/INetFwServices.cs
@@ -0,0 +1,27 @@
+using System;
+using System.Collections;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+namespace NetFwTypeLib
+{
+ [Guid("79649BB4-903E-421B-94C9-79848E79F6EE"), TypeLibType(4160)]
+ [ComImport]
+ public interface INetFwServices : IEnumerable
+ {
+ [DispId(1)]
+ int Count
+ {
+ [DispId(1)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ get;
+ }
+ [DispId(2)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.Interface)]
+ INetFwService Item([In] NET_FW_SERVICE_TYPE_ svcType);
+ [DispId(-4), TypeLibFunc(1)]
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalType = "System.Runtime.InteropServices.CustomMarshalers.EnumeratorToEnumVariantMarshaler")]
+ IEnumerator GetEnumerator();
+ }
+}
diff --git a/Sunfish/Sunfish/Library/NetFwTypeLib/NET_FW_ACTION_.cs b/Sunfish/Sunfish/Library/NetFwTypeLib/NET_FW_ACTION_.cs
new file mode 100644
index 0000000..107bc14
--- /dev/null
+++ b/Sunfish/Sunfish/Library/NetFwTypeLib/NET_FW_ACTION_.cs
@@ -0,0 +1,10 @@
+using System;
+namespace NetFwTypeLib
+{
+ public enum NET_FW_ACTION_
+ {
+ NET_FW_ACTION_BLOCK,
+ NET_FW_ACTION_ALLOW,
+ NET_FW_ACTION_MAX
+ }
+}
diff --git a/Sunfish/Sunfish/Library/NetFwTypeLib/NET_FW_IP_PROTOCOL_.cs b/Sunfish/Sunfish/Library/NetFwTypeLib/NET_FW_IP_PROTOCOL_.cs
new file mode 100644
index 0000000..204b1fd
--- /dev/null
+++ b/Sunfish/Sunfish/Library/NetFwTypeLib/NET_FW_IP_PROTOCOL_.cs
@@ -0,0 +1,10 @@
+using System;
+namespace NetFwTypeLib
+{
+ public enum NET_FW_IP_PROTOCOL_
+ {
+ NET_FW_IP_PROTOCOL_TCP = 6,
+ NET_FW_IP_PROTOCOL_UDP = 17,
+ NET_FW_IP_PROTOCOL_ANY = 256
+ }
+}
diff --git a/Sunfish/Sunfish/Library/NetFwTypeLib/NET_FW_IP_VERSION_.cs b/Sunfish/Sunfish/Library/NetFwTypeLib/NET_FW_IP_VERSION_.cs
new file mode 100644
index 0000000..aa3c94d
--- /dev/null
+++ b/Sunfish/Sunfish/Library/NetFwTypeLib/NET_FW_IP_VERSION_.cs
@@ -0,0 +1,11 @@
+using System;
+namespace NetFwTypeLib
+{
+ public enum NET_FW_IP_VERSION_
+ {
+ NET_FW_IP_VERSION_V4,
+ NET_FW_IP_VERSION_V6,
+ NET_FW_IP_VERSION_ANY,
+ NET_FW_IP_VERSION_MAX
+ }
+}
diff --git a/Sunfish/Sunfish/Library/NetFwTypeLib/NET_FW_MODIFY_STATE_.cs b/Sunfish/Sunfish/Library/NetFwTypeLib/NET_FW_MODIFY_STATE_.cs
new file mode 100644
index 0000000..3ac6bb3
--- /dev/null
+++ b/Sunfish/Sunfish/Library/NetFwTypeLib/NET_FW_MODIFY_STATE_.cs
@@ -0,0 +1,10 @@
+using System;
+namespace NetFwTypeLib
+{
+ public enum NET_FW_MODIFY_STATE_
+ {
+ NET_FW_MODIFY_STATE_OK,
+ NET_FW_MODIFY_STATE_GP_OVERRIDE,
+ NET_FW_MODIFY_STATE_INBOUND_BLOCKED
+ }
+}
diff --git a/Sunfish/Sunfish/Library/NetFwTypeLib/NET_FW_PROFILE_TYPE2_.cs b/Sunfish/Sunfish/Library/NetFwTypeLib/NET_FW_PROFILE_TYPE2_.cs
new file mode 100644
index 0000000..5312829
--- /dev/null
+++ b/Sunfish/Sunfish/Library/NetFwTypeLib/NET_FW_PROFILE_TYPE2_.cs
@@ -0,0 +1,11 @@
+using System;
+namespace NetFwTypeLib
+{
+ public enum NET_FW_PROFILE_TYPE2_
+ {
+ NET_FW_PROFILE2_DOMAIN = 1,
+ NET_FW_PROFILE2_PRIVATE,
+ NET_FW_PROFILE2_PUBLIC = 4,
+ NET_FW_PROFILE2_ALL = 2147483647
+ }
+}
diff --git a/Sunfish/Sunfish/Library/NetFwTypeLib/NET_FW_PROFILE_TYPE_.cs b/Sunfish/Sunfish/Library/NetFwTypeLib/NET_FW_PROFILE_TYPE_.cs
new file mode 100644
index 0000000..6465d12
--- /dev/null
+++ b/Sunfish/Sunfish/Library/NetFwTypeLib/NET_FW_PROFILE_TYPE_.cs
@@ -0,0 +1,11 @@
+using System;
+namespace NetFwTypeLib
+{
+ public enum NET_FW_PROFILE_TYPE_
+ {
+ NET_FW_PROFILE_DOMAIN,
+ NET_FW_PROFILE_STANDARD,
+ NET_FW_PROFILE_CURRENT,
+ NET_FW_PROFILE_TYPE_MAX
+ }
+}
diff --git a/Sunfish/Sunfish/Library/NetFwTypeLib/NET_FW_RULE_DIRECTION_.cs b/Sunfish/Sunfish/Library/NetFwTypeLib/NET_FW_RULE_DIRECTION_.cs
new file mode 100644
index 0000000..8c4dca1
--- /dev/null
+++ b/Sunfish/Sunfish/Library/NetFwTypeLib/NET_FW_RULE_DIRECTION_.cs
@@ -0,0 +1,10 @@
+using System;
+namespace NetFwTypeLib
+{
+ public enum NET_FW_RULE_DIRECTION_
+ {
+ NET_FW_RULE_DIR_IN = 1,
+ NET_FW_RULE_DIR_OUT,
+ NET_FW_RULE_DIR_MAX
+ }
+}
diff --git a/Sunfish/Sunfish/Library/NetFwTypeLib/NET_FW_SCOPE_.cs b/Sunfish/Sunfish/Library/NetFwTypeLib/NET_FW_SCOPE_.cs
new file mode 100644
index 0000000..89478df
--- /dev/null
+++ b/Sunfish/Sunfish/Library/NetFwTypeLib/NET_FW_SCOPE_.cs
@@ -0,0 +1,11 @@
+using System;
+namespace NetFwTypeLib
+{
+ public enum NET_FW_SCOPE_
+ {
+ NET_FW_SCOPE_ALL,
+ NET_FW_SCOPE_LOCAL_SUBNET,
+ NET_FW_SCOPE_CUSTOM,
+ NET_FW_SCOPE_MAX
+ }
+}
diff --git a/Sunfish/Sunfish/Library/NetFwTypeLib/NET_FW_SERVICE_TYPE_.cs b/Sunfish/Sunfish/Library/NetFwTypeLib/NET_FW_SERVICE_TYPE_.cs
new file mode 100644
index 0000000..019ab13
--- /dev/null
+++ b/Sunfish/Sunfish/Library/NetFwTypeLib/NET_FW_SERVICE_TYPE_.cs
@@ -0,0 +1,12 @@
+using System;
+namespace NetFwTypeLib
+{
+ public enum NET_FW_SERVICE_TYPE_
+ {
+ NET_FW_SERVICE_FILE_AND_PRINT,
+ NET_FW_SERVICE_UPNP,
+ NET_FW_SERVICE_REMOTE_DESKTOP,
+ NET_FW_SERVICE_NONE,
+ NET_FW_SERVICE_TYPE_MAX
+ }
+}
diff --git a/Sunfish/Sunfish/Library/Newtonsoft.Json/Bson/BsonBinaryType.cs b/Sunfish/Sunfish/Library/Newtonsoft.Json/Bson/BsonBinaryType.cs
new file mode 100644
index 0000000..3ac0020
--- /dev/null
+++ b/Sunfish/Sunfish/Library/Newtonsoft.Json/Bson/BsonBinaryType.cs
@@ -0,0 +1,46 @@
+#region License
+// Copyright (c) 2007 James Newton-King
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+#endregion
+
+using System;
+
+#nullable disable
+
+namespace Newtonsoft.Json.Bson
+{
+ internal enum BsonBinaryType : byte
+ {
+ Binary = 0x00,
+ Function = 0x01,
+
+ [Obsolete("This type has been deprecated in the BSON specification. Use Binary instead.")]
+ BinaryOld = 0x02,
+
+ [Obsolete("This type has been deprecated in the BSON specification. Use Uuid instead.")]
+ UuidOld = 0x03,
+ Uuid = 0x04,
+ Md5 = 0x05,
+ UserDefined = 0x80
+ }
+}
\ No newline at end of file
diff --git a/Sunfish/Sunfish/Library/Newtonsoft.Json/Bson/BsonBinaryWriter.cs b/Sunfish/Sunfish/Library/Newtonsoft.Json/Bson/BsonBinaryWriter.cs
new file mode 100644
index 0000000..1f3c0aa
--- /dev/null
+++ b/Sunfish/Sunfish/Library/Newtonsoft.Json/Bson/BsonBinaryWriter.cs
@@ -0,0 +1,330 @@
+#region License
+// Copyright (c) 2007 James Newton-King
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+#endregion
+
+using System;
+using System.Globalization;
+using System.IO;
+using System.Text;
+using Newtonsoft.Json.Utilities;
+
+#nullable disable
+
+namespace Newtonsoft.Json.Bson
+{
+ internal class BsonBinaryWriter
+ {
+ private static readonly Encoding Encoding = new UTF8Encoding(false);
+
+ private readonly BinaryWriter _writer;
+
+ private byte[] _largeByteBuffer;
+
+ public DateTimeKind DateTimeKindHandling { get; set; }
+
+ public BsonBinaryWriter(BinaryWriter writer)
+ {
+ DateTimeKindHandling = DateTimeKind.Utc;
+ _writer = writer;
+ }
+
+ public void Flush()
+ {
+ _writer.Flush();
+ }
+
+ public void Close()
+ {
+#if HAVE_STREAM_READER_WRITER_CLOSE
+ _writer.Close();
+#else
+ _writer.Dispose();
+#endif
+ }
+
+ public void WriteToken(BsonToken t)
+ {
+ CalculateSize(t);
+ WriteTokenInternal(t);
+ }
+
+ private void WriteTokenInternal(BsonToken t)
+ {
+ switch (t.Type)
+ {
+ case BsonType.Object:
+ {
+ BsonObject value = (BsonObject)t;
+ _writer.Write(value.CalculatedSize);
+ foreach (BsonProperty property in value)
+ {
+ _writer.Write((sbyte)property.Value.Type);
+ WriteString((string)property.Name.Value, property.Name.ByteCount, null);
+ WriteTokenInternal(property.Value);
+ }
+ _writer.Write((byte)0);
+ }
+ break;
+ case BsonType.Array:
+ {
+ BsonArray value = (BsonArray)t;
+ _writer.Write(value.CalculatedSize);
+ ulong index = 0;
+ foreach (BsonToken c in value)
+ {
+ _writer.Write((sbyte)c.Type);
+ WriteString(index.ToString(CultureInfo.InvariantCulture), MathUtils.IntLength(index), null);
+ WriteTokenInternal(c);
+ index++;
+ }
+ _writer.Write((byte)0);
+ }
+ break;
+ case BsonType.Integer:
+ {
+ BsonValue value = (BsonValue)t;
+ _writer.Write(Convert.ToInt32(value.Value, CultureInfo.InvariantCulture));
+ }
+ break;
+ case BsonType.Long:
+ {
+ BsonValue value = (BsonValue)t;
+ _writer.Write(Convert.ToInt64(value.Value, CultureInfo.InvariantCulture));
+ }
+ break;
+ case BsonType.Number:
+ {
+ BsonValue value = (BsonValue)t;
+ _writer.Write(Convert.ToDouble(value.Value, CultureInfo.InvariantCulture));
+ }
+ break;
+ case BsonType.String:
+ {
+ BsonString value = (BsonString)t;
+ WriteString((string)value.Value, value.ByteCount, value.CalculatedSize - 4);
+ }
+ break;
+ case BsonType.Boolean:
+ _writer.Write(t == BsonBoolean.True);
+ break;
+ case BsonType.Null:
+ case BsonType.Undefined:
+ break;
+ case BsonType.Date:
+ {
+ BsonValue value = (BsonValue)t;
+
+ long ticks = 0;
+
+ if (value.Value is DateTime dateTime)
+ {
+ if (DateTimeKindHandling == DateTimeKind.Utc)
+ {
+ dateTime = dateTime.ToUniversalTime();
+ }
+ else if (DateTimeKindHandling == DateTimeKind.Local)
+ {
+ dateTime = dateTime.ToLocalTime();
+ }
+
+ ticks = DateTimeUtils.ConvertDateTimeToJavaScriptTicks(dateTime, false);
+ }
+#if HAVE_DATE_TIME_OFFSET
+ else
+ {
+ DateTimeOffset dateTimeOffset = (DateTimeOffset)value.Value;
+ ticks = DateTimeUtils.ConvertDateTimeToJavaScriptTicks(dateTimeOffset.UtcDateTime, dateTimeOffset.Offset);
+ }
+#endif
+
+ _writer.Write(ticks);
+ }
+ break;
+ case BsonType.Binary:
+ {
+ BsonBinary value = (BsonBinary)t;
+
+ byte[] data = (byte[])value.Value;
+ _writer.Write(data.Length);
+ _writer.Write((byte)value.BinaryType);
+ _writer.Write(data);
+ }
+ break;
+ case BsonType.Oid:
+ {
+ BsonValue value = (BsonValue)t;
+
+ byte[] data = (byte[])value.Value;
+ _writer.Write(data);
+ }
+ break;
+ case BsonType.Regex:
+ {
+ BsonRegex value = (BsonRegex)t;
+
+ WriteString((string)value.Pattern.Value, value.Pattern.ByteCount, null);
+ WriteString((string)value.Options.Value, value.Options.ByteCount, null);
+ }
+ break;
+ default:
+ throw new ArgumentOutOfRangeException(nameof(t), "Unexpected token when writing BSON: {0}".FormatWith(CultureInfo.InvariantCulture, t.Type));
+ }
+ }
+
+ private void WriteString(string s, int byteCount, int? calculatedlengthPrefix)
+ {
+ if (calculatedlengthPrefix != null)
+ {
+ _writer.Write(calculatedlengthPrefix.GetValueOrDefault());
+ }
+
+ WriteUtf8Bytes(s, byteCount);
+
+ _writer.Write((byte)0);
+ }
+
+ public void WriteUtf8Bytes(string s, int byteCount)
+ {
+ if (s != null)
+ {
+ if (byteCount <= 256)
+ {
+ if (_largeByteBuffer == null)
+ {
+ _largeByteBuffer = new byte[256];
+ }
+
+ Encoding.GetBytes(s, 0, s.Length, _largeByteBuffer, 0);
+ _writer.Write(_largeByteBuffer, 0, byteCount);
+ }
+ else
+ {
+ byte[] bytes = Encoding.GetBytes(s);
+ _writer.Write(bytes);
+ }
+ }
+ }
+
+ private int CalculateSize(int stringByteCount)
+ {
+ return stringByteCount + 1;
+ }
+
+ private int CalculateSizeWithLength(int stringByteCount, bool includeSize)
+ {
+ int baseSize = (includeSize)
+ ? 5 // size bytes + terminator
+ : 1; // terminator
+
+ return baseSize + stringByteCount;
+ }
+
+ private int CalculateSize(BsonToken t)
+ {
+ switch (t.Type)
+ {
+ case BsonType.Object:
+ {
+ BsonObject value = (BsonObject)t;
+
+ int bases = 4;
+ foreach (BsonProperty p in value)
+ {
+ int size = 1;
+ size += CalculateSize(p.Name);
+ size += CalculateSize(p.Value);
+
+ bases += size;
+ }
+ bases += 1;
+ value.CalculatedSize = bases;
+ return bases;
+ }
+ case BsonType.Array:
+ {
+ BsonArray value = (BsonArray)t;
+
+ int size = 4;
+ ulong index = 0;
+ foreach (BsonToken c in value)
+ {
+ size += 1;
+ size += CalculateSize(MathUtils.IntLength(index));
+ size += CalculateSize(c);
+ index++;
+ }
+ size += 1;
+ value.CalculatedSize = size;
+
+ return value.CalculatedSize;
+ }
+ case BsonType.Integer:
+ return 4;
+ case BsonType.Long:
+ return 8;
+ case BsonType.Number:
+ return 8;
+ case BsonType.String:
+ {
+ BsonString value = (BsonString)t;
+ string s = (string)value.Value;
+ value.ByteCount = (s != null) ? Encoding.GetByteCount(s) : 0;
+ value.CalculatedSize = CalculateSizeWithLength(value.ByteCount, value.IncludeLength);
+
+ return value.CalculatedSize;
+ }
+ case BsonType.Boolean:
+ return 1;
+ case BsonType.Null:
+ case BsonType.Undefined:
+ return 0;
+ case BsonType.Date:
+ return 8;
+ case BsonType.Binary:
+ {
+ BsonBinary value = (BsonBinary)t;
+
+ byte[] data = (byte[])value.Value;
+ value.CalculatedSize = 4 + 1 + data.Length;
+
+ return value.CalculatedSize;
+ }
+ case BsonType.Oid:
+ return 12;
+ case BsonType.Regex:
+ {
+ BsonRegex value = (BsonRegex)t;
+ int size = 0;
+ size += CalculateSize(value.Pattern);
+ size += CalculateSize(value.Options);
+ value.CalculatedSize = size;
+
+ return value.CalculatedSize;
+ }
+ default:
+ throw new ArgumentOutOfRangeException(nameof(t), "Unexpected token when writing BSON: {0}".FormatWith(CultureInfo.InvariantCulture, t.Type));
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Sunfish/Sunfish/Library/Newtonsoft.Json/Bson/BsonObjectId.cs b/Sunfish/Sunfish/Library/Newtonsoft.Json/Bson/BsonObjectId.cs
new file mode 100644
index 0000000..4e1461d
--- /dev/null
+++ b/Sunfish/Sunfish/Library/Newtonsoft.Json/Bson/BsonObjectId.cs
@@ -0,0 +1,60 @@
+#region License
+// Copyright (c) 2007 James Newton-King
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+#endregion
+
+using System;
+using Newtonsoft.Json.Utilities;
+
+#nullable disable
+
+namespace Newtonsoft.Json.Bson
+{
+ ///
+ /// Represents a BSON Oid (object id).
+ ///
+ [Obsolete("BSON reading and writing has been moved to its own package. See https://www.nuget.org/packages/Newtonsoft.Json.Bson for more details.")]
+ public class BsonObjectId
+ {
+ ///
+ /// Gets or sets the value of the Oid.
+ ///
+ /// The value of the Oid.
+ public byte[] Value { get; }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The Oid value.
+ public BsonObjectId(byte[] value)
+ {
+ ValidationUtils.ArgumentNotNull(value, nameof(value));
+ if (value.Length != 12)
+ {
+ throw new ArgumentException("An ObjectId must be 12 bytes", nameof(value));
+ }
+
+ Value = value;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Sunfish/Sunfish/Library/Newtonsoft.Json/Bson/BsonReader.cs b/Sunfish/Sunfish/Library/Newtonsoft.Json/Bson/BsonReader.cs
new file mode 100644
index 0000000..4556933
--- /dev/null
+++ b/Sunfish/Sunfish/Library/Newtonsoft.Json/Bson/BsonReader.cs
@@ -0,0 +1,836 @@
+#region License
+// Copyright (c) 2007 James Newton-King
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Text;
+using System.IO;
+using Newtonsoft.Json.Serialization;
+using Newtonsoft.Json.Utilities;
+using Newtonsoft.Json.Linq;
+
+#nullable disable
+
+namespace Newtonsoft.Json.Bson
+{
+ ///
+ /// Represents a reader that provides fast, non-cached, forward-only access to serialized BSON data.
+ ///
+ [Obsolete("BSON reading and writing has been moved to its own package. See https://www.nuget.org/packages/Newtonsoft.Json.Bson for more details.")]
+ public class BsonReader : JsonReader
+ {
+ private const int MaxCharBytesSize = 128;
+ private static readonly byte[] SeqRange1 = new byte[] { 0, 127 }; // range of 1-byte sequence
+ private static readonly byte[] SeqRange2 = new byte[] { 194, 223 }; // range of 2-byte sequence
+ private static readonly byte[] SeqRange3 = new byte[] { 224, 239 }; // range of 3-byte sequence
+ private static readonly byte[] SeqRange4 = new byte[] { 240, 244 }; // range of 4-byte sequence
+
+ private readonly BinaryReader _reader;
+ private readonly List _stack;
+
+ private byte[] _byteBuffer;
+ private char[] _charBuffer;
+
+ private BsonType _currentElementType;
+ private BsonReaderState _bsonReaderState;
+ private ContainerContext _currentContext;
+
+ private bool _readRootValueAsArray;
+ private bool _jsonNet35BinaryCompatibility;
+ private DateTimeKind _dateTimeKindHandling;
+
+ private enum BsonReaderState
+ {
+ Normal = 0,
+ ReferenceStart = 1,
+ ReferenceRef = 2,
+ ReferenceId = 3,
+ CodeWScopeStart = 4,
+ CodeWScopeCode = 5,
+ CodeWScopeScope = 6,
+ CodeWScopeScopeObject = 7,
+ CodeWScopeScopeEnd = 8
+ }
+
+ private class ContainerContext
+ {
+ public readonly BsonType Type;
+ public int Length;
+ public int Position;
+
+ public ContainerContext(BsonType type)
+ {
+ Type = type;
+ }
+ }
+
+ ///
+ /// Gets or sets a value indicating whether binary data reading should be compatible with incorrect Json.NET 3.5 written binary.
+ ///
+ ///
+ /// true if binary data reading will be compatible with incorrect Json.NET 3.5 written binary; otherwise, false.
+ ///
+ [Obsolete("JsonNet35BinaryCompatibility will be removed in a future version of Json.NET.")]
+ public bool JsonNet35BinaryCompatibility
+ {
+ get => _jsonNet35BinaryCompatibility;
+ set => _jsonNet35BinaryCompatibility = value;
+ }
+
+ ///
+ /// Gets or sets a value indicating whether the root object will be read as a JSON array.
+ ///
+ ///
+ /// true if the root object will be read as a JSON array; otherwise, false.
+ ///
+ public bool ReadRootValueAsArray
+ {
+ get => _readRootValueAsArray;
+ set => _readRootValueAsArray = value;
+ }
+
+ ///
+ /// Gets or sets the used when reading values from BSON.
+ ///
+ /// The used when reading values from BSON.
+ public DateTimeKind DateTimeKindHandling
+ {
+ get => _dateTimeKindHandling;
+ set => _dateTimeKindHandling = value;
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The containing the BSON data to read.
+ public BsonReader(Stream stream)
+ : this(stream, false, DateTimeKind.Local)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The containing the BSON data to read.
+ public BsonReader(BinaryReader reader)
+ : this(reader, false, DateTimeKind.Local)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The containing the BSON data to read.
+ /// if set to true the root object will be read as a JSON array.
+ /// The used when reading values from BSON.
+ public BsonReader(Stream stream, bool readRootValueAsArray, DateTimeKind dateTimeKindHandling)
+ {
+ ValidationUtils.ArgumentNotNull(stream, nameof(stream));
+ _reader = new BinaryReader(stream);
+ _stack = new List();
+ _readRootValueAsArray = readRootValueAsArray;
+ _dateTimeKindHandling = dateTimeKindHandling;
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The containing the BSON data to read.
+ /// if set to true the root object will be read as a JSON array.
+ /// The used when reading values from BSON.
+ public BsonReader(BinaryReader reader, bool readRootValueAsArray, DateTimeKind dateTimeKindHandling)
+ {
+ ValidationUtils.ArgumentNotNull(reader, nameof(reader));
+ _reader = reader;
+ _stack = new List();
+ _readRootValueAsArray = readRootValueAsArray;
+ _dateTimeKindHandling = dateTimeKindHandling;
+ }
+
+ private string ReadElement()
+ {
+ _currentElementType = ReadType();
+ string elementName = ReadString();
+ return elementName;
+ }
+
+ ///
+ /// Reads the next JSON token from the underlying .
+ ///
+ ///
+ /// true if the next token was read successfully; false if there are no more tokens to read.
+ ///
+ public override bool Read()
+ {
+ try
+ {
+ bool success;
+
+ switch (_bsonReaderState)
+ {
+ case BsonReaderState.Normal:
+ success = ReadNormal();
+ break;
+ case BsonReaderState.ReferenceStart:
+ case BsonReaderState.ReferenceRef:
+ case BsonReaderState.ReferenceId:
+ success = ReadReference();
+ break;
+ case BsonReaderState.CodeWScopeStart:
+ case BsonReaderState.CodeWScopeCode:
+ case BsonReaderState.CodeWScopeScope:
+ case BsonReaderState.CodeWScopeScopeObject:
+ case BsonReaderState.CodeWScopeScopeEnd:
+ success = ReadCodeWScope();
+ break;
+ default:
+ throw JsonReaderException.Create(this, "Unexpected state: {0}".FormatWith(CultureInfo.InvariantCulture, _bsonReaderState));
+ }
+
+ if (!success)
+ {
+ SetToken(JsonToken.None);
+ return false;
+ }
+
+ return true;
+ }
+ catch (EndOfStreamException)
+ {
+ SetToken(JsonToken.None);
+ return false;
+ }
+ }
+
+ ///
+ /// Changes the reader's state to .
+ /// If is set to true, the underlying is also closed.
+ ///
+ public override void Close()
+ {
+ base.Close();
+
+ if (CloseInput)
+ {
+#if HAVE_STREAM_READER_WRITER_CLOSE
+ _reader?.Close();
+#else
+ _reader?.Dispose();
+#endif
+ }
+ }
+
+ private bool ReadCodeWScope()
+ {
+ switch (_bsonReaderState)
+ {
+ case BsonReaderState.CodeWScopeStart:
+ SetToken(JsonToken.PropertyName, "$code");
+ _bsonReaderState = BsonReaderState.CodeWScopeCode;
+ return true;
+ case BsonReaderState.CodeWScopeCode:
+ // total CodeWScope size - not used
+ ReadInt32();
+
+ SetToken(JsonToken.String, ReadLengthString());
+ _bsonReaderState = BsonReaderState.CodeWScopeScope;
+ return true;
+ case BsonReaderState.CodeWScopeScope:
+ if (CurrentState == State.PostValue)
+ {
+ SetToken(JsonToken.PropertyName, "$scope");
+ return true;
+ }
+ else
+ {
+ SetToken(JsonToken.StartObject);
+ _bsonReaderState = BsonReaderState.CodeWScopeScopeObject;
+
+ ContainerContext newContext = new ContainerContext(BsonType.Object);
+ PushContext(newContext);
+ newContext.Length = ReadInt32();
+
+ return true;
+ }
+ case BsonReaderState.CodeWScopeScopeObject:
+ bool result = ReadNormal();
+ if (result && TokenType == JsonToken.EndObject)
+ {
+ _bsonReaderState = BsonReaderState.CodeWScopeScopeEnd;
+ }
+
+ return result;
+ case BsonReaderState.CodeWScopeScopeEnd:
+ SetToken(JsonToken.EndObject);
+ _bsonReaderState = BsonReaderState.Normal;
+ return true;
+ default:
+ throw new ArgumentOutOfRangeException();
+ }
+ }
+
+ private bool ReadReference()
+ {
+ switch (CurrentState)
+ {
+ case State.ObjectStart:
+ {
+ SetToken(JsonToken.PropertyName, JsonTypeReflector.RefPropertyName);
+ _bsonReaderState = BsonReaderState.ReferenceRef;
+ return true;
+ }
+ case State.Property:
+ {
+ if (_bsonReaderState == BsonReaderState.ReferenceRef)
+ {
+ SetToken(JsonToken.String, ReadLengthString());
+ return true;
+ }
+ else if (_bsonReaderState == BsonReaderState.ReferenceId)
+ {
+ SetToken(JsonToken.Bytes, ReadBytes(12));
+ return true;
+ }
+ else
+ {
+ throw JsonReaderException.Create(this, "Unexpected state when reading BSON reference: " + _bsonReaderState);
+ }
+ }
+ case State.PostValue:
+ {
+ if (_bsonReaderState == BsonReaderState.ReferenceRef)
+ {
+ SetToken(JsonToken.PropertyName, JsonTypeReflector.IdPropertyName);
+ _bsonReaderState = BsonReaderState.ReferenceId;
+ return true;
+ }
+ else if (_bsonReaderState == BsonReaderState.ReferenceId)
+ {
+ SetToken(JsonToken.EndObject);
+ _bsonReaderState = BsonReaderState.Normal;
+ return true;
+ }
+ else
+ {
+ throw JsonReaderException.Create(this, "Unexpected state when reading BSON reference: " + _bsonReaderState);
+ }
+ }
+ default:
+ throw JsonReaderException.Create(this, "Unexpected state when reading BSON reference: " + CurrentState);
+ }
+ }
+
+ private bool ReadNormal()
+ {
+ switch (CurrentState)
+ {
+ case State.Start:
+ {
+ JsonToken token = (!_readRootValueAsArray) ? JsonToken.StartObject : JsonToken.StartArray;
+ BsonType type = (!_readRootValueAsArray) ? BsonType.Object : BsonType.Array;
+
+ SetToken(token);
+ ContainerContext newContext = new ContainerContext(type);
+ PushContext(newContext);
+ newContext.Length = ReadInt32();
+ return true;
+ }
+ case State.Complete:
+ case State.Closed:
+ return false;
+ case State.Property:
+ {
+ ReadType(_currentElementType);
+ return true;
+ }
+ case State.ObjectStart:
+ case State.ArrayStart:
+ case State.PostValue:
+ ContainerContext context = _currentContext;
+ if (context == null)
+ {
+ if (SupportMultipleContent)
+ {
+ goto case State.Start;
+ }
+
+ return false;
+ }
+
+ int lengthMinusEnd = context.Length - 1;
+
+ if (context.Position < lengthMinusEnd)
+ {
+ if (context.Type == BsonType.Array)
+ {
+ ReadElement();
+ ReadType(_currentElementType);
+ return true;
+ }
+ else
+ {
+ SetToken(JsonToken.PropertyName, ReadElement());
+ return true;
+ }
+ }
+ else if (context.Position == lengthMinusEnd)
+ {
+ if (ReadByte() != 0)
+ {
+ throw JsonReaderException.Create(this, "Unexpected end of object byte value.");
+ }
+
+ PopContext();
+ if (_currentContext != null)
+ {
+ MovePosition(context.Length);
+ }
+
+ JsonToken endToken = (context.Type == BsonType.Object) ? JsonToken.EndObject : JsonToken.EndArray;
+ SetToken(endToken);
+ return true;
+ }
+ else
+ {
+ throw JsonReaderException.Create(this, "Read past end of current container context.");
+ }
+ case State.ConstructorStart:
+ break;
+ case State.Constructor:
+ break;
+ case State.Error:
+ break;
+ case State.Finished:
+ break;
+ default:
+ throw new ArgumentOutOfRangeException();
+ }
+
+ return false;
+ }
+
+ private void PopContext()
+ {
+ _stack.RemoveAt(_stack.Count - 1);
+ if (_stack.Count == 0)
+ {
+ _currentContext = null;
+ }
+ else
+ {
+ _currentContext = _stack[_stack.Count - 1];
+ }
+ }
+
+ private void PushContext(ContainerContext newContext)
+ {
+ _stack.Add(newContext);
+ _currentContext = newContext;
+ }
+
+ private byte ReadByte()
+ {
+ MovePosition(1);
+ return _reader.ReadByte();
+ }
+
+ private void ReadType(BsonType type)
+ {
+ switch (type)
+ {
+ case BsonType.Number:
+ double d = ReadDouble();
+
+ if (_floatParseHandling == FloatParseHandling.Decimal)
+ {
+ SetToken(JsonToken.Float, Convert.ToDecimal(d, CultureInfo.InvariantCulture));
+ }
+ else
+ {
+ SetToken(JsonToken.Float, d);
+ }
+ break;
+ case BsonType.String:
+ case BsonType.Symbol:
+ SetToken(JsonToken.String, ReadLengthString());
+ break;
+ case BsonType.Object:
+ {
+ SetToken(JsonToken.StartObject);
+
+ ContainerContext newContext = new ContainerContext(BsonType.Object);
+ PushContext(newContext);
+ newContext.Length = ReadInt32();
+ break;
+ }
+ case BsonType.Array:
+ {
+ SetToken(JsonToken.StartArray);
+
+ ContainerContext newContext = new ContainerContext(BsonType.Array);
+ PushContext(newContext);
+ newContext.Length = ReadInt32();
+ break;
+ }
+ case BsonType.Binary:
+ BsonBinaryType binaryType;
+ byte[] data = ReadBinary(out binaryType);
+
+ object value = (binaryType != BsonBinaryType.Uuid)
+ ? data
+ : (object)new Guid(data);
+
+ SetToken(JsonToken.Bytes, value);
+ break;
+ case BsonType.Undefined:
+ SetToken(JsonToken.Undefined);
+ break;
+ case BsonType.Oid:
+ byte[] oid = ReadBytes(12);
+ SetToken(JsonToken.Bytes, oid);
+ break;
+ case BsonType.Boolean:
+ bool b = Convert.ToBoolean(ReadByte());
+ SetToken(JsonToken.Boolean, b);
+ break;
+ case BsonType.Date:
+ long ticks = ReadInt64();
+ DateTime utcDateTime = DateTimeUtils.ConvertJavaScriptTicksToDateTime(ticks);
+
+ DateTime dateTime;
+ switch (DateTimeKindHandling)
+ {
+ case DateTimeKind.Unspecified:
+ dateTime = DateTime.SpecifyKind(utcDateTime, DateTimeKind.Unspecified);
+ break;
+ case DateTimeKind.Local:
+ dateTime = utcDateTime.ToLocalTime();
+ break;
+ default:
+ dateTime = utcDateTime;
+ break;
+ }
+
+ SetToken(JsonToken.Date, dateTime);
+ break;
+ case BsonType.Null:
+ SetToken(JsonToken.Null);
+ break;
+ case BsonType.Regex:
+ string expression = ReadString();
+ string modifiers = ReadString();
+
+ string regex = @"/" + expression + @"/" + modifiers;
+ SetToken(JsonToken.String, regex);
+ break;
+ case BsonType.Reference:
+ SetToken(JsonToken.StartObject);
+ _bsonReaderState = BsonReaderState.ReferenceStart;
+ break;
+ case BsonType.Code:
+ SetToken(JsonToken.String, ReadLengthString());
+ break;
+ case BsonType.CodeWScope:
+ SetToken(JsonToken.StartObject);
+ _bsonReaderState = BsonReaderState.CodeWScopeStart;
+ break;
+ case BsonType.Integer:
+ SetToken(JsonToken.Integer, (long)ReadInt32());
+ break;
+ case BsonType.TimeStamp:
+ case BsonType.Long:
+ SetToken(JsonToken.Integer, ReadInt64());
+ break;
+ default:
+ throw new ArgumentOutOfRangeException(nameof(type), "Unexpected BsonType value: " + type);
+ }
+ }
+
+ private byte[] ReadBinary(out BsonBinaryType binaryType)
+ {
+ int dataLength = ReadInt32();
+
+ binaryType = (BsonBinaryType)ReadByte();
+
+#pragma warning disable 612,618
+ // the old binary type has the data length repeated in the data for some reason
+ if (binaryType == BsonBinaryType.BinaryOld && !_jsonNet35BinaryCompatibility)
+ {
+ dataLength = ReadInt32();
+ }
+#pragma warning restore 612,618
+
+ return ReadBytes(dataLength);
+ }
+
+ private string ReadString()
+ {
+ EnsureBuffers();
+
+ StringBuilder builder = null;
+
+ int totalBytesRead = 0;
+ // used in case of left over multibyte characters in the buffer
+ int offset = 0;
+ while (true)
+ {
+ int count = offset;
+ byte b;
+ while (count < MaxCharBytesSize && (b = _reader.ReadByte()) > 0)
+ {
+ _byteBuffer[count++] = b;
+ }
+ int byteCount = count - offset;
+ totalBytesRead += byteCount;
+
+ if (count < MaxCharBytesSize && builder == null)
+ {
+ // pref optimization to avoid reading into a string builder
+ // if string is smaller than the buffer then return it directly
+ int length = Encoding.UTF8.GetChars(_byteBuffer, 0, byteCount, _charBuffer, 0);
+
+ MovePosition(totalBytesRead + 1);
+ return new string(_charBuffer, 0, length);
+ }
+ else
+ {
+ // calculate the index of the end of the last full character in the buffer
+ int lastFullCharStop = GetLastFullCharStop(count - 1);
+
+ int charCount = Encoding.UTF8.GetChars(_byteBuffer, 0, lastFullCharStop + 1, _charBuffer, 0);
+
+ if (builder == null)
+ {
+ builder = new StringBuilder(MaxCharBytesSize * 2);
+ }
+
+ builder.Append(_charBuffer, 0, charCount);
+
+ if (lastFullCharStop < byteCount - 1)
+ {
+ offset = byteCount - lastFullCharStop - 1;
+ // copy left over multi byte characters to beginning of buffer for next iteration
+ Array.Copy(_byteBuffer, lastFullCharStop + 1, _byteBuffer, 0, offset);
+ }
+ else
+ {
+ // reached end of string
+ if (count < MaxCharBytesSize)
+ {
+ MovePosition(totalBytesRead + 1);
+ return builder.ToString();
+ }
+
+ offset = 0;
+ }
+ }
+ }
+ }
+
+ private string ReadLengthString()
+ {
+ int length = ReadInt32();
+
+ MovePosition(length);
+
+ string s = GetString(length - 1);
+ _reader.ReadByte();
+
+ return s;
+ }
+
+ private string GetString(int length)
+ {
+ if (length == 0)
+ {
+ return string.Empty;
+ }
+
+ EnsureBuffers();
+
+ StringBuilder builder = null;
+
+ int totalBytesRead = 0;
+
+ // used in case of left over multibyte characters in the buffer
+ int offset = 0;
+ do
+ {
+ int count = ((length - totalBytesRead) > MaxCharBytesSize - offset)
+ ? MaxCharBytesSize - offset
+ : length - totalBytesRead;
+
+ int byteCount = _reader.Read(_byteBuffer, offset, count);
+
+ if (byteCount == 0)
+ {
+ throw new EndOfStreamException("Unable to read beyond the end of the stream.");
+ }
+
+ totalBytesRead += byteCount;
+
+ // Above, byteCount is how many bytes we read this time.
+ // Below, byteCount is how many bytes are in the _byteBuffer.
+ byteCount += offset;
+
+ if (byteCount == length)
+ {
+ // pref optimization to avoid reading into a string builder
+ // first iteration and all bytes read then return string directly
+ int charCount = Encoding.UTF8.GetChars(_byteBuffer, 0, byteCount, _charBuffer, 0);
+ return new string(_charBuffer, 0, charCount);
+ }
+ else
+ {
+ int lastFullCharStop = GetLastFullCharStop(byteCount - 1);
+
+ if (builder == null)
+ {
+ builder = new StringBuilder(length);
+ }
+
+ int charCount = Encoding.UTF8.GetChars(_byteBuffer, 0, lastFullCharStop + 1, _charBuffer, 0);
+ builder.Append(_charBuffer, 0, charCount);
+
+ if (lastFullCharStop < byteCount - 1)
+ {
+ offset = byteCount - lastFullCharStop - 1;
+ // copy left over multi byte characters to beginning of buffer for next iteration
+ Array.Copy(_byteBuffer, lastFullCharStop + 1, _byteBuffer, 0, offset);
+ }
+ else
+ {
+ offset = 0;
+ }
+ }
+ } while (totalBytesRead < length);
+
+ return builder.ToString();
+ }
+
+ private int GetLastFullCharStop(int start)
+ {
+ int lookbackPos = start;
+ int bis = 0;
+ while (lookbackPos >= 0)
+ {
+ bis = BytesInSequence(_byteBuffer[lookbackPos]);
+ if (bis == 0)
+ {
+ lookbackPos--;
+ continue;
+ }
+ else if (bis == 1)
+ {
+ break;
+ }
+ else
+ {
+ lookbackPos--;
+ break;
+ }
+ }
+ if (bis == start - lookbackPos)
+ {
+ //Full character.
+ return start;
+ }
+ else
+ {
+ return lookbackPos;
+ }
+ }
+
+ private int BytesInSequence(byte b)
+ {
+ if (b <= SeqRange1[1])
+ {
+ return 1;
+ }
+ if (b >= SeqRange2[0] && b <= SeqRange2[1])
+ {
+ return 2;
+ }
+ if (b >= SeqRange3[0] && b <= SeqRange3[1])
+ {
+ return 3;
+ }
+ if (b >= SeqRange4[0] && b <= SeqRange4[1])
+ {
+ return 4;
+ }
+ return 0;
+ }
+
+ private void EnsureBuffers()
+ {
+ if (_byteBuffer == null)
+ {
+ _byteBuffer = new byte[MaxCharBytesSize];
+ }
+ if (_charBuffer == null)
+ {
+ int charBufferSize = Encoding.UTF8.GetMaxCharCount(MaxCharBytesSize);
+ _charBuffer = new char[charBufferSize];
+ }
+ }
+
+ private double ReadDouble()
+ {
+ MovePosition(8);
+ return _reader.ReadDouble();
+ }
+
+ private int ReadInt32()
+ {
+ MovePosition(4);
+ return _reader.ReadInt32();
+ }
+
+ private long ReadInt64()
+ {
+ MovePosition(8);
+ return _reader.ReadInt64();
+ }
+
+ private BsonType ReadType()
+ {
+ MovePosition(1);
+ return (BsonType)_reader.ReadSByte();
+ }
+
+ private void MovePosition(int count)
+ {
+ _currentContext.Position += count;
+ }
+
+ private byte[] ReadBytes(int count)
+ {
+ MovePosition(count);
+ return _reader.ReadBytes(count);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Sunfish/Sunfish/Library/Newtonsoft.Json/Bson/BsonToken.cs b/Sunfish/Sunfish/Library/Newtonsoft.Json/Bson/BsonToken.cs
new file mode 100644
index 0000000..202bca6
--- /dev/null
+++ b/Sunfish/Sunfish/Library/Newtonsoft.Json/Bson/BsonToken.cs
@@ -0,0 +1,168 @@
+#region License
+// Copyright (c) 2007 James Newton-King
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+#endregion
+
+using System.Collections;
+using System.Collections.Generic;
+
+#nullable disable
+
+namespace Newtonsoft.Json.Bson
+{
+ internal abstract class BsonToken
+ {
+ public abstract BsonType Type { get; }
+ public BsonToken Parent { get; set; }
+ public int CalculatedSize { get; set; }
+ }
+
+ internal class BsonObject : BsonToken, IEnumerable
+ {
+ private readonly List _children = new List();
+
+ public void Add(string name, BsonToken token)
+ {
+ _children.Add(new BsonProperty { Name = new BsonString(name, false), Value = token });
+ token.Parent = this;
+ }
+
+ public override BsonType Type => BsonType.Object;
+
+ public IEnumerator GetEnumerator()
+ {
+ return _children.GetEnumerator();
+ }
+
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return GetEnumerator();
+ }
+ }
+
+ internal class BsonArray : BsonToken, IEnumerable
+ {
+ private readonly List _children = new List();
+
+ public void Add(BsonToken token)
+ {
+ _children.Add(token);
+ token.Parent = this;
+ }
+
+ public override BsonType Type => BsonType.Array;
+
+ public IEnumerator GetEnumerator()
+ {
+ return _children.GetEnumerator();
+ }
+
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return GetEnumerator();
+ }
+ }
+
+ internal class BsonEmpty : BsonToken
+ {
+ public static readonly BsonToken Null = new BsonEmpty(BsonType.Null);
+ public static readonly BsonToken Undefined = new BsonEmpty(BsonType.Undefined);
+
+ private BsonEmpty(BsonType type)
+ {
+ Type = type;
+ }
+
+ public override BsonType Type { get; }
+ }
+
+ internal class BsonValue : BsonToken
+ {
+ private readonly object _value;
+ private readonly BsonType _type;
+
+ public BsonValue(object value, BsonType type)
+ {
+ _value = value;
+ _type = type;
+ }
+
+ public object Value => _value;
+
+ public override BsonType Type => _type;
+ }
+
+ internal class BsonBoolean : BsonValue
+ {
+ public static readonly BsonBoolean False = new BsonBoolean(false);
+ public static readonly BsonBoolean True = new BsonBoolean(true);
+
+ private BsonBoolean(bool value)
+ : base(value, BsonType.Boolean)
+ {
+ }
+ }
+
+ internal class BsonString : BsonValue
+ {
+ public int ByteCount { get; set; }
+ public bool IncludeLength { get; }
+
+ public BsonString(object value, bool includeLength)
+ : base(value, BsonType.String)
+ {
+ IncludeLength = includeLength;
+ }
+ }
+
+ internal class BsonBinary : BsonValue
+ {
+ public BsonBinaryType BinaryType { get; set; }
+
+ public BsonBinary(byte[] value, BsonBinaryType binaryType)
+ : base(value, BsonType.Binary)
+ {
+ BinaryType = binaryType;
+ }
+ }
+
+ internal class BsonRegex : BsonToken
+ {
+ public BsonString Pattern { get; set; }
+ public BsonString Options { get; set; }
+
+ public BsonRegex(string pattern, string options)
+ {
+ Pattern = new BsonString(pattern, false);
+ Options = new BsonString(options, false);
+ }
+
+ public override BsonType Type => BsonType.Regex;
+ }
+
+ internal class BsonProperty
+ {
+ public BsonString Name { get; set; }
+ public BsonToken Value { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/Sunfish/Sunfish/Library/Newtonsoft.Json/Bson/BsonType.cs b/Sunfish/Sunfish/Library/Newtonsoft.Json/Bson/BsonType.cs
new file mode 100644
index 0000000..fefae2c
--- /dev/null
+++ b/Sunfish/Sunfish/Library/Newtonsoft.Json/Bson/BsonType.cs
@@ -0,0 +1,53 @@
+#region License
+// Copyright (c) 2007 James Newton-King
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+#endregion
+
+#nullable disable
+
+namespace Newtonsoft.Json.Bson
+{
+ internal enum BsonType : sbyte
+ {
+ Number = 1,
+ String = 2,
+ Object = 3,
+ Array = 4,
+ Binary = 5,
+ Undefined = 6,
+ Oid = 7,
+ Boolean = 8,
+ Date = 9,
+ Null = 10,
+ Regex = 11,
+ Reference = 12,
+ Code = 13,
+ Symbol = 14,
+ CodeWScope = 15,
+ Integer = 16,
+ TimeStamp = 17,
+ Long = 18,
+ MinKey = -1,
+ MaxKey = 127
+ }
+}
\ No newline at end of file
diff --git a/Sunfish/Sunfish/Library/Newtonsoft.Json/Bson/BsonWriter.cs b/Sunfish/Sunfish/Library/Newtonsoft.Json/Bson/BsonWriter.cs
new file mode 100644
index 0000000..47d34fa
--- /dev/null
+++ b/Sunfish/Sunfish/Library/Newtonsoft.Json/Bson/BsonWriter.cs
@@ -0,0 +1,539 @@
+#region License
+// Copyright (c) 2007 James Newton-King
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+#endregion
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+#if HAVE_BIG_INTEGER
+using System.Numerics;
+#endif
+using System.Text;
+using Newtonsoft.Json.Utilities;
+using Newtonsoft.Json.Linq;
+using System.Globalization;
+
+#nullable disable
+
+namespace Newtonsoft.Json.Bson
+{
+ ///
+ /// Represents a writer that provides a fast, non-cached, forward-only way of generating BSON data.
+ ///
+ [Obsolete("BSON reading and writing has been moved to its own package. See https://www.nuget.org/packages/Newtonsoft.Json.Bson for more details.")]
+ public class BsonWriter : JsonWriter
+ {
+ private readonly BsonBinaryWriter _writer;
+
+ private BsonToken _root;
+ private BsonToken _parent;
+ private string _propertyName;
+
+ ///
+ /// Gets or sets the used when writing values to BSON.
+ /// When set to no conversion will occur.
+ ///
+ /// The used when writing values to BSON.
+ public DateTimeKind DateTimeKindHandling
+ {
+ get => _writer.DateTimeKindHandling;
+ set => _writer.DateTimeKindHandling = value;
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The to write to.
+ public BsonWriter(Stream stream)
+ {
+ ValidationUtils.ArgumentNotNull(stream, nameof(stream));
+ _writer = new BsonBinaryWriter(new BinaryWriter(stream));
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The to write to.
+ public BsonWriter(BinaryWriter writer)
+ {
+ ValidationUtils.ArgumentNotNull(writer, nameof(writer));
+ _writer = new BsonBinaryWriter(writer);
+ }
+
+ ///
+ /// Flushes whatever is in the buffer to the underlying and also flushes the underlying stream.
+ ///
+ public override void Flush()
+ {
+ _writer.Flush();
+ }
+
+ ///
+ /// Writes the end.
+ ///
+ /// The token.
+ protected override void WriteEnd(JsonToken token)
+ {
+ base.WriteEnd(token);
+ RemoveParent();
+
+ if (Top == 0)
+ {
+ _writer.WriteToken(_root);
+ }
+ }
+
+ ///
+ /// Writes a comment /*...*/ containing the specified text.
+ ///
+ /// Text to place inside the comment.
+ public override void WriteComment(string text)
+ {
+ throw JsonWriterException.Create(this, "Cannot write JSON comment as BSON.", null);
+ }
+
+ ///
+ /// Writes the start of a constructor with the given name.
+ ///
+ /// The name of the constructor.
+ public override void WriteStartConstructor(string name)
+ {
+ throw JsonWriterException.Create(this, "Cannot write JSON constructor as BSON.", null);
+ }
+
+ ///
+ /// Writes raw JSON.
+ ///
+ /// The raw JSON to write.
+ public override void WriteRaw(string json)
+ {
+ throw JsonWriterException.Create(this, "Cannot write raw JSON as BSON.", null);
+ }
+
+ ///
+ /// Writes raw JSON where a value is expected and updates the writer's state.
+ ///
+ /// The raw JSON to write.
+ public override void WriteRawValue(string json)
+ {
+ throw JsonWriterException.Create(this, "Cannot write raw JSON as BSON.", null);
+ }
+
+ ///
+ /// Writes the beginning of a JSON array.
+ ///
+ public override void WriteStartArray()
+ {
+ base.WriteStartArray();
+
+ AddParent(new BsonArray());
+ }
+
+ ///
+ /// Writes the beginning of a JSON object.
+ ///
+ public override void WriteStartObject()
+ {
+ base.WriteStartObject();
+
+ AddParent(new BsonObject());
+ }
+
+ ///
+ /// Writes the property name of a name/value pair on a JSON object.
+ ///
+ /// The name of the property.
+ public override void WritePropertyName(string name)
+ {
+ base.WritePropertyName(name);
+
+ _propertyName = name;
+ }
+
+ ///
+ /// Closes this writer.
+ /// If is set to true, the underlying is also closed.
+ /// If is set to true, the JSON is auto-completed.
+ ///
+ public override void Close()
+ {
+ base.Close();
+
+ if (CloseOutput)
+ {
+ _writer?.Close();
+ }
+ }
+
+ private void AddParent(BsonToken container)
+ {
+ AddToken(container);
+ _parent = container;
+ }
+
+ private void RemoveParent()
+ {
+ _parent = _parent.Parent;
+ }
+
+ private void AddValue(object value, BsonType type)
+ {
+ AddToken(new BsonValue(value, type));
+ }
+
+ internal void AddToken(BsonToken token)
+ {
+ if (_parent != null)
+ {
+ if (_parent is BsonObject bo)
+ {
+ bo.Add(_propertyName, token);
+ _propertyName = null;
+ }
+ else
+ {
+ ((BsonArray)_parent).Add(token);
+ }
+ }
+ else
+ {
+ if (token.Type != BsonType.Object && token.Type != BsonType.Array)
+ {
+ throw JsonWriterException.Create(this, "Error writing {0} value. BSON must start with an Object or Array.".FormatWith(CultureInfo.InvariantCulture, token.Type), null);
+ }
+
+ _parent = token;
+ _root = token;
+ }
+ }
+
+ #region WriteValue methods
+ ///
+ /// Writes a value.
+ /// An error will raised if the value cannot be written as a single JSON token.
+ ///
+ /// The value to write.
+ public override void WriteValue(object value)
+ {
+#if HAVE_BIG_INTEGER
+ if (value is BigInteger i)
+ {
+ SetWriteState(JsonToken.Integer, null);
+ AddToken(new BsonBinary(i.ToByteArray(), BsonBinaryType.Binary));
+ }
+ else
+#endif
+ {
+ base.WriteValue(value);
+ }
+ }
+
+ ///
+ /// Writes a null value.
+ ///
+ public override void WriteNull()
+ {
+ base.WriteNull();
+ AddToken(BsonEmpty.Null);
+ }
+
+ ///
+ /// Writes an undefined value.
+ ///
+ public override void WriteUndefined()
+ {
+ base.WriteUndefined();
+ AddToken(BsonEmpty.Undefined);
+ }
+
+ ///
+ /// Writes a value.
+ ///
+ /// The value to write.
+ public override void WriteValue(string value)
+ {
+ base.WriteValue(value);
+ AddToken(value == null ? BsonEmpty.Null : new BsonString(value, true));
+ }
+
+ ///
+ /// Writes a value.
+ ///
+ /// The value to write.
+ public override void WriteValue(int value)
+ {
+ base.WriteValue(value);
+ AddValue(value, BsonType.Integer);
+ }
+
+ ///
+ /// Writes a value.
+ ///
+ /// The value to write.
+ [CLSCompliant(false)]
+ public override void WriteValue(uint value)
+ {
+ if (value > int.MaxValue)
+ {
+ throw JsonWriterException.Create(this, "Value is too large to fit in a signed 32 bit integer. BSON does not support unsigned values.", null);
+ }
+
+ base.WriteValue(value);
+ AddValue(value, BsonType.Integer);
+ }
+
+ ///
+ /// Writes a value.
+ ///
+ /// The value to write.
+ public override void WriteValue(long value)
+ {
+ base.WriteValue(value);
+ AddValue(value, BsonType.Long);
+ }
+
+ ///
+ /// Writes a value.
+ ///
+ /// The value to write.
+ [CLSCompliant(false)]
+ public override void WriteValue(ulong value)
+ {
+ if (value > long.MaxValue)
+ {
+ throw JsonWriterException.Create(this, "Value is too large to fit in a signed 64 bit integer. BSON does not support unsigned values.", null);
+ }
+
+ base.WriteValue(value);
+ AddValue(value, BsonType.Long);
+ }
+
+ ///
+ /// Writes a value.
+ ///
+ /// The value to write.
+ public override void WriteValue(float value)
+ {
+ base.WriteValue(value);
+ AddValue(value, BsonType.Number);
+ }
+
+ ///
+ /// Writes a value.
+ ///
+ /// The value to write.
+ public override void WriteValue(double value)
+ {
+ base.WriteValue(value);
+ AddValue(value, BsonType.Number);
+ }
+
+ ///
+ /// Writes a value.
+ ///
+ /// The value to write.
+ public override void WriteValue(bool value)
+ {
+ base.WriteValue(value);
+ AddToken(value ? BsonBoolean.True : BsonBoolean.False);
+ }
+
+ ///
+ /// Writes a value.
+ ///
+ /// The value to write.
+ public override void WriteValue(short value)
+ {
+ base.WriteValue(value);
+ AddValue(value, BsonType.Integer);
+ }
+
+ ///
+ /// Writes a value.
+ ///
+ /// The value to write.
+ [CLSCompliant(false)]
+ public override void WriteValue(ushort value)
+ {
+ base.WriteValue(value);
+ AddValue(value, BsonType.Integer);
+ }
+
+ ///
+ /// Writes a value.
+ ///
+ /// The value to write.
+ public override void WriteValue(char value)
+ {
+ base.WriteValue(value);
+ string s = null;
+#if HAVE_CHAR_TO_STRING_WITH_CULTURE
+ s = value.ToString(CultureInfo.InvariantCulture);
+#else
+ s = value.ToString();
+#endif
+ AddToken(new BsonString(s, true));
+ }
+
+ ///
+ /// Writes a value.
+ ///
+ /// The value to write.
+ public override void WriteValue(byte value)
+ {
+ base.WriteValue(value);
+ AddValue(value, BsonType.Integer);
+ }
+
+ ///
+ /// Writes a value.
+ ///
+ /// The value to write.
+ [CLSCompliant(false)]
+ public override void WriteValue(sbyte value)
+ {
+ base.WriteValue(value);
+ AddValue(value, BsonType.Integer);
+ }
+
+ ///
+ /// Writes a value.
+ ///
+ /// The value to write.
+ public override void WriteValue(decimal value)
+ {
+ base.WriteValue(value);
+ AddValue(value, BsonType.Number);
+ }
+
+ ///
+ /// Writes a value.
+ ///
+ /// The value to write.
+ public override void WriteValue(DateTime value)
+ {
+ base.WriteValue(value);
+ value = DateTimeUtils.EnsureDateTime(value, DateTimeZoneHandling);
+ AddValue(value, BsonType.Date);
+ }
+
+#if HAVE_DATE_TIME_OFFSET
+ ///
+ /// Writes a value.
+ ///
+ /// The value to write.
+ public override void WriteValue(DateTimeOffset value)
+ {
+ base.WriteValue(value);
+ AddValue(value, BsonType.Date);
+ }
+#endif
+
+ ///
+ /// Writes a [] value.
+ ///
+ /// The [] value to write.
+ public override void WriteValue(byte[] value)
+ {
+ if (value == null)
+ {
+ WriteNull();
+ return;
+ }
+
+ base.WriteValue(value);
+ AddToken(new BsonBinary(value, BsonBinaryType.Binary));
+ }
+
+ ///
+ /// Writes a value.
+ ///
+ /// The value to write.
+ public override void WriteValue(Guid value)
+ {
+ base.WriteValue(value);
+ AddToken(new BsonBinary(value.ToByteArray(), BsonBinaryType.Uuid));
+ }
+
+ ///
+ /// Writes a value.
+ ///
+ /// The value to write.
+ public override void WriteValue(TimeSpan value)
+ {
+ base.WriteValue(value);
+ AddToken(new BsonString(value.ToString(), true));
+ }
+
+ ///
+ /// Writes a value.
+ ///
+ /// The value to write.
+ public override void WriteValue(Uri value)
+ {
+ if (value == null)
+ {
+ WriteNull();
+ return;
+ }
+
+ base.WriteValue(value);
+ AddToken(new BsonString(value.ToString(), true));
+ }
+ #endregion
+
+ ///
+ /// Writes a [] value that represents a BSON object id.
+ ///
+ /// The Object ID value to write.
+ public void WriteObjectId(byte[] value)
+ {
+ ValidationUtils.ArgumentNotNull(value, nameof(value));
+
+ if (value.Length != 12)
+ {
+ throw JsonWriterException.Create(this, "An object id must be 12 bytes", null);
+ }
+
+ // hack to update the writer state
+ SetWriteState(JsonToken.Undefined, null);
+ AddValue(value, BsonType.Oid);
+ }
+
+ ///
+ /// Writes a BSON regex.
+ ///
+ /// The regex pattern.
+ /// The regex options.
+ public void WriteRegex(string pattern, string options)
+ {
+ ValidationUtils.ArgumentNotNull(pattern, nameof(pattern));
+
+ // hack to update the writer state
+ SetWriteState(JsonToken.Undefined, null);
+ AddToken(new BsonRegex(pattern, options));
+ }
+ }
+}
\ No newline at end of file
diff --git a/Sunfish/Sunfish/Library/Newtonsoft.Json/ConstructorHandling.cs b/Sunfish/Sunfish/Library/Newtonsoft.Json/ConstructorHandling.cs
new file mode 100644
index 0000000..e710744
--- /dev/null
+++ b/Sunfish/Sunfish/Library/Newtonsoft.Json/ConstructorHandling.cs
@@ -0,0 +1,43 @@
+#region License
+// Copyright (c) 2007 James Newton-King
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+#endregion
+
+namespace Newtonsoft.Json
+{
+ ///
+ /// Specifies how constructors are used when initializing objects during deserialization by the .
+ ///
+ public enum ConstructorHandling
+ {
+ ///
+ /// First attempt to use the public default constructor, then fall back to a single parameterized constructor, then to the non-public default constructor.
+ ///
+ Default = 0,
+
+ ///
+ /// Json.NET will use a non-public default constructor before falling back to a parameterized constructor.
+ ///
+ AllowNonPublicDefaultConstructor = 1
+ }
+}
\ No newline at end of file
diff --git a/Sunfish/Sunfish/Library/Newtonsoft.Json/Converters/BinaryConverter.cs b/Sunfish/Sunfish/Library/Newtonsoft.Json/Converters/BinaryConverter.cs
new file mode 100644
index 0000000..7390503
--- /dev/null
+++ b/Sunfish/Sunfish/Library/Newtonsoft.Json/Converters/BinaryConverter.cs
@@ -0,0 +1,212 @@
+#region License
+// Copyright (c) 2007 James Newton-King
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+#endregion
+
+#if HAVE_LINQ || HAVE_ADO_NET
+using System;
+using System.Globalization;
+using Newtonsoft.Json.Utilities;
+using System.Collections.Generic;
+using System.Diagnostics;
+#if HAVE_ADO_NET
+using System.Data.SqlTypes;
+#endif
+
+namespace Newtonsoft.Json.Converters
+{
+ ///
+ /// Converts a binary value to and from a base 64 string value.
+ ///
+ public class BinaryConverter : JsonConverter
+ {
+#if HAVE_LINQ
+ private const string BinaryTypeName = "System.Data.Linq.Binary";
+ private const string BinaryToArrayName = "ToArray";
+ private static ReflectionObject? _reflectionObject;
+#endif
+
+ ///
+ /// Writes the JSON representation of the object.
+ ///
+ /// The to write to.
+ /// The value.
+ /// The calling serializer.
+ public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
+ {
+ if (value == null)
+ {
+ writer.WriteNull();
+ return;
+ }
+
+ byte[] data = GetByteArray(value);
+
+ writer.WriteValue(data);
+ }
+
+ private byte[] GetByteArray(object value)
+ {
+#if HAVE_LINQ
+ if (value.GetType().FullName == BinaryTypeName)
+ {
+ EnsureReflectionObject(value.GetType());
+ MiscellaneousUtils.Assert(_reflectionObject != null);
+
+ return (byte[])_reflectionObject.GetValue(value, BinaryToArrayName)!;
+ }
+#endif
+#if HAVE_ADO_NET
+ if (value is SqlBinary binary)
+ {
+ return binary.Value;
+ }
+#endif
+
+ throw new JsonSerializationException("Unexpected value type when writing binary: {0}".FormatWith(CultureInfo.InvariantCulture, value.GetType()));
+ }
+
+#if HAVE_LINQ
+ private static void EnsureReflectionObject(Type t)
+ {
+ if (_reflectionObject == null)
+ {
+ _reflectionObject = ReflectionObject.Create(t, t.GetConstructor(new[] { typeof(byte[]) }), BinaryToArrayName);
+ }
+ }
+#endif
+
+ ///
+ /// Reads the JSON representation of the object.
+ ///
+ /// The to read from.
+ /// Type of the object.
+ /// The existing value of object being read.
+ /// The calling serializer.
+ /// The object value.
+ public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
+ {
+ if (reader.TokenType == JsonToken.Null)
+ {
+ if (!ReflectionUtils.IsNullable(objectType))
+ {
+ throw JsonSerializationException.Create(reader, "Cannot convert null value to {0}.".FormatWith(CultureInfo.InvariantCulture, objectType));
+ }
+
+ return null;
+ }
+
+ byte[] data;
+
+ if (reader.TokenType == JsonToken.StartArray)
+ {
+ data = ReadByteArray(reader);
+ }
+ else if (reader.TokenType == JsonToken.String)
+ {
+ // current token is already at base64 string
+ // unable to call ReadAsBytes so do it the old fashion way
+ string encodedData = reader.Value!.ToString();
+ data = Convert.FromBase64String(encodedData);
+ }
+ else
+ {
+ throw JsonSerializationException.Create(reader, "Unexpected token parsing binary. Expected String or StartArray, got {0}.".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
+ }
+
+ Type t = (ReflectionUtils.IsNullableType(objectType))
+ ? Nullable.GetUnderlyingType(objectType)
+ : objectType;
+
+#if HAVE_LINQ
+ if (t.FullName == BinaryTypeName)
+ {
+ EnsureReflectionObject(t);
+ MiscellaneousUtils.Assert(_reflectionObject != null);
+
+ return _reflectionObject.Creator!(data);
+ }
+#endif
+
+#if HAVE_ADO_NET
+ if (t == typeof(SqlBinary))
+ {
+ return new SqlBinary(data);
+ }
+#endif
+
+ throw JsonSerializationException.Create(reader, "Unexpected object type when writing binary: {0}".FormatWith(CultureInfo.InvariantCulture, objectType));
+ }
+
+ private byte[] ReadByteArray(JsonReader reader)
+ {
+ List byteList = new List();
+
+ while (reader.Read())
+ {
+ switch (reader.TokenType)
+ {
+ case JsonToken.Integer:
+ byteList.Add(Convert.ToByte(reader.Value, CultureInfo.InvariantCulture));
+ break;
+ case JsonToken.EndArray:
+ return byteList.ToArray();
+ case JsonToken.Comment:
+ // skip
+ break;
+ default:
+ throw JsonSerializationException.Create(reader, "Unexpected token when reading bytes: {0}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
+ }
+ }
+
+ throw JsonSerializationException.Create(reader, "Unexpected end when reading bytes.");
+ }
+
+ ///
+ /// Determines whether this instance can convert the specified object type.
+ ///
+ /// Type of the object.
+ ///
+ /// true if this instance can convert the specified object type; otherwise, false.
+ ///
+ public override bool CanConvert(Type objectType)
+ {
+#if HAVE_LINQ
+ if (objectType.FullName == BinaryTypeName)
+ {
+ return true;
+ }
+#endif
+#if HAVE_ADO_NET
+ if (objectType == typeof(SqlBinary) || objectType == typeof(SqlBinary?))
+ {
+ return true;
+ }
+#endif
+
+ return false;
+ }
+ }
+}
+
+#endif
\ No newline at end of file
diff --git a/Sunfish/Sunfish/Library/Newtonsoft.Json/Converters/BsonObjectIdConverter.cs b/Sunfish/Sunfish/Library/Newtonsoft.Json/Converters/BsonObjectIdConverter.cs
new file mode 100644
index 0000000..5f918de
--- /dev/null
+++ b/Sunfish/Sunfish/Library/Newtonsoft.Json/Converters/BsonObjectIdConverter.cs
@@ -0,0 +1,93 @@
+#region License
+// Copyright (c) 2007 James Newton-King
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+#endregion
+
+using System;
+using Newtonsoft.Json.Bson;
+using System.Globalization;
+using Newtonsoft.Json.Utilities;
+
+#nullable disable
+
+namespace Newtonsoft.Json.Converters
+{
+ ///
+ /// Converts a to and from JSON and BSON.
+ ///
+ [Obsolete("BSON reading and writing has been moved to its own package. See https://www.nuget.org/packages/Newtonsoft.Json.Bson for more details.")]
+ public class BsonObjectIdConverter : JsonConverter
+ {
+ ///
+ /// Writes the JSON representation of the object.
+ ///
+ /// The to write to.
+ /// The value.
+ /// The calling serializer.
+ public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
+ {
+ BsonObjectId objectId = (BsonObjectId)value;
+
+ if (writer is BsonWriter bsonWriter)
+ {
+ bsonWriter.WriteObjectId(objectId.Value);
+ }
+ else
+ {
+ writer.WriteValue(objectId.Value);
+ }
+ }
+
+ ///
+ /// Reads the JSON representation of the object.
+ ///
+ /// The to read from.
+ /// Type of the object.
+ /// The existing value of object being read.
+ /// The calling serializer.
+ /// The object value.
+ public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
+ {
+ if (reader.TokenType != JsonToken.Bytes)
+ {
+ throw new JsonSerializationException("Expected Bytes but got {0}.".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
+ }
+
+ byte[] value = (byte[])reader.Value;
+
+ return new BsonObjectId(value);
+ }
+
+ ///
+ /// Determines whether this instance can convert the specified object type.
+ ///
+ /// Type of the object.
+ ///
+ /// true if this instance can convert the specified object type; otherwise, false.
+ ///
+ public override bool CanConvert(Type objectType)
+ {
+ return (objectType == typeof(BsonObjectId));
+ }
+ }
+}
\ No newline at end of file
diff --git a/Sunfish/Sunfish/Library/Newtonsoft.Json/Converters/CustomCreationConverter.cs b/Sunfish/Sunfish/Library/Newtonsoft.Json/Converters/CustomCreationConverter.cs
new file mode 100644
index 0000000..f693ce5
--- /dev/null
+++ b/Sunfish/Sunfish/Library/Newtonsoft.Json/Converters/CustomCreationConverter.cs
@@ -0,0 +1,101 @@
+#region License
+// Copyright (c) 2007 James Newton-King
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+#endregion
+
+using System;
+using System.Reflection;
+using Newtonsoft.Json.Utilities;
+
+namespace Newtonsoft.Json.Converters
+{
+ ///
+ /// Creates a custom object.
+ ///
+ /// The object type to convert.
+ public abstract class CustomCreationConverter : JsonConverter
+ {
+ ///
+ /// Writes the JSON representation of the object.
+ ///
+ /// The to write to.
+ /// The value.
+ /// The calling serializer.
+ public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
+ {
+ throw new NotSupportedException("CustomCreationConverter should only be used while deserializing.");
+ }
+
+ ///
+ /// Reads the JSON representation of the object.
+ ///
+ /// The to read from.
+ /// Type of the object.
+ /// The existing value of object being read.
+ /// The calling serializer.
+ /// The object value.
+ public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
+ {
+ if (reader.TokenType == JsonToken.Null)
+ {
+ return null;
+ }
+
+ T value = Create(objectType);
+ if (value == null)
+ {
+ throw new JsonSerializationException("No object created.");
+ }
+
+ serializer.Populate(reader, value);
+ return value;
+ }
+
+ ///
+ /// Creates an object which will then be populated by the serializer.
+ ///
+ /// Type of the object.
+ /// The created object.
+ public abstract T Create(Type objectType);
+
+ ///
+ /// Determines whether this instance can convert the specified object type.
+ ///
+ /// Type of the object.
+ ///
+ /// true if this instance can convert the specified object type; otherwise, false.
+ ///
+ public override bool CanConvert(Type objectType)
+ {
+ return typeof(T).IsAssignableFrom(objectType);
+ }
+
+ ///
+ /// Gets a value indicating whether this can write JSON.
+ ///
+ ///
+ /// true if this can write JSON; otherwise, false.
+ ///
+ public override bool CanWrite => false;
+ }
+}
\ No newline at end of file
diff --git a/Sunfish/Sunfish/Library/Newtonsoft.Json/Converters/DataSetConverter.cs b/Sunfish/Sunfish/Library/Newtonsoft.Json/Converters/DataSetConverter.cs
new file mode 100644
index 0000000..61bb625
--- /dev/null
+++ b/Sunfish/Sunfish/Library/Newtonsoft.Json/Converters/DataSetConverter.cs
@@ -0,0 +1,125 @@
+#region License
+// Copyright (c) 2007 James Newton-King
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+#endregion
+
+#if HAVE_ADO_NET
+using System;
+using System.Data;
+using Newtonsoft.Json.Serialization;
+
+namespace Newtonsoft.Json.Converters
+{
+ ///
+ /// Converts a to and from JSON.
+ ///
+ public class DataSetConverter : JsonConverter
+ {
+ ///
+ /// Writes the JSON representation of the object.
+ ///
+ /// The to write to.
+ /// The value.
+ /// The calling serializer.
+ public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
+ {
+ if (value == null)
+ {
+ writer.WriteNull();
+ return;
+ }
+
+ DataSet dataSet = (DataSet)value;
+ DefaultContractResolver? resolver = serializer.ContractResolver as DefaultContractResolver;
+
+ DataTableConverter converter = new DataTableConverter();
+
+ writer.WriteStartObject();
+
+ foreach (DataTable table in dataSet.Tables)
+ {
+ writer.WritePropertyName((resolver != null) ? resolver.GetResolvedPropertyName(table.TableName) : table.TableName);
+
+ converter.WriteJson(writer, table, serializer);
+ }
+
+ writer.WriteEndObject();
+ }
+
+ ///
+ /// Reads the JSON representation of the object.
+ ///
+ /// The to read from.
+ /// Type of the object.
+ /// The existing value of object being read.
+ /// The calling serializer.
+ /// The object value.
+ public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
+ {
+ if (reader.TokenType == JsonToken.Null)
+ {
+ return null;
+ }
+
+ // handle typed datasets
+ DataSet ds = (objectType == typeof(DataSet))
+ ? new DataSet()
+ : (DataSet)Activator.CreateInstance(objectType);
+
+ DataTableConverter converter = new DataTableConverter();
+
+ reader.ReadAndAssert();
+
+ while (reader.TokenType == JsonToken.PropertyName)
+ {
+ DataTable dt = ds.Tables[(string)reader.Value!];
+ bool exists = (dt != null);
+
+ dt = (DataTable)converter.ReadJson(reader, typeof(DataTable), dt, serializer)!;
+
+ if (!exists)
+ {
+ ds.Tables.Add(dt);
+ }
+
+ reader.ReadAndAssert();
+ }
+
+ return ds;
+ }
+
+ ///
+ /// Determines whether this instance can convert the specified value type.
+ ///
+ /// Type of the value.
+ ///
+ /// true if this instance can convert the specified value type; otherwise, false.
+ ///
+ public override bool CanConvert(Type valueType)
+ {
+ return typeof(DataSet).IsAssignableFrom(valueType);
+ }
+ }
+}
+
+#endif
\ No newline at end of file
diff --git a/Sunfish/Sunfish/Library/Newtonsoft.Json/Converters/DataTableConverter.cs b/Sunfish/Sunfish/Library/Newtonsoft.Json/Converters/DataTableConverter.cs
new file mode 100644
index 0000000..7f8c529
--- /dev/null
+++ b/Sunfish/Sunfish/Library/Newtonsoft.Json/Converters/DataTableConverter.cs
@@ -0,0 +1,254 @@
+#region License
+// Copyright (c) 2007 James Newton-King
+//
+// Permission is hereby granted, free of charge, to any person
+// obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without
+// restriction, including without limitation the rights to use,
+// copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following
+// conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+#endregion
+
+#if HAVE_ADO_NET
+using System.Collections;
+using System.Collections.Generic;
+using System.Globalization;
+using Newtonsoft.Json.Utilities;
+using System;
+using System.Data;
+using Newtonsoft.Json.Serialization;
+
+namespace Newtonsoft.Json.Converters
+{
+ ///
+ /// Converts a to and from JSON.
+ ///
+ public class DataTableConverter : JsonConverter
+ {
+ ///
+ /// Writes the JSON representation of the object.
+ ///
+ /// The to write to.
+ /// The value.
+ /// The calling serializer.
+ public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
+ {
+ if (value == null)
+ {
+ writer.WriteNull();
+ return;
+ }
+
+ DataTable table = (DataTable)value;
+ DefaultContractResolver? resolver = serializer.ContractResolver as DefaultContractResolver;
+
+ writer.WriteStartArray();
+
+ foreach (DataRow row in table.Rows)
+ {
+ writer.WriteStartObject();
+ foreach (DataColumn column in row.Table.Columns)
+ {
+ object columnValue = row[column];
+
+ if (serializer.NullValueHandling == NullValueHandling.Ignore && (columnValue == null || columnValue == DBNull.Value))
+ {
+ continue;
+ }
+
+ writer.WritePropertyName((resolver != null) ? resolver.GetResolvedPropertyName(column.ColumnName) : column.ColumnName);
+ serializer.Serialize(writer, columnValue);
+ }
+ writer.WriteEndObject();
+ }
+
+ writer.WriteEndArray();
+ }
+
+ ///
+ /// Reads the JSON representation of the object.
+ ///
+ /// The to read from.
+ /// Type of the object.
+ /// The existing value of object being read.
+ /// The calling serializer.
+ /// The object value.
+ public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
+ {
+ if (reader.TokenType == JsonToken.Null)
+ {
+ return null;
+ }
+
+ if (!(existingValue is DataTable dt))
+ {
+ // handle typed datasets
+ dt = (objectType == typeof(DataTable))
+ ? new DataTable()
+ : (DataTable)Activator.CreateInstance(objectType);
+ }
+
+ // DataTable is inside a DataSet
+ // populate the name from the property name
+ if (reader.TokenType == JsonToken.PropertyName)
+ {
+ dt.TableName = (string)reader.Value!;
+
+ reader.ReadAndAssert();
+
+ if (reader.TokenType == JsonToken.Null)
+ {
+ return dt;
+ }
+ }
+
+ if (reader.TokenType != JsonToken.StartArray)
+ {
+ throw JsonSerializationException.Create(reader, "Unexpected JSON token when reading DataTable. Expected StartArray, got {0}.".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
+ }
+
+ reader.ReadAndAssert();
+
+ while (reader.TokenType != JsonToken.EndArray)
+ {
+ CreateRow(reader, dt, serializer);
+
+ reader.ReadAndAssert();
+ }
+
+ return dt;
+ }
+
+ private static void CreateRow(JsonReader reader, DataTable dt, JsonSerializer serializer)
+ {
+ DataRow dr = dt.NewRow();
+ reader.ReadAndAssert();
+
+ while (reader.TokenType == JsonToken.PropertyName)
+ {
+ string columnName = (string)reader.Value!;
+
+ reader.ReadAndAssert();
+
+ DataColumn column = dt.Columns[columnName];
+ if (column == null)
+ {
+ Type columnType = GetColumnDataType(reader);
+ column = new DataColumn(columnName, columnType);
+ dt.Columns.Add(column);
+ }
+
+ if (column.DataType == typeof(DataTable))
+ {
+ if (reader.TokenType == JsonToken.StartArray)
+ {
+ reader.ReadAndAssert();
+ }
+
+ DataTable nestedDt = new DataTable();
+
+ while (reader.TokenType != JsonToken.EndArray)
+ {
+ CreateRow(reader, nestedDt, serializer);
+
+ reader.ReadAndAssert();
+ }
+
+ dr[columnName] = nestedDt;
+ }
+ else if (column.DataType.IsArray && column.DataType != typeof(byte[]))
+ {
+ if (reader.TokenType == JsonToken.StartArray)
+ {
+ reader.ReadAndAssert();
+ }
+
+ List