Skip to content

Commit

Permalink
v2.8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
msasanmh committed Nov 29, 2023
1 parent 6539e8b commit cedbb8b
Show file tree
Hide file tree
Showing 70 changed files with 1,605 additions and 914 deletions.
26 changes: 17 additions & 9 deletions MsmhToolsClass/MsmhToolsClass/DnsTool/DNSCryptConfigEditor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.Net;
using System.Text;

Expand Down Expand Up @@ -225,19 +226,26 @@ public void ChangePersonalServer(string[] sdns)

public async Task WriteAsync()
{
if (!FileDirectory.IsFileLocked(ConfigPath))
try
{
File.WriteAllText(ConfigPath, string.Empty);
for (int n = 0; n < ConfigList.Count; n++)
if (!FileDirectory.IsFileLocked(ConfigPath))
{
string line = ConfigList[n];
File.WriteAllText(ConfigPath, string.Empty);
for (int n = 0; n < ConfigList.Count; n++)
{
string line = ConfigList[n];

if (n == ConfigList.Count - 1)
await FileDirectory.AppendTextAsync(ConfigPath, line, new UTF8Encoding(false));
else
await FileDirectory.AppendTextLineAsync(ConfigPath, line, new UTF8Encoding(false));
if (n == ConfigList.Count - 1)
await FileDirectory.AppendTextAsync(ConfigPath, line, new UTF8Encoding(false));
else
await FileDirectory.AppendTextLineAsync(ConfigPath, line, new UTF8Encoding(false));
}
//File.WriteAllLines(ConfigPath, ConfigList);
}
//File.WriteAllLines(ConfigPath, ConfigList);
}
catch (Exception ex)
{
Debug.WriteLine("DNSCryptConfigEditor WriteAsync: " + ex.Message);
}
}
}
3 changes: 1 addition & 2 deletions MsmhToolsClass/MsmhToolsClass/ExtensionsMethods.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Reflection;
using System.Reflection;
using System.Text;
using System.Xml;
using System.Text.RegularExpressions;
Expand Down
48 changes: 33 additions & 15 deletions MsmhToolsClass/MsmhToolsClass/ProcessManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@ await Task.Run(async () =>
if (OperatingSystem.IsWindows())
{
using PerformanceCounter performanceCounter = new("Process", "% Processor Time", processName, true);
performanceCounter.NextValue(); // Returns 0
await Task.Delay(delay); // Needs time to calculate
result = performanceCounter.NextValue() / Environment.ProcessorCount;
performanceCounter.NextSample(); // Returns 0
await Task.Delay(delay / 2); // Needs time to calculate
CounterSample first = performanceCounter.NextSample();
await Task.Delay(delay / 2); // Needs time to calculate
CounterSample second = performanceCounter.NextSample();
float final = CounterSample.Calculate(first, second);
result = final / Environment.ProcessorCount;
}
}
catch (Exception ex)
Expand Down Expand Up @@ -356,30 +360,44 @@ public static int ExecuteOnly(string processName, string? args = null, bool hide
//-----------------------------------------------------------------------------------
public static bool FindProcessByName(string processName)
{
int result;
Process[] processes = Process.GetProcessesByName(processName);
result = processes.Length;
int result = 0;
try
{
for (int n = 0; n < processes.Length; n++)
processes[n].Dispose();
Process[] processes = Process.GetProcessesByName(processName);
result = processes.Length;
try
{
for (int n = 0; n < processes.Length; n++)
processes[n].Dispose();
}
catch (Exception) { }
}
catch (Exception ex)
{
Debug.WriteLine("FindProcessByName: " + ex.Message);
}
catch (Exception) { }
return result > 0;
}
//-----------------------------------------------------------------------------------
public static bool FindProcessByPID(int pid)
{
bool result = false;
Process[] processes = Process.GetProcesses();
for (int n = 0; n < processes.Length; n++)
try
{
if (processes[n].Id == pid)
Process[] processes = Process.GetProcesses();
for (int n = 0; n < processes.Length; n++)
{
result = true;
break;
if (processes[n].Id == pid)
{
result = true;
break;
}
processes[n].Dispose();
}
processes[n].Dispose();
}
catch (Exception ex)
{
Debug.WriteLine("FindProcessByPID: " + ex.Message);
}
return result;
}
Expand Down
Loading

0 comments on commit cedbb8b

Please sign in to comment.