Now can import images as icons

As an extension to what was requested, you can now import any images and use those as the shortcut image (including the desktop image!). This amazing new functionality now makes it possible to make your shortcuts look exactly as you want them!
This commit is contained in:
Terry MacDonald 2021-11-05 16:28:58 +13:00
parent ccba5cac40
commit 9e91e0fd45
11 changed files with 350 additions and 353 deletions

View File

@ -151,11 +151,11 @@
<Compile Include="UIForms\LoadingForm.Designer.cs">
<DependentUpon>LoadingForm.cs</DependentUpon>
</Compile>
<Compile Include="UIForms\ChooseIconForm.cs">
<Compile Include="UIForms\ChooseImageForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="UIForms\ChooseIconForm.Designer.cs">
<DependentUpon>ChooseIconForm.cs</DependentUpon>
<Compile Include="UIForms\ChooseImageForm.Designer.cs">
<DependentUpon>ChooseImageForm.cs</DependentUpon>
</Compile>
<Compile Include="UIForms\ProfileSettingsForm.cs">
<SubType>Form</SubType>
@ -195,6 +195,7 @@
<Compile Include="UIForms\StartProgramControl.Designer.cs">
<DependentUpon>StartProgramControl.cs</DependentUpon>
</Compile>
<Compile Include="Utils.cs" />
<Compile Include="Validators.cs" />
<Compile Include="InterProcess\IPCClient.cs" />
<Compile Include="InterProcess\InstanceStatus.cs" />
@ -235,8 +236,8 @@
<DependentUpon>MainForm.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="UIForms\ChooseIconForm.resx">
<DependentUpon>ChooseIconForm.cs</DependentUpon>
<EmbeddedResource Include="UIForms\ChooseImageForm.resx">
<DependentUpon>ChooseImageForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="UIForms\ProfileSettingsForm.resx">
<DependentUpon>ProfileSettingsForm.cs</DependentUpon>
@ -357,6 +358,7 @@
</None>
</ItemGroup>
<ItemGroup>
<None Include="Resources\x.png" />
<None Include="Resources\winwhite.png" />
<None Include="Resources\winblack.png" />
<None Include="Resources\Steam.png" />

View File

