Changeset - 64ee51b8084a
[Not reviewed]
default
0 5 0
Jason Maltzen (jmaltzen) - 9 years ago 2015-12-25 06:56:42
jason.maltzen@unsanctioned.net
Add import/export profile functions
5 files changed with 123 insertions and 7 deletions:
0 comments (0 inline, 0 general)
DesertPaintLab.csproj
Show inline comments
...
 
@@ -41,4 +41,5 @@
 
    <Reference Include="pango-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
 
    <Reference Include="atk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
 
    <Reference Include="System.IO.Compression.FileSystem" />
 
  </ItemGroup>
 
  <ItemGroup>
MainWindow.cs
Show inline comments
...
 
@@ -325,5 +325,5 @@ public partial class MainWindow : Gtk.Wi
 
						if (profileSelected)
 
						{
 
							profile.Import(directory);
 
							profile.ImportFromPP(directory);
 
						}
 
					}
...
 
@@ -755,5 +755,5 @@ 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();
...
 
@@ -791,4 +791,87 @@ public partial class MainWindow : Gtk.Wi
 
        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();
 
    }
 
}
 

	
PlayerProfile.cs
Show inline comments
...
 
@@ -23,4 +23,5 @@
 
using System;
 
using System.IO;
 
using System.IO.Compression;
 
using System.Collections.Generic;
 
using System.Text.RegularExpressions;
...
 
@@ -241,5 +242,5 @@ namespace DesertPaintLab
 
		}
 
		
 
		public void Import(string importDir)
 
		public void ImportFromPP(string importDir)
 
		{
 
			// Convert old file.
...
 
@@ -261,7 +262,12 @@ namespace DesertPaintLab
 
		}
 
		
 
        public void Import(string file)
 
        {
 
            ZipFile.ExtractToDirectory(file, directory);
 
        }
 

 
		public void Export(string file)
 
		{
 
			SaveToPP(file);
 
            ZipFile.CreateFromDirectory(directory, file);
 
		}
 
		
gtk-gui/MainWindow.cs
Show inline comments
...
 
@@ -34,4 +34,8 @@ public partial class MainWindow
 
	private global::Gtk.Action IngredientsAction;
 
	
 
	private global::Gtk.Action ExportProfileAction;
 
	
 
	private global::Gtk.Action ImportProfileAction;
 
	
 
	private global::Gtk.VBox vbox1;
 
	
...
 
@@ -140,4 +144,10 @@ public partial class MainWindow
 
		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);
...
 
@@ -149,5 +159,5 @@ public partial class MainWindow
 
		this.vbox1.Name = "vbox1";
 
		// Container child vbox1.Gtk.Box+BoxChild
 
		this.UIManager.AddUiFromString ("<ui><menubar name='menubar1'><menu name='FileAction' action='FileAction'><menuitem name='NewProfileAction' action='NewProfileAction'/><menuitem name='OpenProfileAction' action='OpenProfileAction'/><menuitem name='ExportForPracticalPaintAction' action='ExportForPracticalPaintAction'/><separator/><menuitem name='ExitAction' action='ExitAction'/></menu><menu name='WindowAction' action='WindowAction'><menuitem name='RunSimulatorAction' action='RunSimulatorAction'/><menuitem name='RecipesAction' action='RecipesAction'/><menuitem name='IngredientsAction' action='IngredientsAction'/></menu><menu name='HelpAction' action='HelpAction'><menuitem name='AboutAction' action='AboutAction'/><menuitem name='ReactionStatusAction' action='ReactionStatusAction'/></menu><menu name='DebugAction' action='DebugAction'><menuitem name='ScreenshotAction' action='ScreenshotAction'/></menu></menubar></ui>");
 
		this.UIManager.AddUiFromString ("<ui><menubar name='menubar1'><menu name='FileAction' action='FileAction'><menuitem name='NewProfileAction' action='NewProfileAction'/><menuitem name='OpenProfileAction' action='OpenProfileAction'/><menuitem name='ExportForPracticalPaintAction' action='ExportForPracticalPaintAction'/><menuitem name='ExportProfileAction' action='ExportProfileAction'/><menuitem name='ImportProfileAction' action='ImportProfileAction'/><separator/><menuitem name='ExitAction' action='ExitAction'/></menu><menu name='WindowAction' action='WindowAction'><menuitem name='RunSimulatorAction' action='RunSimulatorAction'/><menuitem name='RecipesAction' action='RecipesAction'/><menuitem name='IngredientsAction' action='IngredientsAction'/></menu><menu name='HelpAction' action='HelpAction'><menuitem name='AboutAction' action='AboutAction'/><menuitem name='ReactionStatusAction' action='ReactionStatusAction'/></menu><menu name='DebugAction' action='DebugAction'><menuitem name='ScreenshotAction' action='ScreenshotAction'/></menu></menubar></ui>");
 
		this.menubar1 = ((global::Gtk.MenuBar)(this.UIManager.GetWidget ("/menubar1")));
 
		this.menubar1.Name = "menubar1";
...
 
@@ -383,4 +393,6 @@ public partial class MainWindow
 
		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);
gtk-gui/gui.stetic
Show inline comments
...
 
@@ -7,5 +7,5 @@
 
  <import>
 
    <widget-library name="glade-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
 
    <widget-library name="../bin/Release/DesertPaintLab.exe" internal="true" />
 
    <widget-library name="../bin/Debug/DesertPaintLab.exe" internal="true" />
 
  </import>
 
  <widget class="Gtk.Window" id="MainWindow" design-size="629 265">
...
 
@@ -97,4 +97,16 @@
 
        <signal name="Activated" handler="OnShowIngredients" />
 
      </action>
 
      <action id="ExportProfileAction">
 
        <property name="Type">Action</property>
 
        <property name="Label" translatable="yes">Export Profile</property>
 
        <property name="ShortLabel" translatable="yes">Export Profile</property>
 
        <signal name="Activated" handler="OnExportProfile" />
 
      </action>
 
      <action id="ImportProfileAction">
 
        <property name="Type">Action</property>
 
        <property name="Label" translatable="yes">Import Profile</property>
 
        <property name="ShortLabel" translatable="yes">Import Profile</property>
 
        <signal name="Activated" handler="OnImportProfile" />
 
      </action>
 
    </action-group>
 
    <property name="MemberName" />
...
 
@@ -113,4 +125,6 @@
 
                <node type="Menuitem" action="OpenProfileAction" />
 
                <node type="Menuitem" action="ExportForPracticalPaintAction" />
 
                <node type="Menuitem" action="ExportProfileAction" />
 
                <node type="Menuitem" action="ImportProfileAction" />
 
                <node type="Separator" />
 
                <node type="Menuitem" action="ExitAction" />
...
 
@@ -1177,5 +1191,5 @@ You can either import an existing Practi
 
          <widget class="Gtk.MenuBar" id="menubar1">
 
            <property name="MemberName" />
 
            <node name="__gtksharp_64_Stetic_Editor_ActionMenuBar" type="Menubar">
 
            <node name="menubar1" type="Menubar">
 
              <node type="Menu" action="ExportAction">
 
                <node type="Menuitem" action="ExportToWikiAction" />
0 comments (0 inline, 0 general)