Skip to content

Commit

Permalink
Enhancement: Custom path selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Ceiridge committed Apr 3, 2021
1 parent 732ff91 commit a87cec5
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.IO;
using Microsoft.Win32;

namespace ChromeDevExtWarningPatcher.InstallationFinder.Defaults {
internal class CustomPath : Installation {
Expand All @@ -19,5 +20,35 @@ internal class CustomPath : Installation {

return dllFiles;
}

public static InstallationPaths? GuiAddCustomPath() {
OpenFileDialog openFile = new OpenFileDialog {
Title = "Select a chrome.dll",
Filter = "chrome.dll/msedge.dll file (chrome.dll;msedge.dll)|chrome.dll;msedge.dll|Alternative chrome.dll file (*.dll)|*.dll|All files (*.*)|*.*",
FilterIndex = 1
};
openFile.CheckFileExists = openFile.CheckPathExists = openFile.AddExtension = true;

if (!openFile.ShowDialog() ?? true) {
return null;
}

string chromeDllPath = openFile.FileName;

openFile = new OpenFileDialog {
Title = "Select a chrome.exe",
Filter = "Browser executable file (*.exe)|*.exe|All files (*.*)|*.*",
FilterIndex = 1
};
openFile.CheckFileExists = openFile.CheckPathExists = openFile.AddExtension = true;
openFile.InitialDirectory = Directory.GetParent(Path.GetDirectoryName(chromeDllPath)!)!.FullName;

if (!openFile.ShowDialog() ?? true) {
return null;
}

string chromeExePath = openFile.FileName;
return new InstallationPaths("Custom Browser", chromeDllPath, chromeExePath);
}
}
}
86 changes: 44 additions & 42 deletions ChromeDevExtWarningPatcher/MainView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,51 @@
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d"
Title="Ceiridge's Chromium Patcher (Extension Warning Patcher)" Height="450" Width="800" WindowStartupLocation="CenterScreen" Background="{DynamicResource MaterialDesignPaper}" FontFamily="{DynamicResource MaterialDesignFont}" TextElement.Foreground="{DynamicResource MaterialDesignBody}" TextElement.FontWeight="Medium" TextElement.FontSize="14">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<Expander x:Name="BrowserExpander" Header="Select Browsers" IsExpanded="True" Expanded="OnExpanderExpand">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="85*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<cv:SelectionListView DataContext="{Binding BrowserListModel}" />
<Button Grid.Row="1" Content="Add a custom path" Style="{DynamicResource MaterialDesignRaisedLightButton}" HorizontalAlignment="Center" Width="Auto" Margin="0, 3, 0, 0" />
</Grid>
</Expander>

<Expander x:Name="PatchExpander" Grid.Row="1" Header="Select Patches" Expanded="OnExpanderExpand">
<cv:SelectionListView DataContext="{Binding PatchListModel}" />
</Expander>

<Expander x:Name="InstallExpander" Grid.Row="2" Header="Install Patches" Expanded="OnExpanderExpand">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="75*" />
</Grid.RowDefinitions>
<Expander x:Name="BrowserExpander" Header="Select Browsers" IsExpanded="True" Expanded="OnExpanderExpand">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="85*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0, 3, 0, 3">
<Button Content="(Re-)Install" />
<Button Content="Uninstall" Style="{DynamicResource MaterialDesignRaisedLightButton}" Margin="5, 0, 0, 0" Cursor="Hand" />
</StackPanel>
<cv:SelectionListView DataContext="{Binding BrowserListModel}" />
<Button Grid.Row="1" Content="Add a custom path" Style="{DynamicResource MaterialDesignRaisedLightButton}" HorizontalAlignment="Center" Width="Auto" Margin="0, 3, 0, 0" Click="OnAddCustomPath" />
</Grid>
</Expander>

<RichTextBox Grid.Row="1" x:Name="ConsoleBox" Margin="0, 0, 0, 5" IsUndoEnabled="False" IsReadOnly="True" IsReadOnlyCaretVisible="True">
<FlowDocument LineHeight="1">
<Paragraph>
<Run Text="Console" />
</Paragraph>
</FlowDocument>
</RichTextBox>
</Grid>
</Expander>
</Grid>
<Expander x:Name="PatchExpander" Grid.Row="1" Header="Select Patches" Expanded="OnExpanderExpand">
<cv:SelectionListView DataContext="{Binding PatchListModel}" />
</Expander>

<Expander x:Name="InstallExpander" Grid.Row="2" Header="Install Patches" Expanded="OnExpanderExpand">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="75*" />
</Grid.RowDefinitions>

<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0, 3, 0, 3">
<Button Content="(Re-)Install" />
<Button Content="Uninstall" Style="{DynamicResource MaterialDesignRaisedLightButton}" Margin="5, 0, 0, 0" />
</StackPanel>

<RichTextBox Grid.Row="1" x:Name="ConsoleBox" Margin="0, 0, 0, 5" IsUndoEnabled="False" IsReadOnly="True" IsReadOnlyCaretVisible="True">
<FlowDocument LineHeight="1">
<Paragraph>
<Run Text="Console" />
</Paragraph>
</FlowDocument>
</RichTextBox>
</Grid>
</Expander>
</Grid>
</ScrollViewer>
</Window>
32 changes: 20 additions & 12 deletions ChromeDevExtWarningPatcher/MainView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using ChromeDevExtWarningPatcher.InstallationFinder.Defaults;
using Brush = System.Windows.Media.Brush;

namespace ChromeDevExtWarningPatcher {
Expand Down Expand Up @@ -40,21 +41,28 @@ public partial class MainView : Window {
this.Log("Patcher gui initialized");
this.Log("Searching for Chromium installations...");

#region Browser List Initialization

foreach (InstallationPaths paths in this.installationManager.FindAllChromiumInstallations()) {
Icon? icon = System.Drawing.Icon.ExtractAssociatedIcon(paths.ChromeExePath!);
ImageSource? source = icon != null ? Imaging.CreateBitmapSourceFromHIcon(icon.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()) : null; // Turn the icon into an ImageSource for the WPF gui

this.mainModel.BrowserListModel.ElementList.Add(new SelectionListElement(paths.Name) {
Description = paths.ChromeDllPath,
IconImage = source,
Tooltip = paths.ChromeExePath + " & " + paths.ChromeDllPath,
IsSelected = true
});
this.AddInstallationPath(paths);
}
}

private void AddInstallationPath(InstallationPaths paths) {
Icon? icon = System.Drawing.Icon.ExtractAssociatedIcon(paths.ChromeExePath!);
ImageSource? source = icon != null ? Imaging.CreateBitmapSourceFromHIcon(icon.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()) : null; // Turn the icon into an ImageSource for the WPF gui

#endregion
this.mainModel.BrowserListModel.ElementList.Add(new SelectionListElement(paths.Name) {
Description = paths.ChromeDllPath,
IconImage = source,
Tooltip = paths.ChromeExePath + " & " + paths.ChromeDllPath,
IsSelected = true
});
}

private void OnAddCustomPath(object sender, RoutedEventArgs e) {
InstallationPaths? paths = CustomPath.GuiAddCustomPath();
if (paths != null) {
this.AddInstallationPath(paths);
}
}

private void OnExpanderExpand(object sender, RoutedEventArgs e) {
Expand Down

0 comments on commit a87cec5

Please sign in to comment.