Example #1
0
        private void OpenFile(string fileName = "")
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.InitialDirectory = Settings.Default.LastDirectory;

            // Supported Types
            ofd.Filter = Tools.LoadArchiveFilters(_archiveManagers);

            DialogResult dr = DialogResult.OK;

            if (fileName == string.Empty)
            {
                dr = ofd.ShowDialog();
            }

            if (dr != DialogResult.OK)
            {
                return;
            }

            if (fileName == string.Empty)
            {
                fileName = ofd.FileName;
            }

            IArchiveManager tempManager = SelectArchiveManager(fileName);

            try
            {
                if (tempManager?.Load(fileName) == LoadResult.Success)
                {
                    _archiveManager?.Unload();
                    _archiveManager = tempManager;
                    _fileOpen       = true;
                    _hasChanges     = false;

                    LoadDirectories();
                    UpdateForm();
                }

                Settings.Default.LastDirectory = new FileInfo(fileName).DirectoryName;
                Settings.Default.Save();
            }
            catch (Exception ex)
            {
                if (tempManager != null)
                {
                    MessageBox.Show(this, ex.ToString(), tempManager.Name + " - " + tempManager.Description + " Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show(this, ex.ToString(), "Supported Format Load Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }