Skip to content

Commit

Permalink
4.1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Ni1kko committed Oct 15, 2021
1 parent c4df741 commit 6a31b03
Show file tree
Hide file tree
Showing 18 changed files with 159 additions and 97 deletions.
4 changes: 2 additions & 2 deletions Source/HourBoostr.Settings/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("4.1.7")]
[assembly: AssemblyFileVersion("4.1.7")]
[assembly: AssemblyVersion("4.1.8")]
[assembly: AssemblyFileVersion("4.1.8")]
4 changes: 2 additions & 2 deletions Source/HourBoostr/Core/Bot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ public Bot(SingleBoostr.Core.Objects.AccountSettings info)
ServicePointManager.ServerCertificateValidationCallback += mSteam.web.ValidateRemoteCertificate;

/*Create logs*/
mLog = new Log(info.Details.Username, Path.Combine(EndPoint.LOG_FOLDER_PATH, $"{info.Details.Username}.txt"), 1);
mLogChat = new Log($"{info.Details.Username} Chat", Path.Combine(EndPoint.LOG_FOLDER_PATH, $"{info.Details.Username} steam chat.txt"), 1);
mLog = new Log(info.Details.Username, Path.Combine(SingleBoostr.Core.Misc.Const.HourBoostr.LOG_FOLDER, $"{info.Details.Username}.txt"), 1);
mLogChat = new Log($"{info.Details.Username} Chat", Path.Combine(SingleBoostr.Core.Misc.Const.HourBoostr.LOG_FOLDER, $"{info.Details.Username} steam chat.txt"), 1);

/*Assign clients*/
mSteam.client = new SteamClient();
Expand Down
11 changes: 0 additions & 11 deletions Source/HourBoostr/Core/EndPoint.cs

This file was deleted.

2 changes: 1 addition & 1 deletion Source/HourBoostr/Core/GlobalDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace HourBoostr
* https://github.com/JustArchi/ArchiSteamFarm
*/

class GlobalDB : IDisposable
public class GlobalDB : IDisposable
{
private static readonly JsonSerializerSettings CustomSerializerSettings = new JsonSerializerSettings
{
Expand Down
61 changes: 36 additions & 25 deletions Source/HourBoostr/Core/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using HourBoostr.Objects;
using HourBoostr.Enums;
using SingleBoostr.Core.Misc;
using System.Threading.Tasks;

namespace HourBoostr
{
Expand All @@ -27,7 +28,7 @@ class Session
/// <summary>
/// Application settings
/// </summary>
public Config.Settings mSettings;
public Config.Settings mSettings { get; private set; } = null;


/// <summary>
Expand All @@ -44,13 +45,42 @@ public Session(Config.Settings settings)
{
mSettings = settings;

string updateInfo = Updater.Check(Assembly.GetExecutingAssembly()).GetAwaiter().GetResult();

if (settings.CheckForUpdates && !string.IsNullOrEmpty(updateInfo))
Console.WriteLine("There's an update available. Check out https://github.com/Ezzpify/HourBoostr/releases/latest");

}
internal async Task WriteLoadingMessage(string msg)
{
Console.WriteLine($"{msg}.");
await Task.Delay(1 * 1000);
Console.WriteLine($"{msg}..");
await Task.Delay(1 * 1000);
Console.WriteLine($"{msg}...");
await Task.Delay(1 * 1000);
Console.Clear();
}

internal async Task<bool> Startup()
{
if (mSettings == null) return false;

await WriteLoadingMessage($"{Const.HourBoostr.NAME} Loading");

//check for update
string updateInfo = await Updater.Check(Assembly.GetExecutingAssembly());
if (mSettings.CheckForUpdates && !string.IsNullOrEmpty(updateInfo))
{
await WriteLoadingMessage($"{Const.HourBoostr.NAME} has new update");
Console.WriteLine($"Update available. Check out {Const.GitHub.REPO_RELEASE_URL}");
}
else
{
Console.WriteLine($"{Const.HourBoostr.NAME} v{Const.HourBoostr.VERSION} Loaded");
}

//subscribe and start bg worker
mBwg.DoWork += MBwg_DoWork;
mBwg.RunWorkerAsync();

return true;
}


Expand Down Expand Up @@ -101,25 +131,6 @@ private void MBwg_DoWork(object sender, DoWorkEventArgs e)
}
}

private void HideAppToTray()
{

}


/// <summary>
/// Returns the DateTime of when the application was built
/// </summary>
/// <returns>DateTime</returns>
private DateTime GetBuildDate()
{
var version = Assembly.GetEntryAssembly().GetName().Version;
return new DateTime(2000, 1, 1).Add(new TimeSpan(
TimeSpan.TicksPerDay * version.Build +
TimeSpan.TicksPerSecond * 2 * version.Revision));
}


/// <summary>
/// Status for how long the bot has been running
/// </summary>
Expand All @@ -135,7 +146,7 @@ private void ThreadStatus()
string timeSpentOnline = string.Format("{0} Hours {1} Minutes {2} Seconds",
(timeSpan.Days * 24) + timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds);

Console.Title = $"{EndPoint.CONSOLE_TITLE} | Online for: {timeSpentOnline}";
Console.Title = $"{Const.HourBoostr.CONSOLE_TITLE} | Online for: {timeSpentOnline}";
Thread.Sleep(500);
}
}
Expand Down
12 changes: 6 additions & 6 deletions Source/HourBoostr/Core/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static class Settings
/// <returns></returns>
public static Config.Settings GetSettings()
{
if (!File.Exists(EndPoint.SETTINGS_FILE_PATH))
if (!File.Exists(SingleBoostr.Core.Misc.Const.HourBoostr.SETTINGS_FILE))
{
static SingleBoostr.Core.Objects.AccountSettings NewAccount() => new SingleBoostr.Core.Objects.AccountSettings() { Games = new List<int>() { 730, 10 } };

Expand All @@ -30,15 +30,15 @@ public static Config.Settings GetSettings()
}
};

