Compare commits

...

3 Commits

Author SHA1 Message Date
121dfa381d track 2023-05-30 00:23:07 +03:00
80b2df1121 registry 2023-05-28 07:23:03 +03:00
1137495368 registry value 2023-05-24 14:36:03 +03:00
3 changed files with 75 additions and 4 deletions

View File

@@ -7,7 +7,7 @@
<StartupObject>NetWork.Program</StartupObject> <StartupObject>NetWork.Program</StartupObject>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild> <GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<EnableCompressionInSingleFile>true</EnableCompressionInSingleFile>
<StartWorkingDirectory>.</StartWorkingDirectory> <StartWorkingDirectory>.</StartWorkingDirectory>
<SupportedOSPlatformVersion>7.0</SupportedOSPlatformVersion> <SupportedOSPlatformVersion>7.0</SupportedOSPlatformVersion>
@@ -43,6 +43,8 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="AudioControl.x64" Version="1.0.1" /> <PackageReference Include="AudioControl.x64" Version="1.0.1" />
<PackageReference Include="AutoHotkey.Interop" Version="1.0.0.1" /> <PackageReference Include="AutoHotkey.Interop" Version="1.0.0.1" />
<PackageReference Include="LiteDB" Version="5.0.16" />
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="7.0.5" />
<PackageReference Include="Microsoft.Management.Infrastructure" Version="2.0.0" /> <PackageReference Include="Microsoft.Management.Infrastructure" Version="2.0.0" />
<PackageReference Include="Microsoft.NETCore.Windows.ApiSets-x64" Version="1.0.0" /> <PackageReference Include="Microsoft.NETCore.Windows.ApiSets-x64" Version="1.0.0" />
<PackageReference Include="NAudio" Version="2.0.1" /> <PackageReference Include="NAudio" Version="2.0.1" />
@@ -58,6 +60,7 @@
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" /> <PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" /> <PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="SimpleWifi.netstandard" Version="2.0.0" /> <PackageReference Include="SimpleWifi.netstandard" Version="2.0.0" />
<PackageReference Include="SQLite" Version="3.13.0" />
<PackageReference Include="System.Management" Version="6.0.0" /> <PackageReference Include="System.Management" Version="6.0.0" />
<PackageReference Include="System.ServiceProcess.ServiceController" Version="6.0.0" /> <PackageReference Include="System.ServiceProcess.ServiceController" Version="6.0.0" />
<PackageReference Include="TaskScheduler" Version="2.10.1" /> <PackageReference Include="TaskScheduler" Version="2.10.1" />

View File

@@ -8,6 +8,8 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using SQLitePCL;
using LiteDB;
using System.Net.NetworkInformation; using System.Net.NetworkInformation;
using System.ServiceProcess; using System.ServiceProcess;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
@@ -15,6 +17,7 @@ using System.Threading;
using Serilog.Core; using Serilog.Core;
using Serilog.Sinks.File; using Serilog.Sinks.File;
using Serilog.Events; using Serilog.Events;
using Microsoft.Win32;
namespace NetWork namespace NetWork
{ {
@@ -29,7 +32,7 @@ namespace NetWork
foreach (string s in service) { foreach (string s in service) {
Servicer(s, stop); Servicer(s, stop);
} }
} }
private static ServiceController[] GetServices(string service) { private static ServiceController[] GetServices(string service) {
Regex regex = new(service, RegexOptions.IgnoreCase); Regex regex = new(service, RegexOptions.IgnoreCase);
@@ -442,13 +445,14 @@ namespace NetWork
task.FindTask("StartUp and Run").Run(); task.FindTask("StartUp and Run").Run();
} }
public static bool IniData() { public static bool IniData() {
return System.IO.File.ReadAllText("Other\\Data.ini").Equals("RunNetwork"); var toRunOrNotToRun = Registry.GetValue(@"HKEY_CURRENT_USER\Software\SaretNetwork", "Run", 1);
return toRunOrNotToRun is null? true: toRunOrNotToRun.Equals(1)?true:false;
} }
static void Main(string[] args) { static void Main(string[] args) {
Log.Logger = new LoggerConfiguration().WriteTo.File("Logs/NetworkLog.log", LogEventLevel.Debug, Log.Logger = new LoggerConfiguration().WriteTo.File("Logs/NetworkLog.log", LogEventLevel.Debug,
"{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz}[{Level: u3}] {Message:lj}{NewLine}", "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz}[{Level: u3}] {Message:lj}{NewLine}",
rollingInterval: RollingInterval.Minute).CreateLogger(); rollingInterval: RollingInterval.Minute).CreateLogger();
//IgnoreFile.M(); //IgnoreFile.M();
DoTheSchtik(IniData()); DoTheSchtik(IniData());

View File

@@ -0,0 +1,64 @@
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();
}
}
}
}