From 8a4824a5d398bdfe94c29985003f7f8c0b1f4eb0 Mon Sep 17 00:00:00 2001
From: CreepyCrafter24 <33260128+CreepyCrafter24@users.noreply.github.com>
Date: Sat, 21 Dec 2019 13:20:04 +0100
Subject: [PATCH] Dunno
---
cashew/MainForm.Designer.cs | 8 +++-----
cashew/MainForm.cs | 33 +++++++++++++++++++++------------
cashew/MainForm.resx | 18 ++++++++++++++++++
3 files changed, 42 insertions(+), 17 deletions(-)
diff --git a/cashew/MainForm.Designer.cs b/cashew/MainForm.Designer.cs
index 9fb6f27..e43c1ad 100644
--- a/cashew/MainForm.Designer.cs
+++ b/cashew/MainForm.Designer.cs
@@ -275,9 +275,7 @@
this.cseditCode.Size = new System.Drawing.Size(780, 291);
this.cseditCode.TabIndex = 9;
this.cseditCode.TabStop = false;
- this.cseditCode.Text = "using System;\r\n\r\nnamespace Project\r\n{\r\n public class Program\r\n {\r\n p" +
- "ublic static void Main()\r\n {\r\n Console.WriteLine(\"Hello, world" +
- "!\");\r\n }\r\n }\r\n}\r\n";
+ this.cseditCode.Text = resources.GetString("cseditCode.Text");
//
// htmltab
//
@@ -578,12 +576,12 @@
//
this.csSaveFileDialog.DefaultExt = "dat";
this.csSaveFileDialog.FileName = "Project.dat";
- this.csSaveFileDialog.Filter = "Data File|*.dat|Binary|*.exe";
+ this.csSaveFileDialog.Filter = "Data File|*.dat|Library|*.dll|Binary|*.exe";
//
// csOpenFileDialog
//
this.csOpenFileDialog.DefaultExt = "dat";
- this.csOpenFileDialog.Filter = "Data File|*.dat|Binary|*.exe";
+ this.csOpenFileDialog.Filter = "Data File|*.dat|Library|*.dll|Binary|*.exe";
//
// htmlOptionsMenu
//
diff --git a/cashew/MainForm.cs b/cashew/MainForm.cs
index f25c21b..c43f459 100644
--- a/cashew/MainForm.cs
+++ b/cashew/MainForm.cs
@@ -35,7 +35,7 @@ namespace cashew
private readonly Control[] normalControls;
private readonly ToolStripMenuItem[] menuItems;
private string[] cseditcodel = new string[0];
- private string[] cseditrefl = new string[0];
+ private string[] cseditrefl = new string[] { "Microsoft.CSharp.dll", "System.dll", "System.Core.dll", "System.Data.dll", "System.Data.DataSetExtensions.dll", "System.Net.Http.dll", "System.Xml.dll", "System.Xml.Linq.dll" };
public MainForm()
{
@@ -156,7 +156,8 @@ namespace cashew
}
else
{
- File.Copy(compileCS(false).PathToAssembly, csSaveFileDialog.FileName);
+ compileCS(false, csSaveFileDialog.FilterIndex == 2, csSaveFileDialog.FileName);
+ //File.Copy(compileCS(false, csSaveFileDialog.FilterIndex == 2).PathToAssembly, csSaveFileDialog.FileName, true);
}
}
catch (Exception e1)
@@ -184,13 +185,20 @@ namespace cashew
{
_ = results.CompiledAssembly.EntryPoint.Invoke(null, null);
}
- catch (Exception e1)
+ catch
{
- if (!e1.tryCast(out ThreadAbortException ex))
- Invoke((MethodInvoker)delegate ()
- {
- MetroMessageBox.Show(this, e1.Message, "Execution Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
- });
+ try
+ {
+ _ = results.CompiledAssembly.EntryPoint.Invoke(null, new object[] { new string[0] });
+ }
+ catch (Exception e1)
+ {
+ if (!e1.tryCast(out ThreadAbortException ex))
+ Invoke((MethodInvoker)delegate ()
+ {
+ MetroMessageBox.Show(this, e1.Message, "Execution Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ });
+ }
}
});
csScript.Start();
@@ -203,7 +211,7 @@ namespace cashew
}
}
- private CompilerResults compileCS(bool memory = true)
+ private CompilerResults compileCS(bool memory = true, bool library = false, string OF = "")
{
csediterrors.Text = "";
if (cseditref.Text == "Code")
@@ -217,8 +225,9 @@ namespace cashew
CompilerParameters parameters = new CompilerParameters
{
GenerateInMemory = memory,
- GenerateExecutable = true,
+ GenerateExecutable = !library
};
+ parameters.OutputAssembly = memory ? parameters.OutputAssembly : OF;
parameters.ReferencedAssemblies.AddRange(cseditrefl);
CompilerResults results;
using (CSharpCodeProvider provider = new CSharpCodeProvider())
@@ -262,8 +271,7 @@ namespace cashew
{
CSharpDecompiler decompiler = new CSharpDecompiler(csOpenFileDialog.FileName, new DecompilerSettings());
cseditcodel = decompiler.DecompileWholeModuleAsString().Split(new string[] { "\r\n" }, StringSplitOptions.None);
- cseditrefl = Assembly.LoadFrom(csOpenFileDialog.FileName)
- .GetReferencedAssemblies().Where(s => !new string[] { "mscorlib" }.Contains(s.Name))
+ cseditrefl = Assembly.LoadFrom(csOpenFileDialog.FileName).GetReferencedAssemblies().Where(s => !new string[] { "mscorlib" }.Contains(s.Name))
.Select(s => string.IsNullOrWhiteSpace(s.CodeBase) ? (s.Name + ".dll") : s.CodeBase).ToArray();
if (cseditref.Text == "References")
cseditCode.Text = string.Join("\r\n", cseditcodel);
@@ -273,6 +281,7 @@ namespace cashew
}
catch (Exception e1)
{
+ Console.WriteLine(e1.ToString());
MetroMessageBox.Show(this, e1.ToString(), "Failed to Load", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
diff --git a/cashew/MainForm.resx b/cashew/MainForm.resx
index 47c7580..851953e 100644
--- a/cashew/MainForm.resx
+++ b/cashew/MainForm.resx
@@ -122,6 +122,24 @@
NOTE: The output of programs written in Cashew will be printed to the native console, no new window will open up.
This Program uses:
[PACKAGELIST]
+
+
+ using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Program
+{
+ class Program
+ {
+ static void Main(string[] args)
+ {
+ Console.WriteLine("Hello, world");
+ }
+ }
+}
17, 17