Skip to content

Commit

Permalink
Fixed a bunch of depreciation warnings following .NET 9 support
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianLeChat committed Nov 16, 2024
1 parent c4abb5e commit 5ceb48a
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 41 deletions.
1 change: 1 addition & 0 deletions src/FacepunchCommitsMonitor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<ApplicationIcon>logo.ico</ApplicationIcon>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
Expand Down
52 changes: 39 additions & 13 deletions src/Form.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ namespace FacepunchCommitsMonitor
{
public partial class Form : System.Windows.Forms.Form
{
public static double IntervalTime { get; set; } = 180000;
public static Dictionary<string, bool> Repositories { get; set; } = new()
private static Dictionary<string, bool> repositories = new()
{
["Garry's Mod"] = false,
["Rust"] = false,
["Sandbox"] = false
};

private bool cleanupOnShutDown;
private static double intervalTime = 180000;
private static readonly HttpClient client = new();
private readonly Timer interfaceUpdateTimer = new();

Expand Down Expand Up @@ -48,6 +48,32 @@ public Form()
};
}

/// <summary>
/// Defines and retrieves game repositories to be checked
/// </summary>
public static void SetRepositories(Dictionary<string, bool> value)
{
repositories = value;
}

public static Dictionary<string, bool> GetRepositories()
{
return repositories;
}

/// <summary>
/// Defines and retrieves the time interval between two checks
/// </summary>
public static void SetIntervalTime(double value)
{
intervalTime = value;
}

public static double GetIntervalTime()
{
return intervalTime;
}

/// <summary>
/// Opens a URL in the system default browser.
/// </summary>
Expand Down Expand Up @@ -112,11 +138,11 @@ public static async Task CreateToastNotification(Commit data)
/// <summary>
/// Updates UI elements with values from the internal logic.
/// </summary>
private void SafeInvoke(Control element, Action callback)
private static void SafeInvoke(Control element, Action callback)
{
if (element.InvokeRequired)
{
_ = element.BeginInvoke(delegate { SafeInvoke(element, callback); });
_ = element.BeginInvoke(delegate { Form.SafeInvoke(element, callback); });
}
else
{
Expand All @@ -128,17 +154,17 @@ private void SafeInvoke(Control element, Action callback)
private void ActionTimer_Tick(object ?sender, EventArgs e)
{
// Remaining time text
var remainingTime = Math.Round((TimeSpan.FromMilliseconds(IntervalTime) - (DateTime.Now - Monitor.StartTime)).TotalSeconds);
var remainingTime = Math.Round((TimeSpan.FromMilliseconds(GetIntervalTime()) - (DateTime.Now - Monitor.StartTime)).TotalSeconds);

SafeInvoke(label6, new Action(() =>
Form.SafeInvoke(label6, new Action(() =>
{
label6.Text = FindNumbers().Replace(label6.Text, Math.Max(remainingTime, 0).ToString());
}));

// Remaining time progress bar
SafeInvoke(progressBar1, new Action(() =>
Form.SafeInvoke(progressBar1, new Action(() =>
{
progressBar1.Value = Math.Clamp((int)(100 * remainingTime / (IntervalTime / 1000)), 0, 100);
progressBar1.Value = Math.Clamp((int)(100 * remainingTime / (GetIntervalTime() / 1000)), 0, 100);
}));
}

Expand Down Expand Up @@ -208,13 +234,13 @@ private void CheckedListBox1_ItemCheck(object sender, ItemCheckEventArgs args)
switch (args.Index)
{
case 0:
Repositories["Garry's Mod"] = state;
GetRepositories()["Garry's Mod"] = state;
break;
case 1:
Repositories["Rust"] = state;
GetRepositories()["Rust"] = state;
break;
case 2:
Repositories["Sandbox"] = state;
GetRepositories()["Sandbox"] = state;
break;
default:
break;
Expand All @@ -238,10 +264,10 @@ private void CheckBox1_CheckedChanged(object sender, EventArgs e)
/// </summary>
private void NumericUpDown1_ValueChanged(object sender, EventArgs e)
{
IntervalTime = (double)numericUpDown1.Value * 1000;
SetIntervalTime((double)numericUpDown1.Value * 1000);

Monitor.StartTime = DateTime.Now;
Monitor.CheckTimer.Interval = IntervalTime;
Monitor.CheckTimer.Interval = GetIntervalTime();
}
}
}
46 changes: 18 additions & 28 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,25 @@

namespace FacepunchCommitsMonitor
{
public class Commit
public class Commit(string identifier, string category, string repository, string branch, string author, string avatar)
{
public string identifier;
public string category;
public string repository;
public string branch;
public string author;
public string avatar;

public Commit(string identifier, string category, string repository, string branch, string author, string avatar)
{
// Incremented number from the beginning assigned to the commit (generated on the Facepunch side).
this.identifier = identifier;
// Incremented number from the beginning assigned to the commit (generated on the Facepunch side).
public string identifier = identifier;

// "Nice" game name associated with the commit (e.g. "Garry's Mod", "Rust", "S&Box").
this.category = category;
// "Nice" game name associated with the commit (e.g. "Garry's Mod", "Rust", "S&Box").
public string category = category;

// GitHub repository name attached with the commit (e.g. "rust_reboot").
this.repository = repository;
// GitHub repository name attached with the commit (e.g. "rust_reboot").
public string repository = repository;

// Branch involved in the GitHub repository of the commit (e.g. "x86-64").
this.branch = branch;
// Branch involved in the GitHub repository of the commit (e.g. "x86-64").
public string branch = branch;

// Author of the GitHub commit (e.g. "Garry Newman").
this.author = author;
// Author of the GitHub commit (e.g. "Garry Newman").
public string author = author;

// URL to the avatar of the commit author on GitHub (e.g. "https://files.facepunch.com/web/avatar/151-51815457.png").
this.avatar = avatar;
}
// URL to the avatar of the commit author on GitHub (e.g. "https://files.facepunch.com/web/avatar/151-51815457.png").
public string avatar = avatar;
}

public class Monitor
Expand All @@ -41,7 +31,7 @@ public class Monitor

private static uint firstIdentifier;
private static readonly HttpClient client = new();
private static readonly List<string> readedIds = new();
private static readonly List<string> readedIds = [];

/// <summary>
/// The main entry point for the application.
Expand All @@ -57,7 +47,7 @@ private static async Task Main()
{
await CheckForNewCommits(false);
};
CheckTimer.Interval = Form.IntervalTime;
CheckTimer.Interval = Form.GetIntervalTime();
CheckTimer.Enabled = true;

// Default generated code to create the form.
Expand All @@ -73,13 +63,13 @@ private static async Task Main()
/// </summary>
public static string SelectGameCategory(string repository)
{
if (repository.Contains("Garrys") && Form.Repositories["Garry's Mod"])
if (repository.Contains("Garrys") && Form.GetRepositories()["Garry's Mod"])
return "Garry's Mod";

if (repository.Contains("rust") && Form.Repositories["Rust"])
if (repository.Contains("rust") && Form.GetRepositories()["Rust"])
return "Rust";

if (repository.Contains("sbox") && Form.Repositories["Sandbox"])
if (repository.Contains("sbox") && Form.GetRepositories()["Sandbox"])
return "S&Box";

return "N/A";
Expand Down
1 change: 1 addition & 0 deletions tests/MonitorTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using FacepunchCommitsMonitor;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace FacepunchCommitsMonitorTests;
Expand Down

0 comments on commit 5ceb48a

Please sign in to comment.