Skip to content
This repository has been archived by the owner on Apr 3, 2022. It is now read-only.

Commit

Permalink
Add code to find browsers from HKCU
Browse files Browse the repository at this point in the history
  • Loading branch information
spikespaz committed Nov 8, 2018
1 parent 03a063b commit 6dd27d6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
10 changes: 10 additions & 0 deletions source/common.d
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,13 @@ string[string] parseConfig(const string config) {

return data;
}

/// Merge two associative arrays, updating existing values in "baseAA" with new ones from "updateAA".
T[K] mergeAAs(T, K)(T[K] baseAA, T[K] updateAA) {
T[K] newAA = baseAA;

foreach (key; updateAA.byKey())
newAA[key] = updateAA[key];

return newAA;
}
23 changes: 17 additions & 6 deletions source/setup.d
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module setup;

import common: DeflectorSettings, parseConfig, writeSettings, createErrorDialog, getConsoleArgs,
PROJECT_VERSION, ENGINE_TEMPLATES;
import std.windows.registry: Registry, Key;
mergeAAs, PROJECT_VERSION, ENGINE_TEMPLATES;
import std.windows.registry: Registry, Key, RegistryException;
import std.string: strip, split, indexOf, toLower;
import std.socket: SocketException, getAddress;
import std.regex: Regex, regex, matchFirst;
Expand All @@ -19,7 +19,7 @@ void main() {
writeln("Version: " ~ PROJECT_VERSION);

try {
const string[string] browsers = getAvailableBrowsers();
const string[string] browsers = mergeAAs(getAvailableBrowsers(false), getAvailableBrowsers(true));
const string[string] engines = parseConfig(ENGINE_TEMPLATES);

DeflectorSettings settings = promptSettings(browsers, engines);
Expand Down Expand Up @@ -80,12 +80,23 @@ DeflectorSettings promptSettings(const string[string] browsers, const string[str

/// Fetch a list of available browsers from the Windows registry along with their paths.
/// Use the names as the keys in an associative array containing the browser executable paths.
string[string] getAvailableBrowsers() {
string[string] getAvailableBrowsers(const bool currentUser = false) {
string[string] availableBrowsers;
Key startMenuInternetKey = Registry.localMachine.getKey("SOFTWARE\\Clients\\StartMenuInternet");
Key startMenuInternetKey;

if (currentUser)
startMenuInternetKey = Registry.currentUser.getKey("SOFTWARE\\Clients\\StartMenuInternet");
else
startMenuInternetKey = Registry.localMachine.getKey("SOFTWARE\\Clients\\StartMenuInternet");

foreach (key; startMenuInternetKey.keys) {
string browserName = key.getValue("").value_SZ;
string browserName;

try
browserName = key.getValue("").value_SZ;
catch (RegistryException)
continue;

string browserPath = key.getKey("shell\\open\\command").getValue("").value_SZ;

if (!isValidFilename(browserPath) && !exists(browserPath)) {
Expand Down

0 comments on commit 6dd27d6

Please sign in to comment.