Work work

This commit is contained in:
JustArchi
2015-11-01 02:04:44 +01:00
parent 337c397505
commit 164240641b
8 changed files with 233 additions and 85 deletions

View File

@@ -45,7 +45,9 @@ namespace ArchiSteamFarm {
internal static readonly object ConsoleLock = new object();
private static readonly ManualResetEvent ShutdownResetEvent = new ManualResetEvent(false);
private static readonly AssemblyName AssemblyName = Assembly.GetExecutingAssembly().GetName();
private static readonly Assembly Assembly = Assembly.GetExecutingAssembly();
private static readonly string ExecutablePath = Assembly.Location;
private static readonly AssemblyName AssemblyName = Assembly.GetName();
private static readonly string ExeName = AssemblyName.Name + ".exe";
private static readonly string Version = AssemblyName.Version.ToString();
@@ -69,7 +71,7 @@ namespace ArchiSteamFarm {
if (localVersion.CompareTo(remoteVersion) < 0) {
Logging.LogGenericNotice("", "New version is available!");
Logging.LogGenericNotice("", "Consider updating yourself!");
Thread.Sleep(5000);
await Utilities.SleepAsync(5000).ConfigureAwait(false);
} else if (localVersion.CompareTo(remoteVersion) > 0) {
Logging.LogGenericNotice("", "You're currently using pre-release version!");
Logging.LogGenericNotice("", "Be careful!");
@@ -81,6 +83,12 @@ namespace ArchiSteamFarm {
Environment.Exit(exitCode);
}
internal static async Task Restart() {
await Bot.ShutdownAllBots().ConfigureAwait(false);
System.Diagnostics.Process.Start(ExecutablePath);
Environment.Exit(0);
}
internal static string GetUserInput(string botLogin, EUserInputType userInputType) {
string result;
lock (ConsoleLock) {
@@ -107,10 +115,10 @@ namespace ArchiSteamFarm {
return result;
}
internal static void OnBotShutdown(Bot bot) {
internal static async void OnBotShutdown(Bot bot) {
if (Bot.GetRunningBotsCount() == 0) {
Logging.LogGenericInfo("Main", "No bots are running, exiting");
Thread.Sleep(5000); // This might be the only message user gets, consider giving him some time
await Utilities.SleepAsync(5000).ConfigureAwait(false); // This might be the only message user gets, consider giving him some time
ShutdownResetEvent.Set();
}
}
@@ -120,6 +128,16 @@ namespace ArchiSteamFarm {
Task.Run(async () => await CheckForUpdate().ConfigureAwait(false)).Wait();
// Allow loading configs from source tree if it's a debug build
if (Debugging.IsDebugBuild) {
for (var i = 0; i < 4; i++) {
Directory.SetCurrentDirectory("..");
if (Directory.Exists(ConfigDirectoryPath)) {
break;
}
}
}
if (!Directory.Exists(ConfigDirectoryPath)) {
Logging.LogGenericError("Main", "Config directory doesn't exist!");
Console.ReadLine();