This commit is contained in:
CreepyCrafter24 2019-12-21 13:20:04 +01:00
parent 97c4f62677
commit 8a4824a5d3
3 changed files with 42 additions and 17 deletions

View File

@ -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
//

View File

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

View File

@ -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]</value>
</data>
<data name="cseditCode.Text" xml:space="preserve">
<value>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");
}
}
}</value>
</data>
<metadata name="csSaveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>