diff --git a/DesertPaintLab.csproj b/DesertPaintLab.csproj --- a/DesertPaintLab.csproj +++ b/DesertPaintLab.csproj @@ -40,6 +40,7 @@ + diff --git a/MainWindow.cs b/MainWindow.cs --- a/MainWindow.cs +++ b/MainWindow.cs @@ -324,7 +324,7 @@ public partial class MainWindow : Gtk.Wi profileSelected = NewProfile(); if (profileSelected) { - profile.Import(directory); + profile.ImportFromPP(directory); } } } @@ -754,7 +754,7 @@ public partial class MainWindow : Gtk.Wi { string fileName = fileDialog.Filename; string directory = fileDialog.CurrentFolder; - profile.Export(System.IO.Path.Combine(directory, fileName)); + profile.SaveToPP(System.IO.Path.Combine(directory, fileName)); } fileDialog.Destroy(); } @@ -790,5 +790,88 @@ public partial class MainWindow : Gtk.Wi ReagentWindow win = new ReagentWindow(profile); win.Show(); } + + protected void OnExportProfile(object sender, EventArgs e) + { + FileChooserDialog fileDialog = + new FileChooserDialog("Select destination file.", + this, FileChooserAction.Save, + Gtk.Stock.Cancel, ResponseType.Cancel, + Gtk.Stock.Save, ResponseType.Accept); + ResponseType resp = (ResponseType)fileDialog.Run(); + if (resp == ResponseType.Accept) + { + string fileName = fileDialog.Filename; + string directory = fileDialog.CurrentFolder; + string targetFile = System.IO.Path.Combine(directory, fileName); + if (File.Exists(targetFile)) + { + // prompt to overwrite + MessageDialog md = new MessageDialog(this, + DialogFlags.DestroyWithParent, + MessageType.Warning, ButtonsType.OkCancel, + "Overwrite profile at" + + targetFile + "?"); + + resp = (ResponseType)md.Run(); + md.Destroy(); + if (resp == ResponseType.Ok) + { + File.Delete(targetFile); + profile.Export(targetFile); + } + } + else + { + profile.Export(targetFile); + } + } + fileDialog.Destroy(); + } + + protected void OnImportProfile(object sender, EventArgs e) + { + FileChooserDialog fileDialog = + new FileChooserDialog("Select file to import.", + this, FileChooserAction.Open, + Gtk.Stock.Cancel, ResponseType.Cancel, + Gtk.Stock.Open, ResponseType.Accept); + ResponseType resp = (ResponseType)fileDialog.Run(); + if (resp == ResponseType.Accept) + { + string fileName = fileDialog.Filename; + string directory = fileDialog.CurrentFolder; + string targetFile = fileName; + if (directory != null) + { + targetFile = System.IO.Path.Combine(directory, fileName); + } + if (Directory.Exists(profile.Directory)) + { + // prompt to overwrite + MessageDialog md = new MessageDialog(this, + DialogFlags.DestroyWithParent, + MessageType.Warning, ButtonsType.OkCancel, + "Overwrite profile at" + + targetFile + "?"); + + resp = (ResponseType)md.Run(); + md.Destroy(); + if (resp == ResponseType.Ok) + { + Directory.Delete(profile.Directory, true); + profile.Import(targetFile); + } + } + else + { + profile.Import(targetFile); + } + profile.Load(); + PopulateDropDowns(); + recipe.Reactions = profile.Reactions; + } + fileDialog.Destroy(); + } } diff --git a/PlayerProfile.cs b/PlayerProfile.cs --- a/PlayerProfile.cs +++ b/PlayerProfile.cs @@ -22,6 +22,7 @@ using System; using System.IO; +using System.IO.Compression; using System.Collections.Generic; using System.Text.RegularExpressions; @@ -240,7 +241,7 @@ namespace DesertPaintLab return true; } - public void Import(string importDir) + public void ImportFromPP(string importDir) { // Convert old file. ConvertFromPP( @@ -260,9 +261,14 @@ namespace DesertPaintLab } } + public void Import(string file) + { + ZipFile.ExtractToDirectory(file, directory); + } + public void Export(string file) { - SaveToPP(file); + ZipFile.CreateFromDirectory(directory, file); } public void Load() diff --git a/gtk-gui/MainWindow.cs b/gtk-gui/MainWindow.cs --- a/gtk-gui/MainWindow.cs +++ b/gtk-gui/MainWindow.cs @@ -33,6 +33,10 @@ public partial class MainWindow private global::Gtk.Action IngredientsAction; + private global::Gtk.Action ExportProfileAction; + + private global::Gtk.Action ImportProfileAction; + private global::Gtk.VBox vbox1; private global::Gtk.MenuBar menubar1; @@ -139,6 +143,12 @@ public partial class MainWindow this.IngredientsAction = new global::Gtk.Action ("IngredientsAction", "Ingredients", null, null); this.IngredientsAction.ShortLabel = "Ingredients"; w1.Add (this.IngredientsAction, null); + this.ExportProfileAction = new global::Gtk.Action ("ExportProfileAction", "Export Profile", null, null); + this.ExportProfileAction.ShortLabel = "Export Profile"; + w1.Add (this.ExportProfileAction, null); + this.ImportProfileAction = new global::Gtk.Action ("ImportProfileAction", "Import Profile", null, null); + this.ImportProfileAction.ShortLabel = "Import Profile"; + w1.Add (this.ImportProfileAction, null); this.UIManager.InsertActionGroup (w1, 0); this.AddAccelGroup (this.UIManager.AccelGroup); this.Name = "MainWindow"; @@ -148,7 +158,7 @@ public partial class MainWindow this.vbox1 = new global::Gtk.VBox (); this.vbox1.Name = "vbox1"; // Container child vbox1.Gtk.Box+BoxChild - this.UIManager.AddUiFromString (""); + this.UIManager.AddUiFromString (""); this.menubar1 = ((global::Gtk.MenuBar)(this.UIManager.GetWidget ("/menubar1"))); this.menubar1.Name = "menubar1"; this.vbox1.Add (this.menubar1); @@ -382,6 +392,8 @@ public partial class MainWindow this.RecipesAction.Activated += new global::System.EventHandler (this.OnOpenRecipeGenerator); this.ReactionStatusAction.Activated += new global::System.EventHandler (this.OnShowReactionStatus); this.IngredientsAction.Activated += new global::System.EventHandler (this.OnShowIngredients); + this.ExportProfileAction.Activated += new global::System.EventHandler (this.OnExportProfile); + this.ImportProfileAction.Activated += new global::System.EventHandler (this.OnImportProfile); this.ingredient1ComboBox.Changed += new global::System.EventHandler (this.OnChangedIngredient1); this.ingredient2ComboBox.Changed += new global::System.EventHandler (this.OnChangedIngredient2); this.ingredient3ComboBox.Changed += new global::System.EventHandler (this.OnChangedIngredient3); diff --git a/gtk-gui/gui.stetic b/gtk-gui/gui.stetic --- a/gtk-gui/gui.stetic +++ b/gtk-gui/gui.stetic @@ -6,7 +6,7 @@ - + @@ -96,6 +96,18 @@ Ingredients + + Action + Export Profile + Export Profile + + + + Action + Import Profile + Import Profile + + Desert Paint Lab @@ -112,6 +124,8 @@ + + @@ -1176,7 +1190,7 @@ You can either import an existing Practi - +