Skip to content

Commit

Permalink
Fix to drag drop exception when Options not opened
Browse files Browse the repository at this point in the history
Some poor logic uses the OptionsForm controls for settings which doesn't
work when the form hasn't been opened previously. Made a change (fixes
#7).

Also changed the default app.config settings (fixes #6).
  • Loading branch information
ForkandBeard committed Aug 25, 2015
1 parent cce6259 commit 4eee6ef
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 40 deletions.
3 changes: 2 additions & 1 deletion ASU/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
<add key="ThirdPartyImageConverterCommandArgsExportFormat" value="-out {text} -overwrite -quiet -D {file_name}"/>
<add key="ThirdPartyImageConverterCommandArgsConvertImportToBitmap" value="-out bmp -overwrite -quiet -D {temp}"/>
<add key="SuppressThirdPartyImageConverterWarningMessage" value="false"/>
<add key="PromptForDestinationFolder" value="true"/>
<add key="PromptForDestinationFolder" value="false"/>
<add key="AutoOpenDestinationFolder" value="true"/>
<add key="PreservePallette" value="false"/>
<add key="TileOutlineWidth" value="2"/>
<add key="DistanceBetweenFrames" value="3"/>
<add key="ExportedOptionsFileFormat" value="png"/>
Expand Down
4 changes: 2 additions & 2 deletions ASU/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("16.0.0.0")]
[assembly: AssemblyFileVersion("16.0.0.0")]
[assembly: AssemblyVersion("17.0.0.0")]
[assembly: AssemblyFileVersion("17.0.0.0")]
75 changes: 38 additions & 37 deletions ASU/UI/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ private List<Rectangle> Boxes
private static string ThirdPartyImageConverterPath;
public static bool PromptForDestinationFolder = true;
public static bool AutoOpenDestinationFolder = true;

public static bool MakeBackgroundTransparent = true;
public static bool PreservePallette = false;

private System.Threading.Timer multipleUnpackerTimer;
#endregion
Expand All @@ -66,6 +66,41 @@ public MainForm()
this.InitializeComponent();
}

private void MainForm_Load(object sender, System.EventArgs e)
{
try
{
this.SuppressThirdPartyWarningMessage = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["SuppressThirdPartyImageConverterWarningMessage"]);
this.ExportLocationTextBox.Text = AppDomain.CurrentDomain.BaseDirectory;
this.KeyPreview = true;
ThirdPartyImageConverterPath = System.Configuration.ConfigurationManager.AppSettings["ThirdPartyImageConverter"];

if (ThirdPartyImageConverterPath.StartsWith("\\"))
{
ThirdPartyImageConverterPath = AppDomain.CurrentDomain.BaseDirectory + ThirdPartyImageConverterPath;
}
AutoOpenDestinationFolder = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["AutoOpenDestinationFolder"]);
PromptForDestinationFolder = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["PromptForDestinationFolder"]);
Outline.Width = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TileOutlineWidth"]);
DistanceBetweenTiles = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["DistanceBetweenFrames"]);
MakeBackgroundTransparent = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["ExportedOptionsMakeBackgroundTransparent"]);
PreservePallette = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["PreservePallette"]);

Dictionary<string, System.Drawing.Imaging.ImageFormat> formats = new Dictionary<string, System.Drawing.Imaging.ImageFormat>();
formats.Add("png", System.Drawing.Imaging.ImageFormat.Png);
formats.Add("bmp", System.Drawing.Imaging.ImageFormat.Bmp);
formats.Add("gif", System.Drawing.Imaging.ImageFormat.Gif);
formats.Add("tiff", System.Drawing.Imaging.ImageFormat.Tiff);
formats.Add("jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);
formats.Add("jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
ExportFormat = formats[System.Configuration.ConfigurationManager.AppSettings["ExportedOptionsFileFormat"].Replace(".", "").ToLower()];
}
catch (Exception ex)
{
ForkandBeard.Logic.ExceptionHandler.HandleException(ex, "[email protected]");
}
}

