Skip to content

Commit

Permalink
Fix varius compatibility issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
Si13n7 committed Jan 15, 2020
1 parent 25bd68c commit 8b3622c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 73 deletions.
2 changes: 1 addition & 1 deletion src/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
</startup>
<userSettings>
<ImageToIcon.Properties.Settings>
Expand Down
12 changes: 9 additions & 3 deletions src/ImageToIcon.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<SuppressLegacyCodeAnalysisDeprecatedWarning>true</SuppressLegacyCodeAnalysisDeprecatedWarning>
</PropertyGroup>
<PropertyGroup>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProjectGuid>{80F4A31D-BB95-4ED1-95CE-E1057389BEF8}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>ImageToIcon</RootNamespace>
<AssemblyName>ImageToIcon</AssemblyName>
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile />
Expand Down Expand Up @@ -43,8 +49,8 @@
<StartupObject>ImageToIcon.Program</StartupObject>
</PropertyGroup>
<ItemGroup>
<Reference Include="SilDev.CSharpLib">
<HintPath>..\..\SilDev.CSharpLib\bin\SilDev.CSharpLib.dll</HintPath>
<Reference Include="SilDev.CSharpLib32">
<HintPath>..\refs\SilDev\CSharpLib\bin\SilDev.CSharpLib32.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
Expand Down
94 changes: 29 additions & 65 deletions src/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,12 @@ private void OpenBtn_Click(object sender, EventArgs e) =>

private void SaveBtn_Click(object sender, EventArgs e)
{
using (var dialog = new SaveFileDialog { FileName = _fileName, Filter = @"Icon files (*.ico)|*.ico" })
{
if (dialog.ShowDialog() != DialogResult.OK)
return;
var images = ImgPanel.Controls.Cast<Control>().Select(x => (Image)x.BackgroundImage.Clone());
IconEx.Factory.Save(images, dialog.FileName);
MessageBoxEx.Show(this, "File successfully saved!", Text, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
using var dialog = new SaveFileDialog { FileName = _fileName, Filter = @"Icon files (*.ico)|*.ico" };
if (dialog.ShowDialog() != DialogResult.OK)
return;
var images = ImgPanel.Controls.Cast<Control>().Select(x => (Image)x.BackgroundImage.Clone());
IconFactory.Save(images, dialog.FileName);
MessageBoxEx.Show(this, "File successfully saved!", Text, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}

private void UpdateImages(Image image)
Expand All @@ -63,7 +61,7 @@ private void UpdateImages(Image image)

var draw = image;
var size = image.Width;
var sizes = GetSizes();
var sizes = IconFactory.GetSizes(Extended.Checked ? IconFactorySizeOption.Additional : IconFactorySizeOption.Application);
var images = sizes.Where(x => size >= x).Select(x => draw.Redraw(x, x));

SuspendLayout();
Expand Down Expand Up @@ -94,7 +92,7 @@ private void UpdateImages(Image image)
return;
label.BackgroundImage = !newBgImg.Size.Equals(label.Size) ? newBgImg.Redraw(label.Width, label.Height) : newBgImg;
};
ControlEx.DrawBorder(label, color, ControlEx.BorderStyle.Dashed);
ControlEx.DrawBorder(label, color, ControlExBorderStyle.Dashed);
ImgPanel.Controls.Add(label);
}
ImgPanel.ResumeLayout();
Expand All @@ -105,64 +103,30 @@ private void UpdateImages(Image image)

private Image OpenImageFileDialog()
{
using (var dialog = new OpenFileDialog { CheckFileExists = true, CheckPathExists = true, Multiselect = false })
using var dialog = new OpenFileDialog { CheckFileExists = true, CheckPathExists = true, Multiselect = false };
var imageEncoders = ImageCodecInfo.GetImageEncoders();
var extensions = new List<string>();
for (var i = 0; i < imageEncoders.Length; i++)
{
var imageEncoders = ImageCodecInfo.GetImageEncoders();
var extensions = new List<string>();
for (var i = 0; i < imageEncoders.Length; i++)
{
extensions.Add(imageEncoders[i].FilenameExtension.ToLower());
var description = imageEncoders[i].CodecName.Substring(8).Replace("Codec", "Files").Trim();
var pattern = extensions[extensions.Count - 1];
dialog.Filter = string.Format("{0}{1}{2} ({3})|{3}", dialog.Filter, i > 0 ? "|" : string.Empty, description, pattern);
}
dialog.Filter = string.Format("{0}|Image Files ({1})|{1}", dialog.Filter, extensions.Join(";"));
dialog.FilterIndex = imageEncoders.Length + 1;
if (dialog.ShowDialog(this) != DialogResult.OK)
return default(Image);
try
{
var bmp = new Bitmap(dialog.FileName);
_fileName = Path.GetFileNameWithoutExtension(dialog.FileName);
return bmp;
}
catch
{
return null;
}
extensions.Add(imageEncoders[i].FilenameExtension.ToLower());
var description = imageEncoders[i].CodecName.Substring(8).Replace("Codec", "Files").Trim();
var pattern = extensions[extensions.Count - 1];
dialog.Filter = string.Format("{0}{1}{2} ({3})|{3}", dialog.Filter, i > 0 ? "|" : string.Empty, description, pattern);
}
}

private IEnumerable<int> GetSizes()
{
if (Extended.Checked)
return new[]
{
256,
128,
96,
64,
48,
40,
32,
24,
22,
20,
16,
14,
10,
8
};
return new[]
dialog.Filter = string.Format("{0}|Image Files ({1})|{1}", dialog.Filter, extensions.Join(";"));
dialog.FilterIndex = imageEncoders.Length + 1;
if (dialog.ShowDialog(this) != DialogResult.OK)
return default;
try
{
256,
128,
64,
48,
32,
24,
16
};
var bmp = new Bitmap(dialog.FileName);
_fileName = Path.GetFileNameWithoutExtension(dialog.FileName);
return bmp;
}
catch (Exception ex) when (ex.IsCaught())
{
return null;
}
}
}
}
6 changes: 3 additions & 3 deletions src/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Si13n7 Dev.™")]
[assembly: AssemblyProduct("ImageToIcon")]
[assembly: AssemblyCopyright("Copyright © Si13n7 Dev.™ 2019")]
[assembly: AssemblyCopyright("Copyright © Si13n7 Dev.™ 2020")]
[assembly: AssemblyTrademark("Si13n7 Dev.™")]
[assembly: AssemblyCulture("")]

Expand All @@ -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("19.4.29.0")]
[assembly: AssemblyFileVersion("19.4.29.0")]
[assembly: AssemblyVersion("20.1.15.0")]
[assembly: AssemblyFileVersion("20.1.15.0")]
2 changes: 1 addition & 1 deletion src/Properties/Resources.Designer.cs

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

0 comments on commit 8b3622c

Please sign in to comment.