Skip to content
11 changes: 6 additions & 5 deletions RunCat365/CPURepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using RunCat365.Properties;
using System.Diagnostics;

namespace RunCat365
Expand All @@ -28,17 +29,17 @@ internal static class CPUInfoExtension
{
internal static string GetDescription(this CPUInfo cpuInfo)
{
return $"CPU: {cpuInfo.Total:f1}%";
return $"{Strings.SystemInfo_CPU}: {cpuInfo.Total:f1}%";
}

internal static List<string> GenerateIndicator(this CPUInfo cpuInfo)
{
var resultLines = new List<string>
{
$"CPU: {cpuInfo.Total:f1}%",
$" ├─ User: {cpuInfo.User:f1}%",
$" ├─ Kernel: {cpuInfo.Kernel:f1}%",
$" └─ Available: {cpuInfo.Idle:f1}%"
TreeFormatter.CreateRoot($"{Strings.SystemInfo_CPU}: {cpuInfo.Total:f1}%"),
TreeFormatter.CreateNode($"{Strings.SystemInfo_User}: {cpuInfo.User:f1}%", false),
TreeFormatter.CreateNode($"{Strings.SystemInfo_Kernel}: {cpuInfo.Kernel:f1}%", false),
TreeFormatter.CreateNode($"{Strings.SystemInfo_Available}: {cpuInfo.Idle:f1}%", true)
};
return resultLines;
}
Expand Down
36 changes: 19 additions & 17 deletions RunCat365/ContextMenuManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ Action onExit
systemInfoMenu.Text = "-\n-\n-\n-\n-";
systemInfoMenu.Enabled = false;

var runnersMenu = new CustomToolStripMenuItem("Runners");
var runnersMenu = new CustomToolStripMenuItem(Strings.Menu_Runners);
runnersMenu.SetupSubMenusFromEnum<Runner>(
r => r.GetString(),
r => r.GetLocalizedString(),
(parent, sender, e) =>
{
HandleMenuItemSelection<Runner>(
Expand All @@ -60,9 +60,9 @@ Action onExit
r => GetRunnerThumbnailBitmap(getSystemTheme(), r)
);

var themeMenu = new CustomToolStripMenuItem("Theme");
var themeMenu = new CustomToolStripMenuItem(Strings.Menu_Theme);
themeMenu.SetupSubMenusFromEnum<Theme>(
t => t.GetString(),
t => t.GetLocalizedString(),
(parent, sender, e) =>
{
HandleMenuItemSelection<Theme>(
Expand All @@ -77,7 +77,7 @@ Action onExit
_ => null
);

var fpsMaxLimitMenu = new CustomToolStripMenuItem("FPS Max Limit");
var fpsMaxLimitMenu = new CustomToolStripMenuItem(Strings.Menu_FPSMaxLimit);
fpsMaxLimitMenu.SetupSubMenusFromEnum<FPSMaxLimit>(
f => f.GetString(),
(parent, sender, e) =>
Expand All @@ -93,20 +93,20 @@ Action onExit
_ => null
);

var launchAtStartupMenu = new CustomToolStripMenuItem("Launch at startup")
var launchAtStartupMenu = new CustomToolStripMenuItem(Strings.Menu_LaunchAtStartup)
{
Checked = getLaunchAtStartup()
};
launchAtStartupMenu.Click += (sender, e) => HandleStartupMenuClick(sender, toggleLaunchAtStartup);

var settingsMenu = new CustomToolStripMenuItem("Settings");
var settingsMenu = new CustomToolStripMenuItem(Strings.Menu_Settings);
settingsMenu.DropDownItems.AddRange(
themeMenu,
fpsMaxLimitMenu,
launchAtStartupMenu
);

var endlessGameMenu = new CustomToolStripMenuItem("Endless Game");
var endlessGameMenu = new CustomToolStripMenuItem(Strings.Menu_EndlessGame);
endlessGameMenu.Click += (sender, e) => ShowOrActivateGameWindow(getSystemTheme);

var appVersionMenu = new CustomToolStripMenuItem(
Expand All @@ -116,16 +116,16 @@ Action onExit
Enabled = false
};

var repositoryMenu = new CustomToolStripMenuItem("Open Repository");
var repositoryMenu = new CustomToolStripMenuItem(Strings.Menu_OpenRepository);
repositoryMenu.Click += (sender, e) => openRepository();

var informationMenu = new CustomToolStripMenuItem("Information");
var informationMenu = new CustomToolStripMenuItem(Strings.Menu_Information);
informationMenu.DropDownItems.AddRange(
appVersionMenu,
repositoryMenu
);

var exitMenu = new CustomToolStripMenuItem("Exit");
var exitMenu = new CustomToolStripMenuItem(Strings.Menu_Exit);
exitMenu.Click += (sender, e) => onExit();

var contextMenuStrip = new ContextMenuStrip(new Container());
Expand Down Expand Up @@ -164,7 +164,12 @@ Action<T> assignValueAction
childItem.Checked = false;
}
item.Checked = true;
if (tryParseMethod(item.Text, out T parsedValue))

if (item.Tag is T tagValue)
{
assignValueAction(tagValue);
}
else if (tryParseMethod(item.Text, out T parsedValue))
{
assignValueAction(parsedValue);
}
Expand Down Expand Up @@ -213,7 +218,7 @@ private static void HandleStartupMenuClick(object? sender, Func<bool, bool> togg
}
catch (InvalidOperationException ex)
{
MessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
MessageBox.Show(ex.Message, Strings.Message_Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}

}
Expand All @@ -237,10 +242,7 @@ private void ShowOrActivateGameWindow(Func<Theme> getSystemTheme)

internal void ShowBalloonTip()
{
var message = "App has launched. " +
"If the icon is not on the taskbar, it has been omitted, " +
"so please move it manually and pin it.";
notifyIcon.ShowBalloonTip(5000, "RunCat 365", message, ToolTipIcon.Info);
notifyIcon.ShowBalloonTip(5000, "RunCat 365", Strings.Message_AppLaunched, ToolTipIcon.Info);
}

internal void AdvanceFrame()
Expand Down
4 changes: 3 additions & 1 deletion RunCat365/CustomToolStripMenuItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ internal CustomToolStripMenuItem(string? text) : base(text)
Font = new Font("Consolas", 9F, FontStyle.Regular);
}

private CustomToolStripMenuItem(string? text, Image? image, bool isChecked, EventHandler? onClick) : base(text, image, onClick)
private CustomToolStripMenuItem(string? text, Image? image, object? tag, bool isChecked, EventHandler? onClick) : base(text, image, onClick)
{
Tag = tag;
Checked = isChecked;
Font = new Font("Consolas", 9F, FontStyle.Regular);
}
Expand Down Expand Up @@ -88,6 +89,7 @@ internal void SetupSubMenusFromEnum<T>(
var item = new CustomToolStripMenuItem(
entityName,
iconImage,
value,
isChecked(value),
(sender, e) => onClick(this, sender, e)
);
Expand Down
12 changes: 6 additions & 6 deletions RunCat365/EndlessGameForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ internal EndlessGameForm(Theme systemTheme)
FormBorderStyle = FormBorderStyle.FixedDialog;
MaximizeBox = false;
StartPosition = FormStartPosition.CenterScreen;
Text = "Endless Game";
Text = Strings.Window_EndlessGame;
Icon = Resources.AppIcon;
BackColor = systemTheme == Theme.Light ? Color.Gainsboro : Color.Gray;

Expand Down Expand Up @@ -207,15 +207,15 @@ private void RenderScene(object? sender, PaintEventArgs e)
var textColor = systemTheme == Theme.Light ? Color.Black : Color.White;
var g = e.Graphics;

using (Font font15 = new("Courier New", 15))
using (Font font15 = new("Consolas", 15))
using (Brush brush = new SolidBrush(textColor))
{
var stringFormat = new StringFormat
{
Alignment = StringAlignment.Far,
LineAlignment = StringAlignment.Center
};
g.DrawString($"Score: {score}", font15, brush, new Rectangle(20, 0, 560, 50), stringFormat);
g.DrawString($"{Strings.Game_Score}: {score}", font15, brush, new Rectangle(20, 0, 560, 50), stringFormat);
}

roads.Take(20).Select((road, index) => new { road, index }).ToList().ForEach(
Expand All @@ -238,12 +238,12 @@ private void RenderScene(object? sender, PaintEventArgs e)
using Brush fillBrush = new SolidBrush(Color.FromArgb(77, 0, 0, 0));
g.FillRectangle(fillBrush, new Rectangle(0, 0, 600, 250));

using Font font18 = new("Courier New", 18, FontStyle.Bold);
using Font font18 = new("Segoe UI", 16, FontStyle.Bold);
using Brush brush = new SolidBrush(textColor);
var message = "Press space to play.";
var message = Strings.Game_PressSpaceToPlay;
if (status == GameStatus.GameOver)
{
message = "GAME OVER\n\n" + message;
message = $"{Strings.Game_GameOver}\n{message}";
}
var stringFormat = new StringFormat
{
Expand Down
9 changes: 5 additions & 4 deletions RunCat365/MemoryRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using RunCat365.Properties;
using System.Runtime.InteropServices;

namespace RunCat365
Expand All @@ -30,10 +31,10 @@ internal static List<string> GenerateIndicator(this MemoryInfo memoryInfo)
{
var resultLines = new List<string>
{
$"Memory: {memoryInfo.MemoryLoad}%",
$" ├─ Total: {memoryInfo.TotalMemory.ToByteFormatted()}",
$" ├─ Used: {memoryInfo.UsedMemory.ToByteFormatted()}",
$" └─ Available: {memoryInfo.AvailableMemory.ToByteFormatted()}"
TreeFormatter.CreateRoot($"{Strings.SystemInfo_Memory}: {memoryInfo.MemoryLoad}%"),
TreeFormatter.CreateNode($"{Strings.SystemInfo_Total}: {memoryInfo.TotalMemory.ToByteFormatted()}", false),
TreeFormatter.CreateNode($"{Strings.SystemInfo_Used}: {memoryInfo.UsedMemory.ToByteFormatted()}", false),
TreeFormatter.CreateNode($"{Strings.SystemInfo_Available}: {memoryInfo.AvailableMemory.ToByteFormatted()}", true)
};
return resultLines;
}
Expand Down
7 changes: 4 additions & 3 deletions RunCat365/NetworkRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using RunCat365.Properties;
using System.Net.NetworkInformation;

namespace RunCat365
Expand All @@ -27,9 +28,9 @@ internal static class NetworkInfoExtension
internal static List<string> GenerateIndicator(this NetworkInfo networkInfo)
{
return [
$"Network:",
$" ├─ Sent: {FormatSpeed(networkInfo.SentSpeed)}",
$" └─ Received: {FormatSpeed(networkInfo.ReceivedSpeed)}"
TreeFormatter.CreateRoot($"{Strings.SystemInfo_Network}:"),
TreeFormatter.CreateNode($"{Strings.SystemInfo_Sent}: {FormatSpeed(networkInfo.SentSpeed)}", false),
TreeFormatter.CreateNode($"{Strings.SystemInfo_Received}: {FormatSpeed(networkInfo.ReceivedSpeed)}", true)
];
}

Expand Down
6 changes: 6 additions & 0 deletions RunCat365/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Microsoft.Win32;
using RunCat365.Properties;
using System.Diagnostics;
using System.Globalization;
using FormsTimer = System.Windows.Forms.Timer;

namespace RunCat365
Expand All @@ -24,6 +25,11 @@ internal static class Program
[STAThread]
static void Main()
{
#if DEBUG
// Specify language manually.
CultureInfo.CurrentUICulture = new CultureInfo("en-US");
#endif

// Terminate RunCat365 if there's any existing instance.
using var procMutex = new Mutex(true, "_RUNCAT_MUTEX", out var result);
if (!result) return;
Expand Down
Loading
Loading