Skip to content

Commit

Permalink
1.0.8
Browse files Browse the repository at this point in the history
- Added log file debugging throughout entire codebase
- Improved executor calls and asynchronous methods
- Added administrator privilege check on startup
- Improved network calls when checking for updates
- Minor code changes and improvements
  • Loading branch information
Foulest committed Jun 16, 2024
1 parent ad52bef commit 8d729cb
Show file tree
Hide file tree
Showing 14 changed files with 1,085 additions and 843 deletions.
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = 'net.foulest'
version = '1.0.7'
version = '1.0.8'
description = 'RepairKit'

compileJava.options.encoding = 'UTF-8'
Expand All @@ -29,6 +29,10 @@ dependencies {
// https://mvnrepository.com/artifact/net.java.dev.jna/jna-platform
implementation group: 'net.java.dev.jna', name: 'jna-platform', version: '5.14.0'

// OSHI - for system information
// https://central.sonatype.com/artifact/com.github.oshi/oshi-core
implementation group: 'com.github.oshi', name: 'oshi-core', version: '6.6.1'

// JetBrains Annotations - for code inspection and documentation
// https://mvnrepository.com/artifact/org.jetbrains/annotations
compileOnly group: 'org.jetbrains', name: 'annotations', version: '24.1.0'
Expand Down
129 changes: 88 additions & 41 deletions src/main/java/net/foulest/repairkit/RepairKit.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.foulest.repairkit.panels.AutomaticRepairs;
import net.foulest.repairkit.panels.SystemShortcuts;
import net.foulest.repairkit.panels.UsefulPrograms;
import net.foulest.repairkit.util.DebugUtil;
import net.foulest.repairkit.util.UpdateUtil;
import org.jetbrains.annotations.NotNull;

Expand All @@ -32,6 +33,7 @@
import static net.foulest.repairkit.util.CommandUtil.getCommandOutput;
import static net.foulest.repairkit.util.CommandUtil.runCommand;
import static net.foulest.repairkit.util.ConstantUtil.*;
import static net.foulest.repairkit.util.DebugUtil.debug;
import static net.foulest.repairkit.util.FileUtil.*;
import static net.foulest.repairkit.util.ProcessUtil.isProcessRunning;
import static net.foulest.repairkit.util.RegistryUtil.setRegistryIntValue;
Expand All @@ -50,38 +52,113 @@ public class RepairKit extends JFrame {
@Getter
private static boolean windowsUpdateInProgress = false;

/**
* The main method of the program.
*
* @param args The program's arguments.
*/
public static void main(String[] args) {
// Checks if RepairKit is running as administrator.
debug("Checking if RepairKit is running as administrator...");
if (getCommandOutput("net session", false, false).toString().contains("Access is denied.")) {
playSound(ERROR_SOUND);
JOptionPane.showMessageDialog(null,
"Please run RepairKit as an administrator.",
"Error", JOptionPane.ERROR_MESSAGE);
System.exit(0);
return;
}

// Deletes the log file.
runCommand("del /f /q \"" + System.getenv("TEMP") + "\\RepairKit.log\"", false);

// Creates the log file.
DebugUtil.createLogFile();

// Prints system information.
DebugUtil.printSystemInfo(args);

// Checks if RepairKit is running in the temp directory.
debug("Checking if RepairKit is running in the temp directory...");
if (System.getProperty("user.dir").equalsIgnoreCase(tempDirectory.getPath())) {
playSound(ERROR_SOUND);
JOptionPane.showMessageDialog(null, BAD_FILE_LOCATION, "Error", JOptionPane.ERROR_MESSAGE);
System.exit(0);
return;
}

// Checks for incompatibility issues.
debug("Checking for incompatibility issues...");
checkOperatingSystemCompatibility();

// Checks for Windows Update and Medal.
if (!safeMode) {
debug("Checking for Windows Update and Medal...");
checkForWindowsUpdate();
checkForMedal();
}

// Deletes pre-existing RepairKit files.
debug("Deleting pre-existing RepairKit files...");
runCommand("rd /s /q \"" + tempDirectory.getPath() + "\"", false);

// Deletes RepairKit files on shutdown.
debug("Deleting RepairKit files on shutdown...");
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
debug("Shutting down RepairKit...");
runCommand("rd /s /q \"" + tempDirectory.getPath() + "\"", false);
}));

// Sets up necessary app registry keys.
debug("Setting up necessary app registry keys...");
setAppRegistryKeys();

// Launches the program.
debug("Launching the program...");
SwingUtilities.invokeLater(() -> new RepairKit().setVisible(true));
}

