Skip to content

Commit

Permalink
Merge IconExtractor (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
PieterjanDeClippel committed Oct 25, 2023
1 parent 411f7ca commit ff27f39
Show file tree
Hide file tree
Showing 25 changed files with 1,032 additions and 484 deletions.
34 changes: 15 additions & 19 deletions MintPlayer.BrowserDialog.Demo/Form1.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
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 MintPlayer.BrowserDialog.Test;

namespace MintPlayer.BrowserDialog.Test
public partial class MainForm : Form
{
public partial class MainForm : Form
public MainForm()
{
public MainForm()
{
InitializeComponent();
}
InitializeComponent();
}

private void btnPickBrowser_Click(object sender, EventArgs e)
private void btnPickBrowser_Click(object sender, EventArgs e)
{
var dialog = new BrowserDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
var dialog = new BrowserDialog();
if (dialog.ShowDialog() == DialogResult.OK)
if (dialog.SelectedBrowser != null)
{
MessageBox.Show($"You picked {dialog.SelectedBrowser.Name}.\r\nThe executable path is {dialog.SelectedBrowser.ExecutablePath}\r\nThe version is {dialog.SelectedBrowser.Version?.ProductVersion}");
}
else
{
MessageBox.Show($"You picked {dialog.SelectedBrowser.Name}.\r\nThe executable path is {dialog.SelectedBrowser.ExecutablePath}\r\nThe version is {dialog.SelectedBrowser.Version.ProductVersion}");
MessageBox.Show("You didn't select a browser");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<!-- Used for CI/CD on Ubuntu -->
<EnableWindowsTargeting>true</EnableWindowsTargeting>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MintPlayer.BrowserDialog.De
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MintPlayer.PlatformBrowser.Demo", "MintPlayer.PlatformBrowser.Demo\MintPlayer.PlatformBrowser.Demo.csproj", "{938DEBE4-0150-4AE1-B98E-038B5453A52A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MintPlayer.IconUtils", "MintPlayer.IconUtils\MintPlayer.IconUtils.csproj", "{DF75330C-3346-41F8-B713-621F4A80179E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -33,6 +35,10 @@ Global
{938DEBE4-0150-4AE1-B98E-038B5453A52A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{938DEBE4-0150-4AE1-B98E-038B5453A52A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{938DEBE4-0150-4AE1-B98E-038B5453A52A}.Release|Any CPU.Build.0 = Release|Any CPU
{DF75330C-3346-41F8-B713-621F4A80179E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DF75330C-3346-41F8-B713-621F4A80179E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DF75330C-3346-41F8-B713-621F4A80179E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DF75330C-3346-41F8-B713-621F4A80179E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
181 changes: 87 additions & 94 deletions MintPlayer.BrowserDialog/BrowserDialog.cs
Original file line number Diff line number Diff line change
@@ -1,127 +1,120 @@
using MintPlayer.IconUtils;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MintPlayer.BrowserDialog

namespace MintPlayer.BrowserDialog;

public partial class BrowserDialog : Form
{
public partial class BrowserDialog : Form
public BrowserDialog()
{
public BrowserDialog()
{
InitializeComponent();
}
InitializeComponent();
}

private void BrowserDialog_Load(object sender, EventArgs e)
private void BrowserDialog_Load(object sender, EventArgs e)
{
try
{
try
{
// Suspend the drawing of the listview
lvBrowsers.SuspendLayout();
// Suspend the drawing of the listview
lvBrowsers.SuspendLayout();

// Remove all items from the listview
lvBrowsers.Items.Clear();
// Remove all items from the listview
lvBrowsers.Items.Clear();

// Assign a new imagelist
lvBrowsers.LargeImageList = new ImageList
{
ImageSize = new Size(60, 60),
ColorDepth = ColorDepth.Depth32Bit
};
// Assign a new imagelist
lvBrowsers.LargeImageList = new ImageList
{
ImageSize = new Size(60, 60),
ColorDepth = ColorDepth.Depth32Bit
};

// Get all browsers on the system
browsers = PlatformBrowser.PlatformBrowser.GetInstalledBrowsers();
// Get all browsers on the system
browsers = PlatformBrowser.PlatformBrowser.GetInstalledBrowsers();

// Loop through all browsers
for (var i = 0; i < browsers.Count; i++)
{
var browser = browsers[i];
// Loop through all browsers
for (var i = 0; i < browsers.Count; i++)
{
var browser = browsers[i];

// Get image
var icon = IconExtractor.Split(browser.IconPath)[browser.IconIndex < 0 ? 0 : browser.IconIndex];
var icons = IconExtractor.ExtractImagesFromIcon(icon);
var largestSize = icons.Max(i => i.Width);
var largestIcon = icons.LastOrDefault(i => i.Width == largestSize);
// Get image
var icon = IconExtractor.Split(browser.IconPath)[browser.IconIndex < 0 ? 0 : browser.IconIndex];
var icons = IconExtractor.ExtractImagesFromIcon(icon);
var largestSize = icons.Max(i => i.Width);
var largestIcon = icons.LastOrDefault(i => i.Width == largestSize);
if (largestIcon != null)
{
lvBrowsers.LargeImageList.Images.Add(largestIcon);

lvBrowsers.Items.Add(new ListViewItem
{
Text = browser.Name,
Tag = browser.ExecutablePath.Trim('\"'),
ImageIndex = i,
});
}

// Get default browser
defaultBrowser = PlatformBrowser.PlatformBrowser.GetDefaultBrowser(browsers.ToList(), PlatformBrowser.Enums.eProtocolType.Http);

// Select default browser
if (browsers.Contains(defaultBrowser))
lvBrowsers.Items.Add(new ListViewItem
{
var defaultBrowserListItem = lvBrowsers.Items[
browsers.IndexOf(
browsers.FirstOrDefault(b => b.ExecutablePath == defaultBrowser.ExecutablePath)
)
];
defaultBrowserListItem.Focused = defaultBrowserListItem.Selected = true;
}
Text = browser.Name,
Tag = browser.ExecutablePath.Trim('\"'),
ImageIndex = i,
});
}
catch (Exception)
{
// Don't interrupt the dialog
}
finally

// Get default browser
defaultBrowser = PlatformBrowser.PlatformBrowser.GetDefaultBrowser(browsers.ToList(), PlatformBrowser.Enums.EProtocolType.Http);

// Select default browser
if (browsers.Contains(defaultBrowser!))
{
lvBrowsers.ResumeLayout();
var defaultBrowserListItem = lvBrowsers.Items[
browsers.IndexOf(
browsers.FirstOrDefault(b => b.ExecutablePath == defaultBrowser?.ExecutablePath)!
)
];
defaultBrowserListItem.Focused = defaultBrowserListItem.Selected = true;
}
}

private void BrowserDialog_Shown(object sender, EventArgs e)
catch (Exception)
{
lvBrowsers.Focus();
// Don't interrupt the dialog
}
finally
{
lvBrowsers.ResumeLayout();
}
}

private ReadOnlyCollection<PlatformBrowser.Browser> browsers = new ReadOnlyCollection<PlatformBrowser.Browser>(new List<PlatformBrowser.Browser>());
private PlatformBrowser.Browser defaultBrowser;
public PlatformBrowser.Browser SelectedBrowser
private void BrowserDialog_Shown(object sender, EventArgs e)
{
lvBrowsers.Focus();
}

private ReadOnlyCollection<PlatformBrowser.Browser> browsers = new ReadOnlyCollection<PlatformBrowser.Browser>(new List<PlatformBrowser.Browser>());
private PlatformBrowser.Browser? defaultBrowser;
public PlatformBrowser.Browser? SelectedBrowser
{
get
{
get
if (lvBrowsers.SelectedIndices.Count == 0)
{
if (lvBrowsers.SelectedIndices.Count == 0)
{
return null;
}
else
{
return browsers[lvBrowsers.SelectedIndices[0]];
}
return null;
}
set
else
{
lvBrowsers.SelectedIndices.Clear();
if (value == null)
{
return;
}

if (browsers.Any(b => b.Name == value.Name))
{
lvBrowsers.SelectedIndices.Add(browsers.IndexOf(value));
}
return browsers[lvBrowsers.SelectedIndices[0]];
}
}

private void LvBrowsers_SelectedIndexChanged(object sender, EventArgs e)
set
{
btnOK.Enabled = lvBrowsers.SelectedItems.Count != 0;
lvBrowsers.SelectedIndices.Clear();
if (value == null)
{
return;
}

if (browsers.Any(b => b.Name == value.Name))
{
lvBrowsers.SelectedIndices.Add(browsers.IndexOf(value));
}
}
}

private void LvBrowsers_SelectedIndexChanged(object sender, EventArgs e)
{
btnOK.Enabled = lvBrowsers.SelectedItems.Count != 0;
}

}
Loading

0 comments on commit ff27f39

Please sign in to comment.