Пример #1
0
        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());
        }
        private void FileAssociationForm_Load(object sender, EventArgs e)
        {
            listViewCustom1.Items.Clear();

            foreach (Type t in FileManager.GetFileFormats())
            {
                dynamic item = new StaticDynamic(t);
                for (int i = 0; i < item.Extension.Length; i++)
                {
                    string Extension;
                    if (item.Description.Length - 1 < i)
                    {
                        Extension = $"{item.Description[0]} ({item.Extension[i]})";
                    }
                    else
                    {
                        Extension = $"{item.Description[i]} ({item.Extension[i]})";
                    }

                    listViewCustom1.Items.Add(Extension);
                }
            }
        }
Пример #3
0
        private void OpenFile(object sender, EventArgs e)
        {
            if (opening)
            {
                return;
            }
            opening = true;
            String        Filter  = "";
            List <String> Filters = new List <string>();

            Filters.Add("all files (*.*)|*.*");
            List <String> Extenstions        = new List <string>();
            String        AllSupportedFilesA = "All Supported Files (";
            String        AllSupportedFilesB = "|";

            foreach (Plugin p in Program.PluginManager.Plugins)
            {
                foreach (Type t in p.FileFormatTypes)
                {
                    if (t.GetInterfaces().Contains(typeof(IViewable)))
                    {
                        dynamic d = new StaticDynamic(t);
                        String  FilterString;
                        try
                        {
                            FilterString = d.Identifier.GetFileFilter();
                        }
                        catch (NotImplementedException)
                        {
                            continue;
                        }
                        if (FilterString == null || FilterString.Length == 0)
                        {
                            continue;
                        }
                        if (!Filters.Contains(FilterString.ToLower()))
                        {
                            string[] strArray = FilterString.Split(new char[] { '|' });
                            if ((strArray == null) || ((strArray.Length % 2) != 0))
                            {
                                continue;
                            }
                            string[] q = FilterString.Split('|');
                            for (int i = 1; i < q.Length; i += 2)
                            {
                                foreach (string f in q[i].Split(';'))
                                {
                                    if (!Extenstions.Contains(f.ToLower()))
                                    {
                                        Extenstions.Add(f.ToLower());
                                        if (!AllSupportedFilesA.EndsWith("("))
                                        {
                                            AllSupportedFilesA += ", ";
                                        }
                                        AllSupportedFilesA += f.ToLower();
                                        if (!AllSupportedFilesB.EndsWith("|"))
                                        {
                                            AllSupportedFilesB += ";";
                                        }
                                        AllSupportedFilesB += f.ToLower();
                                    }
                                }
                            }
                            Filters.Add(FilterString.ToLower());
                            if (Filter != "")
                            {
                                Filter += "|";
                            }
                            Filter += FilterString;
                        }
                    }
                }
            }
            if (Filter != "")
            {
                Filter  = AllSupportedFilesA + ")" + AllSupportedFilesB + "|" + Filter;
                Filter += "|";
            }
            Filter += "All Files (*.*)|*.*";
            openFileDialog1.Filter = Filter;
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK &&
                openFileDialog1.FileName.Length > 0)
            {
                foreach (String s in openFileDialog1.FileNames)
                {
                    Program.FileManager.OpenFile(new EFEDiskFile(s));
                }
            }
            opening = false;
        }