Skip to content

Commit

Permalink
* Got rid of the unnecessary console logs
Browse files Browse the repository at this point in the history
* Added a message box whether to add JDKKiller to startup or not
* Upgraded to .NET 8.0
  • Loading branch information
OWER396 committed Dec 18, 2024
1 parent bc523dd commit b4b5e6e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
2 changes: 1 addition & 1 deletion JDKKiller/JDKKiller.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
52 changes: 43 additions & 9 deletions JDKKiller/Program.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,44 @@
using Microsoft.Win32;
using System.Diagnostics;
using System.Text.Json;

namespace JDKKiller
{
internal static class Program
{
private static string? JDKPath = Registry.GetValue("HKEY_CURRENT_USER\\Software\\Clickteam\\Fusion Developer 2.5\\General", "JDKDir", null)?.ToString()+"\\bin\\java.exe";
private static readonly string? JDKPath = Registry.GetValue("HKEY_CURRENT_USER\\Software\\Clickteam\\Fusion Developer 2.5\\General", "JDKDir", null)?.ToString()+"\\bin\\java.exe";
private static readonly string ConfigPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\JDKKiller\\config.json";
private static List<Process>? JDKProcesses;
private static Config config;

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
string interval = File.ReadAllText(AppContext.BaseDirectory + "\\.timerinterval");
if(!Directory.Exists(Path.GetDirectoryName(ConfigPath))) Directory.CreateDirectory(Path.GetDirectoryName(ConfigPath));

if(!File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)+"\\JDKKiller\\config.json"))
{
config = new Config() { firstLaunch = true, timerInterval = 5000 };
SaveConfig();
}
else LoadConfig();

if (config.firstLaunch)
{
DialogResult dialogResult = MessageBox.Show("Would you like to have JDKKiller start every time your computer starts?", "JDKKiller", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if(dialogResult == DialogResult.Yes)
{
RegistryKey rk = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
rk.SetValue("JDKKiller", '"'+Process.GetCurrentProcess().MainModule.FileName+'"');
}
config.firstLaunch = false;
SaveConfig();
}
System.Timers.Timer timer = new System.Timers.Timer();
timer.Interval = Int32.Parse(interval);
timer.Interval = config.timerInterval;
timer.Elapsed += timer_Elapsed;
timer.Start();

Expand All @@ -27,10 +49,6 @@ static void Main()

private static void timer_Elapsed(object? sender, System.Timers.ElapsedEventArgs e)
{
Console.WriteLine($"[{DateTime.Now}] Timer tick");
Console.WriteLine($"[{DateTime.Now}] Is CTF process running: {ProcessIsRunning("mmf2u")}");
Console.WriteLine($"[{DateTime.Now}] Is JDK process running: {ProcessIsRunningFilename(JDKPath)}");

if (ProcessIsRunningFilename(JDKPath)) JDKProcesses = GetProcessByFilename(JDKPath);

if (!ProcessIsRunning("mmf2u") && ProcessIsRunningFilename(JDKPath))
Expand Down Expand Up @@ -72,9 +90,19 @@ private static bool ProcessIsRunningFilename(string filename)
return false;
}

private static void LoadConfig()
{
config = JsonSerializer.Deserialize<Config>(File.ReadAllText(ConfigPath));
}

private static void SaveConfig()
{
File.WriteAllText(ConfigPath, JsonSerializer.Serialize(config));
}

}

public class AppTray : ApplicationContext
class AppTray : ApplicationContext
{
private NotifyIcon trayIcon;

Expand All @@ -83,7 +111,7 @@ public AppTray()
trayIcon = new NotifyIcon()
{
Text = "JDKKiller",
Icon = ResourceLoader.GetResource("Icon3.ico"),
Icon = ResourceLoader.GetIcon("Icon3.ico"),
ContextMenuStrip = new ContextMenuStrip()
{
Items = {new ToolStripMenuItem("Exit", null, Exit)}
Expand All @@ -98,4 +126,10 @@ void Exit(object? sender, EventArgs e)
Application.Exit();
}
}

class Config
{
public bool firstLaunch { get; set; }
public int timerInterval { get; set; }
}
}
2 changes: 1 addition & 1 deletion JDKKiller/ResourceLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace JDKKiller
{
public class ResourceLoader
{
public static Icon GetResource(string name)
public static Icon GetIcon(string name)
{
var assembly = Assembly.GetExecutingAssembly();
string resourceName = assembly.GetManifestResourceNames().Single(str => str.EndsWith(name));
Expand Down

0 comments on commit b4b5e6e

Please sign in to comment.