-
Notifications
You must be signed in to change notification settings - Fork 2
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
15a29ba
commit d4be002
Showing
10 changed files
with
405 additions
and
396 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,51 @@ | ||
using System; | ||
|
||
namespace SimpleVoiceroid2Proxy; | ||
|
||
public sealed class ConsoleLogger : ILogger | ||
{ | ||
public static readonly ILogger Instance = new ConsoleLogger(); | ||
|
||
public void Debug(string message) | ||
{ | ||
#if DEBUG | ||
Log(LogLevel.DEBUG, message); | ||
#endif | ||
} | ||
|
||
public void Info(string message) | ||
{ | ||
Log(LogLevel.INFO, message); | ||
} | ||
|
||
public void Warn(string message) | ||
{ | ||
Log(LogLevel.WARN, message); | ||
} | ||
|
||
public void Error(Exception exception, string message) | ||
{ | ||
Log(LogLevel.ERROR, $"{message}\n{exception}"); | ||
} | ||
|
||
private void Log(LogLevel level, string message) | ||
{ | ||
Console.WriteLine($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}] [{level}] {message}"); | ||
} | ||
} | ||
|
||
public interface ILogger | ||
{ | ||
public void Debug(string message); | ||
public void Info(string message); | ||
public void Warn(string message); | ||
public void Error(Exception exception, string message); | ||
} | ||
|
||
public enum LogLevel | ||
{ | ||
DEBUG, | ||
INFO, | ||
WARN, | ||
ERROR, | ||
} |
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 |
---|---|---|
@@ -1,83 +1,23 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
using System.Threading.Tasks; | ||
using SimpleVoiceroid2Proxy.Server; | ||
|
||
namespace SimpleVoiceroid2Proxy | ||
{ | ||
public static class Program | ||
{ | ||
static Program() | ||
{ | ||
KillDuplicatedProcesses(); | ||
} | ||
|
||
public static readonly ILogger Logger = new LoggerImpl(); | ||
private static readonly HttpServer Server = new(); | ||
public static readonly VoiceroidEngine VoiceroidEngine = new(); | ||
|
||
public static void Main() | ||
{ | ||
Task.Run(async () => | ||
{ | ||
await VoiceroidEngine.TalkAsync("準備完了!"); | ||
await Server.ConsumeAsync(); | ||
}).Wait(); | ||
} | ||
|
||
private static void KillDuplicatedProcesses() | ||
{ | ||
var currentProcess = Process.GetCurrentProcess(); | ||
var imageName = Assembly.GetExecutingAssembly() | ||
.Location | ||
.Split(Path.DirectorySeparatorChar) | ||
.Last() | ||
.Replace(".exe", ""); | ||
namespace SimpleVoiceroid2Proxy; | ||
|
||
foreach (var process in Process.GetProcessesByName(imageName).Where(x => x.Id != currentProcess.Id)) | ||
{ | ||
try | ||
{ | ||
process.Kill(); | ||
Logger.Info($"{imageName}.exe (PID: {process.Id}) has been killed."); | ||
} | ||
catch | ||
{ | ||
Logger.Warn($"Failed to kill {imageName}.exe (PID: {process.Id})."); | ||
} | ||
} | ||
} | ||
|
||
private class LoggerImpl : ILogger | ||
{ | ||
public void Info(string message) | ||
{ | ||
Write("Info", message); | ||
} | ||
|
||
public void Warn(string message) | ||
{ | ||
Write("Warn", message); | ||
} | ||
|
||
public void Error(Exception exception) | ||
{ | ||
Write("Error", exception.ToString()); | ||
} | ||
public static class Program | ||
{ | ||
private static readonly HttpServer server = new(); | ||
public static readonly VoiceroidEngine VoiceroidEngine = new(); | ||
|
||
private static void Write(string level, string message) | ||
{ | ||
Console.WriteLine($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] [{level}] {message}"); | ||
} | ||
} | ||
static Program() | ||
{ | ||
Utils.KillDuplicateProcesses(); | ||
} | ||
|
||
public interface ILogger | ||
public static void Main() | ||
{ | ||
public void Info(string message); | ||
public void Warn(string message); | ||
public void Error(Exception exception); | ||
Task.WaitAll( | ||
server.ListenAsync(), | ||
VoiceroidEngine.TalkAsync("準備完了!") | ||
); | ||
} | ||
} |
Oops, something went wrong.