コード例 #1
0
ファイル: MPViewer.cs プロジェクト: JanVanMeirvenne/mpviewer
        private void fileToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            m_managementPack.Clear();
            m_openFileDialog = new OpenFileDialog();
            MPList = new List<ManagementPack>();
            ResourceList = new Dictionary<string, Stream>();
            m_openFileDialog.AddExtension = true;
            m_openFileDialog.CheckPathExists = true;
            m_openFileDialog.Multiselect = true;
            m_openFileDialog.DefaultExt = "mp";
            m_openFileDialog.Filter = "MultiSelect (*.mp;*.xml;*.mpb)|*.xml;*.mp;*.mpb|Sealed MP files (*.mp)|*.mp|Sealed MP bundles (*.mpb)|*.mpb|Unsealed MP files (*.xml)|*.xml";

            m_openFileDialog.InitialDirectory = (string)Application.UserAppDataRegistry.GetValue("MPFolder", (object)"C:\\");

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

            Cursor = Cursors.WaitCursor;

            ManagementPackFileStore store = Utilities.GetManagementPackStoreFromPath(m_openFileDialog.FileName);

                foreach (string FileName in m_openFileDialog.FileNames)
                {
                      if (System.IO.Path.GetExtension(FileName).Equals(".mpb", StringComparison.InvariantCultureIgnoreCase))
            {
                ManagementPackBundleReader reader = ManagementPackBundleFactory.CreateBundleReader();
                try {
                m_bundle = reader.Read(FileName, store);
                foreach (ManagementPack MP in m_bundle.ManagementPacks)
                {
                    m_managementPack.Add(MP.Name, MP);
                    IDictionary<string, Stream> streams = m_bundle.GetStreams(MP);
                    foreach (ManagementPackResource resource in MP.GetResources<ManagementPackResource>())
                    {
                        if (!resource.HasNullStream && streams[resource.Name] != null)
                        {
                            ResourceList.Add(resource.FileName, streams[resource.Name]);

                        }

                    }
                }

                } catch {}
                }

             else {
                try
                {
                    ManagementPack MP = new ManagementPack(FileName, store);
                    m_managementPack.Add(MP.Name, MP);
                }
                catch { }

                }

            }
            Mode = MPMode.File;

            MPPath = Path.GetDirectoryName(m_openFileDialog.FileNames[0]);

            ProcessManagementPacks();
        }
コード例 #2
0
ファイル: MPViewer.cs プロジェクト: kevinye1980/mpviewer
        //---------------------------------------------------------------------
        private void loadManagementPackToolStripMenuItem_Click(object sender, EventArgs e)
        {
            m_openFileDialog = new OpenFileDialog();

            m_openFileDialog.AddExtension    = true;
            m_openFileDialog.CheckPathExists = true;
            m_openFileDialog.DefaultExt      = "mp";
            m_openFileDialog.Filter          = "Sealed MP files (*.mp)|*.mp|Sealed MP bundles (*.mpb)|*.mpb|Unsealed MP files (*.xml)|*.xml";

            m_openFileDialog.InitialDirectory = (string)Application.UserAppDataRegistry.GetValue("MPFolder", (object)"C:\\");

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

            Cursor = Cursors.WaitCursor;

            ManagementPackFileStore store = Utilities.GetManagementPackStoreFromPath(m_openFileDialog.FileName);


            if (System.IO.Path.GetExtension(m_openFileDialog.FileName).Equals(".mpb", StringComparison.InvariantCultureIgnoreCase))
            {
                ManagementPackBundleReader reader = ManagementPackBundleFactory.CreateBundleReader();
                m_bundle = reader.Read(m_openFileDialog.FileName, store);

                // 1 at the time is ok
                if (m_bundle.ManagementPacks.Count == 1)
                {
                    m_managementPack = m_bundle.ManagementPacks[0];
                }
                else
                {
                    // multiple MPs contained in this MPB! - can only open one at the time! Need to ask the user which one.
                    MultipleMPSelectionForm MPListForm = new MultipleMPSelectionForm(m_bundle.ManagementPacks);
                    MPListForm.ShowDialog();

                    //selected in the form
                    m_managementPack = MPListForm.ChosenMP;
                }
            }
            else // we are dealing with an MP or XML - the old stuff works as it did for 2007
            {
                m_managementPack = new ManagementPack(m_openFileDialog.FileName, store);
            }


            ClearViews();

            PopulateObjectTypeTree();


            Application.UserAppDataRegistry.SetValue("MPFolder",
                                                     Path.GetDirectoryName(m_openFileDialog.FileName));

            if (m_managementPack.KeyToken != null)
            {
                Text = string.Format("Management Pack Viewer 2012 - {0} {1} {2}",
                                     Utilities.GetBestManagementPackName(m_managementPack),
                                     m_managementPack.Version.ToString(),
                                     m_managementPack.KeyToken.ToString());
            }
            else
            {
                //TODO - Unsealed don't have keytoken!
                Text = string.Format("Management Pack Viewer 2012 - {0} {1} Unsealed",
                                     Utilities.GetBestManagementPackName(m_managementPack),
                                     m_managementPack.Version.ToString());
            }


            //loading dataset is memory expensive and can take time... so moved to a worker thread
            this.m_progressDialog = new ProgressDialog();
            this.m_progressDialog.Show(this);
            this.backgroundWorker.RunWorkerAsync();



            Cursor = Cursors.Default;

            // now that an MP is loaded, enable the menus
            saveToHTMLToolStripMenuItem.Enabled  = true;
            saveToExcelToolStripMenuItem.Enabled = true;

            //this might make sense or not, if we have loaded XML...
            if (System.IO.Path.GetExtension(m_openFileDialog.FileName).Equals(".mpb", StringComparison.InvariantCultureIgnoreCase) ||
                System.IO.Path.GetExtension(m_openFileDialog.FileName).Equals(".mp", StringComparison.InvariantCultureIgnoreCase))
            {
                unsealManagementPackToolStripMenuItem.Enabled = true;
            }
        }
