private void cseditopen_Click(object sender, EventArgs e) { if (csOpenFileDialog.ShowDialog() != DialogResult.OK) { return; } try { if (csOpenFileDialog.FilterIndex == 1) { Stream s = File.OpenRead(csOpenFileDialog.FileName); string[][] tmp = (string[][])new BinaryFormatter().Deserialize(s); s.Dispose(); _cseditcodel = tmp[0]; _cseditrefl = tmp[1]; cseditCode.Text = string.Join("\r\n", cseditref.Text == "References" ? _cseditcodel : _cseditrefl); } else { CSharpDecompiler decompiler = new CSharpDecompiler(csOpenFileDialog.FileName, new DecompilerSettings()); _cseditcodel = decompiler.DecompileWholeModuleAsString() .Split(new[] { "\r\n" }, StringSplitOptions.None); _cseditrefl = Assembly.LoadFrom(csOpenFileDialog.FileName).GetReferencedAssemblies() .Where(s => !new[] { "mscorlib" }.Contains(s.Name)) .Select(s => string.IsNullOrWhiteSpace(s.CodeBase) ? s.Name + ".dll" : s.CodeBase).ToArray(); cseditCode.Text = string.Join("\r\n", cseditref.Text == "References" ? _cseditcodel : _cseditrefl); } } catch (Exception e1) { Console.WriteLine(e1.ToString()); MetroMessageBox.Show(this, e1.ToString(), "Failed to Load", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void pythonRun_Click(object sender, EventArgs e) { if (_pythonScript != null && _runningStates.Contains(_pythonScript.ThreadState)) { _pythonScript.Abort(); } else { _pythonScript = new Thread(() => { ScriptEngine engine = Python.CreateEngine(); engine.SetSearchPaths(new[] { Path.Combine(Path.GetTempPath(), "Cashew\\Python") }); try { engine.Execute(pythonCode.Text); } catch (Exception e1) { if (!e1.TryCast(out ThreadAbortException _)) { Invoke((MethodInvoker) delegate { MetroMessageBox.Show(this, e1.Message, "Execution Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); }); } } }); _pythonScript.Start(); } }
private void cseditsave_Click(object sender, EventArgs e) { if (csSaveFileDialog.ShowDialog() != DialogResult.OK) { return; } try { if (csSaveFileDialog.FilterIndex == 1) { if (cseditref.Text == "Code") { _cseditrefl = cseditCode.Text.Split(new[] { "\r\n" }, StringSplitOptions.None); } else { _cseditcodel = cseditCode.Text.Split(new[] { "\r\n" }, StringSplitOptions.None); } Stream s = File.OpenWrite(csSaveFileDialog.FileName); new BinaryFormatter().Serialize(s, new[] { _cseditcodel, _cseditrefl }); s.Dispose(); } else { CompileCs(false, csSaveFileDialog.FilterIndex == 2, csSaveFileDialog.FileName); //File.Copy(compileCS(false, csSaveFileDialog.FilterIndex == 2).PathToAssembly, csSaveFileDialog.FileName, true); } } catch (Exception e1) { MetroMessageBox.Show(this, e1.Message, "Failed to Save", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void pythonSave_Click(object sender, EventArgs e) { if (pythonSaveFileDialog.ShowDialog() != DialogResult.OK) { return; } try { File.WriteAllText(pythonSaveFileDialog.FileName, pythonCode.Text); } catch (Exception e1) { MetroMessageBox.Show(this, e1.Message, "Saving Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void pythonOpen_Click(object sender, EventArgs e) { if (pythonOpenFileDialog.ShowDialog() != DialogResult.OK) { return; } try { pythonCode.Text = File.ReadAllText(pythonOpenFileDialog.FileName); } catch (Exception e1) { MetroMessageBox.Show(this, e1.Message, "Loading Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void cseditrun_Click(object sender, EventArgs e) { if (_csScript != null && _runningStates.Contains(_csScript.ThreadState)) { _csScript.Abort(); } else { try { CompilerResults results = CompileCs(); cseditrun.Text = "Stop"; _csScript = new Thread(() => { try { _ = results.CompiledAssembly.EntryPoint.Invoke(null, null); } catch { 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(); csediterrors.Text = "Ready"; } catch (Exception e1) { csediterrors.Text = e1.Message; } } }
private void metroPanel1_Click(object sender, EventArgs e) => MetroMessageBox.Show(this, csediterrors.Text, "Errors", MessageBoxButtons.OK, MessageBoxIcon.Error);