@@ -22,10 +22,13 @@ limitations under the License.
2222
2323*/
2424
25+ using Newtonsoft . Json . Linq ;
2526using System ;
2627using System . Collections . Generic ;
2728using System . IO ;
29+ using System . Reflection ;
2830using System . Threading ;
31+ using System . Threading . Tasks ;
2932
3033namespace ArchiSteamFarm {
3134 internal static class Program {
@@ -39,8 +42,33 @@ internal enum EUserInputType {
3942
4043 internal const ulong ArchiSCFarmGroup = 103582791440160998 ;
4144 internal const string ConfigDirectoryPath = "config" ;
45+ private const string LatestGithubReleaseURL = "https://api.github.com/repos/JustArchi/ArchiSteamFarm/releases/latest" ;
46+
4247 private static readonly HashSet < Bot > Bots = new HashSet < Bot > ( ) ;
4348 internal static readonly object ConsoleLock = new object ( ) ;
49+ internal static string Version { get { return Assembly . GetExecutingAssembly ( ) . GetName ( ) . Version . ToString ( ) ; } }
50+
51+ private static async Task CheckForUpdate ( ) {
52+ JObject response = await Utilities . UrlToJObject ( LatestGithubReleaseURL ) . ConfigureAwait ( false ) ;
53+ if ( response == null ) {
54+ return ;
55+ }
56+
57+ string remoteVersion = response [ "tag_name" ] . ToString ( ) ;
58+ if ( string . IsNullOrEmpty ( remoteVersion ) ) {
59+ return ;
60+ }
61+
62+ string localVersion = Version ;
63+
64+ if ( localVersion . CompareTo ( remoteVersion ) < 0 ) {
65+ Logging . LogGenericNotice ( "" , "New version is available!" ) ;
66+ Logging . LogGenericNotice ( "" , "Local version: " + localVersion ) ;
67+ Logging . LogGenericNotice ( "" , "Remote version: " + remoteVersion ) ;
68+ Logging . LogGenericNotice ( "" , "Consider updating yourself!" ) ;
69+ Thread . Sleep ( 5000 ) ;
70+ }
71+ }
4472
4573 internal static void Exit ( int exitCode = 0 ) {
4674 ShutdownAllBots ( ) ;
@@ -83,6 +111,10 @@ private static void ShutdownAllBots() {
83111 }
84112
85113 private static void Main ( string [ ] args ) {
114+ Logging . LogGenericInfo ( "Main" , "Archi's Steam Farm, version " + Version ) ;
115+
116+ Task . Run ( async ( ) => await CheckForUpdate ( ) . ConfigureAwait ( false ) ) . Wait ( ) ;
117+
86118 // Config directory may not be in the same directory as the .exe, check maximum of 3 levels lower
87119 for ( var i = 0 ; i < 4 && ! Directory . Exists ( ConfigDirectoryPath ) ; i ++ ) {
88120 Directory . SetCurrentDirectory ( ".." ) ;
@@ -97,7 +129,11 @@ private static void Main(string[] args) {
97129 lock ( Bots ) {
98130 foreach ( var configFile in Directory . EnumerateFiles ( ConfigDirectoryPath , "*.xml" ) ) {
99131 string botName = Path . GetFileNameWithoutExtension ( configFile ) ;
100- Bots . Add ( new Bot ( botName ) ) ;
132+ Bot bot = new Bot ( botName ) ;
133+ Bots . Add ( bot ) ;
134+ if ( ! bot . Enabled ) {
135+ Logging . LogGenericInfo ( botName , "Not starting this instance because it's disabled in config file" ) ;
136+ }
101137 }
102138 }
103139
0 commit comments