/**
* Creates a new instance of the program.
*/
public RepairKit() {
// Sets the window properties.
debug("Setting up the window properties...");
setTitle("RepairKit");
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setPreferredSize(new Dimension(758, 550));
setResizable(false);

// Initialize the panels.
debug("Initializing the Automatic Repairs panel...");
AutomaticRepairs automaticRepairs = new AutomaticRepairs();
debug("Initializing the Useful Programs panel...");
UsefulPrograms usefulPrograms = new UsefulPrograms();
debug("Initializing the System Shortcuts panel...");
SystemShortcuts systemShortcuts = new SystemShortcuts();

// Creates the main panel.
debug("Creating the main panel...");
setMainPanel(new JPanel(new CardLayout()));
mainPanel.add(automaticRepairs, "Automatic Repairs");
mainPanel.add(usefulPrograms, "Useful Programs");
mainPanel.add(systemShortcuts, "System Shortcuts");

// Creates the banner panel.
debug("Creating the banner panel...");
JPanel bannerPanel = createBannerPanel();

// Adds the panels to the main panel.
debug("Adding the panels to the main panel...");
add(bannerPanel, BorderLayout.NORTH);
add(mainPanel, BorderLayout.CENTER);

// Checks for updates.
debug("Checking for updates...");
UpdateUtil.checkForUpdates();

// Packs and centers the frame.
debug("Packing and centering the frame...");
pack();
setLocationRelativeTo(null);
}
Expand All @@ -100,6 +177,7 @@ public JPanel createBannerPanel() {
bannerPanel.setPreferredSize(new Dimension(getWidth(), 60));

// Creates the RepairKit icon image.
debug("Creating the RepairKit icon image...");
ImageIcon imageIcon = getImageIcon("icons/RepairKit.png");
Image scaledImage = imageIcon.getImage().getScaledInstance(40, 40, Image.SCALE_SMOOTH);
imageIcon = new ImageIcon(scaledImage);
Expand All @@ -109,6 +187,7 @@ public JPanel createBannerPanel() {
iconLabel.repaint();

// Creates the primary banner label.
debug("Creating the primary banner label...");
JLabel bannerLabelPrimary = createLabel("RepairKit",
new Rectangle(60, 6, 200, 30),
new Font(ARIAL, Font.BOLD, 22)
Expand All @@ -117,6 +196,7 @@ public JPanel createBannerPanel() {
bannerPanel.add(bannerLabelPrimary);

// Creates the secondary banner label.
debug("Creating the secondary banner label...");
JLabel bannerLabelSecondary = createLabel("by Foulest",
new Rectangle(60, 31, 100, 20),
new Font(ARIAL, Font.PLAIN, 14)
Expand All @@ -127,6 +207,7 @@ public JPanel createBannerPanel() {
bannerPanel.add(bannerLabelSecondary);

// Creates the version info label.
debug("Creating the version info label...");
JLabel versionInfo = createLabel("Version:",
new Rectangle(675, 5, 60, 30),
new Font(ARIAL, Font.BOLD, 14)
Expand All @@ -135,6 +216,7 @@ public JPanel createBannerPanel() {
bannerPanel.add(versionInfo);

// Creates the version number label.
debug("Creating the version number label...");
JLabel versionNumber = createLabel(getVersionFromProperties(),
new Rectangle(700, 25, 50, 30),
new Font(ARIAL, Font.PLAIN, 14)
Expand All @@ -145,67 +227,30 @@ public JPanel createBannerPanel() {
bannerPanel.add(versionNumber);

// Creates the Automatic Repairs button.
debug("Creating the Automatic Repairs button...");
JButton automaticRepairs = createPanelButton("Automatic Repairs", new Rectangle(175, 10, 150, 40));
bannerPanel.add(automaticRepairs);

// Creates the Useful Programs button.
debug("Creating the Useful Programs button...");
JButton usefulPrograms = createPanelButton("Useful Programs", new Rectangle(325, 10, 150, 40));
bannerPanel.add(usefulPrograms);

// Creates the System Shortcuts button.
debug("Creating the System Shortcuts button...");
JButton systemShortcuts = createPanelButton("System Shortcuts", new Rectangle(475, 10, 150, 40));
bannerPanel.add(systemShortcuts);
return bannerPanel;
}

/**
* The main method of the program.
*
* @param args The program's arguments.
*/
public static void main(String[] args) {
// Checks if RepairKit is running in the temp directory.
if (System.getProperty("user.dir").equalsIgnoreCase(tempDirectory.getPath())) {
playSound(ERROR_SOUND);
JOptionPane.showMessageDialog(null,
"RepairKit cannot be run from the Temp directory."
+ "\nPlease move the RepairKit folder to a different location and try again.",
"Error", JOptionPane.ERROR_MESSAGE);
System.exit(0);
return;
}

// Checks for incompatibility issues.
checkOperatingSystemCompatibility();

// Checks for Windows Update and Medal.
if (!safeMode) {
checkForWindowsUpdate();
checkForMedal();
}

// Deletes pre-existing RepairKit files.
runCommand("rd /s /q \"" + tempDirectory.getPath() + "\"", false);

// Deletes RepairKit files on shutdown.
Runtime.getRuntime().addShutdownHook(new Thread(() ->
runCommand("rd /s /q \"" + tempDirectory.getPath() + "\"", false))
);

// Sets up necessary app registry keys.
setAppRegistryKeys();

// Launches the program.
SwingUtilities.invokeLater(() -> new RepairKit().setVisible(true));
}

/**
* Checks if the user's operating system is supported.
*/
private static void checkOperatingSystemCompatibility() {
String osName = System.getProperty("os.name");

// Checks if the operating system is 32-bit.
debug("Checking if the operating system is 32-bit...");
if (!System.getProperty("os.arch").contains("64")) {
playSound(ERROR_SOUND);
JOptionPane.showMessageDialog(null,
Expand All @@ -218,6 +263,7 @@ private static void checkOperatingSystemCompatibility() {
}

// Checks if the operating system is outdated (older than Windows 10).
debug("Checking if the operating system is outdated...");
if (!osName.equalsIgnoreCase("Windows 10")
&& !osName.equalsIgnoreCase("Windows 11")) {
if (osName.equalsIgnoreCase("Windows 8.1")
Expand Down Expand Up @@ -246,6 +292,7 @@ private static void checkOperatingSystemCompatibility() {
}

// Checks if the system is booting in Safe Mode.
debug("Checking if the system is booting in Safe Mode...");
if (getCommandOutput("wmic COMPUTERSYSTEM GET BootupState",
false, false).toString().contains("safe")) {
playSound(ERROR_SOUND);
Expand Down
Loading

0 comments on commit 8d729cb

Please sign in to comment.