Files
NetWork/NetWork/RegistarRegistry.cs
2023-05-30 00:23:07 +03:00

65 lines
2.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using Microsoft.Win32;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace NetWork
{
internal class RegistarRegistry
{
public static bool IniData()
{
var toRunOrNotToRun = Registry.GetValue(@"HKEY_CURRENT_USER\Software\SaretNetwork", "Run", 1);
return toRunOrNotToRun is null ? true : toRunOrNotToRun.Equals(1) ? true : false;
}
}
internal class NetworkInterface
{
public string Name { get; set; }
public ListOfPrograms ListOfProgramsToStart { get; set; }
public ListOfPrograms ListOfProgramsToStop { get; set; }
public string[] ServicesToStart { get; set; }
public string[] ServicesToStop { get;set; }
public bool Mute { get; set; }=true;
public NetworkInterface(string name, string url)
{
Name = name;
}
}
internal class ListOfPrograms
{
public string[] ProgramName { get; private set; }
public string[] ProgramPath { get; private set; }
public ListOfPrograms(string url) {
WebClient webClient = new();
string[] data = Regex.Split(Regex.Replace(webClient.DownloadString(url),@"[\{\}]",""),",");
ProgramName = new string[data.Length];
ProgramPath = new string[data.Length];
for(int i = 0; i < data.Length; i++)
{
ProgramName[i] = Regex.Match(data[i], @"(?<="").+(?="":)").Value;
ProgramPath[i] = Regex.Match(data[i], @"(?<=:\s?"")[^""]+").Value;
}
//string d = Regex.Replace(webClient.DownloadString(url), @"[\{\}]", "");
//ProgramName = Regex.Matches(d,@"(?<=\"")\w+(?=\"":)").Select(x => x.Value).ToArray();
}
public ListOfPrograms(string registryHive, string registryName)
{
string location = Regex.IsMatch(registryHive, @"HKEY_") ? Regex.Replace(registryHive, @"^[^\\]+", "")[1..] : registryHive;
RegistryKey key = Registry.CurrentUser.OpenSubKey($"{location}\\{registryName}") ;
ProgramName = key.GetValueNames();
ProgramPath = new string[ProgramName.Length];
for (int i = 0; i < ProgramName.Length; i++)
{
ProgramPath[i] = Registry.GetValue($"HKEY_CURRENT_USER\\{location}\\{registryName}", ProgramName[i], "").ToString();
}
}
}
}