コード例 #3
0
ファイル: MPViewer.cs プロジェクト: jpavleck/mpviewer
        //---------------------------------------------------------------------
        private void loadManagementPackToolStripMenuItem_Click(object sender, EventArgs e)
        {
            m_openFileDialog = new OpenFileDialog();

            m_openFileDialog.AddExtension = true;
            m_openFileDialog.CheckPathExists = true;
            m_openFileDialog.DefaultExt = "mp";
            m_openFileDialog.Filter = "Sealed MP files (*.mp)|*.mp|Sealed MP bundles (*.mpb)|*.mpb|Unsealed MP files (*.xml)|*.xml";

            m_openFileDialog.InitialDirectory = (string)Application.UserAppDataRegistry.GetValue("MPFolder", (object)"C:\\");

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

            Cursor = Cursors.WaitCursor;

            ManagementPackFileStore store = Utilities.GetManagementPackStoreFromPath(m_openFileDialog.FileName);

            if (System.IO.Path.GetExtension(m_openFileDialog.FileName).Equals(".mpb", StringComparison.InvariantCultureIgnoreCase))
            {
                ManagementPackBundleReader reader = ManagementPackBundleFactory.CreateBundleReader();
                m_bundle = reader.Read(m_openFileDialog.FileName, store);

                // 1 at the time is ok
                if (m_bundle.ManagementPacks.Count == 1)
                {
                    m_managementPack = m_bundle.ManagementPacks[0];
                }
                else
                {
                    // multiple MPs contained in this MPB! - can only open one at the time! Need to ask the user which one.
                    MultipleMPSelectionForm MPListForm = new MultipleMPSelectionForm(m_bundle.ManagementPacks);
                    MPListForm.ShowDialog();

                    //selected in the form
                    m_managementPack = MPListForm.ChosenMP;
                }
            }
            else // we are dealing with an MP or XML - the old stuff works as it did for 2007
            {
                m_managementPack = new ManagementPack(m_openFileDialog.FileName, store);
            }

            ClearViews();

            PopulateObjectTypeTree();

            Application.UserAppDataRegistry.SetValue("MPFolder",
                                                        Path.GetDirectoryName(m_openFileDialog.FileName));

            if (m_managementPack.KeyToken != null)
            {
                Text = string.Format("Management Pack Viewer 2012 - {0} {1} {2}",
                                        Utilities.GetBestManagementPackName(m_managementPack),
                                        m_managementPack.Version.ToString(),
                                        m_managementPack.KeyToken.ToString());
            }
            else
            {
                //TODO - Unsealed don't have keytoken!
                Text = string.Format("Management Pack Viewer 2012 - {0} {1} Unsealed",
                                        Utilities.GetBestManagementPackName(m_managementPack),
                                        m_managementPack.Version.ToString());
            }

            //loading dataset is memory expensive and can take time... so moved to a worker thread
            this.m_progressDialog = new ProgressDialog();
            this.m_progressDialog.Show(this);
            this.backgroundWorker.RunWorkerAsync();

            Cursor = Cursors.Default;

            // now that an MP is loaded, enable the menus
            saveToHTMLToolStripMenuItem.Enabled = true;
            saveToExcelToolStripMenuItem.Enabled = true;

            //this might make sense or not, if we have loaded XML...
            if (System.IO.Path.GetExtension(m_openFileDialog.FileName).Equals(".mpb", StringComparison.InvariantCultureIgnoreCase) ||
                System.IO.Path.GetExtension(m_openFileDialog.FileName).Equals(".mp", StringComparison.InvariantCultureIgnoreCase))
            {
                unsealManagementPackToolStripMenuItem.Enabled = true;
            }
        }