public ViewableFile(EFEFile File, Type Format, bool CreateNew = false)
 {
     if (!Format.GetInterfaces().Contains(typeof(IViewable))) throw new ArgumentException("This format is not viewable!");
     this.File = File;
     if (CreateNew) FileFormat = Format.InvokeMember("", System.Reflection.BindingFlags.CreateInstance, null, null, new object[0]);
     else FileFormat = Format.InvokeMember("", System.Reflection.BindingFlags.CreateInstance, null, null, new object[] { File.Data });
     Dialog = FileFormat.GetDialog();
     Dialog.Tag = this;
     Dialog.Text = File.Name;
     Dialog.FormClosing += new FormClosingEventHandler(Dialog_FormClosing);
 }
 public static ListViewItem GetFileItem(EFEFile File)
 {
     Type[] formats = Program.FileManager.GetPossibleFormats(File);
     ListViewItem i = new ListViewItem(File.Name);
     StringBuilder b = new StringBuilder(50);
     Win32Util.StrFormatByteSize(File.Data.Length, b, 50);
     i.SubItems.Add(b.ToString());
     if (formats.Length == 1)
     {
         i.ImageKey = formats[0].ToString();
         dynamic q = new StaticDynamic(formats[0]);
         i.Tag = q.Identifier.GetCategory();
     }
     if (File.IsCompressed) i.ForeColor = Color.Blue;
     return i;
 }
 public Type[] GetPossibleFormats(EFEFile File)
 {
     Dictionary<Type, FormatMatch> Formats = new Dictionary<Type, FormatMatch>();
     bool gotContent = false;
     foreach (Plugin p in Program.PluginManager.Plugins)
     {
         foreach (Type t in p.FileFormatTypes)
         {
             dynamic d = new StaticDynamic(t);
             FormatMatch m = d.Identifier.IsFormat(File);
             if (m == FormatMatch.Content) gotContent = true;
             if (m != FormatMatch.No && !(gotContent && m == FormatMatch.Extension)) Formats.Add(t, m);
         }
     }
     if (gotContent)
     {
         foreach (Type t in Formats.Keys)
         {
             if (Formats[t] == FormatMatch.Extension) Formats.Remove(t);
         }
     }
     return Formats.Keys.ToArray();
 }
        public bool OpenFile(EFEFile File, EFEFile Parent = null)
        {
            foreach (var v in ViewedFiles)
            {
                if (v.File.Equals(File))
                {
                    MessageBox.Show("This file has already been opened!");
                    ((Form1)Application.OpenForms[0]).BringMDIWindowToFront(v.Dialog);
                    return false;
                }
            }
            Type[] formats = GetPossibleFormats(File);
            if (formats.Length == 0) return false;
            List<Type> Viewables = new List<Type>();
            foreach (Type t in formats)
            {
                if (t.GetInterfaces().Contains(typeof(IViewable))) Viewables.Add(t);
            }
            Type tt;
            if (Viewables.Count == 0) return false;
            else if (Viewables.Count == 1) tt = Viewables[0];
            else
            {
                MessageBox.Show("Multiple types match!");
                return false;
            }

            ViewableFile vv = new ViewableFile(File, tt);
            ViewedFiles.Add(vv);
            vv.DialogClosing += new ViewableFile.DialogClosingEventHandler(v_DialogClosing);
            vv.ShowDialog(Application.OpenForms[0]);
            if (Parent != null)
            {
                File.Parent = Parent;
                Parent.Children.Add(File);
            }

            foreach (var v in ViewedFiles)
            {
                if (vv != v && v.Dialog is IUseOtherFiles) ((IUseOtherFiles)v.Dialog).FileOpened(vv);
            }
            return true;
        }
 public ViewableFile GetViewableFileFromFile(EFEFile File)
 {
     foreach (var v in ViewedFiles)
     {
         if (v.File.Equals(File)) return v;
     }
     return null;
 }
 public static void OpenFile(EFEFile File, EFEFile Parent = null)
 {
     Program.FileManager.OpenFile(File, Parent);
 }
 public static ViewableFile GetViewableFileFromFile(EFEFile File)
 {
     return Program.FileManager.GetViewableFileFromFile(File);
 }