-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5897b59
commit b88361a
Showing
5 changed files
with
111 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using DiscordProxyStart.Utils; | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Threading; | ||
|
||
|
||
namespace DiscordProxyStart.Services | ||
{ | ||
|
||
public class GostManager | ||
{ | ||
|
||
private static GostManager _instance; | ||
Check warning on line 14 in DiscordProxyStart/Services/GostManager.cs GitHub Actions / Dotnet Build
|
||
private static readonly object _lock = new object(); | ||
|
||
private readonly string gostPath; | ||
|
||
public static GostManager Instance | ||
{ | ||
get | ||
{ | ||
if (_instance == null) | ||
{ | ||
lock (_lock) | ||
{ | ||
if (_instance == null) | ||
{ | ||
_instance = new GostManager($@"{AppContext.BaseDirectory}gost.exe"); | ||
} | ||
} | ||
} | ||
return _instance; | ||
} | ||
} | ||
|
||
public GostManager(string gostPath) | ||
{ | ||
this.gostPath = gostPath; | ||
} | ||
|
||
private void KillExistingGostProcess() | ||
{ | ||
var processes = Process.GetProcessesByName("gost"); | ||
foreach (var process in processes) | ||
{ | ||
try | ||
{ | ||
string processPath = Path.GetFullPath(process.MainModule?.FileName ?? string.Empty); | ||
|
||
if (string.Equals(processPath, gostPath, StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
process.Kill(); | ||
process.WaitForExit(); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
SimpleLogger.Instance.Info(@$"[KillExistingGostProcessError]{ex}"); | ||
} | ||
} | ||
} | ||
|
||
public void StartProxy(string socksProxyAddress, int localHttpPort) | ||
{ | ||
KillExistingGostProcess(); | ||
var startInfo = new ProcessStartInfo | ||
{ | ||
FileName = gostPath, | ||
Arguments = $"-L=http://127.0.0.1:{localHttpPort} -F={socksProxyAddress}", | ||
UseShellExecute = false, | ||
CreateNoWindow = true, | ||
}; | ||
|
||
Debug.WriteLine(startInfo.Arguments); | ||
var currentProcess = new Process { StartInfo = startInfo }; | ||
currentProcess.Start(); | ||
//currentProcess.WaitForExit(); | ||
Thread.Sleep(3000); | ||
} | ||
} | ||
|
||
|
||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters