Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardosnt committed Apr 14, 2016
1 parent 486eef5 commit a0fcc53
Showing 1 changed file with 55 additions and 39 deletions.
94 changes: 55 additions & 39 deletions src/Core/EssCore.cs
Expand Up @@ -21,6 +21,7 @@

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -56,16 +57,16 @@ namespace Essentials.Core
{
public sealed class EssCore : RocketPlugin
{
/*
TODO:
- AFK KICK
- Improve event system to avoid duplicate events.
*/

internal const string PLUGIN_VERSION = "1.1.9.3";
internal const string ROCKET_VERSION = "4.9.4.0";
internal const string UNTURNED_VERSION = "3.14.12.2";
internal const string PLUGIN_VERSION =

#if EXPERIMENTAL
"1.1.9.3-experimental";
#else
"1.1.9.3";
#endif

internal static EssCore Instance { get; set; }

internal Optional<IEconomyProvider> EconomyProvider { get; set; }
Expand Down Expand Up @@ -291,6 +292,10 @@ select type
#else
CommandWindow.ConsoleOutput.title = "Unturned Server";
#endif

#if EXPERIMENTAL
Logger.LogWarning( "This is an experimental build, can be buggy." );
#endif

TryAddComponent<Tasks>();

Expand Down Expand Up @@ -351,49 +356,60 @@ private void PlayerDisconnectCallback( CSteamID id )

private void CheckUpdates()
{
if ( Config.Updater.CheckUpdates )
if ( !Config.Updater.CheckUpdates )
{
new System.Threading.Thread( () =>
{
Logger.LogInfo( "Checking updates." );
return;
}

var isUpdated = Updater.IsUpdated();
var lastResult = Updater.LastResult;
var worker = new BackgroundWorker();

if ( isUpdated )
{
Logger.LogInfo( "Plugin is up-to-date!" );
return;
}
worker.DoWork += ( sender, args ) =>
{
Logger.LogInfo( "Checking updates." );
Logger.LogInfo( $"New version avalaible: {lastResult.LatestVersion}" );
var isUpdated = Updater.IsUpdated();
var lastResult = Updater.LastResult;
if ( !lastResult.AdditionalData.IsNullOrEmpty() )
{
Newtonsoft.Json.Linq.JToken changesStr;
if ( Newtonsoft.Json.Linq.JObject.Parse( lastResult.AdditionalData ).TryGetValue( "changes", out changesStr ) )
{
Logger.LogInfo( "========================= [ Changes ] =========================" );
if ( isUpdated )
{
Logger.LogInfo( "Plugin is up-to-date!" );
return;
}
changesStr.ToString().Split( '\n' ).ForEach( msg => {
Logger.Log( "", ConsoleColor.Green, suffix: "" );
Logger.Log( " " + msg, ConsoleColor.White, "" );
} );
Logger.LogInfo( $"New version avalaible: {lastResult.LatestVersion}" );
Logger.LogInfo( "" );
if ( !lastResult.AdditionalData.IsNullOrEmpty() )
{
Newtonsoft.Json.Linq.JToken changesStr;
if ( Newtonsoft.Json.Linq.JObject.Parse( lastResult.AdditionalData ).TryGetValue( "changes", out changesStr ) )
{
Logger.LogInfo( "========================= [ Changes ] =========================" );
changesStr.ToString().Split( '\n' ).ForEach( msg => {
Logger.Log( "", ConsoleColor.Green, suffix: "" );
Logger.Log( " " + $"See more in: https://github.com/uEssentials/uEssentials/releases/tag/{lastResult.LatestVersion}", ConsoleColor.White, "" );
Logger.Log( " " + msg, ConsoleColor.White, "" );
} );
Logger.LogInfo( "===============================================================" );
}
}
Logger.LogInfo( "" );
Logger.Log( "", ConsoleColor.Green, suffix: "" );
Logger.Log( " " + $"See more in: https://github.com/uEssentials/uEssentials/releases/tag/{lastResult.LatestVersion}", ConsoleColor.White, "" );
if ( Config.Updater.DownloadLatest )
{
Updater.DownloadLatestRelease( $"{Folder}/updates/" );
Logger.LogInfo( "===============================================================" );
}
} ).Start();
}
}
if ( Config.Updater.DownloadLatest )
{
Updater.DownloadLatestRelease( $"{Folder}/updates/" );
}
};

worker.RunWorkerCompleted += ( sender, args ) => {
if ( args.Error != null )
Logger.LogError( $"Could not update, try again later. ({args.Error.Message})" );
};

worker.RunWorkerAsync();
}

private void UnregisterRocketCommands( bool silent = false )
Expand Down

0 comments on commit a0fcc53

Please sign in to comment.