@ -143,225 +143,6 @@ namespace DisplayMagician
return newBitmap;
}
public static Bitmap GetMeABitmapFromFile(string fileNameAndPath)
{
if (String.IsNullOrWhiteSpace(fileNameAndPath))
{
logger.Warn($"ShortcutItem/GetMeABitmapFromFile: Bitmap fileNameAndPath is empty! Unable to get the icon from the file.");
return null;
}
Icon myIcon = null;
Bitmap bm = null;
Bitmap bmToReturn = new Bitmap(1, 1);
if (fileNameAndPath.EndsWith(".ico"))
{
try
{
logger.Trace($"ShortcutItem/GetMeABitmapFromFile: The file we want to get the image from is an icon file. Attempting to extract the icon file from {fileNameAndPath}.");
myIcon = new Icon(fileNameAndPath, 256, 256);
//Icon myIcon = Icon.ExtractAssociatedIcon(fileNameAndPath);
bm = myIcon.ToBitmap();
//myIcon = Icon.ExtractAssociatedIcon(fileNameAndPath);
//bm = myIcon.ToBitmap();
if (bm.Width > bmToReturn.Width && bm.Height > bmToReturn.Height)
{
bmToReturn = bm;
logger.Trace($"ShortcutItem/GetMeABitmapFromFile: New bitmap from the icon file {fileNameAndPath} using standard Icon access method is larger than the previous one at {bm.Width} x {bm.Height}, so using that instead.");
}
else
{
logger.Trace($"ShortcutItem/GetMeABitmapFromFile: New bitmap from the icon file {fileNameAndPath} using standard Icon access method is smaller or the same size as the previous one at {bm.Width} x {bm.Height}, so using that instead.");
}
}
catch (Exception ex)
{
logger.Warn(ex, $"ShortcutItem/GetMeABitmapFromFile: Exception while trying to extract the icon from a *.ico using Standard Icon tools.");
}
try
{
MultiIcon myMultiIcon = new MultiIcon();
SingleIcon mySingleIcon = myMultiIcon.Add("Icon1");
//mySingleIcon.Load(fileNameAndPath, IconOutputFormat.All);
mySingleIcon.Load(fileNameAndPath);
foreach (IconImage myIconImage in mySingleIcon)
{
bm = myIconImage.Image;
if (bm.Width > bmToReturn.Width && bm.Height > bmToReturn.Height)
{
bmToReturn = bm;
logger.Trace($"ShortcutItem/GetMeABitmapFromFile: New bitmap from the icon file {fileNameAndPath} using MultiIcon access method is larger than the previous one at {bm.Width} x {bm.Height}, so using that instead.");
}
else
{
logger.Trace($"ShortcutItem/GetMeABitmapFromFile: New bitmap from the icon file {fileNameAndPath} using MultiIcon access method is smaller or the same size as the previous one at {bm.Width} x {bm.Height}, so using that instead.");
}
}
}
catch (Exception ex)
{
logger.Warn(ex, $"ShortcutItem/GetMeABitmapFromFile: Exception while trying to extract the icon from a *.ico using MultiIcon tools.");
}
}
else
{
/*try
{
List<Icon> myIcons = ImageUtils.ExtractIconsFromExe(fileNameAndPath, true);
if (myIcons != null && myIcons.Count > 0)
{
foreach (Icon myExtractedIcon in myIcons)
{
bm = myExtractedIcon.ToBitmap();
if (bm.Width > bmToReturn.Width && bm.Height > bmToReturn.Height)
{
bmToReturn = bm;
logger.Trace($"ShortcutItem/GetMeABitmapFromFile: This new bitmap from the icon file {fileNameAndPath} is larger than the previous one at {bm.Width} x {bm.Height}, so using that instead.");
}
}
}
}
catch (Exception ex)
{
logger.Warn(ex, $"ShortcutItem/GetMeABitmapFromFile: Exception while trying to extract the icon from an *.exe or *.dll using ImageUtils.ExtractIconsFromExe.");
}*/
try
{
var ie = new TsudaKageyu.IconExtractor(fileNameAndPath);
Icon[] allIcons = ie.GetAllIcons();
foreach (Icon myExtractedIcon in allIcons)
{
bm = myExtractedIcon.ToBitmap();
if (bm.Width > bmToReturn.Width && bm.Height > bmToReturn.Height)
{
bmToReturn = bm;
logger.Trace($"ShortcutItem/GetMeABitmapFromFile: New bitmap from the exe file {fileNameAndPath} using TsudaKageyu.IconExtractor access method is larger than the previous one at {bm.Width} x {bm.Height}, so using that instead.");
}
else
{
logger.Trace($"ShortcutItem/GetMeABitmapFromFile: New bitmap from the exe file {fileNameAndPath} using TsudaKageyu.IconExtractor access method is smaller or the same size as the previous one at {bm.Width} x {bm.Height}, so using that instead.");
}
}
}
catch (Exception ex)
{
logger.Warn(ex, $"ShortcutItem/GetMeABitmapFromFile: Exception while trying to extract the icon from an *.exe or *.dll using TsudaKageyu.IconExtractor.");
}
}
try
{
List<Icon> myExtractedIcons = MintPlayer.IconUtils.IconExtractor.Split(fileNameAndPath);
Size largeSize = new Size(256, 256);
foreach (Icon myExtractedIcon in myExtractedIcons)
{
try
{
myIcon = (Icon)IconUtil.TryGetIcon(myExtractedIcon, largeSize, 32, true, true);
}
catch (ArgumentNullException nullex)
{
logger.Debug(nullex, $"ShortcutItem/GetMeABitmapFromFile: There was a faulty icon image within this icon that we couldn't test, so skipping it.");
continue;
}
if (myIcon != null)
{
bm = myIcon.ToBitmap();
if (bm.Width > bmToReturn.Width && bm.Height > bmToReturn.Height)
{
bmToReturn = bm;
logger.Trace($"ShortcutItem/GetMeABitmapFromFile: New bitmap from the file {fileNameAndPath} using MintPlayer.IconUtils.IconExtractor access method is larger than the previous one at {bm.Width} x {bm.Height}, so using that instead.");
}
else
{
logger.Trace($"ShortcutItem/GetMeABitmapFromFile: New bitmap from the file {fileNameAndPath} using MintPlayer.IconUtils.IconExtractor access method is smaller or the same size as the previous one at {bm.Width} x {bm.Height}, so using that instead.");
}
}
else
{
logger.Warn($"ShortcutItem/GetMeABitmapFromFile: Couldn't extract an Icon from the file {fileNameAndPath} using MintPlayer.IconUtils.IconExtractor access method, so can't try to get the Icon using IconUtils.TryGetIcon.");
}
}
}
catch (Exception ex)
{
logger.Warn(ex, $"ShortcutItem/GetMeABitmapFromFile: Exception while trying to Split the icon using MintPlayer IconExtractor! ");
}
if (bmToReturn == null)
{
// If we couldn't get any bitmaps at all
logger.Warn( $"ShortcutItem/GetMeABitmapFromFile: Haven't managed to get a valid icon file so returning null :(.");
return null;
}
else if (bmToReturn.Width == 1 && bmToReturn.Height == 1)
{
// If we couldn't extract anything, so we return null
logger.Warn($"ShortcutItem/GetMeABitmapFromFile: Haven't managed to get a valid icon file so returning null instead of a 1x1 bitmap!.");
return null;
}
else
{
return bmToReturn;
}
}
public static Bitmap GetMeABitmapFromFile(ArrayList fileNamesAndPaths)
{
Bitmap bmToReturn = null;
if (fileNamesAndPaths.Count == 0)
{
logger.Warn($"ShortcutItem/GetMeABitmapFromFile2: The fileNamesAndPaths list is empty! Can't get the bitmap from the files.");
return null;
}
logger.Trace($"ShortcutItem/GetMeABitmapFromFile2: We have {fileNamesAndPaths.Count} files to try and extract a bitmap from.");
foreach (string fileNameAndPath in fileNamesAndPaths)
{
logger.Trace($"ShortcutItem/GetMeABitmapFromFile2: Getting a bitmap from {fileNameAndPath} by running GetMeABitmapFromFile.");
Bitmap bm = GetMeABitmapFromFile(fileNameAndPath);
if (bmToReturn == null)
{
bmToReturn = bm;
}
if (bm != null && bm.Width > bmToReturn.Width && bm.Height > bmToReturn.Height)
{
bmToReturn = bm;
}
logger.Trace($"ShortcutItem/GetMeABitmapFromFile2: The biggest bitmap we could get from {fileNameAndPath} was {bm.Width}x{bm.Height}.");
}
// Now we check if the icon is still too small.
logger.Trace($"ShortcutItem/GetMeABitmapFromFile2: The biggest bitmap we could get from the {fileNamesAndPaths.Count} files was {bmToReturn.Width}x{bmToReturn.Height}.");
return bmToReturn;
}
public static List<ShortcutBitmap> GetMeAllBitmapsFromFile(string fileNameAndPath)
{
if (String.IsNullOrWhiteSpace(fileNameAndPath))
@ -375,7 +156,27 @@ namespace DisplayMagician
int bmCount = 0;
string fileNameOnly = Path.GetFileName(fileNameAndPath);
if (fileNameAndPath.EndsWith(".ico"))
if (fileNameAndPath.EndsWith(".jpg") || fileNameAndPath.EndsWith(".gif") || fileNameAndPath.EndsWith(".tif") || fileNameAndPath.EndsWith(".png") || fileNameAndPath.EndsWith(".bmp") ||
fileNameAndPath.EndsWith(".jpeg") || fileNameAndPath.EndsWith(".tiff"))
{
try
{
logger.Trace($"ShortcutItem/GetMeABitmapFromFile: The file we want to get the image from is an image file. Attempting to extract the image from {fileNameAndPath}.");
Bitmap bmap = new Bitmap(fileNameAndPath);
ShortcutBitmap bm = CreateShortcutBitmap(bmap, fileNameOnly, fileNameAndPath, bmCount++);
// Add the shortcutbitmap to the list
bmList.Add(bm);
logger.Trace($"ShortcutItem/GetMeABitmapFromFile: Added new bitmap from the image file {fileNameAndPath} using standard bitmap decoder access method.");
}
catch (Exception ex)
{
logger.Warn(ex, $"ShortcutItem/GetMeABitmapFromFile: Exception while trying to extract the bitmap from an image ({fileNameAndPath})using standard bitmap decoder tools.");
}
}
else if (fileNameAndPath.EndsWith(".ico"))
{
try

View File

@ -37,6 +37,7 @@ namespace DisplayMagician {
public static string AppSteamIconFilename = Path.Combine(AppIconPath, @"Steam.ico");
public static string AppUplayIconFilename = Path.Combine(AppIconPath, @"Uplay.ico");
public static string AppEpicIconFilename = Path.Combine(AppIconPath, @"Epic.ico");
public static string AppDownloadsPath = Utils.GetDownloadsPath();
public static bool AppToastActivated = false;
public static bool WaitingForGameToExit = false;
public static ProgramSettings AppProgramSettings;

View File

@ -26,8 +26,8 @@ using System.Resources;
[assembly: Guid("e4ceaf5e-ad01-4695-b179-31168eb74c48")]
// Version information
[assembly: AssemblyVersion("2.1.0.145")]
[assembly: AssemblyFileVersion("2.1.0.145")]
[assembly: AssemblyVersion("2.1.0.157")]
[assembly: AssemblyFileVersion("2.1.0.157")]
[assembly: NeutralResourcesLanguageAttribute( "en" )]
[assembly: CLSCompliant(true)]

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

View File

@ -1,106 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DisplayMagician.UIForms
{
public partial class ChooseIconForm : Form
{
private ShortcutBitmap _selectedImage = new ShortcutBitmap();
public ChooseIconForm()
{
InitializeComponent();
}
public List<ShortcutBitmap> AvailableImages
{
get;
set;
}
public ShortcutBitmap SelectedImage
{
get;
set;
}
private void btn_back_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
this.Close();
}
private void ChooseIconForm_Load(object sender, EventArgs e)
{
if (AvailableImages.Count > 0)
{
bool alreadySelected = false;
// Load all the images into the list
int imageCount = 1;
foreach (ShortcutBitmap sc in AvailableImages)
{
string[] stringsToAdd = new string[] {
$"Image {sc.Order} from {sc.Name}",
$"{sc.Size.Width} x {sc.Size.Height}"
};
ListViewItem lvi = new ListViewItem(stringsToAdd);
lvi.Name = sc.UUID;
if (sc.Equals(SelectedImage))
{
lvi.Selected = true;
pb_selected_icon.Image = SelectedImage.Image;
_selectedImage = sc;
}
lv_icons.Items.Add(lvi);
}
// Select the first largest image listed if there isn't one already
if (lv_icons.SelectedItems.Count == 0)
{
lv_icons.Items[0].Selected = true;
pb_selected_icon.Image = AvailableImages[0].Image;
_selectedImage = AvailableImages[0];
}
}
}
private void btn_select_Click(object sender, EventArgs e)
{
SelectedImage = _selectedImage;
DialogResult = DialogResult.OK;
this.Close();
}
private void lv_icons_SelectedIndexChanged(object sender, EventArgs e)
{
if (lv_icons.SelectedItems.Count > 0)
{
string uuidToFind = lv_icons.SelectedItems[0].Name;
foreach (ShortcutBitmap sc in AvailableImages)
{
if (sc.UUID.Equals(uuidToFind))
{
pb_selected_icon.Image = sc.Image;
_selectedImage = sc;
break;
}
}
}
}
private void btn_add_Click(object sender, EventArgs e)
{
}
}
}

View File

@ -1,7 +1,7 @@

namespace DisplayMagician.UIForms
{
partial class ChooseIconForm
partial class ChooseImageForm
{
/// <summary>
/// Required designer variable.
@ -29,16 +29,18 @@ namespace DisplayMagician.UIForms
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ChooseIconForm));
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ChooseImageForm));
this.lv_icons = new System.Windows.Forms.ListView();
this.columnHeaderName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeaderSize = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.pb_selected_icon = new System.Windows.Forms.PictureBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.btn_add = new System.Windows.Forms.Button();
this.btn_select = new System.Windows.Forms.Button();
this.btn_back = new System.Windows.Forms.Button();
this.columnHeaderSize = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.dialog_open = new System.Windows.Forms.OpenFileDialog();
this.btn_remove = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pb_selected_icon)).BeginInit();
this.SuspendLayout();
//
@ -64,6 +66,11 @@ namespace DisplayMagician.UIForms
this.columnHeaderName.Text = "Name";
this.columnHeaderName.Width = 270;
//
// columnHeaderSize
//
this.columnHeaderSize.Text = "Size";
this.columnHeaderSize.Width = 70;
//
// pb_selected_icon
//
this.pb_selected_icon.BackColor = System.Drawing.Color.DimGray;
@ -82,9 +89,9 @@ namespace DisplayMagician.UIForms
this.label1.ForeColor = System.Drawing.Color.White;
this.label1.Location = new System.Drawing.Point(139, 21);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(125, 16);
this.label1.Size = new System.Drawing.Size(138, 16);
this.label1.TabIndex = 2;
this.label1.Text = "Choose icon to use:";
this.label1.Text = "Choose image to use:";
this.label1.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// label2
@ -95,9 +102,9 @@ namespace DisplayMagician.UIForms
this.label2.ForeColor = System.Drawing.Color.White;
this.label2.Location = new System.Drawing.Point(457, 21);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(93, 16);
this.label2.Size = new System.Drawing.Size(106, 16);
this.label2.TabIndex = 3;
this.label2.Text = "Selected icon:";
this.label2.Text = "Selected image:";
this.label2.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// btn_add
@ -107,9 +114,9 @@ namespace DisplayMagician.UIForms
this.btn_add.ForeColor = System.Drawing.Color.White;
this.btn_add.Location = new System.Drawing.Point(26, 261);
this.btn_add.Name = "btn_add";
this.btn_add.Size = new System.Drawing.Size(77, 30);
this.btn_add.Size = new System.Drawing.Size(86, 30);
this.btn_add.TabIndex = 39;
this.btn_add.Text = "Add icons";
this.btn_add.Text = "Add images";
this.btn_add.UseVisualStyleBackColor = true;
this.btn_add.Click += new System.EventHandler(this.btn_add_Click);
//
@ -118,11 +125,11 @@ namespace DisplayMagician.UIForms
this.btn_select.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btn_select.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btn_select.ForeColor = System.Drawing.Color.White;
this.btn_select.Location = new System.Drawing.Point(218, 261);
this.btn_select.Location = new System.Drawing.Point(305, 261);
this.btn_select.Name = "btn_select";
this.btn_select.Size = new System.Drawing.Size(176, 30);
this.btn_select.Size = new System.Drawing.Size(178, 30);
this.btn_select.TabIndex = 40;
this.btn_select.Text = "Save and use selected icon";
this.btn_select.Text = "Save and use selected image";
this.btn_select.UseVisualStyleBackColor = true;
this.btn_select.Click += new System.EventHandler(this.btn_select_Click);
//
@ -139,17 +146,30 @@ namespace DisplayMagician.UIForms
this.btn_back.UseVisualStyleBackColor = true;
this.btn_back.Click += new System.EventHandler(this.btn_back_Click);
//
// columnHeaderSize
// dialog_open
//
this.columnHeaderSize.Text = "Size";
this.columnHeaderSize.Width = 70;
this.dialog_open.FileName = "openFileDialog1";
//
// ChooseIconForm
// btn_remove
//
this.btn_remove.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btn_remove.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btn_remove.ForeColor = System.Drawing.Color.White;
this.btn_remove.Location = new System.Drawing.Point(153, 261);
this.btn_remove.Name = "btn_remove";
this.btn_remove.Size = new System.Drawing.Size(113, 30);
this.btn_remove.TabIndex = 42;
this.btn_remove.Text = "Remove image";
this.btn_remove.UseVisualStyleBackColor = true;
this.btn_remove.Click += new System.EventHandler(this.btn_remove_Click);
//
// ChooseImageForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.Black;
this.ClientSize = new System.Drawing.Size(629, 319);
this.Controls.Add(this.btn_remove);
this.Controls.Add(this.btn_back);
this.Controls.Add(this.btn_select);
this.Controls.Add(this.btn_add);
@ -161,11 +181,11 @@ namespace DisplayMagician.UIForms
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "ChooseIconForm";
this.Name = "ChooseImageForm";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Choose shortcut icon";
this.Text = "Choose shortcut image";
this.TopMost = true;
this.Load += new System.EventHandler(this.ChooseIconForm_Load);
((System.ComponentModel.ISupportInitialize)(this.pb_selected_icon)).EndInit();
@ -185,5 +205,7 @@ namespace DisplayMagician.UIForms
private System.Windows.Forms.Button btn_back;
private System.Windows.Forms.ColumnHeader columnHeaderName;
private System.Windows.Forms.ColumnHeader columnHeaderSize;
private System.Windows.Forms.OpenFileDialog dialog_open;
private System.Windows.Forms.Button btn_remove;
}
}

