-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhancement: Added installation finders, improved gui
- Loading branch information
Showing
15 changed files
with
322 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
namespace ChromeDevExtWarningPatcher.ComponentModels { | ||
public class MainModel { | ||
public SelectionListModel BrowserListModel => new SelectionListModel(); | ||
public SelectionListModel PatchListModel => new SelectionListModel(); | ||
public SelectionListModel BrowserListModel { get; set; } = new SelectionListModel(); | ||
public SelectionListModel PatchListModel { get; set; } = new SelectionListModel(); | ||
} | ||
} |
5 changes: 3 additions & 2 deletions
5
ChromeDevExtWarningPatcher/ComponentModels/SelectionListElement.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
ChromeDevExtWarningPatcher/ComponentModels/SelectionListModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,9 @@ | ||
using System.Collections.ObjectModel; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Threading.Tasks; | ||
|
||
namespace ChromeDevExtWarningPatcher.ComponentModels { | ||
public class SelectionListModel { | ||
[Required] | ||
public ObservableCollection<SelectionListElement> ElementList { get; set; } = new ObservableCollection<SelectionListElement>(); | ||
|
||
public SelectionListModel() { | ||
Task.Run(async () => { | ||
await Task.Delay(100); | ||
this.ElementList.Add(new SelectionListElement("Edge") { | ||
Description = "Very edgy" | ||
}); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
ChromeDevExtWarningPatcher/InstallationFinder/Defaults/Brave.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
|
||
namespace ChromeDevExtWarningPatcher.InstallationFinder.Defaults { | ||
internal class Brave : Installation { | ||
public Brave() : base("Brave") { } | ||
|
||
public override List<InstallationPaths> FindInstallationPaths() { | ||
List<InstallationPaths> dllFiles = new List<InstallationPaths>(); | ||
|
||
AddDllAndExeToList(dllFiles, this.GetLatestDllAndExe(new DirectoryInfo(@"C:\Program Files (x86)\BraveSoftware\Brave-Browser\Application"), "chrome.dll", "brave.exe")); | ||
AddDllAndExeToList(dllFiles, this.GetLatestDllAndExe(new DirectoryInfo(@"C:\Program Files\BraveSoftware\Brave-Browser\Application"), "chrome.dll", "brave.exe")); | ||
|
||
return dllFiles; | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
ChromeDevExtWarningPatcher/InstallationFinder/Defaults/Chrome.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
|
||
namespace ChromeDevExtWarningPatcher.InstallationFinder.Defaults { | ||
internal class Chrome : Installation { | ||
public Chrome() : base("Chrome") { } | ||
|
||
public override List<InstallationPaths> FindInstallationPaths() { | ||
List<InstallationPaths> dllFiles = new List<InstallationPaths>(); | ||
|
||
AddDllAndExeToList(dllFiles, this.GetLatestDllAndExe(new DirectoryInfo(@"C:\Program Files (x86)\Google\Chrome\Application"), "chrome.dll", "chrome.exe")); | ||
AddDllAndExeToList(dllFiles, this.GetLatestDllAndExe(new DirectoryInfo(@"C:\Program Files (x86)\Google\Chrome Beta\Application"), "chrome.dll", "chrome.exe")); | ||
|
||
AddDllAndExeToList(dllFiles, this.GetLatestDllAndExe(new DirectoryInfo(@"C:\Program Files\Google\Chrome\Application"), "chrome.dll", "chrome.exe")); | ||
AddDllAndExeToList(dllFiles, this.GetLatestDllAndExe(new DirectoryInfo(@"C:\Program Files\Google\Chrome Beta\Application"), "chrome.dll", "chrome.exe")); | ||
|
||
return dllFiles; | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
ChromeDevExtWarningPatcher/InstallationFinder/Defaults/CustomPath.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
|
||
namespace ChromeDevExtWarningPatcher.InstallationFinder.Defaults { | ||
internal class CustomPath : Installation { | ||
private readonly string path; | ||
|
||
public CustomPath(string path) : base("CustomPath") { | ||
this.path = path; | ||
} | ||
|
||
public override List<InstallationPaths> FindInstallationPaths() { | ||
List<InstallationPaths> dllFiles = new List<InstallationPaths>(); | ||
|
||
AddDllAndExeToList(dllFiles, this.GetLatestDllAndExe(new DirectoryInfo(this.path), "chrome.dll", "chrome.exe")); | ||
AddDllAndExeToList(dllFiles, this.GetLatestDllAndExe(new DirectoryInfo(this.path), "msedge.dll", "msedge.exe")); | ||
AddDllAndExeToList(dllFiles, this.GetLatestDllAndExe(new DirectoryInfo(this.path), "chrome.dll", "brave.exe")); | ||
AddDllAndExeToList(dllFiles, this.GetLatestDllAndExe(new DirectoryInfo(this.path), "browser.dll", "browser.exe")); | ||
|
||
return dllFiles; | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
ChromeDevExtWarningPatcher/InstallationFinder/Defaults/Edge.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
|
||
namespace ChromeDevExtWarningPatcher.InstallationFinder.Defaults { | ||
internal class Edge : Installation { | ||
public Edge() : base("Edge") { } | ||
|
||
public override List<InstallationPaths> FindInstallationPaths() { | ||
List<InstallationPaths> dllFiles = new List<InstallationPaths>(); | ||
|
||
AddDllAndExeToList(dllFiles, this.GetLatestDllAndExe(new DirectoryInfo(@"C:\Program Files (x86)\Microsoft\Edge\Application"), "msedge.dll", "msedge.exe")); | ||
AddDllAndExeToList(dllFiles, this.GetLatestDllAndExe(new DirectoryInfo(@"C:\Program Files\Microsoft\Edge\Application"), "msedge.dll", "msedge.exe")); | ||
|
||
return dllFiles; | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
ChromeDevExtWarningPatcher/InstallationFinder/Defaults/Yandex.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
|
||
namespace ChromeDevExtWarningPatcher.InstallationFinder.Defaults { | ||
internal class Yandex : Installation { | ||
public Yandex() : base("Yandex") { } | ||
|
||
public override List<InstallationPaths> FindInstallationPaths() { | ||
List<InstallationPaths> dllFiles = new List<InstallationPaths>(); | ||
|
||
string appDataLocal = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); | ||
AddDllAndExeToList(dllFiles, this.GetLatestDllAndExe(new DirectoryInfo(Path.Combine(appDataLocal, @"Yandex\YandexBrowser\Application")), "browser.dll", "browser.exe")); | ||
|
||
return dllFiles; | ||
} | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
ChromeDevExtWarningPatcher/InstallationFinder/Installation.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace ChromeDevExtWarningPatcher.InstallationFinder { | ||
internal abstract class Installation { | ||
protected string Name; | ||
|
||
protected Installation(string name) { | ||
this.Name = name; | ||
} | ||
|
||
public abstract List<InstallationPaths> FindInstallationPaths(); | ||
|
||
protected InstallationPaths GetLatestDllAndExe(DirectoryInfo versionsFolder, string dllName, string exeName) { | ||
if (!versionsFolder.Exists) { | ||
return new InstallationPaths(this.Name); | ||
} | ||
|
||
InstallationPaths paths = new InstallationPaths(this.Name); | ||
|
||
List<DirectoryInfo> chromeVersions = new List<DirectoryInfo>(versionsFolder.EnumerateDirectories()); | ||
chromeVersions = chromeVersions.OrderByDescending(dirInfo => GetUnixTime(dirInfo.LastWriteTime)).ToList(); | ||
|
||
foreach (DirectoryInfo chromeVersion in chromeVersions) { | ||
if (chromeVersion.Name.Contains(".")) { | ||
foreach (FileInfo file in chromeVersion.EnumerateFiles()) { | ||
if (file.Name.Equals(dllName)) { | ||
paths.ChromeDllPath = file.FullName; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
FileInfo chromeExe = new FileInfo(Path.Combine(versionsFolder.FullName, exeName)); | ||
if (chromeExe.Exists && paths.ChromeDllPath != null) { // Every installation path also has to have a chrome.exe, otherwise the entire patcher won't work | ||
paths.ChromeExePath = chromeExe.FullName; | ||
return paths; | ||
} | ||
|
||
return new InstallationPaths(this.Name); | ||
} | ||
|
||
protected static void AddDllAndExeToList(List<InstallationPaths> pathList, InstallationPaths latestDllAndExe) { | ||
if (latestDllAndExe.ChromeDllPath != null && latestDllAndExe.ChromeExePath != null) { | ||
pathList.Add(latestDllAndExe); | ||
} | ||
} | ||
|
||
public static double GetUnixTime(DateTime date) { | ||
return (date.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
ChromeDevExtWarningPatcher/InstallationFinder/InstallationManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using ChromeDevExtWarningPatcher.InstallationFinder.Defaults; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
|
||
namespace ChromeDevExtWarningPatcher.InstallationFinder { | ||
public class InstallationManager { | ||
private readonly List<Installation> installationFinders = new List<Installation>(); | ||
|
||
public InstallationManager() { | ||
this.installationFinders.Clear(); | ||
this.installationFinders.Add(new Chrome()); | ||
this.installationFinders.Add(new Brave()); | ||
this.installationFinders.Add(new Edge()); | ||
this.installationFinders.Add(new Yandex()); | ||
} | ||
|
||
public List<InstallationPaths> FindAllChromiumInstallations() { | ||
List<InstallationPaths> installations = new List<InstallationPaths>(); | ||
|
||
foreach (Installation installation in this.installationFinders) { | ||
foreach (InstallationPaths paths in installation.FindInstallationPaths()) { | ||
if (paths.Is64Bit()) { // Force x64 installations | ||
installations.Add(paths); | ||
} | ||
} | ||
} | ||
|
||
return installations; | ||
} | ||
|
||
// Taken from https://stackoverflow.com/questions/480696/how-to-find-if-a-native-dll-file-is-compiled-as-x64-or-x86 | ||
public static bool IsImageX64(string peFilePath) { | ||
using FileStream stream = new FileStream(peFilePath, FileMode.Open, FileAccess.Read); | ||
using BinaryReader reader = new BinaryReader(stream); | ||
|
||
//check the MZ signature to ensure it's a valid Portable Executable image | ||
if (reader.ReadUInt16() != 23117) { | ||
throw new BadImageFormatException("Not a valid Portable Executable image", peFilePath); | ||
} | ||
|
||
// seek to, and read, e_lfanew then advance the stream to there (start of NT header) | ||
stream.Seek(0x3A, SeekOrigin.Current); | ||
stream.Seek(reader.ReadUInt32(), SeekOrigin.Begin); | ||
|
||
// Ensure the NT header is valid by checking the "PE\0\0" signature | ||
if (reader.ReadUInt32() != 17744) { | ||
throw new BadImageFormatException("Not a valid Portable Executable image", peFilePath); | ||
} | ||
|
||
// seek past the file header, then read the magic number from the optional header | ||
stream.Seek(20, SeekOrigin.Current); | ||
ushort magicByte = reader.ReadUInt16(); | ||
return magicByte == 0x20B; | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
ChromeDevExtWarningPatcher/InstallationFinder/InstallationPaths.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using System.IO; | ||
|
||
namespace ChromeDevExtWarningPatcher.InstallationFinder { | ||
public class InstallationPaths { | ||
[Required] | ||
public string Name; | ||
public string? ChromeDllPath, ChromeExePath; | ||
|
||
public InstallationPaths(string name, string chromeDllPath, string chromeExePath) { | ||
this.Name = name; | ||
this.ChromeDllPath = chromeDllPath; | ||
this.ChromeExePath = chromeExePath; | ||
} | ||
|
||
public InstallationPaths(string name, FileInfo chromeDll, FileInfo chromeExe) : this(name, chromeDll.FullName, chromeExe.FullName) { } | ||
|
||
public InstallationPaths(string name) { | ||
this.Name = name; | ||
} | ||
|
||
public bool Is64Bit() { | ||
if(this.ChromeDllPath == null || this.ChromeExePath == null) { | ||
return false; | ||
} | ||
|
||
return InstallationManager.IsImageX64(this.ChromeDllPath) && InstallationManager.IsImageX64(this.ChromeExePath); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.