From 407a183da45e551b61eb028e7bdd4e6b10be0b63 Mon Sep 17 00:00:00 2001 From: Garritt McCune Date: Thu, 31 Aug 2017 23:45:06 -0500 Subject: [PATCH] First version of the MKV file info serializer engine. Currently unable to balance tags. --- MKVTest/.gitignore => .gitignore | 3 +- MKVTest/MKVTest.sln => MKVTest.sln | 0 MKVTest/{MKVTest => }/App.config | 0 MKVTest/{MKVTest => }/Form1.Designer.cs | 118 +++++----- MKVTest/{MKVTest => }/Form1.cs | 7 + MKVTest/{MKVTest => }/Form1.resx | 0 MKVTest/{MKVTest => }/MKVTest.csproj | 1 + MKVTest/MKVTest/SerializeMkvInfo.cs | 80 ------- MKVTest/{MKVTest => }/MkvFile.cs | 0 MKVTest/{MKVTest => }/MkvFileInfo.cs | 0 .../{MKVTest => }/MkvSegmentInformation.cs | 0 MKVTest/{MKVTest => }/MkvTrack.cs | 0 MKVTest/{MKVTest => }/Program.cs | 0 .../{MKVTest => }/Properties/AssemblyInfo.cs | 0 .../Properties/Resources.Designer.cs | 0 .../{MKVTest => }/Properties/Resources.resx | 0 .../Properties/Settings.Designer.cs | 0 .../Properties/Settings.settings | 0 MKVTest/SerializeMkvInfo.cs | 209 ++++++++++++++++++ MKVTest/XmlTag.cs | 15 ++ MKVTest/{MKVTest => }/mkvinfo.exe | Bin MKVTest/{MKVTest => }/mkvpropedit.exe | Bin 22 files changed, 302 insertions(+), 131 deletions(-) rename MKVTest/.gitignore => .gitignore (77%) rename MKVTest/MKVTest.sln => MKVTest.sln (100%) rename MKVTest/{MKVTest => }/App.config (100%) rename MKVTest/{MKVTest => }/Form1.Designer.cs (83%) rename MKVTest/{MKVTest => }/Form1.cs (95%) rename MKVTest/{MKVTest => }/Form1.resx (100%) rename MKVTest/{MKVTest => }/MKVTest.csproj (99%) delete mode 100644 MKVTest/MKVTest/SerializeMkvInfo.cs rename MKVTest/{MKVTest => }/MkvFile.cs (100%) rename MKVTest/{MKVTest => }/MkvFileInfo.cs (100%) rename MKVTest/{MKVTest => }/MkvSegmentInformation.cs (100%) rename MKVTest/{MKVTest => }/MkvTrack.cs (100%) rename MKVTest/{MKVTest => }/Program.cs (100%) rename MKVTest/{MKVTest => }/Properties/AssemblyInfo.cs (100%) rename MKVTest/{MKVTest => }/Properties/Resources.Designer.cs (100%) rename MKVTest/{MKVTest => }/Properties/Resources.resx (100%) rename MKVTest/{MKVTest => }/Properties/Settings.Designer.cs (100%) rename MKVTest/{MKVTest => }/Properties/Settings.settings (100%) create mode 100644 MKVTest/SerializeMkvInfo.cs create mode 100644 MKVTest/XmlTag.cs rename MKVTest/{MKVTest => }/mkvinfo.exe (100%) rename MKVTest/{MKVTest => }/mkvpropedit.exe (100%) diff --git a/MKVTest/.gitignore b/.gitignore similarity index 77% rename from MKVTest/.gitignore rename to .gitignore index b5c1ce4..48cdbb6 100644 --- a/MKVTest/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ MKVTest/bin MKVTest/obj *.mkv *.txt -MKVTest/.vs \ No newline at end of file +MKVTest/.vs +.vs \ No newline at end of file diff --git a/MKVTest/MKVTest.sln b/MKVTest.sln similarity index 100% rename from MKVTest/MKVTest.sln rename to MKVTest.sln diff --git a/MKVTest/MKVTest/App.config b/MKVTest/App.config similarity index 100% rename from MKVTest/MKVTest/App.config rename to MKVTest/App.config diff --git a/MKVTest/MKVTest/Form1.Designer.cs b/MKVTest/Form1.Designer.cs similarity index 83% rename from MKVTest/MKVTest/Form1.Designer.cs rename to MKVTest/Form1.Designer.cs index d656758..1f95ee9 100644 --- a/MKVTest/MKVTest/Form1.Designer.cs +++ b/MKVTest/Form1.Designer.cs @@ -36,24 +36,25 @@ this.selectFileMainMenu = new System.Windows.Forms.ToolStripMenuItem(); this.inputFilesListView = new System.Windows.Forms.ListView(); this.detailsGroupBox = new System.Windows.Forms.GroupBox(); - this.buttonPanel = new System.Windows.Forms.Panel(); - this.applyChangesButton = new System.Windows.Forms.Button(); this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); this.currentTitleLabel = new System.Windows.Forms.Label(); + this.buttonPanel = new System.Windows.Forms.Panel(); + this.applyChangesButton = new System.Windows.Forms.Button(); + this.debugToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.tableLayoutPanel1.SuspendLayout(); this.mainMenuStrip.SuspendLayout(); this.detailsGroupBox.SuspendLayout(); - this.buttonPanel.SuspendLayout(); this.flowLayoutPanel1.SuspendLayout(); + this.buttonPanel.SuspendLayout(); this.SuspendLayout(); // // selectFolderButton // this.selectFolderButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.selectFolderButton.Location = new System.Drawing.Point(2, 8); - this.selectFolderButton.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.selectFolderButton.Location = new System.Drawing.Point(4, 12); + this.selectFolderButton.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.selectFolderButton.Name = "selectFolderButton"; - this.selectFolderButton.Size = new System.Drawing.Size(80, 29); + this.selectFolderButton.Size = new System.Drawing.Size(147, 54); this.selectFolderButton.TabIndex = 1; this.selectFolderButton.Text = "Select Folder"; this.selectFolderButton.UseVisualStyleBackColor = true; @@ -71,15 +72,16 @@ this.tableLayoutPanel1.Controls.Add(this.buttonPanel, 2, 4); this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); + this.tableLayoutPanel1.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); this.tableLayoutPanel1.Name = "tableLayoutPanel1"; this.tableLayoutPanel1.RowCount = 5; - this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 55F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 25.08529F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 37.45736F)); this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 37.45736F)); - this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 43F)); - this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); - this.tableLayoutPanel1.Size = new System.Drawing.Size(560, 401); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 79F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 37F)); + this.tableLayoutPanel1.Size = new System.Drawing.Size(1027, 740); this.tableLayoutPanel1.TabIndex = 2; // // mainMenuStrip @@ -87,10 +89,12 @@ this.tableLayoutPanel1.SetColumnSpan(this.mainMenuStrip, 3); this.mainMenuStrip.ImageScalingSize = new System.Drawing.Size(28, 28); this.mainMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.fileMainMenu}); + this.fileMainMenu, + this.debugToolStripMenuItem}); this.mainMenuStrip.Location = new System.Drawing.Point(0, 0); this.mainMenuStrip.Name = "mainMenuStrip"; - this.mainMenuStrip.Size = new System.Drawing.Size(560, 24); + this.mainMenuStrip.Padding = new System.Windows.Forms.Padding(11, 4, 0, 4); + this.mainMenuStrip.Size = new System.Drawing.Size(1027, 42); this.mainMenuStrip.TabIndex = 2; this.mainMenuStrip.Text = "menuStrip1"; // @@ -100,19 +104,19 @@ this.openFolderFileMainMenu, this.selectFileMainMenu}); this.fileMainMenu.Name = "fileMainMenu"; - this.fileMainMenu.Size = new System.Drawing.Size(37, 20); + this.fileMainMenu.Size = new System.Drawing.Size(56, 34); this.fileMainMenu.Text = "&File"; // // openFolderFileMainMenu // this.openFolderFileMainMenu.Name = "openFolderFileMainMenu"; - this.openFolderFileMainMenu.Size = new System.Drawing.Size(139, 22); + this.openFolderFileMainMenu.Size = new System.Drawing.Size(218, 34); this.openFolderFileMainMenu.Text = "&Open Folder"; // // selectFileMainMenu // this.selectFileMainMenu.Name = "selectFileMainMenu"; - this.selectFileMainMenu.Size = new System.Drawing.Size(139, 22); + this.selectFileMainMenu.Size = new System.Drawing.Size(218, 34); this.selectFileMainMenu.Text = "&Select File"; // // inputFilesListView @@ -120,10 +124,11 @@ this.tableLayoutPanel1.SetColumnSpan(this.inputFilesListView, 2); this.inputFilesListView.Dock = System.Windows.Forms.DockStyle.Fill; this.inputFilesListView.LabelWrap = false; - this.inputFilesListView.Location = new System.Drawing.Point(3, 33); + this.inputFilesListView.Location = new System.Drawing.Point(6, 61); + this.inputFilesListView.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); this.inputFilesListView.Name = "inputFilesListView"; this.tableLayoutPanel1.SetRowSpan(this.inputFilesListView, 4); - this.inputFilesListView.Size = new System.Drawing.Size(330, 365); + this.inputFilesListView.Size = new System.Drawing.Size(603, 673); this.inputFilesListView.TabIndex = 3; this.inputFilesListView.UseCompatibleStateImageBehavior = false; this.inputFilesListView.View = System.Windows.Forms.View.Details; @@ -132,65 +137,77 @@ // this.detailsGroupBox.Controls.Add(this.flowLayoutPanel1); this.detailsGroupBox.Dock = System.Windows.Forms.DockStyle.Fill; - this.detailsGroupBox.Location = new System.Drawing.Point(339, 33); + this.detailsGroupBox.Location = new System.Drawing.Point(621, 61); + this.detailsGroupBox.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); this.detailsGroupBox.Name = "detailsGroupBox"; + this.detailsGroupBox.Padding = new System.Windows.Forms.Padding(6, 6, 6, 6); this.tableLayoutPanel1.SetRowSpan(this.detailsGroupBox, 3); - this.detailsGroupBox.Size = new System.Drawing.Size(218, 320); + this.detailsGroupBox.Size = new System.Drawing.Size(400, 592); this.detailsGroupBox.TabIndex = 5; this.detailsGroupBox.TabStop = false; this.detailsGroupBox.Text = "Details"; // - // buttonPanel - // - this.buttonPanel.Controls.Add(this.applyChangesButton); - this.buttonPanel.Controls.Add(this.selectFolderButton); - this.buttonPanel.Dock = System.Windows.Forms.DockStyle.Fill; - this.buttonPanel.Location = new System.Drawing.Point(339, 359); - this.buttonPanel.Name = "buttonPanel"; - this.buttonPanel.Size = new System.Drawing.Size(218, 39); - this.buttonPanel.TabIndex = 8; - // - // applyChangesButton - // - this.applyChangesButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.applyChangesButton.Enabled = false; - this.applyChangesButton.Location = new System.Drawing.Point(112, 7); - this.applyChangesButton.Name = "applyChangesButton"; - this.applyChangesButton.Size = new System.Drawing.Size(102, 29); - this.applyChangesButton.TabIndex = 2; - this.applyChangesButton.Text = "Apply Changes"; - this.applyChangesButton.UseVisualStyleBackColor = true; - this.applyChangesButton.Click += new System.EventHandler(this.applyChangesButton_Click); - // // flowLayoutPanel1 // this.flowLayoutPanel1.Controls.Add(this.currentTitleLabel); this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; this.flowLayoutPanel1.FlowDirection = System.Windows.Forms.FlowDirection.TopDown; - this.flowLayoutPanel1.Location = new System.Drawing.Point(3, 16); + this.flowLayoutPanel1.Location = new System.Drawing.Point(6, 28); + this.flowLayoutPanel1.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); this.flowLayoutPanel1.Name = "flowLayoutPanel1"; - this.flowLayoutPanel1.Size = new System.Drawing.Size(212, 301); + this.flowLayoutPanel1.Size = new System.Drawing.Size(388, 558); this.flowLayoutPanel1.TabIndex = 0; // // currentTitleLabel // this.currentTitleLabel.AutoSize = true; - this.currentTitleLabel.Location = new System.Drawing.Point(2, 0); - this.currentTitleLabel.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.currentTitleLabel.Location = new System.Drawing.Point(4, 0); + this.currentTitleLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.currentTitleLabel.Name = "currentTitleLabel"; - this.currentTitleLabel.Size = new System.Drawing.Size(67, 13); + this.currentTitleLabel.Size = new System.Drawing.Size(125, 25); this.currentTitleLabel.TabIndex = 11; this.currentTitleLabel.Text = "Current Title:"; // + // buttonPanel + // + this.buttonPanel.Controls.Add(this.applyChangesButton); + this.buttonPanel.Controls.Add(this.selectFolderButton); + this.buttonPanel.Dock = System.Windows.Forms.DockStyle.Fill; + this.buttonPanel.Location = new System.Drawing.Point(621, 665); + this.buttonPanel.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); + this.buttonPanel.Name = "buttonPanel"; + this.buttonPanel.Size = new System.Drawing.Size(400, 69); + this.buttonPanel.TabIndex = 8; + // + // applyChangesButton + // + this.applyChangesButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.applyChangesButton.Enabled = false; + this.applyChangesButton.Location = new System.Drawing.Point(205, 10); + this.applyChangesButton.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); + this.applyChangesButton.Name = "applyChangesButton"; + this.applyChangesButton.Size = new System.Drawing.Size(187, 54); + this.applyChangesButton.TabIndex = 2; + this.applyChangesButton.Text = "Apply Changes"; + this.applyChangesButton.UseVisualStyleBackColor = true; + this.applyChangesButton.Click += new System.EventHandler(this.applyChangesButton_Click); + // + // debugToolStripMenuItem + // + this.debugToolStripMenuItem.Name = "debugToolStripMenuItem"; + this.debugToolStripMenuItem.Size = new System.Drawing.Size(87, 34); + this.debugToolStripMenuItem.Text = "Debug"; + this.debugToolStripMenuItem.Click += new System.EventHandler(this.debugToolStripMenuItem_Click); + // // Form1 // this.AcceptButton = this.selectFolderButton; - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleDimensions = new System.Drawing.SizeF(11F, 24F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(560, 401); + this.ClientSize = new System.Drawing.Size(1027, 740); this.Controls.Add(this.tableLayoutPanel1); this.MainMenuStrip = this.mainMenuStrip; - this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.Name = "Form1"; this.Text = "Form1"; this.tableLayoutPanel1.ResumeLayout(false); @@ -198,9 +215,9 @@ this.mainMenuStrip.ResumeLayout(false); this.mainMenuStrip.PerformLayout(); this.detailsGroupBox.ResumeLayout(false); - this.buttonPanel.ResumeLayout(false); this.flowLayoutPanel1.ResumeLayout(false); this.flowLayoutPanel1.PerformLayout(); + this.buttonPanel.ResumeLayout(false); this.ResumeLayout(false); } @@ -218,6 +235,7 @@ private System.Windows.Forms.Button applyChangesButton; private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1; private System.Windows.Forms.Label currentTitleLabel; + private System.Windows.Forms.ToolStripMenuItem debugToolStripMenuItem; } } diff --git a/MKVTest/MKVTest/Form1.cs b/MKVTest/Form1.cs similarity index 95% rename from MKVTest/MKVTest/Form1.cs rename to MKVTest/Form1.cs index 90b8a55..81c4611 100644 --- a/MKVTest/MKVTest/Form1.cs +++ b/MKVTest/Form1.cs @@ -234,5 +234,12 @@ namespace MKVTest flowLayoutPanel1.Controls.Clear(); flowLayoutPanel1.Invalidate(); } + + private void debugToolStripMenuItem_Click(object sender, EventArgs e) + { + var s = new SerializeMkvInfo(); + var xml = s.SerializeFile("C:\\Users\\Crypto\\Documents\\Source Control\\mkvbatcheditor\\MKVTest\\info.txt"); + File.WriteAllLines("C:\\Users\\Crypto\\Desktop\\1234Testing.txt", xml.ToArray()); + } } } diff --git a/MKVTest/MKVTest/Form1.resx b/MKVTest/Form1.resx similarity index 100% rename from MKVTest/MKVTest/Form1.resx rename to MKVTest/Form1.resx diff --git a/MKVTest/MKVTest/MKVTest.csproj b/MKVTest/MKVTest.csproj similarity index 99% rename from MKVTest/MKVTest/MKVTest.csproj rename to MKVTest/MKVTest.csproj index 0b23721..0459be7 100644 --- a/MKVTest/MKVTest/MKVTest.csproj +++ b/MKVTest/MKVTest.csproj @@ -58,6 +58,7 @@ + Form1.cs diff --git a/MKVTest/MKVTest/SerializeMkvInfo.cs b/MKVTest/MKVTest/SerializeMkvInfo.cs deleted file mode 100644 index 8fc6461..0000000 --- a/MKVTest/MKVTest/SerializeMkvInfo.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MKVTest -{ - class SerializeMkvInfo - { - - public string Serialize(string filePath) - { - var file = File.ReadAllLines(filePath); - var depth = 0; - - foreach (var line in file) - { - - } - } - - private string - - private int GetDepth(string line) - { - var depth = -1; - - for (var i = 0; i < line.Length; i++) - { - if (char.IsPunctuation(line[i]) || char.IsWhiteSpace(line[i])) - { - depth++; - } - else - { - break; - } - } - - return depth; - } - - private bool IsClusterHead(string data) - { - var isClusterHeader = false; - - switch (data) - { - case "EBML head": - - break; - case "Chapters": - - break; - case "Segment": - - break; - case "Segment information": - - break; - case "Segment tracks": - - break; - case "A track": - - break; - case "Video track": - - break; - case "Audio track": - - break; - } - - return isClusterHeader; - } - } -} diff --git a/MKVTest/MKVTest/MkvFile.cs b/MKVTest/MkvFile.cs similarity index 100% rename from MKVTest/MKVTest/MkvFile.cs rename to MKVTest/MkvFile.cs diff --git a/MKVTest/MKVTest/MkvFileInfo.cs b/MKVTest/MkvFileInfo.cs similarity index 100% rename from MKVTest/MKVTest/MkvFileInfo.cs rename to MKVTest/MkvFileInfo.cs diff --git a/MKVTest/MKVTest/MkvSegmentInformation.cs b/MKVTest/MkvSegmentInformation.cs similarity index 100% rename from MKVTest/MKVTest/MkvSegmentInformation.cs rename to MKVTest/MkvSegmentInformation.cs diff --git a/MKVTest/MKVTest/MkvTrack.cs b/MKVTest/MkvTrack.cs similarity index 100% rename from MKVTest/MKVTest/MkvTrack.cs rename to MKVTest/MkvTrack.cs diff --git a/MKVTest/MKVTest/Program.cs b/MKVTest/Program.cs similarity index 100% rename from MKVTest/MKVTest/Program.cs rename to MKVTest/Program.cs diff --git a/MKVTest/MKVTest/Properties/AssemblyInfo.cs b/MKVTest/Properties/AssemblyInfo.cs similarity index 100% rename from MKVTest/MKVTest/Properties/AssemblyInfo.cs rename to MKVTest/Properties/AssemblyInfo.cs diff --git a/MKVTest/MKVTest/Properties/Resources.Designer.cs b/MKVTest/Properties/Resources.Designer.cs similarity index 100% rename from MKVTest/MKVTest/Properties/Resources.Designer.cs rename to MKVTest/Properties/Resources.Designer.cs diff --git a/MKVTest/MKVTest/Properties/Resources.resx b/MKVTest/Properties/Resources.resx similarity index 100% rename from MKVTest/MKVTest/Properties/Resources.resx rename to MKVTest/Properties/Resources.resx diff --git a/MKVTest/MKVTest/Properties/Settings.Designer.cs b/MKVTest/Properties/Settings.Designer.cs similarity index 100% rename from MKVTest/MKVTest/Properties/Settings.Designer.cs rename to MKVTest/Properties/Settings.Designer.cs diff --git a/MKVTest/MKVTest/Properties/Settings.settings b/MKVTest/Properties/Settings.settings similarity index 100% rename from MKVTest/MKVTest/Properties/Settings.settings rename to MKVTest/Properties/Settings.settings diff --git a/MKVTest/SerializeMkvInfo.cs b/MKVTest/SerializeMkvInfo.cs new file mode 100644 index 0000000..0e94b41 --- /dev/null +++ b/MKVTest/SerializeMkvInfo.cs @@ -0,0 +1,209 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MKVTest +{ + internal class SerializeMkvInfo + { + + public List SerializeFile(string filePath) + { + var file = File.ReadAllLines(filePath); + if (file.Length == 0) return new List(); + var lastDepthLevel = 0; + var xml = new StringBuilder(); + var stack = new Stack(); + var test = new List(); + for (var i = 0; i < file.Length; i++) + { + var depth = GetDepth(file[i]); + var tag = CreateTagFromString(file[i]); + var padding = new StringBuilder(); + for (var j = depth; j != 0; j--) + { + padding.Append(" "); + } + + //xml.Append(padding + "<" + tag.Name + ">" + tag.Value == string.Empty ? Environment.NewLine : string.Empty); + test.Add(padding + "<" + tag.Name + ">"); + //if (stack.Count != 0) + //{ + // var t = stack.Pop(); + // //xml.Append(t.Value + ""); + // test.Add(t.Value + ""); + //} + if (depth == lastDepthLevel) + { + if (stack.Count != 0) + { + if (!string.IsNullOrEmpty(stack.Peek().Value)) + { + var t = stack.Pop(); + //xml.Append(t.Value + ""); + test[test.Count - 1] = test[test.Count - 1] + (tag.Value + ""; + continue; + } + else + { + var t = stack.Pop(); + test.Insert(i, padding + ""); + } + } + + //xml.Append("<" + tag.Name + ">"); + //test.Add("<" + tag.Name + ">"); + } + else if (depth < lastDepthLevel) + { + //Moving up + if (stack.Count != 0) + { + var t = stack.Pop(); + //xml.Append(t.Value + ""); + test[test.Count - 1] = test[test.Count - 1] + (tag.Value + ""; + continue; + } + + } + else + { + if (stack.Count != 0 && i != 0) + { + if (!string.IsNullOrEmpty(stack.Peek().Value)) + { + var t = stack.Pop(); + //xml.Append(t.Value + ""); + test.Add(t.Value + ""); + } + test[test.Count - 1] = test[test.Count - 1] + (tag.Value + ""; + continue; + } + } + stack.Push(tag); + lastDepthLevel = depth; + } + + + return test; + } + + private XmlTag CreateTagFromString(string text, XmlTag parent = null) + { + var tag = new XmlTag(); + var clearingPadding = true; + var foundDelimiter = false; + var name = new StringBuilder(); + var value = new StringBuilder(); + + for (var i = 0; i < text.Length; i++) + { + if ((char.IsSymbol(text[i]) || char.IsPunctuation(text[i]) || char.IsWhiteSpace(text[i])) && clearingPadding) + { + continue; + } + + if (text[i].ToString() == ":" && !foundDelimiter) + { + foundDelimiter = true; + continue; + } + + clearingPadding = false; + if (foundDelimiter) + { + value.Append(text[i]); + } + else + { + name.Append(text[i]); + } + } + + tag.Name = FormatTagName(name.ToString()); + tag.Value = value.ToString().Trim(); + tag.Parent = parent; + + return tag; + } + + private string FormatTagName(string text) + { + var name = new StringBuilder(); + var previousCharWasWhiteSpace = false; + + foreach (var c in text) + { + if (!char.IsWhiteSpace(c)) + { + name.Append(previousCharWasWhiteSpace ? char.ToUpper(c) : c); + previousCharWasWhiteSpace = false; + } + + if (char.IsWhiteSpace(c)) + { + previousCharWasWhiteSpace = true; + } + } + + return name.ToString(); + } + + private int GetDepth(string line) + { + var depth = 0; + + for (var i = 0; i < line.Length; i++) + { + if (char.IsPunctuation(line[i]) || char.IsWhiteSpace(line[i]) || char.IsSymbol(line[i])) + { + depth++; + } + else + { + break; + } + } + + return depth; + } + + private bool IsClusterHead(string data) + { + var isClusterHeader = false; + + switch (data) + { + case "EBML head": + + break; + case "Chapters": + + break; + case "Segment": + + break; + case "Segment information": + + break; + case "Segment tracks": + + break; + case "A track": + + break; + case "Video track": + + break; + case "Audio track": + + break; + } + + return isClusterHeader; + } + } +} diff --git a/MKVTest/XmlTag.cs b/MKVTest/XmlTag.cs new file mode 100644 index 0000000..f23b381 --- /dev/null +++ b/MKVTest/XmlTag.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MKVTest +{ + class XmlTag + { + public string Name; + public string Value; + public XmlTag Parent; + } +} diff --git a/MKVTest/MKVTest/mkvinfo.exe b/MKVTest/mkvinfo.exe similarity index 100% rename from MKVTest/MKVTest/mkvinfo.exe rename to MKVTest/mkvinfo.exe diff --git a/MKVTest/MKVTest/mkvpropedit.exe b/MKVTest/mkvpropedit.exe similarity index 100% rename from MKVTest/MKVTest/mkvpropedit.exe rename to MKVTest/mkvpropedit.exe