private bool CompileBg(string code, CodeEditorParameters cedp = null)
        {
            CodeEditorParameters cep = Tag as CodeEditorParameters;

            System.CodeDom.Compiler.CompilerResults cr = NetDasm.Compile(code, cep.File, cep.References);
            compilerErrors.ItemsSource      = NetDasm.GetCompilerErrors(cr);
            compilerErrorsBorder.Background = new System.Windows.Media.SolidColorBrush(compilerErrors.Items.Count > 0 ? System.Windows.Media.Colors.OrangeRed : System.Windows.Media.Colors.LightGray);
            return(compilerErrors.ItemsSource == null);
        }
        void OpenDecompiledCode(string segment = null)
        {
            AshFile af = new AshFile(pwner, decompilationResult, EditorType.Compiler);

            af.Tag = new CodeEditorParameters()
            {
                File = SourceFile, References = nd.ResolvedReferences.ToArray()
            };
            disasmFile.Child     = af;
            af.NeedsSaveChanged += delegate(bool ns) { NeedsSave = ns; };
            this.FileSaved      += delegate(AshFile f)
            {
                NetDasm.CompileFromCs(af.compilerCode.Text, SourceFile, (af.Tag as CodeEditorParameters).References);
            };
        }
 void loadFile()
 {
     bool eSave = false;
     pwner.SetStatus(string.Empty);
     img.Source = null;
     txtEditor.Visibility = Visibility.Collapsed;
     binEditor.Visibility = Visibility.Collapsed;
     imgPane.Visibility = Visibility.Collapsed;
     disasm.Visibility = Visibility.Collapsed;
     compi.Visibility = Visibility.Collapsed;
     iledit.Visibility = Visibility.Collapsed;
     resedit.Visibility = Visibility.Collapsed;
     nd = null;
     List<string> viewAsText = new List<string>() { "xaml", "xml" };
     List<string> viewAsImage = new List<string>() { "png", "bmp", "jpg", "ico" };
     long fl = new System.IO.FileInfo(sourcefile).Length;
     pwner.SetStatus(sourcefile, true);
     string stat = string.Format("{0:0} {1}", (fl > 1024 ? (fl / 1024) : fl), (fl > 1024 ? "Kb" : "bytes"));
     if (et == EditorType.Default)
     {
         string e = Path.GetExtension(sourcefile).Substring(1);
         if (viewAsText.Contains(e)) et = EditorType.Text;
         else if (viewAsImage.Contains(e)) et = EditorType.Image;
         else if (e == "dll") et = EditorType.Assembly;
         else et = EditorType.Binary;
     }
     switch (et)
     {
         case EditorType.Text:
             eSave = true;
             try
             {
                 tbEdit.Text = System.IO.File.ReadAllText(sourcefile, Encoding.UTF8);
             }
             catch (Exception e) { MessageBox.Show(e.Message); }
             txtEditor.Visibility = Visibility.Visible;
             break;
         case EditorType.Compiler:
             eSave = true;
             compilerCode.Text = System.IO.File.ReadAllText(sourcefile, Encoding.UTF8);
             compi.Visibility = Visibility.Visible;
             break;
         case EditorType.Image:
             BitmapImage bi = StaticBitmap.Read(sourcefile);
             img.Source = bi;
             stat = string.Format("{0:0}x{1:0}px | {2}", bi.Width, bi.Height, stat);
             imgPane.Visibility = Visibility.Visible;
             break;
         case EditorType.Assembly:
             nd = new NetDasm(this);
             nd.LoadAsm(sourcefile);
             disasm.Visibility = Visibility.Visible;
             Disassemble();
             eSave = true;
             break;
         case EditorType.Binary:
             Be.Windows.Forms.HexBox hb = new Be.Windows.Forms.HexBox() { ByteProvider = new Be.Windows.Forms.FileByteProvider(sourcefile), ByteCharConverter = new Be.Windows.Forms.DefaultByteCharConverter(), BytesPerLine = 16, UseFixedBytesPerLine = true, StringViewVisible = true, VScrollBarVisible = true };
             hb.TextChanged += delegate(object sender, EventArgs ev) { NeedsSave = true; };
             binHost.Child = hb;
             binEditor.Visibility = Visibility.Visible;
             break;
         case EditorType.Resource:
             resedit.Visibility = Visibility.Visible;
             break;
     }
     pwner.SetStatus(stat);
     CanSave = eSave;
     pwner.menu_save.IsEnabled = CanSave;
     OnFileLoaded();
 }
 public void loadasm(string fn)
 {
     nd = new NetDasm(this);
     nd.LoadAsm(fn);
 }
 public void loadasm(string fn)
 {
     nd = new NetDasm(this);
     nd.LoadAsm(fn);
 }
        void loadFile()
        {
            bool eSave = false;

            pwner.SetStatus(string.Empty);
            img.Source           = null;
            txtEditor.Visibility = Visibility.Collapsed;
            binEditor.Visibility = Visibility.Collapsed;
            imgPane.Visibility   = Visibility.Collapsed;
            disasm.Visibility    = Visibility.Collapsed;
            compi.Visibility     = Visibility.Collapsed;
            iledit.Visibility    = Visibility.Collapsed;
            resedit.Visibility   = Visibility.Collapsed;
            nd = null;
            List <string> viewAsText = new List <string>()
            {
                "xaml", "xml"
            };
            List <string> viewAsImage = new List <string>()
            {
                "png", "bmp", "jpg", "ico"
            };
            long fl = new System.IO.FileInfo(sourcefile).Length;

            pwner.SetStatus(sourcefile, true);
            string stat = string.Format("{0:0} {1}", (fl > 1024 ? (fl / 1024) : fl), (fl > 1024 ? "Kb" : "bytes"));

            if (et == EditorType.Default)
            {
                string e = Path.GetExtension(sourcefile).Substring(1);
                if (viewAsText.Contains(e))
                {
                    et = EditorType.Text;
                }
                else if (viewAsImage.Contains(e))
                {
                    et = EditorType.Image;
                }
                else if (e == "dll")
                {
                    et = EditorType.Assembly;
                }
                else
                {
                    et = EditorType.Binary;
                }
            }
            switch (et)
            {
            case EditorType.Text:
                eSave = true;
                try
                {
                    tbEdit.Text = System.IO.File.ReadAllText(sourcefile, Encoding.UTF8);
                }
                catch (Exception e) { MessageBox.Show(e.Message); }
                txtEditor.Visibility = Visibility.Visible;
                break;

            case EditorType.Compiler:
                eSave             = true;
                compilerCode.Text = System.IO.File.ReadAllText(sourcefile, Encoding.UTF8);
                compi.Visibility  = Visibility.Visible;
                break;

            case EditorType.Image:
                BitmapImage bi = StaticBitmap.Read(sourcefile);
                img.Source         = bi;
                stat               = string.Format("{0:0}x{1:0}px | {2}", bi.Width, bi.Height, stat);
                imgPane.Visibility = Visibility.Visible;
                break;

            case EditorType.Assembly:
                nd = new NetDasm(this);
                nd.LoadAsm(sourcefile);
                disasm.Visibility = Visibility.Visible;
                Disassemble();
                eSave = true;
                break;

            case EditorType.Binary:
                Be.Windows.Forms.HexBox hb = new Be.Windows.Forms.HexBox()
                {
                    ByteProvider = new Be.Windows.Forms.FileByteProvider(sourcefile), ByteCharConverter = new Be.Windows.Forms.DefaultByteCharConverter(), BytesPerLine = 16, UseFixedBytesPerLine = true, StringViewVisible = true, VScrollBarVisible = true
                };
                hb.TextChanged      += delegate(object sender, EventArgs ev) { NeedsSave = true; };
                binHost.Child        = hb;
                binEditor.Visibility = Visibility.Visible;
                break;

            case EditorType.Resource:
                resedit.Visibility = Visibility.Visible;
                break;
            }
            pwner.SetStatus(stat);
            CanSave = eSave;
            pwner.menu_save.IsEnabled = CanSave;
            OnFileLoaded();
        }