-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathProgram.cs
More file actions
112 lines (90 loc) · 3.43 KB
/
Program.cs
File metadata and controls
112 lines (90 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* Copyright (c) 2013, SteamDB. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
* Future non-SteamKit stuff should go in this file.
*/
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading;
using SteamKit2;
namespace SteamDatabaseBackend
{
internal static class Program
{
private static List<GCIdler> GCIdlers = new List<GCIdler>();
public static void Main()
{
var version = Assembly.GetExecutingAssembly().GetName().Version;
string date = new DateTime(2000, 01, 01).AddDays(version.Build).AddSeconds(version.Revision * 2).ToUniversalTime().ToString();
Log.WriteInfo("Main", "Built on {0} UTC", date);
try
{
Settings.Load();
}
catch (Exception e)
{
Log.WriteError("Settings", "{0}", e.Message);
return;
}
if (Settings.Current.SteamKitDebug)
{
DebugLog.AddListener(new Log.SteamKitLogger());
DebugLog.Enabled = true;
}
Console.CancelKeyPress += delegate
{
Log.WriteInfo("Main", "Exiting...");
foreach (var idler in GCIdlers)
{
try
{
idler.IsRunning = false;
idler.Client.Disconnect();
}
catch { }
}
Steam.Instance.IsRunning = false;
try { Steam.Instance.Timer.Stop(); } catch { }
try { DepotProcessor.ThreadPool.Shutdown(true, 1000); } catch { }
try { Steam.Instance.SecondaryPool.Shutdown(true, 1000); } catch { }
try { Steam.Instance.ProcessorPool.Shutdown(true, 1000); } catch { }
try { Steam.Instance.Client.Disconnect(); } catch { }
if (Settings.Current.IRC.Enabled)
{
IRC.Instance.Kill();
}
DbWorker.ExecuteNonQuery("TRUNCATE TABLE `GC`");
};
Thread thread = new Thread(new ThreadStart(Steam.Instance.Init));
thread.Name = "Steam";
thread.Start();
if (Settings.Current.FullRun > 0)
{
Settings.Current.IRC.Enabled = false;
return;
}
foreach (var idler in Settings.Current.GameCoordinatorIdlers)
{
if (string.IsNullOrWhiteSpace(idler.Username) || string.IsNullOrWhiteSpace(idler.Password) || idler.AppID <= 0)
{
Log.WriteWarn("Settings", "Invalid GC coordinator settings");
continue;
}
Log.WriteInfo("Main", "Starting GC idler for app {0}", idler.AppID);
var instance = new GCIdler(idler.AppID, idler.Username, idler.Password);
thread = new Thread(new ThreadStart(instance.Run));
thread.Name = "Steam";
thread.Start();
GCIdlers.Add(instance);
}
if (Settings.CanConnectToIRC())
{
SteamProxy.Instance.ReloadImportant();
IRC.Instance.Init();
}
}
}
}