View File

@ -0,0 +1,215 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DisplayMagician.UIForms
{
public partial class ChooseImageForm : Form
{
private ShortcutBitmap _selectedImage = new ShortcutBitmap();
public ChooseImageForm()
{
InitializeComponent();
}
public List<ShortcutBitmap> AvailableImages
{
get;
set;
}
public ShortcutBitmap SelectedImage
{
get;
set;
}
private void btn_back_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
this.Close();
}
private void ChooseIconForm_Load(object sender, EventArgs e)
{
UpdateImageListBox();
/*if (AvailableImages.Count > 0)
{
bool alreadySelected = false;
// Load all the images into the list
int imageCount = 1;
foreach (ShortcutBitmap sc in AvailableImages)
{
string[] stringsToAdd = new string[] {
$"Image {sc.Order} from {sc.Name}",
$"{sc.Size.Width} x {sc.Size.Height}"
};
ListViewItem lvi = new ListViewItem(stringsToAdd);
lvi.Name = sc.UUID;
if (sc.Equals(SelectedImage))
{
lvi.Selected = true;
pb_selected_icon.Image = SelectedImage.Image;
_selectedImage = sc;
}
lv_icons.Items.Add(lvi);
}
// Select the first largest image listed if there isn't one already
if (lv_icons.SelectedItems.Count == 0)
{
lv_icons.Items[0].Selected = true;
pb_selected_icon.Image = AvailableImages[0].Image;
_selectedImage = AvailableImages[0];
}
}*/
}
private void UpdateImageListBox()
{
lv_icons.Items.Clear();
if (AvailableImages.Count > 0)
{
bool alreadySelected = false;
// Load all the images into the list
int imageCount = 1;
foreach (ShortcutBitmap sc in AvailableImages)
{
string[] stringsToAdd = new string[] {
$"Image {sc.Order} from {sc.Name}",
$"{sc.Size.Width} x {sc.Size.Height}"
};
ListViewItem lvi = new ListViewItem(stringsToAdd);
lvi.Name = sc.UUID;
if (sc.Equals(SelectedImage))
{
lvi.Selected = true;
pb_selected_icon.Image = SelectedImage.Image;
_selectedImage = sc;
}
lv_icons.Items.Add(lvi);
}
// Select the first largest image listed if there isn't one already
if (lv_icons.SelectedItems.Count == 0)
{
lv_icons.Items[0].Selected = true;
pb_selected_icon.Image = AvailableImages[0].Image;
_selectedImage = AvailableImages[0];
}
}
}
private void btn_select_Click(object sender, EventArgs e)
{
SelectedImage = _selectedImage;
DialogResult = DialogResult.OK;
this.Close();
}
private void lv_icons_SelectedIndexChanged(object sender, EventArgs e)
{
if (lv_icons.SelectedItems.Count > 0)
{
string uuidToFind = lv_icons.SelectedItems[0].Name;
foreach (ShortcutBitmap sc in AvailableImages)
{
if (sc.UUID.Equals(uuidToFind))
{
pb_selected_icon.Image = sc.Image;
_selectedImage = sc;
break;
}
}
}
}
private void btn_add_Click(object sender, EventArgs e)
{
dialog_open.InitialDirectory = Program.AppDownloadsPath;
dialog_open.DefaultExt = "*.exe; *.com; *.ico; *.bmp; *.jpg; *.png; *.tif; *.gif";
dialog_open.Filter = "All exe and image files (*.exe; *.com; *.ico; *.bmp; *.jpg; *.png; *.tif; *.gif) | *.exe; *.com; *.ico; *.bmp; *.jpg; *.png; *.tif; *.gif | All files(*.*) | *.*";
if (dialog_open.ShowDialog(this) == DialogResult.OK)
{
if (File.Exists(dialog_open.FileName))
{
try
{
List<ShortcutBitmap> newImages = ImageUtils.GetMeAllBitmapsFromFile(dialog_open.FileName);
if (newImages.Count == 0)
{
MessageBox.Show(
$"No new images found when parsing {dialog_open.FileName} for images. Are you sure it's a valid image format?",
"Add images to icon",
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
}
else
{
AvailableImages.AddRange(ImageUtils.GetMeAllBitmapsFromFile(dialog_open.FileName));
UpdateImageListBox();
MessageBox.Show(
$"Added {newImages.Count} image(s) from {dialog_open.FileName} to the end of this image list.",
"Add images to icon",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
dialog_open.FileName = string.Empty;
}
catch(Exception ex)
{
MessageBox.Show(
$"Unable to parse {dialog_open.FileName} for images. Are you sure it's a valid image format?",
"Add images to icon",
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
}
}
else
{
MessageBox.Show(
$"Unable to open {dialog_open.FileName} to parse it for images. Are you sure you have the right file permissions?",
"Add images to icon",
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
}
}
}
private void btn_remove_Click(object sender, EventArgs e)
{
if (lv_icons.SelectedItems.Count > 0)
{
string uuidToFind = lv_icons.SelectedItems[0].Name;
foreach (ShortcutBitmap sc in AvailableImages)
{
if (sc.UUID.Equals(uuidToFind))
{
AvailableImages.Remove(sc);
pb_selected_icon.Image = null;
_selectedImage = default(ShortcutBitmap);
UpdateImageListBox();
return;
}
}
// If we get here we didn't find anything to remove!
MessageBox.Show(
$"Unable to remove selected item from the list of images!",
"Remove image from icon",
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
}
}
}
}

View File

@ -117,6 +117,9 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="dialog_open.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>

View File

@ -2734,7 +2734,7 @@ namespace DisplayMagician.UIForms
{
if (rb_standalone.Checked && _availableImages.Count > 0)
{
ChooseIconForm exeIconForm = new ChooseIconForm();
ChooseImageForm exeIconForm = new ChooseImageForm();
exeIconForm.AvailableImages = _availableImages;
exeIconForm.SelectedImage = _selectedImage;
if (exeIconForm.ShowDialog() == DialogResult.OK)
@ -2751,7 +2751,7 @@ namespace DisplayMagician.UIForms
{
if (rb_launcher.Checked && _shortcutToEdit.AvailableImages.Count > 0)
{
ChooseIconForm gameIconForm = new ChooseIconForm();
ChooseImageForm gameIconForm = new ChooseImageForm();
gameIconForm.AvailableImages = _availableImages;
gameIconForm.SelectedImage = _selectedImage;
if (gameIconForm.ShowDialog() == DialogResult.OK)

59
DisplayMagician/Utils.cs Normal file
View File

@ -0,0 +1,59 @@
using System;
using System.Runtime.InteropServices;
namespace DisplayMagician
{
class Utils
{
// 1. Import InteropServices
/// 2. Declare DownloadsFolder KNOWNFOLDERID
private static Guid FolderDownloads = new Guid("374DE290-123F-4565-9164-39C4925E467B");
/// 3. Import SHGetKnownFolderPath method
/// <summary>
/// Retrieves the full path of a known folder identified by the folder's KnownFolderID.
/// </summary>
/// <param name="id">A KnownFolderID that identifies the folder.</param>
/// <param name="flags">Flags that specify special retrieval options. This value can be
/// 0; otherwise, one or more of the KnownFolderFlag values.</param>
/// <param name="token">An access token that represents a particular user. If this
/// parameter is NULL, which is the most common usage, the function requests the known
/// folder for the current user. Assigning a value of -1 indicates the Default User.
/// The default user profile is duplicated when any new user account is created.
/// Note that access to the Default User folders requires administrator privileges.
/// </param>
/// <param name="path">When this method returns, contains the address of a string that
/// specifies the path of the known folder. The returned path does not include a
/// trailing backslash.</param>
/// <returns>Returns S_OK if successful, or an error value otherwise.</returns>
[DllImport("shell32.dll", CharSet = CharSet.Auto)]
private static extern int SHGetKnownFolderPath(ref Guid id, int flags, IntPtr token, out IntPtr path);
/// 4. Declare method that returns the Downloads Path as string
/// <summary>
/// Returns the absolute downloads directory specified on the system.
/// </summary>
/// <returns></returns>
public static string GetDownloadsPath()
{
if (Environment.OSVersion.Version.Major < 6) throw new NotSupportedException();
IntPtr pathPtr = IntPtr.Zero;
try
{
SHGetKnownFolderPath(ref FolderDownloads, 0, IntPtr.Zero, out pathPtr);
return Marshal.PtrToStringUni(pathPtr);
}
finally
{
Marshal.FreeCoTaskMem(pathPtr);
}
}
}
}