From 52d5bbdf420529206313424894167a276e5ecb3e Mon Sep 17 00:00:00 2001 From: NotImplementedLife Date: Fri, 28 Jul 2023 19:02:47 +0300 Subject: [PATCH] fixed remove keep data glitch --- MainForm.Designer.cs | 761 +++++++++++++++++++++++++++------------ MainForm.Exports.cs | 202 +++++++++++ MainForm.Properties.cs | 25 ++ MainForm.RequestFiles.cs | 113 ++++++ MainForm.SoundCreate.cs | 314 ++++++++++++++++ MainForm.cs | 684 ++--------------------------------- Utils/ExceptionGuard.cs | 29 ++ 7 files changed, 1253 insertions(+), 875 deletions(-) create mode 100644 MainForm.Exports.cs create mode 100644 MainForm.Properties.cs create mode 100644 MainForm.RequestFiles.cs create mode 100644 MainForm.SoundCreate.cs create mode 100644 Utils/ExceptionGuard.cs diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index b0b5483..2df2264 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -45,16 +45,30 @@ this.MusicAttributePathSelector = new TaikoSoundEditor.PathSelector(); this.label8 = new System.Windows.Forms.Label(); this.tabPage2 = new System.Windows.Forms.TabPage(); - this.RemoveSongButton = new System.Windows.Forms.Button(); - this.DatatableSpaces = new System.Windows.Forms.CheckBox(); - this.ExportOpenOnFinished = new System.Windows.Forms.CheckBox(); - this.ExportAllButton = new System.Windows.Forms.Button(); - this.ExportSoundBanksButton = new System.Windows.Forms.Button(); - this.ExportSoundFoldersButton = new System.Windows.Forms.Button(); - this.ExportDatatableButton = new System.Windows.Forms.Button(); - this.CreateButton = new System.Windows.Forms.Button(); - this.groupBox8 = new System.Windows.Forms.GroupBox(); - this.NewSoundsBox = new System.Windows.Forms.ListBox(); + this.SoundViewTab = new System.Windows.Forms.TabControl(); + this.SoundViewerSimple = new System.Windows.Forms.TabPage(); + this.groupBox11 = new System.Windows.Forms.GroupBox(); + this.label19 = new System.Windows.Forms.Label(); + this.SimpleStarUraBox = new System.Windows.Forms.NumericUpDown(); + this.label17 = new System.Windows.Forms.Label(); + this.SimpleStarManiaBox = new System.Windows.Forms.NumericUpDown(); + this.label18 = new System.Windows.Forms.Label(); + this.SimpleStarHardBox = new System.Windows.Forms.NumericUpDown(); + this.label16 = new System.Windows.Forms.Label(); + this.SimpleStarNormalBox = new System.Windows.Forms.NumericUpDown(); + this.label15 = new System.Windows.Forms.Label(); + this.SimpleStarEasyBox = new System.Windows.Forms.NumericUpDown(); + this.label14 = new System.Windows.Forms.Label(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.label13 = new System.Windows.Forms.Label(); + this.SimpleGenreBox = new System.Windows.Forms.ComboBox(); + this.label12 = new System.Windows.Forms.Label(); + this.label11 = new System.Windows.Forms.Label(); + this.SimpleDetailBox = new System.Windows.Forms.TextBox(); + this.SimpleSubtitleBox = new System.Windows.Forms.TextBox(); + this.SimpleTitleBox = new System.Windows.Forms.TextBox(); + this.label4 = new System.Windows.Forms.Label(); + this.SoundViewerExpert = new System.Windows.Forms.TabPage(); this.groupBox4 = new System.Windows.Forms.GroupBox(); this.EditorTable = new System.Windows.Forms.TableLayoutPanel(); this.panel3 = new System.Windows.Forms.Panel(); @@ -71,11 +85,24 @@ this.WordSubGrid = new System.Windows.Forms.PropertyGrid(); this.WordsGB = new System.Windows.Forms.GroupBox(); this.WordsGrid = new System.Windows.Forms.PropertyGrid(); + this.MusicOrderTab = new System.Windows.Forms.TabPage(); + this.RemoveSongButton = new System.Windows.Forms.Button(); + this.DatatableSpaces = new System.Windows.Forms.CheckBox(); + this.ExportOpenOnFinished = new System.Windows.Forms.CheckBox(); + this.ExportAllButton = new System.Windows.Forms.Button(); + this.ExportSoundBanksButton = new System.Windows.Forms.Button(); + this.ExportSoundFoldersButton = new System.Windows.Forms.Button(); + this.ExportDatatableButton = new System.Windows.Forms.Button(); + this.CreateButton = new System.Windows.Forms.Button(); + this.groupBox8 = new System.Windows.Forms.GroupBox(); + this.NewSoundsBox = new System.Windows.Forms.ListBox(); this.groupBox3 = new System.Windows.Forms.GroupBox(); this.LoadedMusicBox = new System.Windows.Forms.ListBox(); this.tabPage3 = new System.Windows.Forms.TabPage(); this.panel4 = new System.Windows.Forms.Panel(); this.groupBox10 = new System.Windows.Forms.GroupBox(); + this.label3 = new System.Windows.Forms.Label(); + this.SilenceBox = new System.Windows.Forms.NumericUpDown(); this.groupBox9 = new System.Windows.Forms.GroupBox(); this.TjaEncShiftJIS = new System.Windows.Forms.RadioButton(); this.TjaEncUTF8 = new System.Windows.Forms.RadioButton(); @@ -90,15 +117,22 @@ this.TJASelector = new TaikoSoundEditor.PathSelector(); this.AudioFileSelector = new TaikoSoundEditor.PathSelector(); this.label10 = new System.Windows.Forms.Label(); - this.SilenceBox = new System.Windows.Forms.NumericUpDown(); - this.label3 = new System.Windows.Forms.Label(); + this.LocateInMusicOrderButton = new System.Windows.Forms.Button(); this.TabControl.SuspendLayout(); this.tabPage1.SuspendLayout(); this.panel1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.groupBox1.SuspendLayout(); this.tabPage2.SuspendLayout(); - this.groupBox8.SuspendLayout(); + this.SoundViewTab.SuspendLayout(); + this.SoundViewerSimple.SuspendLayout(); + this.groupBox11.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.SimpleStarUraBox)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.SimpleStarManiaBox)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.SimpleStarHardBox)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.SimpleStarNormalBox)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.SimpleStarEasyBox)).BeginInit(); + this.SoundViewerExpert.SuspendLayout(); this.groupBox4.SuspendLayout(); this.EditorTable.SuspendLayout(); this.panel3.SuspendLayout(); @@ -109,12 +143,13 @@ this.WordDetailGB.SuspendLayout(); this.WordSubGB.SuspendLayout(); this.WordsGB.SuspendLayout(); + this.groupBox8.SuspendLayout(); this.groupBox3.SuspendLayout(); this.tabPage3.SuspendLayout(); this.panel4.SuspendLayout(); this.groupBox10.SuspendLayout(); - this.groupBox9.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.SilenceBox)).BeginInit(); + this.groupBox9.SuspendLayout(); this.SuspendLayout(); // // TabControl @@ -309,6 +344,8 @@ // // tabPage2 // + this.tabPage2.BackColor = System.Drawing.Color.White; + this.tabPage2.Controls.Add(this.SoundViewTab); this.tabPage2.Controls.Add(this.RemoveSongButton); this.tabPage2.Controls.Add(this.DatatableSpaces); this.tabPage2.Controls.Add(this.ExportOpenOnFinished); @@ -318,7 +355,6 @@ this.tabPage2.Controls.Add(this.ExportDatatableButton); this.tabPage2.Controls.Add(this.CreateButton); this.tabPage2.Controls.Add(this.groupBox8); - this.tabPage2.Controls.Add(this.groupBox4); this.tabPage2.Controls.Add(this.groupBox3); this.tabPage2.Location = new System.Drawing.Point(4, 5); this.tabPage2.Name = "tabPage2"; @@ -326,7 +362,421 @@ this.tabPage2.Size = new System.Drawing.Size(676, 452); this.tabPage2.TabIndex = 1; this.tabPage2.Text = "tabPage2"; - this.tabPage2.UseVisualStyleBackColor = true; + // + // SoundViewTab + // + this.SoundViewTab.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.SoundViewTab.Controls.Add(this.SoundViewerSimple); + this.SoundViewTab.Controls.Add(this.SoundViewerExpert); + this.SoundViewTab.Controls.Add(this.MusicOrderTab); + this.SoundViewTab.Location = new System.Drawing.Point(139, 7); + this.SoundViewTab.Name = "SoundViewTab"; + this.SoundViewTab.SelectedIndex = 0; + this.SoundViewTab.Size = new System.Drawing.Size(529, 324); + this.SoundViewTab.TabIndex = 13; + // + // SoundViewerSimple + // + this.SoundViewerSimple.Controls.Add(this.LocateInMusicOrderButton); + this.SoundViewerSimple.Controls.Add(this.groupBox11); + this.SoundViewerSimple.Controls.Add(this.label14); + this.SoundViewerSimple.Controls.Add(this.textBox1); + this.SoundViewerSimple.Controls.Add(this.label13); + this.SoundViewerSimple.Controls.Add(this.SimpleGenreBox); + this.SoundViewerSimple.Controls.Add(this.label12); + this.SoundViewerSimple.Controls.Add(this.label11); + this.SoundViewerSimple.Controls.Add(this.SimpleDetailBox); + this.SoundViewerSimple.Controls.Add(this.SimpleSubtitleBox); + this.SoundViewerSimple.Controls.Add(this.SimpleTitleBox); + this.SoundViewerSimple.Controls.Add(this.label4); + this.SoundViewerSimple.Location = new System.Drawing.Point(4, 24); + this.SoundViewerSimple.Name = "SoundViewerSimple"; + this.SoundViewerSimple.Padding = new System.Windows.Forms.Padding(3); + this.SoundViewerSimple.Size = new System.Drawing.Size(521, 296); + this.SoundViewerSimple.TabIndex = 1; + this.SoundViewerSimple.Text = "Simple View"; + this.SoundViewerSimple.UseVisualStyleBackColor = true; + // + // groupBox11 + // + this.groupBox11.Controls.Add(this.label19); + this.groupBox11.Controls.Add(this.SimpleStarUraBox); + this.groupBox11.Controls.Add(this.label17); + this.groupBox11.Controls.Add(this.SimpleStarManiaBox); + this.groupBox11.Controls.Add(this.label18); + this.groupBox11.Controls.Add(this.SimpleStarHardBox); + this.groupBox11.Controls.Add(this.label16); + this.groupBox11.Controls.Add(this.SimpleStarNormalBox); + this.groupBox11.Controls.Add(this.label15); + this.groupBox11.Controls.Add(this.SimpleStarEasyBox); + this.groupBox11.Location = new System.Drawing.Point(232, 6); + this.groupBox11.Name = "groupBox11"; + this.groupBox11.Size = new System.Drawing.Size(243, 110); + this.groupBox11.TabIndex = 10; + this.groupBox11.TabStop = false; + this.groupBox11.Text = "Stars"; + // + // label19 + // + this.label19.AutoSize = true; + this.label19.Location = new System.Drawing.Point(6, 82); + this.label19.Name = "label19"; + this.label19.Size = new System.Drawing.Size(25, 15); + this.label19.TabIndex = 9; + this.label19.Text = "Ura"; + // + // SimpleStarUraBox + // + this.SimpleStarUraBox.Location = new System.Drawing.Point(42, 80); + this.SimpleStarUraBox.Name = "SimpleStarUraBox"; + this.SimpleStarUraBox.Size = new System.Drawing.Size(64, 23); + this.SimpleStarUraBox.TabIndex = 8; + // + // label17 + // + this.label17.AutoSize = true; + this.label17.Location = new System.Drawing.Point(112, 53); + this.label17.Name = "label17"; + this.label17.Size = new System.Drawing.Size(40, 15); + this.label17.TabIndex = 7; + this.label17.Text = "Mania"; + // + // SimpleStarManiaBox + // + this.SimpleStarManiaBox.Location = new System.Drawing.Point(165, 51); + this.SimpleStarManiaBox.Name = "SimpleStarManiaBox"; + this.SimpleStarManiaBox.Size = new System.Drawing.Size(64, 23); + this.SimpleStarManiaBox.TabIndex = 6; + // + // label18 + // + this.label18.AutoSize = true; + this.label18.Location = new System.Drawing.Point(6, 53); + this.label18.Name = "label18"; + this.label18.Size = new System.Drawing.Size(33, 15); + this.label18.TabIndex = 5; + this.label18.Text = "Hard"; + // + // SimpleStarHardBox + // + this.SimpleStarHardBox.Location = new System.Drawing.Point(42, 51); + this.SimpleStarHardBox.Name = "SimpleStarHardBox"; + this.SimpleStarHardBox.Size = new System.Drawing.Size(64, 23); + this.SimpleStarHardBox.TabIndex = 4; + // + // label16 + // + this.label16.AutoSize = true; + this.label16.Location = new System.Drawing.Point(112, 24); + this.label16.Name = "label16"; + this.label16.Size = new System.Drawing.Size(47, 15); + this.label16.TabIndex = 3; + this.label16.Text = "Normal"; + // + // SimpleStarNormalBox + // + this.SimpleStarNormalBox.Location = new System.Drawing.Point(165, 22); + this.SimpleStarNormalBox.Name = "SimpleStarNormalBox"; + this.SimpleStarNormalBox.Size = new System.Drawing.Size(64, 23); + this.SimpleStarNormalBox.TabIndex = 2; + // + // label15 + // + this.label15.AutoSize = true; + this.label15.Location = new System.Drawing.Point(6, 24); + this.label15.Name = "label15"; + this.label15.Size = new System.Drawing.Size(30, 15); + this.label15.TabIndex = 1; + this.label15.Text = "Easy"; + // + // SimpleStarEasyBox + // + this.SimpleStarEasyBox.Location = new System.Drawing.Point(42, 22); + this.SimpleStarEasyBox.Name = "SimpleStarEasyBox"; + this.SimpleStarEasyBox.Size = new System.Drawing.Size(64, 23); + this.SimpleStarEasyBox.TabIndex = 0; + // + // label14 + // + this.label14.AutoSize = true; + this.label14.Location = new System.Drawing.Point(6, 9); + this.label14.Name = "label14"; + this.label14.Size = new System.Drawing.Size(17, 15); + this.label14.TabIndex = 9; + this.label14.Text = "Id"; + // + // textBox1 + // + this.textBox1.Location = new System.Drawing.Point(77, 6); + this.textBox1.Name = "textBox1"; + this.textBox1.ReadOnly = true; + this.textBox1.Size = new System.Drawing.Size(149, 23); + this.textBox1.TabIndex = 8; + // + // label13 + // + this.label13.AutoSize = true; + this.label13.Location = new System.Drawing.Point(6, 125); + this.label13.Name = "label13"; + this.label13.Size = new System.Drawing.Size(38, 15); + this.label13.TabIndex = 7; + this.label13.Text = "Genre"; + // + // SimpleGenreBox + // + this.SimpleGenreBox.FormattingEnabled = true; + this.SimpleGenreBox.Location = new System.Drawing.Point(77, 122); + this.SimpleGenreBox.Name = "SimpleGenreBox"; + this.SimpleGenreBox.Size = new System.Drawing.Size(149, 23); + this.SimpleGenreBox.TabIndex = 6; + // + // label12 + // + this.label12.AutoSize = true; + this.label12.Location = new System.Drawing.Point(6, 96); + this.label12.Name = "label12"; + this.label12.Size = new System.Drawing.Size(37, 15); + this.label12.TabIndex = 5; + this.label12.Text = "Detail"; + // + // label11 + // + this.label11.AutoSize = true; + this.label11.Location = new System.Drawing.Point(6, 67); + this.label11.Name = "label11"; + this.label11.Size = new System.Drawing.Size(47, 15); + this.label11.TabIndex = 4; + this.label11.Text = "Subtitle"; + // + // SimpleDetailBox + // + this.SimpleDetailBox.Location = new System.Drawing.Point(77, 93); + this.SimpleDetailBox.Name = "SimpleDetailBox"; + this.SimpleDetailBox.Size = new System.Drawing.Size(149, 23); + this.SimpleDetailBox.TabIndex = 3; + // + // SimpleSubtitleBox + // + this.SimpleSubtitleBox.Location = new System.Drawing.Point(77, 64); + this.SimpleSubtitleBox.Name = "SimpleSubtitleBox"; + this.SimpleSubtitleBox.Size = new System.Drawing.Size(149, 23); + this.SimpleSubtitleBox.TabIndex = 2; + // + // SimpleTitleBox + // + this.SimpleTitleBox.Location = new System.Drawing.Point(77, 35); + this.SimpleTitleBox.Name = "SimpleTitleBox"; + this.SimpleTitleBox.Size = new System.Drawing.Size(149, 23); + this.SimpleTitleBox.TabIndex = 1; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(6, 38); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(29, 15); + this.label4.TabIndex = 0; + this.label4.Text = "Title"; + // + // SoundViewerExpert + // + this.SoundViewerExpert.Controls.Add(this.groupBox4); + this.SoundViewerExpert.Location = new System.Drawing.Point(4, 24); + this.SoundViewerExpert.Name = "SoundViewerExpert"; + this.SoundViewerExpert.Padding = new System.Windows.Forms.Padding(3); + this.SoundViewerExpert.Size = new System.Drawing.Size(521, 296); + this.SoundViewerExpert.TabIndex = 0; + this.SoundViewerExpert.Text = "Expert View"; + this.SoundViewerExpert.UseVisualStyleBackColor = true; + // + // groupBox4 + // + this.groupBox4.Controls.Add(this.EditorTable); + this.groupBox4.Dock = System.Windows.Forms.DockStyle.Fill; + this.groupBox4.Location = new System.Drawing.Point(3, 3); + this.groupBox4.Name = "groupBox4"; + this.groupBox4.Size = new System.Drawing.Size(515, 290); + this.groupBox4.TabIndex = 4; + this.groupBox4.TabStop = false; + this.groupBox4.Text = "Sound Data"; + // + // EditorTable + // + this.EditorTable.ColumnCount = 3; + this.EditorTable.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33F)); + this.EditorTable.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 34F)); + this.EditorTable.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33F)); + this.EditorTable.Controls.Add(this.panel3, 1, 0); + this.EditorTable.Controls.Add(this.groupBox5, 0, 0); + this.EditorTable.Controls.Add(this.panel2, 2, 0); + this.EditorTable.Dock = System.Windows.Forms.DockStyle.Fill; + this.EditorTable.Location = new System.Drawing.Point(3, 19); + this.EditorTable.Name = "EditorTable"; + this.EditorTable.RowCount = 1; + this.EditorTable.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.EditorTable.Size = new System.Drawing.Size(509, 268); + this.EditorTable.TabIndex = 7; + this.EditorTable.Resize += new System.EventHandler(this.EditorTable_Resize); + // + // panel3 + // + this.panel3.Controls.Add(this.groupBox6); + this.panel3.Controls.Add(this.groupBox7); + this.panel3.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel3.Location = new System.Drawing.Point(170, 3); + this.panel3.Name = "panel3"; + this.panel3.Size = new System.Drawing.Size(167, 262); + this.panel3.TabIndex = 5; + // + // groupBox6 + // + this.groupBox6.Controls.Add(this.MusicAttributesGrid); + this.groupBox6.Dock = System.Windows.Forms.DockStyle.Fill; + this.groupBox6.Location = new System.Drawing.Point(0, 0); + this.groupBox6.Name = "groupBox6"; + this.groupBox6.Size = new System.Drawing.Size(167, 138); + this.groupBox6.TabIndex = 5; + this.groupBox6.TabStop = false; + this.groupBox6.Text = "Music Attributes"; + // + // MusicAttributesGrid + // + this.MusicAttributesGrid.Dock = System.Windows.Forms.DockStyle.Fill; + this.MusicAttributesGrid.HelpVisible = false; + this.MusicAttributesGrid.Location = new System.Drawing.Point(3, 19); + this.MusicAttributesGrid.Name = "MusicAttributesGrid"; + this.MusicAttributesGrid.Size = new System.Drawing.Size(161, 116); + this.MusicAttributesGrid.TabIndex = 3; + this.MusicAttributesGrid.ToolbarVisible = false; + // + // groupBox7 + // + this.groupBox7.Controls.Add(this.MusicOrderGrid); + this.groupBox7.Dock = System.Windows.Forms.DockStyle.Bottom; + this.groupBox7.Location = new System.Drawing.Point(0, 138); + this.groupBox7.Name = "groupBox7"; + this.groupBox7.Size = new System.Drawing.Size(167, 124); + this.groupBox7.TabIndex = 6; + this.groupBox7.TabStop = false; + this.groupBox7.Text = "Music Order"; + // + // MusicOrderGrid + // + this.MusicOrderGrid.Dock = System.Windows.Forms.DockStyle.Fill; + this.MusicOrderGrid.HelpVisible = false; + this.MusicOrderGrid.Location = new System.Drawing.Point(3, 19); + this.MusicOrderGrid.Name = "MusicOrderGrid"; + this.MusicOrderGrid.Size = new System.Drawing.Size(161, 102); + this.MusicOrderGrid.TabIndex = 3; + this.MusicOrderGrid.ToolbarVisible = false; + // + // groupBox5 + // + this.groupBox5.Controls.Add(this.MusicInfoGrid); + this.groupBox5.Dock = System.Windows.Forms.DockStyle.Fill; + this.groupBox5.Location = new System.Drawing.Point(3, 3); + this.groupBox5.Name = "groupBox5"; + this.groupBox5.Size = new System.Drawing.Size(161, 262); + this.groupBox5.TabIndex = 4; + this.groupBox5.TabStop = false; + this.groupBox5.Text = "Music Info"; + // + // MusicInfoGrid + // + this.MusicInfoGrid.Dock = System.Windows.Forms.DockStyle.Fill; + this.MusicInfoGrid.HelpVisible = false; + this.MusicInfoGrid.Location = new System.Drawing.Point(3, 19); + this.MusicInfoGrid.Name = "MusicInfoGrid"; + this.MusicInfoGrid.Size = new System.Drawing.Size(155, 240); + this.MusicInfoGrid.TabIndex = 3; + this.MusicInfoGrid.ToolbarVisible = false; + // + // panel2 + // + this.panel2.Controls.Add(this.WordDetailGB); + this.panel2.Controls.Add(this.WordSubGB); + this.panel2.Controls.Add(this.WordsGB); + this.panel2.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel2.Location = new System.Drawing.Point(343, 3); + this.panel2.Name = "panel2"; + this.panel2.Size = new System.Drawing.Size(163, 262); + this.panel2.TabIndex = 6; + // + // WordDetailGB + // + this.WordDetailGB.Controls.Add(this.WordDetailGrid); + this.WordDetailGB.Dock = System.Windows.Forms.DockStyle.Top; + this.WordDetailGB.Location = new System.Drawing.Point(0, 184); + this.WordDetailGB.Name = "WordDetailGB"; + this.WordDetailGB.Size = new System.Drawing.Size(163, 96); + this.WordDetailGB.TabIndex = 8; + this.WordDetailGB.TabStop = false; + this.WordDetailGB.Text = "Word Detail"; + // + // WordDetailGrid + // + this.WordDetailGrid.Dock = System.Windows.Forms.DockStyle.Fill; + this.WordDetailGrid.HelpVisible = false; + this.WordDetailGrid.Location = new System.Drawing.Point(3, 19); + this.WordDetailGrid.Name = "WordDetailGrid"; + this.WordDetailGrid.Size = new System.Drawing.Size(157, 74); + this.WordDetailGrid.TabIndex = 3; + this.WordDetailGrid.ToolbarVisible = false; + // + // WordSubGB + // + this.WordSubGB.Controls.Add(this.WordSubGrid); + this.WordSubGB.Dock = System.Windows.Forms.DockStyle.Top; + this.WordSubGB.Location = new System.Drawing.Point(0, 88); + this.WordSubGB.Name = "WordSubGB"; + this.WordSubGB.Size = new System.Drawing.Size(163, 96); + this.WordSubGB.TabIndex = 7; + this.WordSubGB.TabStop = false; + this.WordSubGB.Text = "Word Sub"; + // + // WordSubGrid + // + this.WordSubGrid.Dock = System.Windows.Forms.DockStyle.Fill; + this.WordSubGrid.HelpVisible = false; + this.WordSubGrid.Location = new System.Drawing.Point(3, 19); + this.WordSubGrid.Name = "WordSubGrid"; + this.WordSubGrid.Size = new System.Drawing.Size(157, 74); + this.WordSubGrid.TabIndex = 3; + this.WordSubGrid.ToolbarVisible = false; + // + // WordsGB + // + this.WordsGB.Controls.Add(this.WordsGrid); + this.WordsGB.Dock = System.Windows.Forms.DockStyle.Top; + this.WordsGB.Location = new System.Drawing.Point(0, 0); + this.WordsGB.Name = "WordsGB"; + this.WordsGB.Size = new System.Drawing.Size(163, 88); + this.WordsGB.TabIndex = 6; + this.WordsGB.TabStop = false; + this.WordsGB.Text = "Words"; + // + // WordsGrid + // + this.WordsGrid.Dock = System.Windows.Forms.DockStyle.Fill; + this.WordsGrid.HelpVisible = false; + this.WordsGrid.Location = new System.Drawing.Point(3, 19); + this.WordsGrid.Name = "WordsGrid"; + this.WordsGrid.PropertySort = System.Windows.Forms.PropertySort.Alphabetical; + this.WordsGrid.Size = new System.Drawing.Size(157, 66); + this.WordsGrid.TabIndex = 3; + this.WordsGrid.ToolbarVisible = false; + // + // MusicOrderTab + // + this.MusicOrderTab.Location = new System.Drawing.Point(4, 24); + this.MusicOrderTab.Name = "MusicOrderTab"; + this.MusicOrderTab.Padding = new System.Windows.Forms.Padding(3); + this.MusicOrderTab.Size = new System.Drawing.Size(521, 296); + this.MusicOrderTab.TabIndex = 2; + this.MusicOrderTab.Text = "Music Order"; + this.MusicOrderTab.UseVisualStyleBackColor = true; // // RemoveSongButton // @@ -439,185 +889,6 @@ this.NewSoundsBox.TabIndex = 1; this.NewSoundsBox.SelectedIndexChanged += new System.EventHandler(this.NewSoundsBox_SelectedIndexChanged); // - // groupBox4 - // - this.groupBox4.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.groupBox4.Controls.Add(this.EditorTable); - this.groupBox4.Location = new System.Drawing.Point(139, 6); - this.groupBox4.Name = "groupBox4"; - this.groupBox4.Size = new System.Drawing.Size(531, 331); - this.groupBox4.TabIndex = 4; - this.groupBox4.TabStop = false; - this.groupBox4.Text = "Sound Data"; - // - // EditorTable - // - this.EditorTable.ColumnCount = 3; - this.EditorTable.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33F)); - this.EditorTable.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 34F)); - this.EditorTable.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33F)); - this.EditorTable.Controls.Add(this.panel3, 1, 0); - this.EditorTable.Controls.Add(this.groupBox5, 0, 0); - this.EditorTable.Controls.Add(this.panel2, 2, 0); - this.EditorTable.Dock = System.Windows.Forms.DockStyle.Fill; - this.EditorTable.Location = new System.Drawing.Point(3, 19); - this.EditorTable.Name = "EditorTable"; - this.EditorTable.RowCount = 1; - this.EditorTable.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this.EditorTable.Size = new System.Drawing.Size(525, 309); - this.EditorTable.TabIndex = 7; - this.EditorTable.Resize += new System.EventHandler(this.EditorTable_Resize); - // - // panel3 - // - this.panel3.Controls.Add(this.groupBox6); - this.panel3.Controls.Add(this.groupBox7); - this.panel3.Dock = System.Windows.Forms.DockStyle.Fill; - this.panel3.Location = new System.Drawing.Point(176, 3); - this.panel3.Name = "panel3"; - this.panel3.Size = new System.Drawing.Size(172, 303); - this.panel3.TabIndex = 5; - // - // groupBox6 - // - this.groupBox6.Controls.Add(this.MusicAttributesGrid); - this.groupBox6.Dock = System.Windows.Forms.DockStyle.Fill; - this.groupBox6.Location = new System.Drawing.Point(0, 0); - this.groupBox6.Name = "groupBox6"; - this.groupBox6.Size = new System.Drawing.Size(172, 179); - this.groupBox6.TabIndex = 5; - this.groupBox6.TabStop = false; - this.groupBox6.Text = "Music Attributes"; - // - // MusicAttributesGrid - // - this.MusicAttributesGrid.Dock = System.Windows.Forms.DockStyle.Fill; - this.MusicAttributesGrid.HelpVisible = false; - this.MusicAttributesGrid.Location = new System.Drawing.Point(3, 19); - this.MusicAttributesGrid.Name = "MusicAttributesGrid"; - this.MusicAttributesGrid.Size = new System.Drawing.Size(166, 157); - this.MusicAttributesGrid.TabIndex = 3; - this.MusicAttributesGrid.ToolbarVisible = false; - // - // groupBox7 - // - this.groupBox7.Controls.Add(this.MusicOrderGrid); - this.groupBox7.Dock = System.Windows.Forms.DockStyle.Bottom; - this.groupBox7.Location = new System.Drawing.Point(0, 179); - this.groupBox7.Name = "groupBox7"; - this.groupBox7.Size = new System.Drawing.Size(172, 124); - this.groupBox7.TabIndex = 6; - this.groupBox7.TabStop = false; - this.groupBox7.Text = "Music Order"; - // - // MusicOrderGrid - // - this.MusicOrderGrid.Dock = System.Windows.Forms.DockStyle.Fill; - this.MusicOrderGrid.HelpVisible = false; - this.MusicOrderGrid.Location = new System.Drawing.Point(3, 19); - this.MusicOrderGrid.Name = "MusicOrderGrid"; - this.MusicOrderGrid.Size = new System.Drawing.Size(166, 102); - this.MusicOrderGrid.TabIndex = 3; - this.MusicOrderGrid.ToolbarVisible = false; - // - // groupBox5 - // - this.groupBox5.Controls.Add(this.MusicInfoGrid); - this.groupBox5.Dock = System.Windows.Forms.DockStyle.Fill; - this.groupBox5.Location = new System.Drawing.Point(3, 3); - this.groupBox5.Name = "groupBox5"; - this.groupBox5.Size = new System.Drawing.Size(167, 303); - this.groupBox5.TabIndex = 4; - this.groupBox5.TabStop = false; - this.groupBox5.Text = "Music Info"; - // - // MusicInfoGrid - // - this.MusicInfoGrid.Dock = System.Windows.Forms.DockStyle.Fill; - this.MusicInfoGrid.HelpVisible = false; - this.MusicInfoGrid.Location = new System.Drawing.Point(3, 19); - this.MusicInfoGrid.Name = "MusicInfoGrid"; - this.MusicInfoGrid.Size = new System.Drawing.Size(161, 281); - this.MusicInfoGrid.TabIndex = 3; - this.MusicInfoGrid.ToolbarVisible = false; - // - // panel2 - // - this.panel2.Controls.Add(this.WordDetailGB); - this.panel2.Controls.Add(this.WordSubGB); - this.panel2.Controls.Add(this.WordsGB); - this.panel2.Dock = System.Windows.Forms.DockStyle.Fill; - this.panel2.Location = new System.Drawing.Point(354, 3); - this.panel2.Name = "panel2"; - this.panel2.Size = new System.Drawing.Size(168, 303); - this.panel2.TabIndex = 6; - // - // WordDetailGB - // - this.WordDetailGB.Controls.Add(this.WordDetailGrid); - this.WordDetailGB.Dock = System.Windows.Forms.DockStyle.Top; - this.WordDetailGB.Location = new System.Drawing.Point(0, 184); - this.WordDetailGB.Name = "WordDetailGB"; - this.WordDetailGB.Size = new System.Drawing.Size(168, 96); - this.WordDetailGB.TabIndex = 8; - this.WordDetailGB.TabStop = false; - this.WordDetailGB.Text = "Word Detail"; - // - // WordDetailGrid - // - this.WordDetailGrid.Dock = System.Windows.Forms.DockStyle.Fill; - this.WordDetailGrid.HelpVisible = false; - this.WordDetailGrid.Location = new System.Drawing.Point(3, 19); - this.WordDetailGrid.Name = "WordDetailGrid"; - this.WordDetailGrid.Size = new System.Drawing.Size(162, 74); - this.WordDetailGrid.TabIndex = 3; - this.WordDetailGrid.ToolbarVisible = false; - // - // WordSubGB - // - this.WordSubGB.Controls.Add(this.WordSubGrid); - this.WordSubGB.Dock = System.Windows.Forms.DockStyle.Top; - this.WordSubGB.Location = new System.Drawing.Point(0, 88); - this.WordSubGB.Name = "WordSubGB"; - this.WordSubGB.Size = new System.Drawing.Size(168, 96); - this.WordSubGB.TabIndex = 7; - this.WordSubGB.TabStop = false; - this.WordSubGB.Text = "Word Sub"; - // - // WordSubGrid - // - this.WordSubGrid.Dock = System.Windows.Forms.DockStyle.Fill; - this.WordSubGrid.HelpVisible = false; - this.WordSubGrid.Location = new System.Drawing.Point(3, 19); - this.WordSubGrid.Name = "WordSubGrid"; - this.WordSubGrid.Size = new System.Drawing.Size(162, 74); - this.WordSubGrid.TabIndex = 3; - this.WordSubGrid.ToolbarVisible = false; - // - // WordsGB - // - this.WordsGB.Controls.Add(this.WordsGrid); - this.WordsGB.Dock = System.Windows.Forms.DockStyle.Top; - this.WordsGB.Location = new System.Drawing.Point(0, 0); - this.WordsGB.Name = "WordsGB"; - this.WordsGB.Size = new System.Drawing.Size(168, 88); - this.WordsGB.TabIndex = 6; - this.WordsGB.TabStop = false; - this.WordsGB.Text = "Words"; - // - // WordsGrid - // - this.WordsGrid.Dock = System.Windows.Forms.DockStyle.Fill; - this.WordsGrid.HelpVisible = false; - this.WordsGrid.Location = new System.Drawing.Point(3, 19); - this.WordsGrid.Name = "WordsGrid"; - this.WordsGrid.PropertySort = System.Windows.Forms.PropertySort.Alphabetical; - this.WordsGrid.Size = new System.Drawing.Size(162, 66); - this.WordsGrid.TabIndex = 3; - this.WordsGrid.ToolbarVisible = false; - // // groupBox3 // this.groupBox3.Controls.Add(this.LoadedMusicBox); @@ -641,6 +912,7 @@ // // tabPage3 // + this.tabPage3.BackColor = System.Drawing.Color.White; this.tabPage3.Controls.Add(this.panel4); this.tabPage3.Location = new System.Drawing.Point(4, 5); this.tabPage3.Name = "tabPage3"; @@ -648,7 +920,6 @@ this.tabPage3.Size = new System.Drawing.Size(676, 452); this.tabPage3.TabIndex = 2; this.tabPage3.Text = "tabPage3"; - this.tabPage3.UseVisualStyleBackColor = true; // // panel4 // @@ -683,6 +954,32 @@ this.groupBox10.TabStop = false; this.groupBox10.Text = "Create new sound"; // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(181, 154); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(50, 15); + this.label3.TabIndex = 21; + this.label3.Text = "seconds"; + // + // SilenceBox + // + this.SilenceBox.Location = new System.Drawing.Point(133, 152); + this.SilenceBox.Maximum = new decimal(new int[] { + 10, + 0, + 0, + 0}); + this.SilenceBox.Name = "SilenceBox"; + this.SilenceBox.Size = new System.Drawing.Size(42, 23); + this.SilenceBox.TabIndex = 20; + this.SilenceBox.Value = new decimal(new int[] { + 3, + 0, + 0, + 0}); + // // groupBox9 // this.groupBox9.Controls.Add(this.TjaEncShiftJIS); @@ -839,31 +1136,14 @@ this.label10.TabIndex = 8; this.label10.Text = "Audio file"; // - // SilenceBox + // LocateInMusicOrderButton // - this.SilenceBox.Location = new System.Drawing.Point(133, 152); - this.SilenceBox.Maximum = new decimal(new int[] { - 10, - 0, - 0, - 0}); - this.SilenceBox.Name = "SilenceBox"; - this.SilenceBox.Size = new System.Drawing.Size(42, 23); - this.SilenceBox.TabIndex = 20; - this.SilenceBox.Value = new decimal(new int[] { - 3, - 0, - 0, - 0}); - // - // label3 - // - this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(181, 154); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(50, 15); - this.label3.TabIndex = 21; - this.label3.Text = "seconds"; + this.LocateInMusicOrderButton.Location = new System.Drawing.Point(238, 121); + this.LocateInMusicOrderButton.Name = "LocateInMusicOrderButton"; + this.LocateInMusicOrderButton.Size = new System.Drawing.Size(136, 23); + this.LocateInMusicOrderButton.TabIndex = 11; + this.LocateInMusicOrderButton.Text = "Locate in Music Order"; + this.LocateInMusicOrderButton.UseVisualStyleBackColor = true; // // MainForm // @@ -884,7 +1164,17 @@ this.groupBox1.PerformLayout(); this.tabPage2.ResumeLayout(false); this.tabPage2.PerformLayout(); - this.groupBox8.ResumeLayout(false); + this.SoundViewTab.ResumeLayout(false); + this.SoundViewerSimple.ResumeLayout(false); + this.SoundViewerSimple.PerformLayout(); + this.groupBox11.ResumeLayout(false); + this.groupBox11.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.SimpleStarUraBox)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.SimpleStarManiaBox)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.SimpleStarHardBox)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.SimpleStarNormalBox)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.SimpleStarEasyBox)).EndInit(); + this.SoundViewerExpert.ResumeLayout(false); this.groupBox4.ResumeLayout(false); this.EditorTable.ResumeLayout(false); this.panel3.ResumeLayout(false); @@ -895,14 +1185,15 @@ this.WordDetailGB.ResumeLayout(false); this.WordSubGB.ResumeLayout(false); this.WordsGB.ResumeLayout(false); + this.groupBox8.ResumeLayout(false); this.groupBox3.ResumeLayout(false); this.tabPage3.ResumeLayout(false); this.panel4.ResumeLayout(false); this.groupBox10.ResumeLayout(false); this.groupBox10.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.SilenceBox)).EndInit(); this.groupBox9.ResumeLayout(false); this.groupBox9.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.SilenceBox)).EndInit(); this.ResumeLayout(false); } @@ -973,5 +1264,31 @@ private RadioButton TjaEncAuto; private NumericUpDown SilenceBox; private Label label3; + private TabControl SoundViewTab; + private TabPage SoundViewerExpert; + private TabPage SoundViewerSimple; + private TextBox SimpleSubtitleBox; + private TextBox SimpleTitleBox; + private Label label4; + private TextBox SimpleDetailBox; + private Label label12; + private Label label11; + private ComboBox SimpleGenreBox; + private Label label13; + private Label label14; + private TextBox textBox1; + private TabPage MusicOrderTab; + private GroupBox groupBox11; + private Label label17; + private NumericUpDown SimpleStarManiaBox; + private Label label18; + private NumericUpDown SimpleStarHardBox; + private Label label16; + private NumericUpDown SimpleStarNormalBox; + private Label label15; + private NumericUpDown SimpleStarEasyBox; + private Label label19; + private NumericUpDown SimpleStarUraBox; + private Button LocateInMusicOrderButton; } } \ No newline at end of file diff --git a/MainForm.Exports.cs b/MainForm.Exports.cs new file mode 100644 index 0000000..689d372 --- /dev/null +++ b/MainForm.Exports.cs @@ -0,0 +1,202 @@ +using System.Diagnostics; +using TaikoSoundEditor.Data; +using TaikoSoundEditor.Utils; + +namespace TaikoSoundEditor +{ + partial class MainForm + { + private void ExportDatatable(string path) + { + Logger.Info($"Exporting Datatable to '{path}'"); + var mi = new MusicInfos(); + mi.Items.AddRange(MusicInfos.Items); + mi.Items.AddRange(AddedMusic.Select(_ => _.MusicInfo)); + + var ma = new MusicAttributes(); + ma.Items.AddRange(MusicAttributes.Items); + ma.Items.AddRange(AddedMusic.Select(_ => _.MusicAttribute)); + + var mo = new MusicOrders(); + + var mbyg = MusicOrders.Items.GroupBy(_ => _.GenreNo).Select(_ => (_.Key, List: _.ToList())).ToDictionary(_ => _.Key, _ => _.List); + + foreach (var m in AddedMusic.Select(_ => _.MusicOrder)) + { + if (!mbyg.ContainsKey(m.GenreNo)) + mbyg[m.GenreNo] = new List(); + mbyg[m.GenreNo] = mbyg[m.GenreNo].Prepend(m).ToList(); + } + + foreach (var key in mbyg.Keys.OrderBy(_ => _)) + { + mo.Items.AddRange(mbyg[key]); + } + + var wl = new WordList(); + wl.Items.AddRange(WordList.Items); + wl.Items.AddRange(AddedMusic.Select(_ => new List() { _.Word, _.WordSub, _.WordDetail }).SelectMany(_ => _)); + + var jmi = JsonFix(Json.Serialize(mi, !DatatableSpaces.Checked)); + var jma = JsonFix(Json.Serialize(ma)); + var jmo = JsonFix(Json.Serialize(mo)); + var jwl = JsonFix(Json.Serialize(wl, !DatatableSpaces.Checked)); + + jma = jma.Replace("\"new\": true,", "\"new\":true,"); + jma = jma.Replace("\"new\": false,", "\"new\":false,"); + + File.WriteAllText(Path.Combine(path, "musicinfo"), jmi); + File.WriteAllText(Path.Combine(path, "music_attribute"), jma); + File.WriteAllText(Path.Combine(path, "music_order"), jmo); + File.WriteAllText(Path.Combine(path, "wordlist"), jwl); + + GZ.CompressToFile(Path.Combine(path, "musicinfo.bin"), jmi); + GZ.CompressToFile(Path.Combine(path, "music_attribute.bin"), jma); + GZ.CompressToFile(Path.Combine(path, "music_order.bin"), jmo); + GZ.CompressToFile(Path.Combine(path, "wordlist.bin"), jwl); + } + + private void ExportNusBanks(string path) + { + Logger.Info($"Exporting NUS3BaNKS to '{path}'"); + foreach (var ns in AddedMusic) + { + File.WriteAllBytes(Path.Combine(path, $"song_{ns.Id}.nus3bank"), ns.Nus3Bank); + } + } + + private void ExportSoundBinaries(string path) + { + Logger.Info($"Exporting Sound .bin's to '{path}'"); + foreach (var ns in AddedMusic) + { + var sdir = Path.Combine(path, ns.Id); + + if (!Directory.Exists(sdir)) + Directory.CreateDirectory(sdir); + + File.WriteAllBytes(Path.Combine(sdir, $"{ns.Id}_e.bin"), ns.EBin); + File.WriteAllBytes(Path.Combine(sdir, $"{ns.Id}_n.bin"), ns.NBin); + File.WriteAllBytes(Path.Combine(sdir, $"{ns.Id}_h.bin"), ns.HBin); + File.WriteAllBytes(Path.Combine(sdir, $"{ns.Id}_m.bin"), ns.MBin); + + File.WriteAllBytes(Path.Combine(sdir, $"{ns.Id}_e_1.bin"), ns.EBin1); + File.WriteAllBytes(Path.Combine(sdir, $"{ns.Id}_n_1.bin"), ns.NBin1); + File.WriteAllBytes(Path.Combine(sdir, $"{ns.Id}_h_1.bin"), ns.HBin1); + File.WriteAllBytes(Path.Combine(sdir, $"{ns.Id}_m_1.bin"), ns.MBin1); + + File.WriteAllBytes(Path.Combine(sdir, $"{ns.Id}_e_2.bin"), ns.EBin2); + File.WriteAllBytes(Path.Combine(sdir, $"{ns.Id}_n_2.bin"), ns.NBin2); + File.WriteAllBytes(Path.Combine(sdir, $"{ns.Id}_h_2.bin"), ns.HBin2); + File.WriteAllBytes(Path.Combine(sdir, $"{ns.Id}_m_2.bin"), ns.MBin2); + + if (ns.MusicAttribute.CanPlayUra) + { + File.WriteAllBytes(Path.Combine(sdir, $"{ns.Id}_x.bin"), ns.XBin); + File.WriteAllBytes(Path.Combine(sdir, $"{ns.Id}_x_1.bin"), ns.XBin1); + File.WriteAllBytes(Path.Combine(sdir, $"{ns.Id}_x_2.bin"), ns.XBin2); + } + } + } + + + private void ExportDatatableButton_Click(object sender, EventArgs e) => ExceptionGuard.Run(() => + { + Logger.Info($"Clicked ExportDatatableButton"); + var path = PickPath(); + if (path == null) + { + MessageBox.Show("No path chosen. Operation canceled"); + return; + } + ExportDatatable(path); + MessageBox.Show("Done"); + if (ExportOpenOnFinished.Checked) + Process.Start($"explorer.exe", path); + }); + + private void ExportSoundFoldersButton_Click(object sender, EventArgs e) => ExceptionGuard.Run(() => + { + Logger.Info($"Clicked ExportSoundFoldersButton"); + var path = PickPath(); + if (path == null) + { + MessageBox.Show("No path chosen. Operation canceled"); + return; + } + ExportSoundBinaries(path); + MessageBox.Show("Done"); + if (ExportOpenOnFinished.Checked) + Process.Start($"explorer.exe", path); + }); + + private void ExportSoundBanksButton_Click(object sender, EventArgs e) => ExceptionGuard.Run(() => + { + Logger.Info($"Clicked ExportSoundBanksButton"); + var path = PickPath(); + if (path == null) + { + MessageBox.Show("No path chosen. Operation canceled"); + return; + } + ExportNusBanks(path); + MessageBox.Show("Done"); + if (ExportOpenOnFinished.Checked) + Process.Start($"explorer.exe", path); + }); + + private string PickPath() + { + Logger.Info($"Picking path dialog"); + var picker = new FolderPicker(); + if (picker.ShowDialog() == true) + return picker.ResultPath; + return null; + } + + private void ExportAllButton_Click(object sender, EventArgs e) => ExceptionGuard.Run(() => + { + Logger.Info($"Clicked Export All"); + var path = PickPath(); + if (path == null) + { + MessageBox.Show("No path chosen. Operation canceled"); + return; + } + + var dtpath = Path.Combine(path, "datatable"); + if (!Directory.Exists(dtpath)) Directory.CreateDirectory(dtpath); + + var nupath = Path.Combine(path, "sound"); + if (!Directory.Exists(nupath)) Directory.CreateDirectory(nupath); + + var sbpath = Path.Combine(path, "fumen"); + if (!Directory.Exists(sbpath)) Directory.CreateDirectory(sbpath); + + ExportDatatable(dtpath); + ExportSoundBinaries(sbpath); + ExportNusBanks(nupath); + MessageBox.Show("Done"); + if (ExportOpenOnFinished.Checked) + Process.Start($"explorer.exe", path); + }); + + private string JsonFix(string json) + { + var specialChars = "!@#$%^&*()_+=`~[]{}<>\\/'"; + foreach (var c in specialChars) + { + json = json.Replace($"\\u00{((int)c):X2}", $"{c}"); + } + + + return json + .Replace("\\u0022", "\\\"") + .Replace("\r\n ", "\r\n\t\t") + .Replace("\r\n ", "\r\n\t\t") + .Replace("{\r\n \"items\": [", "{\"items\":[") + .Replace(" }", "\t}") + .Replace(" ]\r\n}", "\t]\r\n}"); + } + } +} diff --git a/MainForm.Properties.cs b/MainForm.Properties.cs new file mode 100644 index 0000000..75b5141 --- /dev/null +++ b/MainForm.Properties.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TaikoSoundEditor.Data; + +namespace TaikoSoundEditor +{ + partial class MainForm + { + private string MusicAttributePath { get; set; } + private string MusicOrderPath { get; set; } + private string MusicInfoPath { get; set; } + private string WordListPath { get; set; } + + private MusicAttributes MusicAttributes; + private MusicOrders MusicOrders; + private WordList WordList; + private MusicInfos MusicInfos; + private List AddedMusic { get; set; } = new List(); + private BindingSource AddedMusicBinding { get; set; } + private BindingSource LoadedMusicBinding; + } +} diff --git a/MainForm.RequestFiles.cs b/MainForm.RequestFiles.cs new file mode 100644 index 0000000..01b1920 --- /dev/null +++ b/MainForm.RequestFiles.cs @@ -0,0 +1,113 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TaikoSoundEditor.Data; +using TaikoSoundEditor.Utils; + +namespace TaikoSoundEditor +{ + partial class MainForm + { + #region Requesting Files + + private void WordListPathSelector_PathChanged(object sender, EventArgs args) + { + Logger.Info($"WordListPathSelector_PathChanged : {WordListPathSelector.Path}"); + WordListPath = WordListPathSelector.Path; + } + + private void MusicInfoPathSelector_PathChanged(object sender, EventArgs args) + { + Logger.Info($"MusicInfoPathSelector_PathChanged : {MusicInfoPathSelector.Path}"); + MusicInfoPath = MusicInfoPathSelector.Path; + } + + private void MusicOrderPathSelector_PathChanged(object sender, EventArgs args) + { + Logger.Info($"MusicOrderPathSelector_PathChanged : {MusicOrderPathSelector.Path}"); + MusicOrderPath = MusicOrderPathSelector.Path; + } + + private void MusicAttributePathSelector_PathChanged(object sender, EventArgs args) + { + Logger.Info($"MusicAttributePathSelector_PathChanged : {MusicAttributePathSelector.Path}"); + MusicAttributePath = MusicAttributePathSelector.Path; + } + + private void DirSelector_PathChanged(object sender, EventArgs args) => ExceptionGuard.Run(() => + { + Logger.Info($"MusicAttributePathSelector_PathChanged : {DirSelector.Path}"); + var dir = DirSelector.Path; + var files = new string[] { "music_attribute.bin", "music_order.bin", "musicinfo.bin", "wordlist.bin" }; + var sels = new PathSelector[] { MusicAttributePathSelector, MusicOrderPathSelector, MusicInfoPathSelector, WordListPathSelector }; + + List NotFoundFiles = new List(); + + for (int i = 0; i < files.Length; i++) + { + var path = Path.Combine(dir, files[i]); + if (!File.Exists(path)) + { + NotFoundFiles.Add(files[i]); + continue; + } + sels[i].Path = path; + } + + if (NotFoundFiles.Count > 0) + { + Logger.Warning("The following files could not be found:\n\n" + String.Join("\n", NotFoundFiles)); + MessageBox.Show("The following files could not be found:\n\n" + String.Join("\n", NotFoundFiles)); + } + }); + + private void OkButton_Click(object sender, EventArgs e) => ExceptionGuard.Run(() => + { + Logger.Info($"Clicked 'Looks good' "); + + try + { + MusicAttributes = Json.Deserialize(GZ.DecompressString(MusicAttributePath)); + } + catch (Exception ex) + { + throw new Exception($"Failed to parse\n{MusicAttributePath}\nReason:\n{ex.InnerException}"); + } + try + { + MusicOrders = Json.Deserialize(GZ.DecompressString(MusicOrderPath)); + } + catch (Exception ex) + { + throw new Exception($"Failed to parse\n{MusicOrderPath}\nReason:\n{ex.InnerException}"); + } + try + { + MusicInfos = Json.Deserialize(GZ.DecompressString(MusicInfoPath)); + } + catch (Exception ex) + { + throw new Exception($"Failed to parse\n{MusicInfoPath}\nReason:\n{ex.InnerException}"); + } + try + { + WordList = Json.Deserialize(GZ.DecompressString(WordListPath)); + } + catch (Exception ex) + { + throw new Exception($"Failed to parse\n{WordListPath}\nReason:\n{ex.InnerException}"); + } + + Logger.Info($"Setting LoadedMusicBox DataSource"); + + LoadedMusicBinding = new BindingSource(); + LoadedMusicBinding.DataSource = MusicInfos.Items.Where(mi => mi.UniqueId != 0).ToList(); + LoadedMusicBox.DataSource = LoadedMusicBinding; + TabControl.SelectedIndex = 1; + }); + + #endregion + } +} diff --git a/MainForm.SoundCreate.cs b/MainForm.SoundCreate.cs new file mode 100644 index 0000000..55ee018 --- /dev/null +++ b/MainForm.SoundCreate.cs @@ -0,0 +1,314 @@ +using System.Data; +using TaikoSoundEditor.Data; +using TaikoSoundEditor.Utils; + +namespace TaikoSoundEditor +{ + partial class MainForm + { + private void CreateButton_Click(object sender, EventArgs e) + { + Logger.Info($"Clicked Create Button"); + AudioFileSelector.Path = ""; + TJASelector.Path = ""; + SongNameBox.Text = "(6 characters id...)"; + TabControl.SelectedIndex = 2; + } + + private void CreateBackButton_Click(object sender, EventArgs e) + { + Logger.Info($"Clicked Back Button"); + TabControl.SelectedIndex = 1; + } + + private void TJASelector_PathChanged(object sender, EventArgs args) + { + if (TJASelector.Path == null) return; + if (SongNameBox.Text != "" && SongNameBox.Text != "(6 characters id...)") return; + + var name = Path.GetFileNameWithoutExtension(TJASelector.Path); + if (name.Length == 6) + SongNameBox.Text = name; + } + + private void AddSilenceBox_CheckedChanged(object sender, EventArgs e) + { + SilenceBox.Enabled = AddSilenceBox.Checked; + } + + private void CreateOkButton_Click(object sender, EventArgs e) => ExceptionGuard.Run(() => + { + Logger.Info($"Clicked Ok Button"); + FeedbackBox.Clear(); + var audioFilePath = AudioFileSelector.Path; + var tjaPath = TJASelector.Path; + var songName = SongNameBox.Text; + var id = Math.Max(MusicAttributes.GetNewId(), AddedMusic.Count == 0 ? 0 : AddedMusic.Max(_ => _.UniqueId) + 1); + + Logger.Info($"Audio File = {audioFilePath}"); + Logger.Info($"TJA File = {tjaPath}"); + Logger.Info($"Song Name (Id) = {songName}"); + Logger.Info($"UniqueId = {id}"); + + if (songName == null || songName.Length == 0 || songName.Length > 6) + { + WarnWithBox("Invalid song name."); + return; + } + + if (!MusicAttributes.IsValidSongId(songName) || AddedMusic.Any(m => m.Id == songName)) + { + WarnWithBox("Duplicate song name. Choose another"); + return; + } + + FeedbackBox.AppendText("Creating temp dir\r\n"); + + CreateTmpDir(); + + FeedbackBox.AppendText("Parsing TJA\r\n"); + + Logger.Info("Parsing TJA"); + + var tja = TjaEncAuto.Checked ? TJA.ReadDefault(tjaPath) + : TjaEncUTF8.Checked ? TJA.ReadAsUTF8(tjaPath) + : TJA.ReadAsShiftJIS(tjaPath); + + File.WriteAllText("tja.txt", tja.ToString()); + + + var seconds = AddSilenceBox.Checked ? (int)Math.Ceiling(tja.Headers.Offset + (int)SilenceBox.Value) : 0; + if (seconds < 0) seconds = 0; + + + FeedbackBox.AppendText("Converting to wav\r\n"); + WAV.ConvertToWav(audioFilePath, $@".-tmp\{songName}.wav", seconds); + + + Logger.Info("Adjusting seconds of silence"); + tja.Headers.Offset -= seconds; + tja.Headers.DemoStart += seconds; + + var text = File.ReadAllLines(tjaPath); + + text = text.Select(l => + { + if (l.StartsWith("OFFSET:")) + return $"OFFSET:{tja.Headers.Offset:n3}"; + if (l.StartsWith("DEMOSTART:")) + return $"DEMOSTART:{tja.Headers.DemoStart:n3}"; + return l; + }).ToArray(); + + var missingCourses = new int[] { 0, 1, 2, 3 }.Where(i => !tja.Courses.Keys.Contains(i)).ToArray(); + var courseNames = new string[] { "Easy", "Normal", "Hard", "Oni" }; + + if (missingCourses.Length > 0) + { + + var caption = $"There are missing courses in the TJA file for difficulties: {string.Join(", ", missingCourses.Select(i => courseNames[i]))}.\n" + + $"Do you want to add a placeholder for the missing courses?"; + + if (MessageBox.Show(caption, "Warning", MessageBoxButtons.YesNo) == DialogResult.Yes) + { + foreach (var difficulty in missingCourses) + { + text = text.Concat(new string[] + { + "", + $"COURSE:{courseNames[difficulty]}", + "LEVEL:1", + "BALLOON:", + "SCOREINIT:", + "SCOREDIFF:", + "#START", + "1", + "#END" + }).ToArray(); + + tja.Courses[difficulty] = new TJA.Course(difficulty, new TJA.CourseHeader(), new List + { + new TJA.Measure(new int[]{1,1}, new Dictionary(), "1", new List()) + }); + } + } + } + + + Logger.Info("Creating temporary tja"); + var newTja = @$".-tmp\{Path.GetFileName(tjaPath)}"; + File.WriteAllLines(newTja, text); + + + + + FeedbackBox.AppendText("Running tja2fumen\r\n"); + + var tja_binaries = TJA.RunTja2Fumen(newTja); + + Logger.Info("Creating new sonud data"); + FeedbackBox.AppendText("Creating sound data\r\n"); + NewSongData ns = new NewSongData(); + + ns.UniqueId = id; + ns.Id = songName; + + ns.Wav = File.ReadAllBytes($@".-tmp\{songName}.wav"); + ns.EBin = tja_binaries[0]; + ns.HBin = tja_binaries[1]; + ns.MBin = tja_binaries[2]; + ns.NBin = tja_binaries[3]; + + ns.EBin1 = tja_binaries[5]; + ns.HBin1 = tja_binaries[6]; + ns.MBin1 = tja_binaries[7]; + ns.NBin1 = tja_binaries[8]; + + ns.EBin2 = tja_binaries[10]; + ns.HBin2 = tja_binaries[11]; + ns.MBin2 = tja_binaries[12]; + ns.NBin2 = tja_binaries[13]; + + + var selectedMusicInfo = LoadedMusicBox.SelectedItem as MusicInfo; + + var mi = (selectedMusicInfo ?? (NewSoundsBox.SelectedItem as NewSongData)?.MusicInfo ?? new MusicInfo()).Clone(); + mi.Id = songName; + mi.UniqueId = id; + ns.MusicInfo = mi; + + var mo = new MusicOrder(); + mo.Id = songName; + mo.UniqueId = id; + ns.MusicOrder = mo; + + var ma = selectedMusicInfo != null ? MusicAttributes.GetByUniqueId(selectedMusicInfo.UniqueId).Clone() : new MusicAttribute(); + ma.Id = songName; + ma.UniqueId = id; + ma.New = true; + ns.MusicAttribute = ma; + + ns.Word = new Word { Key = $"song_{songName}", JapaneseText = tja.Headers.Title }; + ns.WordSub = new Word { Key = $"song_sub_{songName}", JapaneseText = tja.Headers.Subtitle }; + ns.WordDetail = new Word { Key = $"song_detail_{songName}", JapaneseText = tja.Headers.TitleJa }; + + mi.EasyOnpuNum = tja.Courses[0].NotesCount; + mi.NormalOnpuNum = tja.Courses[1].NotesCount; + mi.HardOnpuNum = tja.Courses[2].NotesCount; + mi.ManiaOnpuNum = tja.Courses[3].NotesCount; + + mi.BranchEasy = tja.Courses[0].HasBranches; + mi.BranchNormal = tja.Courses[1].HasBranches; + mi.BranchHard = tja.Courses[2].HasBranches; + mi.BranchMania = tja.Courses[3].HasBranches; + + mi.StarEasy = tja.Courses[0].Headers.Level; + mi.StarNormal = tja.Courses[1].Headers.Level; + mi.StarHard = tja.Courses[2].Headers.Level; + mi.StarMania = tja.Courses[3].Headers.Level; + + if (tja.Courses.ContainsKey(4)) + { + FeedbackBox.AppendText("URA course detected\r\n"); + mi.UraOnpuNum = tja.Courses[4].NotesCount; + mi.StarUra = tja.Courses[4].Headers.Level; + mi.BranchUra = tja.Courses[4].HasBranches; + ma.CanPlayUra = true; + } + else + { + ma.CanPlayUra = false; + } + + FeedbackBox.AppendText("Adjusting shinuti\r\n"); + + mi.ShinutiEasy = (mi.ShinutiScoreEasy / mi.EasyOnpuNum) / 10 * 10; + mi.ShinutiNormal = (mi.ShinutiScoreNormal / mi.NormalOnpuNum) / 10 * 10; + mi.ShinutiHard = (mi.ShinutiScoreHard / mi.HardOnpuNum) / 10 * 10; + mi.ShinutiMania = (mi.ShinutiScoreMania / mi.ManiaOnpuNum) / 10 * 10; + + mi.ShinutiEasyDuet = (mi.ShinutiScoreEasyDuet / mi.EasyOnpuNum) / 10 * 10; + mi.ShinutiNormalDuet = (mi.ShinutiScoreNormalDuet / mi.NormalOnpuNum) / 10 * 10; + mi.ShinutiHardDuet = (mi.ShinutiScoreHardDuet / mi.HardOnpuNum) / 10 * 10; + mi.ShinutiManiaDuet = (mi.ShinutiScoreManiaDuet / mi.ManiaOnpuNum) / 10 * 10; + + if (ma.CanPlayUra) + { + mi.ShinutiScoreUra = 1002320; + mi.ShinutiScoreUraDuet = 1002320; + mi.ShinutiUra = (mi.ShinutiScoreUra / mi.UraOnpuNum) / 10 * 10; + mi.ShinutiUraDuet = (mi.ShinutiScoreUraDuet / mi.UraOnpuNum) / 10 * 10; + } + + if (ma.CanPlayUra) + { + ns.XBin = tja_binaries[4]; + ns.XBin1 = tja_binaries[9]; + ns.XBin2 = tja_binaries[14]; + } + + mi.SongFileName = $"sound/song_{songName}"; + + mi.RendaTimeEasy = 0; + mi.RendaTimeHard = 0; + mi.RendaTimeMania = 0; + mi.RendaTimeNormal = 0; + mi.RendaTimeUra = 0; + mi.FuusenTotalEasy = 0; + mi.FuusenTotalHard = 0; + mi.FuusenTotalMania = 0; + mi.FuusenTotalNormal = 0; + mi.FuusenTotalUra = 0; + + Dictionary genres = new Dictionary + { + { "POP", 0 }, + { "ANIME", 1 }, + { "KIDS", 2 }, + { "VOCALOID", 3 }, + { "GAME MUSIC", 4 }, + { "NAMCO ORIGINAL", 5 }, + }; + + if (tja.Headers.Genre != null && genres.ContainsKey(tja.Headers.Genre.ToUpper())) + mi.GenreNo = genres[tja.Headers.Genre.ToUpper()]; + + FeedbackBox.AppendText("Converting to idsp\r\n"); + IDSP.WavToIdsp($@".-tmp\{songName}.wav", $@".-tmp\{songName}.idsp"); + + var idsp = File.ReadAllBytes($@".-tmp\{songName}.idsp"); + + + FeedbackBox.AppendText("Creating nus3bank file\r\n"); + + ns.Nus3Bank = NUS3Bank.GetNus3Bank(songName, id, idsp, tja.Headers.DemoStart); + + + Logger.Info("Conversion done"); + FeedbackBox.AppendText("Done\r\n"); + + AddedMusic.Add(ns); + AddedMusicBinding.ResetBindings(false); + + NewSoundsBox.ClearSelected(); + NewSoundsBox.SelectedItem = ns; + + TabControl.SelectedIndex = 1; + FeedbackBox.Clear(); + }); + + + private static void CreateTmpDir() + { + Logger.Info($"Creating .-tmp/"); + if (!Directory.Exists(".-tmp")) + Directory.CreateDirectory(".-tmp"); + } + + private static void WarnWithBox(string message) + { + Logger.Warning("Displayed: " + message); + MessageBox.Show(message); + } + } +} diff --git a/MainForm.cs b/MainForm.cs index 9469bcd..e04acdf 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -1,9 +1,5 @@ -using System.ComponentModel; -using System.Diagnostics; -using System.IO; -using System.Text.RegularExpressions; -using System.Threading.Tasks.Dataflow; using TaikoSoundEditor.Data; +using TaikoSoundEditor.Utils; namespace TaikoSoundEditor { @@ -27,144 +23,11 @@ namespace TaikoSoundEditor private void TabControl_SelectedIndexChanged(object sender, EventArgs e) { Logger.Info($"Commuted to tab {TabControl.SelectedIndex}"); - } - - private string MusicAttributePath { get; set; } - private string MusicOrderPath { get; set; } - private string MusicInfoPath { get; set; } - private string WordListPath { get; set; } - - private MusicAttributes MusicAttributes; - private MusicOrders MusicOrders; - private WordList WordList; - private MusicInfos MusicInfos; - private List AddedMusic { get; set; } = new List(); - private BindingSource AddedMusicBinding { get; set; } - - #region Requesting Files - - private void WordListPathSelector_PathChanged(object sender, EventArgs args) - { - Logger.Info($"WordListPathSelector_PathChanged : {WordListPathSelector.Path}"); - WordListPath = WordListPathSelector.Path; - } - - private void MusicInfoPathSelector_PathChanged(object sender, EventArgs args) - { - Logger.Info($"MusicInfoPathSelector_PathChanged : {MusicInfoPathSelector.Path}"); - MusicInfoPath = MusicInfoPathSelector.Path; - } - - private void MusicOrderPathSelector_PathChanged(object sender, EventArgs args) - { - Logger.Info($"MusicOrderPathSelector_PathChanged : {MusicOrderPathSelector.Path}"); - MusicOrderPath = MusicOrderPathSelector.Path; - } - - private void MusicAttributePathSelector_PathChanged(object sender, EventArgs args) - { - Logger.Info($"MusicAttributePathSelector_PathChanged : {MusicAttributePathSelector.Path}"); - MusicAttributePath = MusicAttributePathSelector.Path; - } - - private void DirSelector_PathChanged(object sender, EventArgs args) => RunGuard(() => - { - Logger.Info($"MusicAttributePathSelector_PathChanged : {DirSelector.Path}"); - var dir = DirSelector.Path; - var files = new string[] { "music_attribute.bin", "music_order.bin", "musicinfo.bin", "wordlist.bin" }; - var sels = new PathSelector[] { MusicAttributePathSelector, MusicOrderPathSelector, MusicInfoPathSelector, WordListPathSelector }; - - List NotFoundFiles = new List(); - - for (int i = 0; i < files.Length; i++) - { - var path = Path.Combine(dir, files[i]); - if (!File.Exists(path)) - { - NotFoundFiles.Add(files[i]); - continue; - } - sels[i].Path = path; - } - - if (NotFoundFiles.Count > 0) - { - Logger.Warning("The following files could not be found:\n\n" + String.Join("\n", NotFoundFiles)); - MessageBox.Show("The following files could not be found:\n\n" + String.Join("\n", NotFoundFiles)); - } - }); - - private void OkButton_Click(object sender, EventArgs e) => RunGuard(() => - { - Logger.Info($"Clicked 'Looks good' "); - - try - { - MusicAttributes = Json.Deserialize(GZ.DecompressString(MusicAttributePath)); - } - catch (Exception ex) - { - throw new Exception($"Failed to parse\n{MusicAttributePath}\nReason:\n{ex.InnerException}"); - } - try - { - MusicOrders = Json.Deserialize(GZ.DecompressString(MusicOrderPath)); - } - catch (Exception ex) - { - throw new Exception($"Failed to parse\n{MusicOrderPath}\nReason:\n{ex.InnerException}"); - } - try - { - MusicInfos = Json.Deserialize(GZ.DecompressString(MusicInfoPath)); - } - catch (Exception ex) - { - throw new Exception($"Failed to parse\n{MusicInfoPath}\nReason:\n{ex.InnerException}"); - } - try - { - WordList = Json.Deserialize(GZ.DecompressString(WordListPath)); - } - catch (Exception ex) - { - throw new Exception($"Failed to parse\n{WordListPath}\nReason:\n{ex.InnerException}"); - } - - Logger.Info($"Setting LoadedMusicBox DataSource"); - - LoadedMusicBinding = new BindingSource(); - LoadedMusicBinding.DataSource = MusicInfos.Items.Where(mi => mi.UniqueId != 0).ToList(); - LoadedMusicBox.DataSource = LoadedMusicBinding; - TabControl.SelectedIndex = 1; - }); - - BindingSource LoadedMusicBinding; - - #endregion - - - public static void RunGuard(Action action) - { - try - { - action(); - } - catch (Exception ex) - { - Error(ex); - } - } - - public static void Error(Exception e) - { - MessageBox.Show(e.Message, "An error has occured"); - Logger.Error(e); - } + } #region Editor - private void GridsShow(MusicInfo item) + private void LoadMusicInfo(MusicInfo item) { Logger.Info($"Showing properties for MusicInfo: {item}"); @@ -187,6 +50,19 @@ namespace TaikoSoundEditor WordDetailGrid.SelectedObject = WordList.GetBySongDetail(item.Id); } + private void LoadNewSongData(NewSongData item) + { + Logger.Info($"Selection Changed NewSongData: {item}"); + Logger.Info($"Showing properties for NewSongData: {item}"); + MusicInfoGrid.SelectedObject = item?.MusicInfo; + MusicAttributesGrid.SelectedObject = item?.MusicAttribute; + MusicOrderGrid.SelectedObject = item?.MusicOrder; + WordsGrid.SelectedObject = item?.Word; + WordSubGrid.SelectedObject = item?.WordSub; + WordDetailGrid.SelectedObject = item?.WordDetail; + indexChanging = false; + } + private bool indexChanging = false; private void LoadedMusicBox_SelectedIndexChanged(object sender, EventArgs e) @@ -196,7 +72,7 @@ namespace TaikoSoundEditor NewSoundsBox.SelectedItem = null; var item = LoadedMusicBox.SelectedItem as MusicInfo; Logger.Info($"Selection Changed MusicItem: {item}"); - GridsShow(item); + LoadMusicInfo(item); indexChanging = false; } @@ -211,514 +87,12 @@ namespace TaikoSoundEditor indexChanging = true; LoadedMusicBox.SelectedItem = null; var item = NewSoundsBox.SelectedItem as NewSongData; - Logger.Info($"Selection Changed NewSongData: {item}"); - Logger.Info($"Showing properties for NewSongData: {item}"); - MusicInfoGrid.SelectedObject = item?.MusicInfo; - MusicAttributesGrid.SelectedObject = item?.MusicAttribute; - MusicOrderGrid.SelectedObject = item?.MusicOrder; - WordsGrid.SelectedObject = item?.Word; - WordSubGrid.SelectedObject = item?.WordSub; - WordDetailGrid.SelectedObject = item?.WordDetail; - indexChanging = false; + LoadNewSongData(item); } - #endregion + #endregion - private void CreateButton_Click(object sender, EventArgs e) - { - Logger.Info($"Clicked Create Button"); - AudioFileSelector.Path = ""; - TJASelector.Path = ""; - SongNameBox.Text = "(6 characters id...)"; - TabControl.SelectedIndex = 2; - } - - private void CreateBackButton_Click(object sender, EventArgs e) - { - Logger.Info($"Clicked Back Button"); - TabControl.SelectedIndex = 1; - } - - - private void WarnWithBox(string message) - { - Logger.Warning("Displayed: " + message); - MessageBox.Show(message); - } - - private void CreateOkButton_Click(object sender, EventArgs e) => RunGuard(() => - { - Logger.Info($"Clicked Ok Button"); - FeedbackBox.Clear(); - var audioFilePath = AudioFileSelector.Path; - var tjaPath = TJASelector.Path; - var songName = SongNameBox.Text; - var id = Math.Max(MusicAttributes.GetNewId(), AddedMusic.Count == 0 ? 0 : AddedMusic.Max(_ => _.UniqueId) + 1); - - Logger.Info($"Audio File = {audioFilePath}"); - Logger.Info($"TJA File = {tjaPath}"); - Logger.Info($"Song Name (Id) = {songName}"); - Logger.Info($"UniqueId = {id}"); - - if (songName == null || songName.Length == 0 || songName.Length > 6) - { - WarnWithBox("Invalid song name."); - return; - } - - if (!MusicAttributes.IsValidSongId(songName) || AddedMusic.Any(m => m.Id == songName)) - { - WarnWithBox("Duplicate song name. Choose another"); - return; - } - - FeedbackBox.AppendText("Creating temp dir\r\n"); - - CreateTmpDir(); - - FeedbackBox.AppendText("Parsing TJA\r\n"); - - Logger.Info("Parsing TJA"); - - var tja = TjaEncAuto.Checked ? TJA.ReadDefault(tjaPath) - : TjaEncUTF8.Checked ? TJA.ReadAsUTF8(tjaPath) - : TJA.ReadAsShiftJIS(tjaPath); - - File.WriteAllText("tja.txt", tja.ToString()); - - - var seconds = AddSilenceBox.Checked ? (int)Math.Ceiling(tja.Headers.Offset + (int)SilenceBox.Value) : 0; - if (seconds < 0) seconds = 0; - - - FeedbackBox.AppendText("Converting to wav\r\n"); - WAV.ConvertToWav(audioFilePath, $@".-tmp\{songName}.wav", seconds); - - - Logger.Info("Adjusting seconds of silence"); - tja.Headers.Offset -= seconds; - tja.Headers.DemoStart += seconds; - - var text = File.ReadAllLines(tjaPath); - - text = text.Select(l => - { - if (l.StartsWith("OFFSET:")) - return $"OFFSET:{tja.Headers.Offset:n3}"; - if (l.StartsWith("DEMOSTART:")) - return $"DEMOSTART:{tja.Headers.DemoStart:n3}"; - return l; - }).ToArray(); - - var missingCourses = new int[] { 0, 1, 2, 3 }.Where(i => !tja.Courses.Keys.Contains(i)).ToArray(); - var courseNames = new string[] { "Easy", "Normal", "Hard", "Oni" }; - - if (missingCourses.Length > 0) - { - - var caption = $"There are missing courses in the TJA file for difficulties: {string.Join(", ", missingCourses.Select(i => courseNames[i]))}.\n" + - $"Do you want to add a placeholder for the missing courses?"; - - if (MessageBox.Show(caption, "Warning", MessageBoxButtons.YesNo) == DialogResult.Yes) - { - foreach (var difficulty in missingCourses) - { - text = text.Concat(new string[] - { - "", - $"COURSE:{courseNames[difficulty]}", - "LEVEL:1", - "BALLOON:", - "SCOREINIT:", - "SCOREDIFF:", - "#START", - "1", - "#END" - }).ToArray(); - - tja.Courses[difficulty] = new TJA.Course(difficulty, new TJA.CourseHeader(), new List - { - new TJA.Measure(new int[]{1,1}, new Dictionary(), "1", new List()) - }); - } - } - } - - - Logger.Info("Creating temporary tja"); - var newTja = @$".-tmp\{Path.GetFileName(tjaPath)}"; - File.WriteAllLines(newTja, text); - - - - - FeedbackBox.AppendText("Running tja2fumen\r\n"); - - var tja_binaries = TJA.RunTja2Fumen(newTja); - - Logger.Info("Creating new sonud data"); - FeedbackBox.AppendText("Creating sound data\r\n"); - NewSongData ns = new NewSongData(); - - ns.UniqueId = id; - ns.Id = songName; - - ns.Wav = File.ReadAllBytes($@".-tmp\{songName}.wav"); - ns.EBin = tja_binaries[0]; - ns.HBin = tja_binaries[1]; - ns.MBin = tja_binaries[2]; - ns.NBin = tja_binaries[3]; - - ns.EBin1 = tja_binaries[5]; - ns.HBin1 = tja_binaries[6]; - ns.MBin1 = tja_binaries[7]; - ns.NBin1 = tja_binaries[8]; - - ns.EBin2 = tja_binaries[10]; - ns.HBin2 = tja_binaries[11]; - ns.MBin2 = tja_binaries[12]; - ns.NBin2 = tja_binaries[13]; - - - var selectedMusicInfo = LoadedMusicBox.SelectedItem as MusicInfo; - - var mi = (selectedMusicInfo ?? (NewSoundsBox.SelectedItem as NewSongData)?.MusicInfo ?? new MusicInfo()).Clone(); - mi.Id = songName; - mi.UniqueId = id; - ns.MusicInfo = mi; - - var mo = new MusicOrder(); - mo.Id = songName; - mo.UniqueId = id; - ns.MusicOrder = mo; - - var ma = selectedMusicInfo != null ? MusicAttributes.GetByUniqueId(selectedMusicInfo.UniqueId).Clone() : new MusicAttribute(); - ma.Id = songName; - ma.UniqueId = id; - ma.New = true; - ns.MusicAttribute = ma; - - ns.Word = new Word { Key = $"song_{songName}", JapaneseText = tja.Headers.Title }; - ns.WordSub = new Word { Key = $"song_sub_{songName}", JapaneseText = tja.Headers.Subtitle }; - ns.WordDetail = new Word { Key = $"song_detail_{songName}", JapaneseText = tja.Headers.TitleJa }; - - mi.EasyOnpuNum = tja.Courses[0].NotesCount; - mi.NormalOnpuNum = tja.Courses[1].NotesCount; - mi.HardOnpuNum = tja.Courses[2].NotesCount; - mi.ManiaOnpuNum = tja.Courses[3].NotesCount; - - mi.BranchEasy = tja.Courses[0].HasBranches; - mi.BranchNormal = tja.Courses[1].HasBranches; - mi.BranchHard = tja.Courses[2].HasBranches; - mi.BranchMania = tja.Courses[3].HasBranches; - - mi.StarEasy = tja.Courses[0].Headers.Level; - mi.StarNormal = tja.Courses[1].Headers.Level; - mi.StarHard = tja.Courses[2].Headers.Level; - mi.StarMania = tja.Courses[3].Headers.Level; - - if (tja.Courses.ContainsKey(4)) - { - FeedbackBox.AppendText("URA course detected\r\n"); - mi.UraOnpuNum = tja.Courses[4].NotesCount; - mi.StarUra = tja.Courses[4].Headers.Level; - mi.BranchUra = tja.Courses[4].HasBranches; - ma.CanPlayUra = true; - } - else - { - ma.CanPlayUra = false; - } - - FeedbackBox.AppendText("Adjusting shinuti\r\n"); - - mi.ShinutiEasy = (mi.ShinutiScoreEasy / mi.EasyOnpuNum) / 10 * 10; - mi.ShinutiNormal = (mi.ShinutiScoreNormal / mi.NormalOnpuNum) / 10 * 10; - mi.ShinutiHard = (mi.ShinutiScoreHard / mi.HardOnpuNum) / 10 * 10; - mi.ShinutiMania = (mi.ShinutiScoreMania / mi.ManiaOnpuNum) / 10 * 10; - - mi.ShinutiEasyDuet = (mi.ShinutiScoreEasyDuet / mi.EasyOnpuNum) / 10 * 10; - mi.ShinutiNormalDuet = (mi.ShinutiScoreNormalDuet / mi.NormalOnpuNum) / 10 * 10; - mi.ShinutiHardDuet = (mi.ShinutiScoreHardDuet / mi.HardOnpuNum) / 10 * 10; - mi.ShinutiManiaDuet = (mi.ShinutiScoreManiaDuet / mi.ManiaOnpuNum) / 10 * 10; - - if (ma.CanPlayUra) - { - mi.ShinutiScoreUra = 1002320; - mi.ShinutiScoreUraDuet = 1002320; - mi.ShinutiUra = (mi.ShinutiScoreUra / mi.UraOnpuNum) / 10 * 10; - mi.ShinutiUraDuet = (mi.ShinutiScoreUraDuet / mi.UraOnpuNum) / 10 * 10; - } - - if (ma.CanPlayUra) - { - ns.XBin = tja_binaries[4]; - ns.XBin1 = tja_binaries[9]; - ns.XBin2 = tja_binaries[14]; - } - - mi.SongFileName = $"sound/song_{songName}"; - - mi.RendaTimeEasy = 0; - mi.RendaTimeHard = 0; - mi.RendaTimeMania = 0; - mi.RendaTimeNormal = 0; - mi.RendaTimeUra = 0; - mi.FuusenTotalEasy = 0; - mi.FuusenTotalHard = 0; - mi.FuusenTotalMania = 0; - mi.FuusenTotalNormal = 0; - mi.FuusenTotalUra = 0; - - Dictionary genres = new Dictionary - { - { "POP", 0 }, - { "ANIME", 1 }, - { "KIDS", 2 }, - { "VOCALOID", 3 }, - { "GAME MUSIC", 4 }, - { "NAMCO ORIGINAL", 5 }, - }; - - if (tja.Headers.Genre != null && genres.ContainsKey(tja.Headers.Genre.ToUpper())) - mi.GenreNo = genres[tja.Headers.Genre.ToUpper()]; - - FeedbackBox.AppendText("Converting to idsp\r\n"); - IDSP.WavToIdsp($@".-tmp\{songName}.wav", $@".-tmp\{songName}.idsp"); - - var idsp = File.ReadAllBytes($@".-tmp\{songName}.idsp"); - - - FeedbackBox.AppendText("Creating nus3bank file\r\n"); - - ns.Nus3Bank = NUS3Bank.GetNus3Bank(songName, id, idsp, tja.Headers.DemoStart); - - - Logger.Info("Conversion done"); - FeedbackBox.AppendText("Done\r\n"); - - AddedMusic.Add(ns); - AddedMusicBinding.ResetBindings(false); - - NewSoundsBox.ClearSelected(); - NewSoundsBox.SelectedItem = ns; - - TabControl.SelectedIndex = 1; - FeedbackBox.Clear(); - }); - - private void CreateTmpDir() - { - Logger.Info($"Creating .-tmp/"); - if (!Directory.Exists(".-tmp")) - Directory.CreateDirectory(".-tmp"); - } - - private string JsonFix(string json) - { - var specialChars = "!@#$%^&*()_+=`~[]{}<>\\/'"; - foreach(var c in specialChars) - { - json = json.Replace($"\\u00{((int)c):X2}", $"{c}"); - } - - - return json - .Replace("\\u0022", "\\\"") - .Replace("\r\n ", "\r\n\t\t") - .Replace("\r\n ", "\r\n\t\t") - .Replace("{\r\n \"items\": [", "{\"items\":[") - .Replace(" }", "\t}") - .Replace(" ]\r\n}", "\t]\r\n}"); - } - - private void ExportDatatable(string path) - { - Logger.Info($"Exporting Datatable to '{path}'"); - var mi = new MusicInfos(); - mi.Items.AddRange(MusicInfos.Items); - mi.Items.AddRange(AddedMusic.Select(_ => _.MusicInfo)); - - var ma = new MusicAttributes(); - ma.Items.AddRange(MusicAttributes.Items); - ma.Items.AddRange(AddedMusic.Select(_ => _.MusicAttribute)); - - var mo = new MusicOrders(); - - var mbyg = MusicOrders.Items.GroupBy(_ => _.GenreNo).Select(_ => (_.Key, List: _.ToList())).ToDictionary(_ => _.Key, _ => _.List); - - foreach (var m in AddedMusic.Select(_ => _.MusicOrder)) - { - if (!mbyg.ContainsKey(m.GenreNo)) - mbyg[m.GenreNo] = new List(); - mbyg[m.GenreNo] = mbyg[m.GenreNo].Prepend(m).ToList(); - } - - foreach(var key in mbyg.Keys.OrderBy(_=>_)) - { - mo.Items.AddRange(mbyg[key]); - } - - var wl = new WordList(); - wl.Items.AddRange(WordList.Items); - wl.Items.AddRange(AddedMusic.Select(_ => new List() { _.Word, _.WordSub, _.WordDetail }).SelectMany(_ => _)); - - var jmi = JsonFix(Json.Serialize(mi, !DatatableSpaces.Checked)); - var jma = JsonFix(Json.Serialize(ma)); - var jmo = JsonFix(Json.Serialize(mo)); - var jwl = JsonFix(Json.Serialize(wl, !DatatableSpaces.Checked)); - - jma = jma.Replace("\"new\": true,", "\"new\":true,"); - jma = jma.Replace("\"new\": false,", "\"new\":false,"); - - File.WriteAllText(Path.Combine(path,"musicinfo"), jmi); - File.WriteAllText(Path.Combine(path,"music_attribute"), jma); - File.WriteAllText(Path.Combine(path,"music_order"), jmo); - File.WriteAllText(Path.Combine(path, "wordlist"), jwl); - - GZ.CompressToFile(Path.Combine(path,"musicinfo.bin"), jmi); - GZ.CompressToFile(Path.Combine(path, "music_attribute.bin"), jma); - GZ.CompressToFile(Path.Combine(path, "music_order.bin"), jmo); - GZ.CompressToFile(Path.Combine(path, "wordlist.bin"), jwl); - } - - private void ExportNusBanks(string path) - { - Logger.Info($"Exporting NUS3BaNKS to '{path}'"); - foreach (var ns in AddedMusic) - { - File.WriteAllBytes(Path.Combine(path, $"song_{ns.Id}.nus3bank"), ns.Nus3Bank); - } - } - - private void ExportSoundBinaries(string path) - { - Logger.Info($"Exporting Sound .bin's to '{path}'"); - foreach (var ns in AddedMusic) - { - var sdir = Path.Combine(path, ns.Id); - - if (!Directory.Exists(sdir)) - Directory.CreateDirectory(sdir); - - File.WriteAllBytes(Path.Combine(sdir, $"{ns.Id}_e.bin"), ns.EBin); - File.WriteAllBytes(Path.Combine(sdir, $"{ns.Id}_n.bin"), ns.NBin); - File.WriteAllBytes(Path.Combine(sdir, $"{ns.Id}_h.bin"), ns.HBin); - File.WriteAllBytes(Path.Combine(sdir, $"{ns.Id}_m.bin"), ns.MBin); - - File.WriteAllBytes(Path.Combine(sdir, $"{ns.Id}_e_1.bin"), ns.EBin1); - File.WriteAllBytes(Path.Combine(sdir, $"{ns.Id}_n_1.bin"), ns.NBin1); - File.WriteAllBytes(Path.Combine(sdir, $"{ns.Id}_h_1.bin"), ns.HBin1); - File.WriteAllBytes(Path.Combine(sdir, $"{ns.Id}_m_1.bin"), ns.MBin1); - - File.WriteAllBytes(Path.Combine(sdir, $"{ns.Id}_e_2.bin"), ns.EBin2); - File.WriteAllBytes(Path.Combine(sdir, $"{ns.Id}_n_2.bin"), ns.NBin2); - File.WriteAllBytes(Path.Combine(sdir, $"{ns.Id}_h_2.bin"), ns.HBin2); - File.WriteAllBytes(Path.Combine(sdir, $"{ns.Id}_m_2.bin"), ns.MBin2); - - if(ns.MusicAttribute.CanPlayUra) - { - File.WriteAllBytes(Path.Combine(sdir, $"{ns.Id}_x.bin"), ns.XBin); - File.WriteAllBytes(Path.Combine(sdir, $"{ns.Id}_x_1.bin"), ns.XBin1); - File.WriteAllBytes(Path.Combine(sdir, $"{ns.Id}_x_2.bin"), ns.XBin2); - } - } - } - - - private void ExportDatatableButton_Click(object sender, EventArgs e) => RunGuard(() => - { - Logger.Info($"Clicked ExportDatatableButton"); - var path = PickPath(); - if (path == null) - { - MessageBox.Show("No path chosen. Operation canceled"); - return; - } - ExportDatatable(path); - MessageBox.Show("Done"); - if (ExportOpenOnFinished.Checked) - Process.Start($"explorer.exe", path); - }); - - private void ExportSoundFoldersButton_Click(object sender, EventArgs e) => RunGuard(() => - { - Logger.Info($"Clicked ExportSoundFoldersButton"); - var path = PickPath(); - if (path == null) - { - MessageBox.Show("No path chosen. Operation canceled"); - return; - } - ExportSoundBinaries(path); - MessageBox.Show("Done"); - if (ExportOpenOnFinished.Checked) - Process.Start($"explorer.exe", path); - }); - - private void ExportSoundBanksButton_Click(object sender, EventArgs e) => RunGuard(() => - { - Logger.Info($"Clicked ExportSoundBanksButton"); - var path = PickPath(); - if (path == null) - { - MessageBox.Show("No path chosen. Operation canceled"); - return; - } - ExportNusBanks(path); - MessageBox.Show("Done"); - if (ExportOpenOnFinished.Checked) - Process.Start($"explorer.exe", path); - }); - - private string PickPath() - { - Logger.Info($"Picking path dialog"); - var picker = new FolderPicker(); - if (picker.ShowDialog() == true) - return picker.ResultPath; - return null; - } - - private void ExportAllButton_Click(object sender, EventArgs e) => RunGuard(() => - { - Logger.Info($"Clicked Export All"); - var path = PickPath(); - if (path == null) - { - MessageBox.Show("No path chosen. Operation canceled"); - return; - } - - var dtpath = Path.Combine(path, "datatable"); - if (!Directory.Exists(dtpath)) Directory.CreateDirectory(dtpath); - - var nupath = Path.Combine(path, "sound"); - if (!Directory.Exists(nupath)) Directory.CreateDirectory(nupath); - - var sbpath = Path.Combine(path, "fumen"); - if (!Directory.Exists(sbpath)) Directory.CreateDirectory(sbpath); - - ExportDatatable(dtpath); - ExportSoundBinaries(sbpath); - ExportNusBanks(nupath); - MessageBox.Show("Done"); - if (ExportOpenOnFinished.Checked) - Process.Start($"explorer.exe", path); - - }); - - private void TJASelector_PathChanged(object sender, EventArgs args) - { - if (TJASelector.Path == null) return; - if (SongNameBox.Text != "" && SongNameBox.Text != "(6 characters id...)") return; - - var name = Path.GetFileNameWithoutExtension(TJASelector.Path); - if (name.Length == 6) - SongNameBox.Text = name; - } - - private void RemoveSongButton_Click(object sender, EventArgs e) => RunGuard(() => + private void RemoveSongButton_Click(object sender, EventArgs e) => ExceptionGuard.Run(() => { Logger.Info("Clicked remove song"); if (NewSoundsBox.SelectedItem != null) @@ -753,15 +127,19 @@ namespace TaikoSoundEditor Logger.Info("Removing word detail"); WordList.Items.Remove(wd); - Logger.Info("Refreshing list"); + Logger.Info("Refreshing list"); + LoadedMusicBinding.DataSource = MusicInfos.Items.Where(mi => mi.UniqueId != 0).ToList(); LoadedMusicBinding.ResetBindings(false); + + var sel = LoadedMusicBox.SelectedIndex; + + if (sel >= MusicInfos.Items.Count) + sel = MusicInfos.Items.Count - 1; + + LoadedMusicBox.SelectedItem = null; + LoadedMusicBox.SelectedIndex = sel; return; } - }); - - private void AddSilenceBox_CheckedChanged(object sender, EventArgs e) - { - SilenceBox.Enabled = AddSilenceBox.Checked; - } + }); } } \ No newline at end of file diff --git a/Utils/ExceptionGuard.cs b/Utils/ExceptionGuard.cs new file mode 100644 index 0000000..71cd6be --- /dev/null +++ b/Utils/ExceptionGuard.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TaikoSoundEditor.Utils +{ + internal static class ExceptionGuard + { + public static void Run(Action action) + { + try + { + action(); + } + catch (Exception ex) + { + Error(ex); + } + } + + public static void Error(Exception e) + { + MessageBox.Show(e.Message, "An error occured"); + Logger.Error(e); + } + } +}