File.WriteAllText(EndPoint.SETTINGS_FILE_PATH, JsonConvert.SerializeObject(settings, Formatting.Indented));
Console.WriteLine($"Settings file has been written at {EndPoint.SETTINGS_FILE_PATH}\nPlease close the program and edit the settings.");
File.WriteAllText(SingleBoostr.Core.Misc.Const.HourBoostr.SETTINGS_FILE, JsonConvert.SerializeObject(settings, Formatting.Indented));
Console.WriteLine($"Settings file has been written at {SingleBoostr.Core.Misc.Const.HourBoostr.SETTINGS_FILE}\nPlease close the program and edit the settings.");
}
else
{
var serializeSettings = new JsonSerializerSettings() { MissingMemberHandling = MissingMemberHandling.Error };
try
{
var settings = JsonConvert.DeserializeObject<Config.Settings>(File.ReadAllText(EndPoint.SETTINGS_FILE_PATH));
var settings = JsonConvert.DeserializeObject<Config.Settings>(File.ReadAllText(SingleBoostr.Core.Misc.Const.HourBoostr.SETTINGS_FILE));
settings.Accounts = settings.Accounts.Where(o => !string.IsNullOrWhiteSpace(o.Details.Username)).Distinct().ToList();

return settings;
Expand All @@ -61,15 +61,15 @@ public static Config.Settings GetSettings()
/// <returns>Return true. Lol.</returns>
public static bool SaveSettings(Config.Settings settings)
{
File.WriteAllText(EndPoint.SETTINGS_FILE_PATH, JsonConvert.SerializeObject(settings, Formatting.Indented));
File.WriteAllText(SingleBoostr.Core.Misc.Const.HourBoostr.SETTINGS_FILE, JsonConvert.SerializeObject(settings, Formatting.Indented));
return true;
}

public static void UpdateAccount(SingleBoostr.Core.Objects.AccountSettings acc)
{
var settings = GetSettings();
settings.Accounts.First(o => o.Details.Username == acc.Details.Username).Details.LoginKey = acc.Details.LoginKey;
File.WriteAllText(EndPoint.SETTINGS_FILE_PATH, JsonConvert.SerializeObject(settings, Formatting.Indented));
File.WriteAllText(SingleBoostr.Core.Misc.Const.HourBoostr.SETTINGS_FILE, JsonConvert.SerializeObject(settings, Formatting.Indented));

//var account = GetSettings().Accounts.First(o => o.Details.Username == acc.Details.Username);
//account = acc;
Expand Down
1 change: 0 additions & 1 deletion Source/HourBoostr/HourBoostr.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@
<Compile Include="Core\Log.cs" />
<Compile Include="Enums\LogLevel.cs" />
<Compile Include="Objects\Config.cs" />
<Compile Include="Core\EndPoint.cs" />
<Compile Include="Enums\BotState.cs" />
<Compile Include="Enums\ChatMessageData.cs" />
<Compile Include="Core\ExtraHandler.cs" />
Expand Down
41 changes: 22 additions & 19 deletions Source/HourBoostr/Program.cs
Original file line number Diff line number Diff line change
@@ -1,55 +1,58 @@
using System;
using System.IO;
using System.Threading;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Nito.AsyncEx;

namespace HourBoostr
{
class Program
public class Program
{
/// <summary>
/// Global database
/// </summary>
static public GlobalDB mGlobalDB;


internal static GlobalDB mGlobalDB;

/// <summary>
/// Our session
/// </summary>
static private Session mSession;


private static Session mSession;

/// <summary>
/// Main function
/// Too many comments
/// </summary>
/// <param name="args">No args</param>
[STAThread]
static void Main(string[] args)
public static void Main() => AsyncContext.Run(() => MainAsync());

/// <summary>
/// Boostr startup method
/// </summary>
private protected static async Task MainAsync()
{
/*Create a folder for our account sentry files*/
Console.Title = EndPoint.CONSOLE_TITLE;
Directory.CreateDirectory(EndPoint.SENTRY_FOLDER_PATH);
Directory.CreateDirectory(EndPoint.LOG_FOLDER_PATH);

Console.Title = SingleBoostr.Core.Misc.Const.HourBoostr.CONSOLE_TITLE;
Directory.CreateDirectory(SingleBoostr.Core.Misc.Const.HourBoostr.SENTRY_FOLDER);
Directory.CreateDirectory(SingleBoostr.Core.Misc.Const.HourBoostr.LOG_FOLDER);
/*Load global database*/
mGlobalDB = GlobalDB.Load(EndPoint.GLOBAL_SETTINGS_FILE_PATH);
mGlobalDB = GlobalDB.Load(SingleBoostr.Core.Misc.Const.HourBoostr.GLOBAL_SETTINGS_FILE);
if (mGlobalDB == null)
{
Console.WriteLine($"Error loading global db at {EndPoint.GLOBAL_SETTINGS_FILE_PATH}. Delete file if problem is consistent.");
Console.WriteLine($"Error loading global db at {SingleBoostr.Core.Misc.Const.HourBoostr.GLOBAL_SETTINGS_FILE}. Delete file if problem is consistent.");
}
else
{
if (mGlobalDB.CellID == 0)
mGlobalDB.CellID = 66;

/*Read the application settings and start our session*/
var settings = Settings.GetSettings();
if (settings != null)
{
if (settings.Accounts.Count > 0)
{
mSession = new Session(settings);
var running = await mSession.Startup();
if(!running) Console.WriteLine("Error loading Boostr");
while (mSession.mBwg.IsBusy)
Thread.Sleep(250);
}
Expand Down
4 changes: 2 additions & 2 deletions Source/HourBoostr/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("4.1.7")]
[assembly: AssemblyFileVersion("4.1.7")]
[assembly: AssemblyVersion("4.1.8")]
[assembly: AssemblyFileVersion("4.1.8")]
7 changes: 7 additions & 0 deletions Source/SingleBoostr.Core/Misc/Const.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,24 @@ public sealed class Steam
public sealed class SingleBoostr
{
public const string NAME = "SingleBoostr";
public const string VERSION = "4.1.8";
public static string IDLER_EXE => $"{NAME}.Game.exe";
public static string APP_LIST => $"{NAME}.AppList.json";
public static string SETTINGS_FILE => $"{NAME}.Settings.json";
public static string CONSOLE_TITLE = $"{NAME} v{VERSION}";
}

public sealed class HourBoostr
{
public const string NAME = "HourBoostr";
public const string VERSION = "4.1.8";
public static string IDLER_EXE => $"{NAME}.exe";
public static string SETTINGS_EXE => $"{NAME}.Settings.exe";
public static string SETTINGS_FILE => $"{NAME}.Settings.json";
public static string GLOBAL_SETTINGS_FILE = "GlobalDB.hb";
public static string SENTRY_FOLDER = "Sentryfiles";
public static string LOG_FOLDER = "Logs";
public static string CONSOLE_TITLE = $"{NAME} v{VERSION}";
}

public sealed class Discord
Expand Down
66 changes: 54 additions & 12 deletions Source/SingleBoostr.Core/Misc/UpdateCheck.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,75 @@
using System.Threading.Tasks;
using System.Net;
using System.Net;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using RestSharp;
using Newtonsoft.Json;
using SingleBoostr.Core.Objects;
using System.Reflection;
using System.Linq;
using System.Collections.Generic;

namespace SingleBoostr.Core.Misc
{
public class Updater
{
private const string jsonFileURL = "https://raw.githubusercontent.com/Ni1kko/HourBoostr/master/version.json";

/// <summary>
/// Gets name of given assembly
/// </summary>
/// <param name="assembly"></param>
/// <returns>assembly name</returns>
private static string GetName(Assembly assembly) => assembly.GetName().Name;
private static string GetVersion(Assembly assembly) => assembly.GetName().Version.ToString();
private static bool UpdateAvailable(Assembly assembly, Application App) => !GetVersion(assembly).Equals($"{App.Version}.0");

/// <summary>
/// Downloads json list of assembly's that we handle though updater
/// </summary>
/// <param name="url"></param>
/// <returns>json list of of object(Application)</returns>
private static async Task<List<Application>> DownloadConfig(string url)
{
var response = await new RestClient(url).ExecuteAsync(new RestRequest());
return response.StatusCode == HttpStatusCode.OK ? JsonConvert.DeserializeObject<UpdateHolder>(response.Content).Applications : null;
}

/// <summary>
/// Get local version of given assembly
/// </summary>
/// <param name="assembly"></param>
/// <returns>local version of given assembly</returns>
public static string GetLocalVersion(Assembly assembly) => assembly.GetName().Version.ToString();

/// <summary>
/// Get server version of given assembly
/// </summary>
/// <param name="assembly"></param>
/// <returns>server version of given assembly</returns>
public static async Task<string> GetServerVersion(Assembly assembly)
{
var apps = await DownloadConfig(Const.GitHub.VERSION_FILE_URL);
var app = apps.Where(x => x.Name.ToLower().Equals(GetName(assembly).ToLower())).First();
return app.Version;
}

/// <summary>
/// Does given assembly have update available
/// </summary>
/// <param name="assembly"></param>
/// <returns>true if update, false if not </returns>
public static async Task<bool> UpdateAvailable(Assembly assembly)
{
var serverVersion = await GetServerVersion(assembly);
return !GetLocalVersion(assembly).Equals($"{serverVersion}.0");
}

/// <summary>
/// Check if given assembly have update available
/// </summary>
/// <param name="assembly"></param>
/// <returns>information about update or empty string if no update</returns>
public static async Task<string> Check(Assembly assembly)
{
var apps = await DownloadConfig(jsonFileURL);
var apps = await DownloadConfig(Const.GitHub.VERSION_FILE_URL);
var app = apps.Where(x => x.Name.ToLower().Equals(GetName(assembly).ToLower())).First();
return UpdateAvailable(assembly, app) ? app.Info : string.Empty;
var hasUpdate = await UpdateAvailable(assembly);
return hasUpdate ? app.Info : string.Empty;
}
}
}
}
Loading

0 comments on commit 6a31b03

Please sign in to comment.