Skip to content

Commit

Permalink
Add manifest editing to GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
bbepis committed May 22, 2018
1 parent 4d7ce7e commit 8230a15
Show file tree
Hide file tree
Showing 5 changed files with 228 additions and 23 deletions.
6 changes: 6 additions & 0 deletions ZipStudio.Core/Manifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class Manifest
{
protected XDocument xmlDocument;
protected XmlSchemaSet xmlSchemaSet;
protected UTF8Encoding utfEncoding = new UTF8Encoding(true);

#region Properties

Expand Down Expand Up @@ -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)
{
Expand Down
22 changes: 22 additions & 0 deletions ZipStudio.Core/Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions ZipStudio.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/CodeAnnotations/NamespacesWithAnnotations/=ZipStudio_002EAnnotations/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
177 changes: 155 additions & 22 deletions ZipStudio/formMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 43 additions & 1 deletion ZipStudio/formMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public Mod CurrentMod
{
currentMod = value;
UpdateModDetails();
SetManifestDatabinds(value.Manifest);

saveToolStripMenuItem.Enabled = true;
saveAsToolStripMenuItem.Enabled = true;
}
}

Expand All @@ -40,14 +44,14 @@ private void UpdateModDetails()
public formMain()
{
InitializeComponent();
InitBindings();
}

private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog
{
Filter = "Compressed folders (*.zip)|*.zip",

};

if (dialog.ShowDialog() != DialogResult.OK)
Expand All @@ -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))
Expand Down Expand Up @@ -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
}
}

0 comments on commit 8230a15

Please sign in to comment.