First version of the MKV file info serializer engine. Currently unable to balance tags.

This commit is contained in:
2017-08-31 23:45:06 -05:00
parent 1f14137c5b
commit 407a183da4
22 changed files with 302 additions and 131 deletions
+1
View File
@@ -5,3 +5,4 @@ MKVTest/obj
*.mkv
*.txt
MKVTest/.vs
.vs
View File
@@ -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;
}
}
@@ -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());
}
}
}
@@ -58,6 +58,7 @@
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SerializeMkvInfo.cs" />
<Compile Include="XmlTag.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
-80
View File
@@ -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;
}
}
}
+209
View File
@@ -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<String> SerializeFile(string filePath)
{
var file = File.ReadAllLines(filePath);
if (file.Length == 0) return new List<string>();
var lastDepthLevel = 0;
var xml = new StringBuilder();
var stack = new Stack<XmlTag>();
var test = new List<string>();
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 + "</" + t.Name + ">");
// test.Add(t.Value + "</" + t.Name + ">");
//}
if (depth == lastDepthLevel)
{
if (stack.Count != 0)
{
if (!string.IsNullOrEmpty(stack.Peek().Value))
{
var t = stack.Pop();
//xml.Append(t.Value + "</" + t.Name + ">");
test[test.Count - 1] = test[test.Count - 1] + (tag.Value + "</") + tag.Name + ">";
continue;
}
else
{
var t = stack.Pop();
test.Insert(i, padding + "</" + t.Name + ">");
}
}
//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 + "</" + t.Name + ">");
test[test.Count - 1] = test[test.Count - 1] + (tag.Value + "</") + tag.Name + ">";
continue;
}
}
else
{
if (stack.Count != 0 && i != 0)
{
if (!string.IsNullOrEmpty(stack.Peek().Value))
{
var t = stack.Pop();
//xml.Append(t.Value + "</" + t.Name + ">");
test.Add(t.Value + "</" + t.Name + ">");
}
test[test.Count - 1] = test[test.Count - 1] + (tag.Value + "</") + tag.Name + ">";
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;
}
}
}
+15
View File
@@ -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;
}
}