Example #1
0
        private IArchiveManager SelectArchiveManager(string filename, bool batchMode = false)
        {
            IArchiveManager result = null;

            // first look for managers whose extension matches that of our file name
            List <IArchiveManager> matchingManagers = _archiveManagers.Where(manager => manager.Extension.Split(';').Any(s => filename.ToLower().EndsWith(s))).ToList();

            result = matchingManagers.FirstOrDefault(manager => manager.Identify(filename));

            // if none of them match, then try all other managers
            if (result == null)
            {
                result = _archiveManagers.Except(matchingManagers).FirstOrDefault(manager => manager.Identify(filename));
            }

            if (result == null && !batchMode)
            {
                MessageBox.Show("None of the installed plugins are able to open the file.", "Unsupported Format", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            return(result == null ? null : (IArchiveManager)Activator.CreateInstance(result.GetType()));
        }