diff --git a/ZipStudio.Core/Manifest.cs b/ZipStudio.Core/Manifest.cs index 7092b9d..b9b5faf 100644 --- a/ZipStudio.Core/Manifest.cs +++ b/ZipStudio.Core/Manifest.cs @@ -14,6 +14,7 @@ public class Manifest { protected XDocument xmlDocument; protected XmlSchemaSet xmlSchemaSet; + protected UTF8Encoding utfEncoding = new UTF8Encoding(true); #region Properties @@ -104,6 +105,11 @@ public string Export() { return xmlDocument.ToString(); } + + public byte[] ExportAsBytes() + { + return utfEncoding.GetBytes(Export()); + } public static bool TryParseManifest(Stream stream, out Manifest manifest) { diff --git a/ZipStudio.Core/Mod.cs b/ZipStudio.Core/Mod.cs index c5ca1b6..d9f032e 100644 --- a/ZipStudio.Core/Mod.cs +++ b/ZipStudio.Core/Mod.cs @@ -9,12 +9,15 @@ namespace ZipStudio.Core { public class Mod : IDisposable { + public string Filename { get; protected set; } + public ZipFile ZipFile { get; protected set; } public Manifest Manifest { get; protected set; } public Mod(string filename) { + Filename = filename; ZipFile = new ZipFile(filename); var manifestentry = ZipFile.Entries.FirstOrDefault(x => x.FileName == "manifest.xml"); @@ -29,6 +32,25 @@ public Mod(string filename) } } + public void Save() + { + Save(Filename); + } + + public void Save(string filename) + { + var manifestentry = ZipFile.Entries.FirstOrDefault(x => x.FileName == "manifest.xml"); + + if (manifestentry != null) + { + ZipFile.RemoveEntry(manifestentry); + } + + ZipFile.AddEntry("manifest.xml", Manifest.ExportAsBytes()); + + ZipFile.Save(filename); + } + public void Dispose() { ZipFile.Dispose(); diff --git a/ZipStudio.sln.DotSettings b/ZipStudio.sln.DotSettings new file mode 100644 index 0000000..e307395 --- /dev/null +++ b/ZipStudio.sln.DotSettings @@ -0,0 +1,2 @@ + + True \ No newline at end of file diff --git a/ZipStudio/formMain.Designer.cs b/ZipStudio/formMain.Designer.cs index f22916a..9955caa 100644 --- a/ZipStudio/formMain.Designer.cs +++ b/ZipStudio/formMain.Designer.cs @@ -36,6 +36,8 @@ private void InitializeComponent() this.tabPage2 = new System.Windows.Forms.TabPage(); this.tabPage3 = new System.Windows.Forms.TabPage(); this.tabPage4 = new System.Windows.Forms.TabPage(); + this.imgLogo = new System.Windows.Forms.PictureBox(); + this.lblVersionInfo = new System.Windows.Forms.Label(); this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -47,16 +49,27 @@ private void InitializeComponent() this.toolsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.importToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.folderToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.lblVersionInfo = new System.Windows.Forms.Label(); - this.imgLogo = new System.Windows.Forms.PictureBox(); + this.txtGUID = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.txtName = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.txtAuthor = new System.Windows.Forms.TextBox(); + this.label4 = new System.Windows.Forms.Label(); + this.txtVersion = new System.Windows.Forms.TextBox(); + this.label5 = new System.Windows.Forms.Label(); + this.txtWebsite = new System.Windows.Forms.TextBox(); + this.label6 = new System.Windows.Forms.Label(); + this.txtDescription = new System.Windows.Forms.TextBox(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); this.splitContainer1.SuspendLayout(); this.tabControl1.SuspendLayout(); + this.tabPage2.SuspendLayout(); this.tabPage4.SuspendLayout(); - this.menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.imgLogo)).BeginInit(); + this.menuStrip1.SuspendLayout(); this.SuspendLayout(); // // splitContainer1 @@ -109,6 +122,18 @@ private void InitializeComponent() // // tabPage2 // + this.tabPage2.Controls.Add(this.label6); + this.tabPage2.Controls.Add(this.txtDescription); + this.tabPage2.Controls.Add(this.label5); + this.tabPage2.Controls.Add(this.txtWebsite); + this.tabPage2.Controls.Add(this.label4); + this.tabPage2.Controls.Add(this.txtVersion); + this.tabPage2.Controls.Add(this.label3); + this.tabPage2.Controls.Add(this.txtAuthor); + this.tabPage2.Controls.Add(this.label2); + this.tabPage2.Controls.Add(this.txtName); + this.tabPage2.Controls.Add(this.label1); + this.tabPage2.Controls.Add(this.txtGUID); this.tabPage2.Location = new System.Drawing.Point(4, 22); this.tabPage2.Name = "tabPage2"; this.tabPage2.Padding = new System.Windows.Forms.Padding(3); @@ -137,6 +162,27 @@ private void InitializeComponent() this.tabPage4.Text = "About"; this.tabPage4.UseVisualStyleBackColor = true; // + // imgLogo + // + this.imgLogo.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.imgLogo.Image = ((System.Drawing.Image)(resources.GetObject("imgLogo.Image"))); + this.imgLogo.Location = new System.Drawing.Point(279, 12); + this.imgLogo.Name = "imgLogo"; + this.imgLogo.Size = new System.Drawing.Size(235, 235); + this.imgLogo.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; + this.imgLogo.TabIndex = 1; + this.imgLogo.TabStop = false; + this.imgLogo.DoubleClick += new System.EventHandler(this.imgLogo_DoubleClick); + // + // lblVersionInfo + // + this.lblVersionInfo.AutoSize = true; + this.lblVersionInfo.Location = new System.Drawing.Point(12, 12); + this.lblVersionInfo.Name = "lblVersionInfo"; + this.lblVersionInfo.Size = new System.Drawing.Size(98, 65); + this.lblVersionInfo.TabIndex = 0; + this.lblVersionInfo.Text = "ZipStudio vX.X.X.X\r\n\r\nCore vX.X.X.X\r\n\r\nBy Bepis"; + // // menuStrip1 // this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -187,12 +233,15 @@ private void InitializeComponent() // // saveToolStripMenuItem // + this.saveToolStripMenuItem.Enabled = false; this.saveToolStripMenuItem.Name = "saveToolStripMenuItem"; this.saveToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.saveToolStripMenuItem.Text = "&Save"; + this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click); // // saveAsToolStripMenuItem // + this.saveAsToolStripMenuItem.Enabled = false; this.saveAsToolStripMenuItem.Name = "saveAsToolStripMenuItem"; this.saveAsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.saveAsToolStripMenuItem.Text = "Save As..."; @@ -216,30 +265,100 @@ private void InitializeComponent() // folderToolStripMenuItem // this.folderToolStripMenuItem.Name = "folderToolStripMenuItem"; - this.folderToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.folderToolStripMenuItem.Size = new System.Drawing.Size(107, 22); this.folderToolStripMenuItem.Text = "Folder"; this.folderToolStripMenuItem.Click += new System.EventHandler(this.folderToolStripMenuItem_Click); // - // lblVersionInfo + // txtGUID // - this.lblVersionInfo.AutoSize = true; - this.lblVersionInfo.Location = new System.Drawing.Point(12, 12); - this.lblVersionInfo.Name = "lblVersionInfo"; - this.lblVersionInfo.Size = new System.Drawing.Size(98, 65); - this.lblVersionInfo.TabIndex = 0; - this.lblVersionInfo.Text = "ZipStudio vX.X.X.X\r\n\r\nCore vX.X.X.X\r\n\r\nBy Bepis"; + this.txtGUID.Location = new System.Drawing.Point(76, 9); + this.txtGUID.Name = "txtGUID"; + this.txtGUID.Size = new System.Drawing.Size(157, 20); + this.txtGUID.TabIndex = 0; // - // imgLogo + // label1 // - this.imgLogo.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.imgLogo.Image = ((System.Drawing.Image)(resources.GetObject("imgLogo.Image"))); - this.imgLogo.Location = new System.Drawing.Point(279, 12); - this.imgLogo.Name = "imgLogo"; - this.imgLogo.Size = new System.Drawing.Size(235, 235); - this.imgLogo.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; - this.imgLogo.TabIndex = 1; - this.imgLogo.TabStop = false; - this.imgLogo.DoubleClick += new System.EventHandler(this.imgLogo_DoubleClick); + this.label1.Location = new System.Drawing.Point(7, 12); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(63, 16); + this.label1.TabIndex = 1; + this.label1.Text = "GUID:"; + // + // label2 + // + this.label2.Location = new System.Drawing.Point(7, 38); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(63, 16); + this.label2.TabIndex = 3; + this.label2.Text = "Name:"; + // + // txtName + // + this.txtName.Location = new System.Drawing.Point(76, 35); + this.txtName.Name = "txtName"; + this.txtName.Size = new System.Drawing.Size(157, 20); + this.txtName.TabIndex = 2; + // + // label3 + // + this.label3.Location = new System.Drawing.Point(7, 64); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(63, 16); + this.label3.TabIndex = 5; + this.label3.Text = "Author:"; + // + // txtAuthor + // + this.txtAuthor.Location = new System.Drawing.Point(76, 61); + this.txtAuthor.Name = "txtAuthor"; + this.txtAuthor.Size = new System.Drawing.Size(157, 20); + this.txtAuthor.TabIndex = 4; + // + // label4 + // + this.label4.Location = new System.Drawing.Point(7, 90); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(63, 16); + this.label4.TabIndex = 7; + this.label4.Text = "Version:"; + // + // txtVersion + // + this.txtVersion.Location = new System.Drawing.Point(76, 87); + this.txtVersion.Name = "txtVersion"; + this.txtVersion.Size = new System.Drawing.Size(157, 20); + this.txtVersion.TabIndex = 6; + // + // label5 + // + this.label5.Location = new System.Drawing.Point(7, 116); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(63, 16); + this.label5.TabIndex = 9; + this.label5.Text = "Website:"; + // + // txtWebsite + // + this.txtWebsite.Location = new System.Drawing.Point(76, 113); + this.txtWebsite.Name = "txtWebsite"; + this.txtWebsite.Size = new System.Drawing.Size(157, 20); + this.txtWebsite.TabIndex = 8; + // + // label6 + // + this.label6.Location = new System.Drawing.Point(7, 142); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(63, 16); + this.label6.TabIndex = 11; + this.label6.Text = "Description:"; + // + // txtDescription + // + this.txtDescription.Location = new System.Drawing.Point(76, 139); + this.txtDescription.Multiline = true; + this.txtDescription.Name = "txtDescription"; + this.txtDescription.Size = new System.Drawing.Size(331, 177); + this.txtDescription.TabIndex = 10; // // formMain // @@ -257,11 +376,13 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); this.splitContainer1.ResumeLayout(false); this.tabControl1.ResumeLayout(false); + this.tabPage2.ResumeLayout(false); + this.tabPage2.PerformLayout(); this.tabPage4.ResumeLayout(false); this.tabPage4.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.imgLogo)).EndInit(); this.menuStrip1.ResumeLayout(false); this.menuStrip1.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.imgLogo)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -289,6 +410,18 @@ private void InitializeComponent() private System.Windows.Forms.TreeView trvZip; private System.Windows.Forms.PictureBox imgLogo; private System.Windows.Forms.Label lblVersionInfo; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.TextBox txtDescription; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.TextBox txtWebsite; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.TextBox txtVersion; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.TextBox txtAuthor; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.TextBox txtName; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox txtGUID; } } diff --git a/ZipStudio/formMain.cs b/ZipStudio/formMain.cs index 7f3f39a..6b77bfa 100644 --- a/ZipStudio/formMain.cs +++ b/ZipStudio/formMain.cs @@ -25,6 +25,10 @@ public Mod CurrentMod { currentMod = value; UpdateModDetails(); + SetManifestDatabinds(value.Manifest); + + saveToolStripMenuItem.Enabled = true; + saveAsToolStripMenuItem.Enabled = true; } } @@ -40,6 +44,7 @@ private void UpdateModDetails() public formMain() { InitializeComponent(); + InitBindings(); } private void openToolStripMenuItem_Click(object sender, EventArgs e) @@ -47,7 +52,6 @@ private void openToolStripMenuItem_Click(object sender, EventArgs e) OpenFileDialog dialog = new OpenFileDialog { Filter = "Compressed folders (*.zip)|*.zip", - }; if (dialog.ShowDialog() != DialogResult.OK) @@ -56,6 +60,15 @@ private void openToolStripMenuItem_Click(object sender, EventArgs e) CurrentMod = new Mod(dialog.FileName); } + private void saveToolStripMenuItem_Click(object sender, EventArgs e) + { + if (currentMod == null) + return; + + WriteToBindingManifest(); + currentMod.Save(); + } + private void folderToolStripMenuItem_Click(object sender, EventArgs e) { if (Importer.ImportFromDirectory(out Mod mod, out string message)) @@ -94,5 +107,34 @@ private void imgLogo_DoubleClick(object sender, EventArgs e) } #endregion + + #region Manifest Databinding + + private BindingSource manifestSource = new BindingSource(); + + private void InitBindings() + { + manifestSource = new BindingSource(); + manifestSource.DataSource = typeof(Manifest); + + txtGUID.DataBindings.Add(nameof(Label.Text), manifestSource, nameof(Manifest.Guid)); + txtName.DataBindings.Add(nameof(Label.Text), manifestSource, nameof(Manifest.Name)); + txtVersion.DataBindings.Add(nameof(Label.Text), manifestSource, nameof(Manifest.Version)); + txtAuthor.DataBindings.Add(nameof(Label.Text), manifestSource, nameof(Manifest.Author)); + txtWebsite.DataBindings.Add(nameof(Label.Text), manifestSource, nameof(Manifest.Website)); + txtDescription.DataBindings.Add(nameof(Label.Text), manifestSource, nameof(Manifest.Description)); + } + + private void SetManifestDatabinds(Manifest manifest) + { + manifestSource.DataSource = manifest; + } + + private void WriteToBindingManifest() + { + manifestSource.EndEdit(); + } + + #endregion } }