Switched to top level main.
This commit is contained in:
parent
34e4e9b1a9
commit
78a683620f
1 changed files with 131 additions and 138 deletions
|
@ -1,80 +1,43 @@
|
|||
using SharpChat;
|
||||
using SharpChat.Configuration;
|
||||
using SharpChat.EventStorage;
|
||||
using SharpChat.Flashii;
|
||||
using System.Text;
|
||||
|
||||
namespace SharpChat;
|
||||
const string CONFIG = "sharpchat.cfg";
|
||||
|
||||
public class Program {
|
||||
public const string CONFIG = "sharpchat.cfg";
|
||||
|
||||
public static void Main() {
|
||||
Console.WriteLine(@" _____ __ ________ __ ");
|
||||
Console.WriteLine(@" / ___// /_ ____ __________ / ____/ /_ ____ _/ /_");
|
||||
Console.WriteLine(@" \__ \/ __ \/ __ `/ ___/ __ \/ / / __ \/ __ `/ __/");
|
||||
Console.WriteLine(@" ___/ / / / / /_/ / / / /_/ / /___/ / / / /_/ / /_ ");
|
||||
Console.WriteLine(@"/____/_/ /_/\__,_/_/ / .___/\____/_/ /_/\__,_/\__/ ");
|
||||
/**/Console.Write(@" /__/");
|
||||
if(SharpInfo.IsDebugBuild) {
|
||||
Console.WriteLine(@" _____ __ ________ __ ");
|
||||
Console.WriteLine(@" / ___// /_ ____ __________ / ____/ /_ ____ _/ /_");
|
||||
Console.WriteLine(@" \__ \/ __ \/ __ `/ ___/ __ \/ / / __ \/ __ `/ __/");
|
||||
Console.WriteLine(@" ___/ / / / / /_/ / / / /_/ / /___/ / / / /_/ / /_ ");
|
||||
Console.WriteLine(@"/____/_/ /_/\__,_/_/ / .___/\____/_/ /_/\__,_/\__/ ");
|
||||
/**/Console.Write(@" /__/");
|
||||
if(SharpInfo.IsDebugBuild) {
|
||||
Console.WriteLine();
|
||||
Console.Write(@"== ");
|
||||
Console.Write(SharpInfo.VersionString);
|
||||
Console.WriteLine(@" == DBG ==");
|
||||
} else
|
||||
} else
|
||||
Console.WriteLine(SharpInfo.VersionStringShort.PadLeft(28, ' '));
|
||||
|
||||
using ManualResetEvent mre = new(false);
|
||||
bool hasCancelled = false;
|
||||
using ManualResetEvent mre = new(false);
|
||||
bool hasCancelled = false;
|
||||
|
||||
void cancelKeyPressHandler(object? sender, ConsoleCancelEventArgs ev) {
|
||||
void cancelKeyPressHandler(object? sender, ConsoleCancelEventArgs ev) {
|
||||
Console.CancelKeyPress -= cancelKeyPressHandler;
|
||||
hasCancelled = true;
|
||||
ev.Cancel = true;
|
||||
mre.Set();
|
||||
};
|
||||
Console.CancelKeyPress += cancelKeyPressHandler;
|
||||
}
|
||||
;
|
||||
Console.CancelKeyPress += cancelKeyPressHandler;
|
||||
|
||||
if(hasCancelled) return;
|
||||
if(hasCancelled) return;
|
||||
|
||||
string configFile = CONFIG;
|
||||
string configFile = CONFIG;
|
||||
|
||||
// If the config file doesn't exist and we're using the default path, run the converter
|
||||
if(!File.Exists(configFile) && configFile == CONFIG)
|
||||
ConvertConfiguration();
|
||||
|
||||
using StreamConfig config = StreamConfig.FromPath(configFile);
|
||||
|
||||
if(hasCancelled) return;
|
||||
|
||||
using HttpClient httpClient = new(new HttpClientHandler() {
|
||||
UseProxy = false,
|
||||
});
|
||||
httpClient.DefaultRequestHeaders.Add("User-Agent", SharpInfo.ProgramName);
|
||||
|
||||
if(hasCancelled) return;
|
||||
|
||||
FlashiiClient flashii = new(httpClient, config.ScopeTo("msz"));
|
||||
|
||||
if(hasCancelled) return;
|
||||
|
||||
EventStorage.EventStorage evtStore;
|
||||
if(string.IsNullOrWhiteSpace(config.SafeReadValue("mariadb:host", string.Empty))) {
|
||||
evtStore = new VirtualEventStorage();
|
||||
} else {
|
||||
MariaDBEventStorage mdbes = new(MariaDBEventStorage.BuildConnString(config.ScopeTo("mariadb")));
|
||||
evtStore = mdbes;
|
||||
mdbes.RunMigrations();
|
||||
}
|
||||
|
||||
if(hasCancelled) return;
|
||||
|
||||
using SockChatServer scs = new(flashii, flashii, evtStore, config.ScopeTo("chat"));
|
||||
scs.Listen(mre);
|
||||
|
||||
mre.WaitOne();
|
||||
}
|
||||
|
||||
private static void ConvertConfiguration() {
|
||||
// If the config file doesn't exist and we're using the default path, run the converter
|
||||
if(!File.Exists(configFile) && configFile == CONFIG) {
|
||||
using Stream s = new FileStream(CONFIG, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
|
||||
s.SetLength(0);
|
||||
s.Flush();
|
||||
|
@ -143,5 +106,35 @@ public class Program {
|
|||
sw.WriteLine($"#mariadb:db <database>");
|
||||
|
||||
sw.Flush();
|
||||
}
|
||||
}
|
||||
|
||||
using StreamConfig config = StreamConfig.FromPath(configFile);
|
||||
|
||||
if(hasCancelled) return;
|
||||
|
||||
using HttpClient httpClient = new(new HttpClientHandler() {
|
||||
UseProxy = false,
|
||||
});
|
||||
httpClient.DefaultRequestHeaders.Add("User-Agent", SharpInfo.ProgramName);
|
||||
|
||||
if(hasCancelled) return;
|
||||
|
||||
FlashiiClient flashii = new(httpClient, config.ScopeTo("msz"));
|
||||
|
||||
if(hasCancelled) return;
|
||||
|
||||
EventStorage evtStore;
|
||||
if(string.IsNullOrWhiteSpace(config.SafeReadValue("mariadb:host", string.Empty))) {
|
||||
evtStore = new VirtualEventStorage();
|
||||
} else {
|
||||
MariaDBEventStorage mdbes = new(MariaDBEventStorage.BuildConnString(config.ScopeTo("mariadb")));
|
||||
evtStore = mdbes;
|
||||
mdbes.RunMigrations();
|
||||
}
|
||||
|
||||
if(hasCancelled) return;
|
||||
|
||||
using SockChatServer scs = new(flashii, flashii, evtStore, config.ScopeTo("chat"));
|
||||
scs.Listen(mre);
|
||||
|
||||
mre.WaitOne();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue