Skip to content

Commit

Permalink
Bug fixes and minor improvements
Browse files Browse the repository at this point in the history
- Fixed a bug that could cause a crash when the program starts.
- New column: "FPKG" - Displays whether a PKG is a fake PKG.
- Other minor improvements.
  • Loading branch information
hippie68 authored Jan 21, 2025
1 parent 6b89f24 commit 4930e10
Show file tree
Hide file tree
Showing 24 changed files with 424 additions and 363 deletions.
60 changes: 25 additions & 35 deletions src/About.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,50 @@
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.program.Program;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.*;

public class About extends Dialog {
private Shell shell;
private Composite composite;

public About(Shell parent, int style, GUI gui) {
public About(Shell parent) {
super(parent, SWT.NONE);
this.shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
Shell shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
shell.setText("About");
shell.setLayout(new GridLayout(1, false));

Composite composite = new Composite(shell, SWT.NONE);
composite.setLayout(new GridLayout(1, false));
this.composite = composite;
shell.setLayout(new GridLayout(1, true));
ShellHelpers.setShellMargin(shell);

Label titleLabel = createCenteredLabel("PS4 PKG Manager");
Label titleLabel = createLabel(shell, SWT.CENTER, "PS4 PKG Manager");
setFontScalingFactor(titleLabel, 2);

createCenteredLabel("Copyright (c) 2024 hippie68");
createCenteredLabel("Release #" + Version.currentVersion);
createLabel(shell, SWT.CENTER, "Copyright \u00a9 2025 hippie68");
createLabel(shell, SWT.CENTER, "Release #" + Version.currentVersion);

new Label(composite, SWT.NONE);

createLink("Settings and database location: <a>" + gui.dataDirectory + "</a>",
e -> Program.launch(gui.dataDirectory));
createLink("Project homepage: <a>https://github.com/hippie68/ps4-pkg-manager</a>",
new Label(shell, SWT.NONE);
Runtime.getRuntime().gc();
long memoryUsage = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / (1024 * 1024);
createLabel(shell, SWT.LEFT, "RAM usage: " + memoryUsage + " MiB");
createLink(shell, "Settings and database location: <a>" + GUI.dataDirectory + "</a>",
e -> Program.launch(GUI.dataDirectory));
createLink(shell, "Project homepage: <a>https://github.com/hippie68/ps4-pkg-manager</a>",
e -> Program.launch("https://github.com/hippie68/ps4-pkg-manager"));

new Label(shell, SWT.NONE);
ShellHelpers.createDialogButtons(shell, SWT.CENTER, new DialogButton("Close", e -> shell.close()));

shell.pack();
GUI.centerShell(shell);
ShellHelpers.centerShell(shell);
shell.open();
}

private Label createCenteredLabel(String text) {
Label label = new Label(composite, SWT.CENTER);
private Label createLabel(Composite parent, int style, String text) {
Label label = new Label(parent, style);
label.setText(text);
label.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false));
label.setLayoutData(new GridData(style, SWT.CENTER, true, false));
return label;
}

private Link createLink(String text, Listener listener) {
Link link = new Link(composite, SWT.NONE);
private void createLink(Shell shell, String text, Listener listener) {
Link link = new Link(shell, SWT.NONE);
link.setText(text);
link.addListener(SWT.Selection, listener);
return link;
}

private void setFontScalingFactor(Control control, double factor) {
Expand All @@ -65,6 +56,5 @@ private void setFontScalingFactor(Control control, double factor) {
fd[0].setStyle(SWT.BOLD);
control.setFont(new Font(Display.getCurrent(), fd[0]));
control.getFont().dispose();
// TODO: is everything properly disposed?
}
}
}
7 changes: 4 additions & 3 deletions src/AddFtpFilesDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class AddFtpFilesDialog {
Label connectionStatus;
ProgressBar progressBar;

// TODO: extract long code blocks to separate methods.
public AddFtpFilesDialog(Shell parent, GUI gui) {
TabContent tabContent = gui.getCurrentTabContent();

Expand Down Expand Up @@ -100,7 +101,7 @@ public AddFtpFilesDialog(Shell parent, GUI gui) {
shell.pack();

String ip = ipCombo.getText();
Integer port = Integer.valueOf(portCombo.getText());
int port = Integer.parseInt(portCombo.getText());
this.ftpThread = new Thread(() -> {
FtpClient client = new FtpClient();
try {
Expand Down Expand Up @@ -245,7 +246,7 @@ public AddFtpFilesDialog(Shell parent, GUI gui) {

shell.setDefaultButton(connect);
shell.pack();
GUI.centerShell(shell);
ShellHelpers.centerShell(shell);
shell.open();
}
}
}
4 changes: 2 additions & 2 deletions src/ChangeFtpPathDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public ChangeFtpPathDialog(Shell parent, GUI gui, TabContent tabContent, TableIt
});

shell.pack();
GUI.centerShell(shell);
ShellHelpers.centerShell(shell);
shell.open();
}

}
}
40 changes: 20 additions & 20 deletions src/Column.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
public enum Column {
// To maintain backward compatibility, this order must never be changed. New columns must be added at the end.
// Once a new program version is released, new columns must never be removed. If a column ever becomes obsolete, it
// must be replaced with a placeholder containing obsolescence information.
// must be replaced with a placeholder containing obsolescence information. In such a case, the static variable
// "length" must be calculated differently not to include obsolete columns.
INDEX("Index", "Represents the ascending order in which PKGs were added in the current session", false, SWT.LEFT,
Comparators.longComparator),
PATH("Path", Platform.DIRECTORY_TERM + " and file name combined", false, SWT.LEFT, Comparators.stringComparator),
Expand All @@ -25,19 +26,22 @@ public enum Column {
Comparators.stringComparator),
COMPATIBILITY_CHECKSUM("Compatibility checksum",
"Indicates whether app and patch PKGs are compatible with each other (\"married\")", true, SWT.LEFT,
Comparators.stringComparator);
Comparators.stringComparator),
FAKE("FPKG", "A check mark means the PKG is a fake PKG", false, SWT.CENTER, Comparators.boolComparator);

public final String name;
public final String tooltip;
public boolean enabledByDefault;
public final boolean enabledByDefault;
public final int style;
public final Comparator<String> comparator;
public static final int length = values().length;

// The order in which the current program version displays columns by default. May be changed arbitrarily.
public static final int[] order = { INDEX.ordinal(), PATH.ordinal(), DIRECTORY.ordinal(), FILENAME.ordinal(),
TITLE.ordinal(), TITLE_ID.ordinal(), REGION.ordinal(), TYPE.ordinal(), VERSION.ordinal(), BACKPORT.ordinal(),
SDK.ordinal(), FIRMWARE.ordinal(), SIZE.ordinal(), RELEASE_TAGS.ordinal(), COMPATIBILITY_CHECKSUM.ordinal() };
TITLE.ordinal(), TITLE_ID.ordinal(), REGION.ordinal(), TYPE.ordinal(), VERSION.ordinal(), FAKE.ordinal(),
BACKPORT.ordinal(), SDK.ordinal(), FIRMWARE.ordinal(), SIZE.ordinal(), RELEASE_TAGS.ordinal(),
COMPATIBILITY_CHECKSUM.ordinal()
};

Column(String name, String tooltip, boolean enabledByDefault, int style, Comparator<String> comparator) {
this.name = name;
Expand All @@ -57,22 +61,21 @@ public static Column get(int ordinal) {
}

class Comparators {
static final Comparator<String> longComparator = (a, b) -> Long.signum(Long.valueOf(a) - Long.valueOf(b));
static final Comparator<String> longComparator = (a, b) -> Long.signum(Long.parseLong(a) - Long.parseLong(b));

static final Comparator<String> stringComparator = (a, b) -> a.compareToIgnoreCase(b);
static final Comparator<String> stringComparator = String::compareToIgnoreCase;

static final Comparator<String> boolComparator = (a, b) -> a.length() == b.length() ? 0
: a.length() > b.length() ? -1 : 1;
static final Comparator<String> boolComparator = (a, b) -> Integer.compare(b.length(), a.length());

static final Comparator<String> numberComparator = (a, b) -> {
double fa, fb;
try {
fa = Double.valueOf(a);
fa = Double.parseDouble(a);
} catch (NumberFormatException e) {
fa = Double.MAX_VALUE;
}
try {
fb = Double.valueOf(b);
fb = Double.parseDouble(b);
} catch (NumberFormatException e) {
fb = Double.MAX_VALUE;
if (fa == fb)
Expand All @@ -88,15 +91,12 @@ class Comparators {
static private String toKB(String size) {
String[] split = size.split(" ");
split[0] = split[0].replace(decimalSeparator, "");
switch (split[1]) {
case "GB":
return split[0] + "000000";
case "MB":
return split[0] + "000";
default:
return split[0];
}
return switch (split[1]) {
case "GB" -> split[0] + "000000";
case "MB" -> split[0] + "000";
default -> split[0];
};
}

static final Comparator<String> sizeComparator = (a, b) -> longComparator.compare(toKB(a), toKB(b));
}
}
14 changes: 7 additions & 7 deletions src/CustomActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import org.eclipse.swt.widgets.Text;

public class CustomActions {
private Shell shell;
private final Shell shell;
public static CustomAction[] actions;
private Composite customActionsGroup;
private final Composite customActionsGroup;

// Known pattern variables; the order matters: singular, more specific variables come first.
// If variables are added or meanings are changed, isValidPkgSelection() must also be updated.
Expand Down Expand Up @@ -118,14 +118,14 @@ public CustomActions(Shell parent) {

shell.setDefaultButton(close);
shell.pack();
GUI.centerShell(shell);
ShellHelpers.centerShell(shell);
shell.open();
}

// Helper function for isValidPkgSelection().
private static int countSubstrings(String string, String substring) {
int count = 0;
int next = 0;
int next;
while ((next = string.indexOf(substring)) != -1) {
count++;
string = string.substring(next + substring.length());
Expand Down Expand Up @@ -227,7 +227,7 @@ public static void loadActionsFromFile(String filename) {
String line = reader.readLine().trim();
int barIndex = line.indexOf('|');
String name = line.substring(0, barIndex).trim();
String command = line.substring(barIndex + 1, line.length()).trim();
String command = line.substring(barIndex + 1).trim();

actions.add(new CustomAction(name, command));
}
Expand All @@ -236,7 +236,7 @@ public static void loadActionsFromFile(String filename) {
} catch (NullPointerException e) {
}

if (actions.size() != 0)
if (!actions.isEmpty())
CustomActions.actions = actions.toArray(new CustomAction[0]);
}

Expand Down Expand Up @@ -333,4 +333,4 @@ private void addCustomAction(Composite parent, String name, String command) {
while (Display.getCurrent().readAndDispatch())
;
}
}
}
4 changes: 2 additions & 2 deletions src/ErrorMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ErrorMessage {
ok.setText("OK");
ok.addListener(SWT.Selection, e -> shell.close());
shell.pack();
GUI.centerShell(shell);
ShellHelpers.centerShell(shell);
shell.open();
}
}
}
4 changes: 2 additions & 2 deletions src/ExitMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public ExitMessage(Shell parent, String message) {
label.setText(message);

shell.pack();
GUI.centerShell(shell);
ShellHelpers.centerShell(shell);
parent.setVisible(false);
shell.open();

Expand All @@ -32,4 +32,4 @@ public ExitMessage(Shell parent, String message) {
public void close() {
shell.close();
}
}
}
Loading

0 comments on commit 4930e10

Please sign in to comment.