From 701a36ddfb57de5bec7c22f68bb0b2c5297bdf7a Mon Sep 17 00:00:00 2001 From: ItzTacos <47322543+ItzTacosOfficial@users.noreply.github.com> Date: Wed, 19 Apr 2023 16:02:44 +0200 Subject: [PATCH] Added plugin install button --- NSMBe5/Plugin/PluginSelector.Designer.cs | 212 ++++++++++++----------- NSMBe5/Plugin/PluginSelector.cs | 52 +++++- 2 files changed, 160 insertions(+), 104 deletions(-) diff --git a/NSMBe5/Plugin/PluginSelector.Designer.cs b/NSMBe5/Plugin/PluginSelector.Designer.cs index 70ed721..d884f73 100644 --- a/NSMBe5/Plugin/PluginSelector.Designer.cs +++ b/NSMBe5/Plugin/PluginSelector.Designer.cs @@ -28,108 +28,125 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - this.pluginGridView = new System.Windows.Forms.DataGridView(); - this.PluginGridID = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.PluginGridName = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.PluginGridPriority = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.PluginGridEnabled = new System.Windows.Forms.DataGridViewCheckBoxColumn(); - this.saveBtn = new System.Windows.Forms.Button(); - this.romPlugsCb = new System.Windows.Forms.CheckBox(); - ((System.ComponentModel.ISupportInitialize)(this.pluginGridView)).BeginInit(); - this.SuspendLayout(); - // - // pluginGridView - // - this.pluginGridView.AllowUserToAddRows = false; - this.pluginGridView.AllowUserToDeleteRows = false; - this.pluginGridView.AllowUserToResizeRows = false; - this.pluginGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + this.pluginGridView = new System.Windows.Forms.DataGridView(); + this.PluginGridID = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.PluginGridName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.PluginGridPriority = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.PluginGridEnabled = new System.Windows.Forms.DataGridViewCheckBoxColumn(); + this.saveBtn = new System.Windows.Forms.Button(); + this.romPlugsCb = new System.Windows.Forms.CheckBox(); + this.installButton = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.pluginGridView)).BeginInit(); + this.SuspendLayout(); + // + // pluginGridView + // + this.pluginGridView.AllowUserToAddRows = false; + this.pluginGridView.AllowUserToDeleteRows = false; + this.pluginGridView.AllowUserToResizeRows = false; + this.pluginGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.pluginGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.pluginGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.pluginGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.pluginGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.PluginGridID, this.PluginGridName, this.PluginGridPriority, this.PluginGridEnabled}); - this.pluginGridView.Location = new System.Drawing.Point(12, 12); - this.pluginGridView.Name = "pluginGridView"; - this.pluginGridView.RowHeadersWidth = 51; - this.pluginGridView.RowTemplate.Height = 24; - this.pluginGridView.Size = new System.Drawing.Size(347, 293); - this.pluginGridView.TabIndex = 0; - this.pluginGridView.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.pluginGridView_CellEndEdit); - // - // PluginGridID - // - this.PluginGridID.HeaderText = "ID"; - this.PluginGridID.MinimumWidth = 6; - this.PluginGridID.Name = "PluginGridID"; - this.PluginGridID.ReadOnly = true; - this.PluginGridID.Visible = false; - this.PluginGridID.Width = 125; - // - // PluginGridName - // - this.PluginGridName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.PluginGridName.HeaderText = "Name"; - this.PluginGridName.MinimumWidth = 6; - this.PluginGridName.Name = "PluginGridName"; - this.PluginGridName.ReadOnly = true; - // - // PluginGridPriority - // - this.PluginGridPriority.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.ColumnHeader; - this.PluginGridPriority.HeaderText = "Priority"; - this.PluginGridPriority.MinimumWidth = 6; - this.PluginGridPriority.Name = "PluginGridPriority"; - this.PluginGridPriority.Width = 77; - // - // PluginGridEnabled - // - this.PluginGridEnabled.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.ColumnHeader; - this.PluginGridEnabled.HeaderText = "Enabled"; - this.PluginGridEnabled.MinimumWidth = 6; - this.PluginGridEnabled.Name = "PluginGridEnabled"; - this.PluginGridEnabled.Width = 64; - // - // saveBtn - // - this.saveBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.saveBtn.Location = new System.Drawing.Point(227, 315); - this.saveBtn.Name = "saveBtn"; - this.saveBtn.Size = new System.Drawing.Size(132, 37); - this.saveBtn.TabIndex = 1; - this.saveBtn.Text = "Save"; - this.saveBtn.UseVisualStyleBackColor = true; - this.saveBtn.Click += new System.EventHandler(this.saveBtn_Click); - // - // romPlugsCb - // - this.romPlugsCb.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.romPlugsCb.AutoSize = true; - this.romPlugsCb.Location = new System.Drawing.Point(12, 324); - this.romPlugsCb.Name = "romPlugsCb"; - this.romPlugsCb.Size = new System.Drawing.Size(152, 20); - this.romPlugsCb.TabIndex = 2; - this.romPlugsCb.Text = "Enable ROM plugins"; - this.romPlugsCb.UseVisualStyleBackColor = true; - // - // PluginSelector - // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(371, 364); - this.Controls.Add(this.romPlugsCb); - this.Controls.Add(this.saveBtn); - this.Controls.Add(this.pluginGridView); - this.Name = "PluginSelector"; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; - this.Text = "Plugin Selector"; - this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.PluginSelector_FormClosed); - ((System.ComponentModel.ISupportInitialize)(this.pluginGridView)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); + this.pluginGridView.Location = new System.Drawing.Point(9, 10); + this.pluginGridView.Margin = new System.Windows.Forms.Padding(2); + this.pluginGridView.Name = "pluginGridView"; + this.pluginGridView.RowHeadersWidth = 51; + this.pluginGridView.RowTemplate.Height = 24; + this.pluginGridView.Size = new System.Drawing.Size(260, 238); + this.pluginGridView.TabIndex = 0; + this.pluginGridView.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.pluginGridView_CellEndEdit); + // + // PluginGridID + // + this.PluginGridID.HeaderText = "ID"; + this.PluginGridID.MinimumWidth = 6; + this.PluginGridID.Name = "PluginGridID"; + this.PluginGridID.ReadOnly = true; + this.PluginGridID.Visible = false; + this.PluginGridID.Width = 125; + // + // PluginGridName + // + this.PluginGridName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.PluginGridName.HeaderText = "Name"; + this.PluginGridName.MinimumWidth = 6; + this.PluginGridName.Name = "PluginGridName"; + this.PluginGridName.ReadOnly = true; + // + // PluginGridPriority + // + this.PluginGridPriority.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.ColumnHeader; + this.PluginGridPriority.HeaderText = "Priority"; + this.PluginGridPriority.MinimumWidth = 6; + this.PluginGridPriority.Name = "PluginGridPriority"; + this.PluginGridPriority.Width = 63; + // + // PluginGridEnabled + // + this.PluginGridEnabled.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.ColumnHeader; + this.PluginGridEnabled.HeaderText = "Enabled"; + this.PluginGridEnabled.MinimumWidth = 6; + this.PluginGridEnabled.Name = "PluginGridEnabled"; + this.PluginGridEnabled.Width = 52; + // + // saveBtn + // + this.saveBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.saveBtn.Location = new System.Drawing.Point(207, 256); + this.saveBtn.Margin = new System.Windows.Forms.Padding(2); + this.saveBtn.Name = "saveBtn"; + this.saveBtn.Size = new System.Drawing.Size(62, 30); + this.saveBtn.TabIndex = 1; + this.saveBtn.Text = "Save"; + this.saveBtn.UseVisualStyleBackColor = true; + this.saveBtn.Click += new System.EventHandler(this.saveBtn_Click); + // + // romPlugsCb + // + this.romPlugsCb.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.romPlugsCb.AutoSize = true; + this.romPlugsCb.Location = new System.Drawing.Point(9, 262); + this.romPlugsCb.Margin = new System.Windows.Forms.Padding(2); + this.romPlugsCb.Name = "romPlugsCb"; + this.romPlugsCb.Size = new System.Drawing.Size(123, 17); + this.romPlugsCb.TabIndex = 2; + this.romPlugsCb.Text = "Enable ROM plugins"; + this.romPlugsCb.UseVisualStyleBackColor = true; + // + // installButton + // + this.installButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.installButton.Location = new System.Drawing.Point(138, 256); + this.installButton.Name = "installButton"; + this.installButton.Size = new System.Drawing.Size(64, 30); + this.installButton.TabIndex = 3; + this.installButton.Text = "Install"; + this.installButton.UseVisualStyleBackColor = true; + this.installButton.Click += new System.EventHandler(this.installButton_Click); + // + // PluginSelector + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(278, 296); + this.Controls.Add(this.installButton); + this.Controls.Add(this.romPlugsCb); + this.Controls.Add(this.saveBtn); + this.Controls.Add(this.pluginGridView); + this.Margin = new System.Windows.Forms.Padding(2); + this.Name = "PluginSelector"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Plugin Selector"; + this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.PluginSelector_FormClosed); + ((System.ComponentModel.ISupportInitialize)(this.pluginGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); } @@ -142,5 +159,6 @@ private void InitializeComponent() private System.Windows.Forms.DataGridViewTextBoxColumn PluginGridName; private System.Windows.Forms.DataGridViewTextBoxColumn PluginGridPriority; private System.Windows.Forms.DataGridViewCheckBoxColumn PluginGridEnabled; - } + private System.Windows.Forms.Button installButton; + } } \ No newline at end of file diff --git a/NSMBe5/Plugin/PluginSelector.cs b/NSMBe5/Plugin/PluginSelector.cs index bd8c8c1..468f55e 100644 --- a/NSMBe5/Plugin/PluginSelector.cs +++ b/NSMBe5/Plugin/PluginSelector.cs @@ -1,4 +1,5 @@ -using System; +using NSMBe5.DSFileSystem; +using System; using System.Windows.Forms; namespace NSMBe5.Plugin @@ -14,12 +15,7 @@ public PluginSelector() romPlugsCb.Checked = Properties.Settings.Default.EnableRomPlugin; - PluginInfo[] infos = PluginManager.GetAvailablePlugins(); - - foreach (PluginInfo info in infos) - { - pluginGridView.Rows.Add(info.id, info.name, info.priority.ToString(), info.enabled); - } + LoadGridViewElements(); Current = this; } @@ -51,6 +47,36 @@ private void saveBtn_Click(object sender, EventArgs e) Close(); } + private void installButton_Click(object sender, EventArgs e) + { + OpenFileDialog dialog = new OpenFileDialog(); + + dialog.Filter = "NSMBe Plugins (*.dll)|*.dll|All Files (*.*)|*.*"; + dialog.FilterIndex = 1; + dialog.Multiselect = true; + + DialogResult result = dialog.ShowDialog(this); + + if (result != DialogResult.OK) + return; + + string pluginPath = PluginManager.GetPluginDirectory(); + + if (!System.IO.Directory.Exists(pluginPath)) + System.IO.Directory.CreateDirectory(pluginPath); + + foreach (string path in dialog.FileNames) + { + string dest = System.IO.Path.Combine(pluginPath, System.IO.Path.GetFileName(path)); + + System.IO.File.Copy(path, dest); + + PluginManager.LoadPlugin(dest); + } + + LoadGridViewElements(); + } + private void pluginGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 2) @@ -68,6 +94,18 @@ private void PluginSelector_FormClosed(object sender, FormClosedEventArgs e) Current = null; } + private void LoadGridViewElements() + { + pluginGridView.Rows.Clear(); + + PluginInfo[] infos = PluginManager.GetAvailablePlugins(); + + foreach (PluginInfo info in infos) + { + pluginGridView.Rows.Add(info.id, info.name, info.priority.ToString(), info.enabled); + } + } + public static void Open() { if (Current != null)