From d00f2a35dfd20a3ca74621ddfa7083ac5d695a80 Mon Sep 17 00:00:00 2001 From: N00MKRAD Date: Sat, 19 Sep 2020 22:40:33 +0200 Subject: [PATCH] model tree wip --- Code/Cupscale/EsrganData.cs | 3 + Code/Cupscale/MainForm.Designer.cs | 19 ++++ Code/Cupscale/MainForm.cs | 5 + Code/Forms/ModelSelectForm.Designer.cs | 135 +++++++++++++++++++++++++ Code/Forms/ModelSelectForm.cs | 58 +++++++++++ Code/Forms/ModelSelectForm.resx | 120 ++++++++++++++++++++++ Code/Forms/SettingsForm.cs | 2 +- Code/UI/ExtensionMethods.cs | 6 ++ Code/UI/UIHelpers.cs | 4 + 9 files changed, 351 insertions(+), 1 deletion(-) create mode 100644 Code/Forms/ModelSelectForm.Designer.cs create mode 100644 Code/Forms/ModelSelectForm.cs create mode 100644 Code/Forms/ModelSelectForm.resx diff --git a/Code/Cupscale/EsrganData.cs b/Code/Cupscale/EsrganData.cs index bbda457..bf8b284 100644 --- a/Code/Cupscale/EsrganData.cs +++ b/Code/Cupscale/EsrganData.cs @@ -7,6 +7,7 @@ namespace Cupscale internal class EsrganData { public static List models = new List(); + public static List modelsFullPath = new List(); public static void CheckModelDir() { @@ -30,6 +31,7 @@ public static void ReloadModelList() return; } models.Clear(); + modelsFullPath.Clear(); string[] files = Directory.GetFiles(text); string[] array = files; foreach (string path in array) @@ -38,6 +40,7 @@ public static void ReloadModelList() if (fileName.EndsWith(".pth")) { models.Add(fileName.Replace(".pth", "")); + modelsFullPath.Add(path); } } } diff --git a/Code/Cupscale/MainForm.Designer.cs b/Code/Cupscale/MainForm.Designer.cs index 7cd31a4..39e5d7c 100644 --- a/Code/Cupscale/MainForm.Designer.cs +++ b/Code/Cupscale/MainForm.Designer.cs @@ -57,6 +57,7 @@ private void InitializeComponent() this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel(); this.panel5 = new System.Windows.Forms.Panel(); + this.model1TreeBtn = new System.Windows.Forms.Button(); this.interpConfigureBtn = new System.Windows.Forms.Button(); this.label4 = new System.Windows.Forms.Label(); this.chainRbtn = new System.Windows.Forms.RadioButton(); @@ -217,6 +218,7 @@ private void InitializeComponent() // panel5 // this.panel5.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.panel5.Controls.Add(this.model1TreeBtn); this.panel5.Controls.Add(this.interpConfigureBtn); this.panel5.Controls.Add(this.label4); this.panel5.Controls.Add(this.chainRbtn); @@ -233,6 +235,22 @@ private void InitializeComponent() this.panel5.Size = new System.Drawing.Size(338, 311); this.panel5.TabIndex = 1; // + // model1TreeBtn + // + this.model1TreeBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.model1TreeBtn.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); + this.model1TreeBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.model1TreeBtn.ForeColor = System.Drawing.Color.White; + this.model1TreeBtn.Location = new System.Drawing.Point(198, 198); + this.model1TreeBtn.Name = "model1TreeBtn"; + this.model1TreeBtn.Size = new System.Drawing.Size(129, 23); + this.model1TreeBtn.TabIndex = 17; + this.model1TreeBtn.Text = "Tree"; + this.model1TreeBtn.TextAlign = System.Drawing.ContentAlignment.TopCenter; + this.model1TreeBtn.UseVisualStyleBackColor = false; + this.model1TreeBtn.Click += new System.EventHandler(this.model1TreeBtn_Click); + // // interpConfigureBtn // this.interpConfigureBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) @@ -1061,5 +1079,6 @@ private void InitializeComponent() private TextBox batchFileList; private TableLayoutPanel tableLayoutPanel7; private HTAlt.WinForms.HTButton settingsBtn; + private Button model1TreeBtn; } } diff --git a/Code/Cupscale/MainForm.cs b/Code/Cupscale/MainForm.cs index 917c4c9..fc5a2e7 100644 --- a/Code/Cupscale/MainForm.cs +++ b/Code/Cupscale/MainForm.cs @@ -245,5 +245,10 @@ private void copyCompToClipboardBtn_Click(object sender, EventArgs e) if (prevClipboardTypeCombox.SelectedIndex == 0) ClipboardPreview.CopyToClipboardSideBySide(); if (prevClipboardTypeCombox.SelectedIndex == 1) ClipboardPreview.CopyToClipboardSlider(); } + + private void model1TreeBtn_Click(object sender, EventArgs e) + { + new ModelSelectForm(); + } } } diff --git a/Code/Forms/ModelSelectForm.Designer.cs b/Code/Forms/ModelSelectForm.Designer.cs new file mode 100644 index 0000000..13e8506 --- /dev/null +++ b/Code/Forms/ModelSelectForm.Designer.cs @@ -0,0 +1,135 @@ +namespace Cupscale.Forms +{ + partial class ModelSelectForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.modelTree = new System.Windows.Forms.TreeView(); + this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); + this.panel1 = new System.Windows.Forms.Panel(); + this.confirmBtn = new HTAlt.WinForms.HTButton(); + this.cancelBtn = new HTAlt.WinForms.HTButton(); + this.tableLayoutPanel1.SuspendLayout(); + this.panel1.SuspendLayout(); + this.SuspendLayout(); + // + // modelTree + // + this.modelTree.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48))))); + this.modelTree.Dock = System.Windows.Forms.DockStyle.Fill; + this.modelTree.ForeColor = System.Drawing.Color.White; + this.modelTree.Location = new System.Drawing.Point(3, 3); + this.modelTree.Name = "modelTree"; + this.modelTree.Size = new System.Drawing.Size(714, 664); + this.modelTree.TabIndex = 0; + // + // tableLayoutPanel1 + // + this.tableLayoutPanel1.ColumnCount = 1; + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel1.Controls.Add(this.modelTree, 0, 0); + this.tableLayoutPanel1.Controls.Add(this.panel1, 0, 1); + this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; + this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); + this.tableLayoutPanel1.Name = "tableLayoutPanel1"; + this.tableLayoutPanel1.RowCount = 2; + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 50F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel1.Size = new System.Drawing.Size(720, 720); + this.tableLayoutPanel1.TabIndex = 1; + // + // panel1 + // + this.panel1.Controls.Add(this.cancelBtn); + this.panel1.Controls.Add(this.confirmBtn); + this.panel1.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel1.Location = new System.Drawing.Point(3, 673); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(714, 44); + this.panel1.TabIndex = 1; + // + // confirmBtn + // + this.confirmBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.confirmBtn.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); + this.confirmBtn.FlatAppearance.BorderSize = 0; + this.confirmBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.confirmBtn.ForeColor = System.Drawing.Color.White; + this.confirmBtn.Location = new System.Drawing.Point(186, 6); + this.confirmBtn.Margin = new System.Windows.Forms.Padding(180, 6, 6, 6); + this.confirmBtn.Name = "confirmBtn"; + this.confirmBtn.Size = new System.Drawing.Size(162, 32); + this.confirmBtn.TabIndex = 12; + this.confirmBtn.Text = "Select Model"; + this.confirmBtn.UseVisualStyleBackColor = false; + this.confirmBtn.Click += new System.EventHandler(this.confirmBtn_Click); + // + // cancelBtn + // + this.cancelBtn.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.cancelBtn.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); + this.cancelBtn.FlatAppearance.BorderSize = 0; + this.cancelBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.cancelBtn.ForeColor = System.Drawing.Color.White; + this.cancelBtn.Location = new System.Drawing.Point(366, 6); + this.cancelBtn.Margin = new System.Windows.Forms.Padding(6, 6, 180, 6); + this.cancelBtn.Name = "cancelBtn"; + this.cancelBtn.Size = new System.Drawing.Size(162, 32); + this.cancelBtn.TabIndex = 13; + this.cancelBtn.Text = "Cancel"; + this.cancelBtn.UseVisualStyleBackColor = false; + this.cancelBtn.Click += new System.EventHandler(this.cancelBtn_Click); + // + // ModelSelectForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(32)))), ((int)(((byte)(32)))), ((int)(((byte)(32))))); + this.ClientSize = new System.Drawing.Size(720, 720); + this.Controls.Add(this.tableLayoutPanel1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; + this.Name = "ModelSelectForm"; + this.Text = "ModelSelectForm"; + this.Load += new System.EventHandler(this.ModelSelectForm_Load); + this.tableLayoutPanel1.ResumeLayout(false); + this.panel1.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.TreeView modelTree; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; + private System.Windows.Forms.Panel panel1; + private HTAlt.WinForms.HTButton cancelBtn; + private HTAlt.WinForms.HTButton confirmBtn; + } +} \ No newline at end of file diff --git a/Code/Forms/ModelSelectForm.cs b/Code/Forms/ModelSelectForm.cs new file mode 100644 index 0000000..340e6d2 --- /dev/null +++ b/Code/Forms/ModelSelectForm.cs @@ -0,0 +1,58 @@ +using Cupscale.IO; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Cupscale.Forms +{ + public partial class ModelSelectForm : Form + { + public string selectedModel; + + public ModelSelectForm() + { + InitializeComponent(); + Show(); + CenterToScreen(); + } + + private void ModelSelectForm_Load(object sender, EventArgs e) + { + DirectoryInfo modelsDir = new DirectoryInfo(Config.Get("modelPath")); + BuildTree(modelsDir, modelTree.Nodes); + modelTree.ExpandAll(); + } + + private void BuildTree(DirectoryInfo directoryInfo, TreeNodeCollection addInMe) + { + TreeNode curNode = addInMe.Add(directoryInfo.Name); + + foreach (FileInfo file in directoryInfo.GetFiles()) + { + curNode.Nodes.Add(file.FullName, Path.ChangeExtension(file.Name, null)); + } + foreach (DirectoryInfo subdir in directoryInfo.GetDirectories()) + { + if(subdir.GetFiles().Length > 0) + BuildTree(subdir, curNode.Nodes); + } + } + + private void confirmBtn_Click(object sender, EventArgs e) + { + selectedModel = modelTree.SelectedNode.Text; + } + + private void cancelBtn_Click(object sender, EventArgs e) + { + Close(); + } + } +} diff --git a/Code/Forms/ModelSelectForm.resx b/Code/Forms/ModelSelectForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Code/Forms/ModelSelectForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Code/Forms/SettingsForm.cs b/Code/Forms/SettingsForm.cs index 89c5cef..3465a6d 100644 --- a/Code/Forms/SettingsForm.cs +++ b/Code/Forms/SettingsForm.cs @@ -17,7 +17,7 @@ public SettingsForm() { InitializeComponent(); Show(); - CenterToParent(); + CenterToScreen(); } private void SettingsForm_Load(object sender, EventArgs e) diff --git a/Code/UI/ExtensionMethods.cs b/Code/UI/ExtensionMethods.cs index c80518c..7da5fd2 100644 --- a/Code/UI/ExtensionMethods.cs +++ b/Code/UI/ExtensionMethods.cs @@ -1,3 +1,4 @@ +using System.IO; using System.Text.RegularExpressions; using System.Windows.Forms; @@ -20,5 +21,10 @@ public static int GetInt(this ComboBox combobox) { return int.Parse(combobox.Text.TrimNumbers()); } + + public static string GetParentDir (this string path) + { + return Directory.GetParent(path).FullName; + } } } diff --git a/Code/UI/UIHelpers.cs b/Code/UI/UIHelpers.cs index f43c9d9..15b3afa 100644 --- a/Code/UI/UIHelpers.cs +++ b/Code/UI/UIHelpers.cs @@ -1,6 +1,10 @@ using System; +using System.Collections.Generic; using System.Drawing; +using System.IO; +using System.Linq; using System.Windows.Forms; +using Cupscale.UI; using Cyotek.Windows.Forms; namespace Cupscale