private List<BO.ImageUnpacker> unpackers = new List<BO.ImageUnpacker>();
private void CreateUnpacker(Bitmap image, string fileName)
{
Expand All @@ -83,7 +118,7 @@ private void CreateUnpacker(Bitmap image, string fileName)

this.ZoomPanel.Visible = false;

unpacker = new BO.ImageUnpacker(image, fileName, MakeBackgroundTransparent && !this.Options.PreservePalletteCheckBox.Checked);
unpacker = new BO.ImageUnpacker(image, fileName, MakeBackgroundTransparent && !PreservePallette);
this.unpackers.Add(unpacker);
}

Expand Down Expand Up @@ -386,40 +421,6 @@ private void frmMain_FormClosing(object sender, System.Windows.Forms.FormClosing
}
}

private void MainForm_Load(object sender, System.EventArgs e)
{
try
{
this.SuppressThirdPartyWarningMessage = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["SuppressThirdPartyImageConverterWarningMessage"]);
this.ExportLocationTextBox.Text = AppDomain.CurrentDomain.BaseDirectory;
this.KeyPreview = true;
ThirdPartyImageConverterPath = System.Configuration.ConfigurationManager.AppSettings["ThirdPartyImageConverter"];

if (ThirdPartyImageConverterPath.StartsWith("\\"))
{
ThirdPartyImageConverterPath = AppDomain.CurrentDomain.BaseDirectory + ThirdPartyImageConverterPath;
}
AutoOpenDestinationFolder = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["AutoOpenDestinationFolder"]);
PromptForDestinationFolder = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["PromptForDestinationFolder"]);
Outline.Width = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TileOutlineWidth"]);
DistanceBetweenTiles = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["DistanceBetweenFrames"]);
MakeBackgroundTransparent = Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["ExportedOptionsMakeBackgroundTransparent"]);

Dictionary<string, System.Drawing.Imaging.ImageFormat> formats = new Dictionary<string, System.Drawing.Imaging.ImageFormat>();
formats.Add("png", System.Drawing.Imaging.ImageFormat.Png);
formats.Add("bmp", System.Drawing.Imaging.ImageFormat.Bmp);
formats.Add("gif", System.Drawing.Imaging.ImageFormat.Gif);
formats.Add("tiff", System.Drawing.Imaging.ImageFormat.Tiff);
formats.Add("jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);
formats.Add("jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
ExportFormat = formats[System.Configuration.ConfigurationManager.AppSettings["ExportedOptionsFileFormat"].Replace(".", "").ToLower()];
}
catch (Exception ex)
{
ForkandBeard.Logic.ExceptionHandler.HandleException(ex, "[email protected]");
}
}

private void MainPanel_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
object dropped = null;
Expand Down Expand Up @@ -1026,7 +1027,7 @@ private void ExportUnpackers(List<BO.ImageUnpacker> unpackers)
objGraphics.Dispose();
}

if (this.Options != null && this.Options.PreservePalletteCheckBox.Checked)
if (PreservePallette)
{
if (unpacker.GetPallette() != null)
{
Expand Down
3 changes: 3 additions & 0 deletions ASU/UI/OptionsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ private void OptionsForm_Load(object sender, System.EventArgs e)
this.HoverColourPanel.BackColor = MainForm.HoverFill.Color;
this.DistanceBetweenTilesUpDown.Value = MainForm.DistanceBetweenTiles;
this.OutlineWidthUpDown.Value = Convert.ToDecimal(MainForm.Outline.Width);
this.PreservePalletteCheckBox.Checked = MainForm.PreservePallette;

if (MainForm.ExportFormat != null)
{
this.ExportFormatComboBox.SelectedItem = MainForm.ExportFormat;
Expand Down Expand Up @@ -96,6 +98,7 @@ private void CloseButton_Click(System.Object sender, System.EventArgs e)
MainForm.PromptForDestinationFolder = this.PromptDestinationFolderCheckBox.Checked;
MainForm.AutoOpenDestinationFolder = this.OpenExportedDestinationCheckBox.Checked;
MainForm.MakeBackgroundTransparent = this.ExportBGTransparentCheckBox.Checked;
MainForm.PreservePallette = this.PreservePalletteCheckBox.Checked;

if (this.ExportFormatComboBox.Text != STR_ADVANCED_EXPORT_FILE_FORMAT)
{
Expand Down

0 comments on commit 4eee6ef

Please sign in to comment.