Skip to content

Commit

Permalink
tools: add more potentially localized texts, replace deprecated API
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahli committed Aug 5, 2023
1 parent e5d0862 commit 2a48d61
Show file tree
Hide file tree
Showing 15 changed files with 115 additions and 75 deletions.
Binary file modified dev/compile-spring-boot.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import com.kichik.pecoff4j.ResourceDirectory;
import com.kichik.pecoff4j.ResourceEntry;
import com.kichik.pecoff4j.constant.ResourceType;
import com.kichik.pecoff4j.io.DataReader;
import com.kichik.pecoff4j.io.PEParser;
import com.kichik.pecoff4j.io.ResourceParser;
import com.kichik.pecoff4j.resources.StringFileInfo;
import com.kichik.pecoff4j.resources.StringTable;
import com.kichik.pecoff4j.resources.VersionInfo;
Expand Down Expand Up @@ -160,7 +160,7 @@ public int[] getVersion(@NonNull final GameDef gameDef, final boolean isPtr) {
for (final ResourceEntry entry : entries) {
final byte[] data = entry.getData();
@SuppressWarnings("ObjectAllocationInLoop")
final VersionInfo version = ResourceParser.readVersionInfo(data);
final VersionInfo version = VersionInfo.read(new DataReader(data));

final StringFileInfo strings = version.getStringFileInfo();
final StringTable table = strings.getTable(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ protected SettingsController settingsController(final ApplicationContext appCont
@Bean
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
protected SettingsGamesPathsController settingsGamesPathsController(
final ConfigService configService, final FileService fileService) {
return new SettingsGamesPathsController(configService, fileService);
final ConfigService configService, final FileService fileService, final GameService gameService) {
return new SettingsGamesPathsController(configService, fileService, gameService);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,10 @@ public void checkBaseUiUpdate() {
try {
if (baseUiService.isOutdated(GameType.SC2, true)) {
if (primaryStage.hasPrimaryStage()) {
navigationController.appendNotification(new Notification(Messages.getString(
"browse.notification.sc2PtrOutOfDate"), NavigationController.BROWSE_TAB, "sc2PtrOutOfDate"));
navigationController.appendNotification(new Notification(
Messages.getString("browse.notification.sc2PtrOutOfDate"),
NavigationController.BROWSE_TAB,
"sc2PtrOutOfDate"));
} else {
log.warn(Messages.getString("browse.notification.sc2PtrOutOfDate"));
}
Expand All @@ -236,8 +238,8 @@ public void checkBaseUiUpdate() {
try {
if (baseUiService.isOutdated(GameType.HEROES, false)) {
if (primaryStage.hasPrimaryStage()) {
navigationController.appendNotification(new Notification(Messages.getString(
"browse.notification.heroesOutOfDate"),
navigationController.appendNotification(new Notification(
Messages.getString("browse.notification.heroesOutOfDate"),
NavigationController.BROWSE_TAB,
"heroesOutOfDate"));
} else {
Expand All @@ -250,8 +252,8 @@ public void checkBaseUiUpdate() {
try {
if (baseUiService.isOutdated(GameType.HEROES, true)) {
if (primaryStage.hasPrimaryStage()) {
navigationController.appendNotification(new Notification(Messages.getString(
"browse.notification.heroesPtrOutOfDate"),
navigationController.appendNotification(new Notification(
Messages.getString("browse.notification.heroesPtrOutOfDate"),
NavigationController.BROWSE_TAB,
"heroesPtrOutOfDate"));
} else {
Expand Down Expand Up @@ -385,7 +387,8 @@ public void onAppClosingEvent(final AppClosingEvent appCLosingEvent) {
//noinspection ResultOfMethodCallIgnored
executor.awaitTermination(120L, TimeUnit.SECONDS);
} catch (final InterruptedException e) {
log.error("ERROR: Executor timed out waiting for Worker Theads to terminate. A Thread might run rampage.",
log.error(
"ERROR: Executor timed out waiting for Worker Threads to terminate. A Thread might run rampage.",
e);
Thread.currentThread().interrupt();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,9 @@ public void update() {
}

private void updateBaseUiDetails() {
heroesBaseUiDetailsLabel.setText(buildBaseUiDetailsString(
GameType.HEROES,
heroesBaseUiDetailsLabel.setText(buildBaseUiDetailsString(GameType.HEROES,
baseUiService.isPtrActive(gameService.getGameDef(GameType.HEROES))));
sc2BaseUiDetailsLabel.setText(buildBaseUiDetailsString(
GameType.SC2,
sc2BaseUiDetailsLabel.setText(buildBaseUiDetailsString(GameType.SC2,
baseUiService.isPtrActive(gameService.getGameDef(GameType.SC2))));
}

Expand All @@ -226,12 +224,12 @@ private String buildBaseUiDetailsString(final GameType gameType, final boolean i
}
try {
if (baseUiService.isOutdated(gameType, isPtr)) {
sb.append(" - requires update");
sb.append(Messages.getString("browse.requiresUpdate"));
} else {
sb.append(" - up to date");
sb.append(Messages.getString("browse.upToDate"));
}
} catch (final IOException e) {
sb.append(" - could not check game version");
sb.append(Messages.getString("browse.couldNotCheckGameVersion"));
log.trace("Error: could not check game version", e);
}
return sb.toString();
Expand All @@ -250,7 +248,7 @@ public void extractBaseUiHeroes() {

private void extractBaseUi(final GameType gameType, final boolean usePtr) throws IOException {
final ObservableList<Tab> tabs = progressController.getTabPane().getTabs();
final String tabName = "Extract " + gameType.name();
final String tabName = String.format(Messages.getString("browse.extract"), gameType.name());
Tab newTab = null;
BaseUiExtractionController extractionController = null;

Expand All @@ -277,7 +275,7 @@ private void extractBaseUi(final GameType gameType, final boolean usePtr) throws
scrollPane.visibleProperty().bind(Bindings.isNotEmpty(newTxtArea.getChildren()));

final FXMLSpringLoader loader = new FXMLSpringLoader(appContext);
final var rootNode = loader.<AnchorPane>load("classpath:view/Progress_ExtractBaseUi.fxml");
final AnchorPane rootNode = loader.load("classpath:view/Progress_ExtractBaseUi.fxml");

newTab.setContent(rootNode);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public AddProjectController(final ProjectService projectService, final FileServi

public void browsePathAction() {
final DirectoryChooser directoryChooser = new DirectoryChooser();
directoryChooser.setTitle("Select an existing Observer UI's directory.");
directoryChooser.setTitle(Messages.getString("addProject.selectExistingObserverUiDirectory"));
final Path path = fileService.cutTillValidDirectory(Path.of(projectPathLabel.getText()));
if (path != null) {
directoryChooser.setInitialDirectory(path.toFile());
Expand All @@ -67,7 +67,7 @@ private Window getWindow() {
*/
public void setProjectToEdit(final Project project) {
this.project = project;
dialog.setTitle("Edit Observer Interface Project...");
dialog.setTitle(Messages.getString("addProject.editObserverInterfaceProject"));
projectNameLabel.setText(project.getName());
projectPathLabel.setText(project.getProjectPath().toString());
gameDropdown.getSelectionModel().select(project.getGameType());
Expand All @@ -88,7 +88,7 @@ public void initialize(final Dialog<Project> dialog) {
*/
private void initialize() {
if (dialog != null) {
dialog.setTitle("Add Observer Interface Project...");
dialog.setTitle(Messages.getString("addProject.addObserverInterfaceProject"));
final DialogPane dialogPane = dialog.getDialogPane();
dialogPane.getButtonTypes().addAll(ButtonType.APPLY, ButtonType.CANCEL);
final Button okBttn = (Button) dialogPane.lookupButton(ButtonType.APPLY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,11 @@ public void removeSelectedAction() {
final Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.initOwner(getWindow());
if (selectedItems.length > 1) {
alert.setTitle(String.format("Remove selected Projects from list? - %s items selected",
selectedItems.length));
alert.setTitle(String.format(Messages.getString("removeProject.removeSelected"), selectedItems.length));
} else {
alert.setTitle("Remove selected Project from list? - 1 item selected");
alert.setTitle(Messages.getString("removeProject.removeSelectedSingle"));
}
alert.setHeaderText("""
Are you sure you want to remove the selected projects?
This will not remove any files from the project.
""");
alert.setHeaderText(Messages.getString("removeProject.removeSelectedWarning"));
final ButtonType result = alert.showAndWait().orElse(null);
if (result == ButtonType.OK) {
for (final Project p : selectedItems) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public NewProjectController(final ProjectService projectService, final FileServi

public void browsePathAction() {
final DirectoryChooser directoryChooser = new DirectoryChooser();
directoryChooser.setTitle("Select a directory to create a template Project in");
directoryChooser.setTitle(Messages.getString("newProject.selectDirectory"));
final Path path = fileService.cutTillValidDirectory(Path.of(projectPathLabel.getText()));
if (path != null) {
directoryChooser.setInitialDirectory(path.toFile());
Expand Down Expand Up @@ -78,7 +78,7 @@ public void initialize(final Dialog<Project> dialog) {
*/
private void initialize() {
if (dialog != null) {
dialog.setTitle("Create new Observer Interface Project...");
dialog.setTitle(Messages.getString("newProject.dialogTitle"));
final DialogPane dialogPane = dialog.getDialogPane();
dialogPane.getButtonTypes().addAll(ButtonType.APPLY, ButtonType.CANCEL);
final Button okBttn = (Button) dialogPane.lookupButton(ButtonType.APPLY);
Expand Down Expand Up @@ -112,11 +112,9 @@ public void newProjectAction(final Event event) {
if (!projectService.getProjectsOfPath(path).isEmpty()) {
final Alert alert = Alerts.buildErrorAlert(
dialog.getOwner(),
"An Error occurred",
"Project's path already used in another project",
String.format(
"Could not create a Project for path '%s' as it is already registered in another project.",
path));
Messages.getString("Main.anErrorOccurred"),
Messages.getString("newProject.pathAlreadyUsedInOtherProject.header"),
String.format(Messages.getString("newProject.pathAlreadyUsedInOtherProject.content"), path));
alert.showAndWait();
return;
}
Expand All @@ -130,9 +128,10 @@ public void newProjectAction(final Event event) {
log.error("ERROR: Could not create project.", e);
final Alert alert = Alerts.buildErrorAlert(
dialog.getOwner(),
"An Error occurred",
"Could not create the Project.",
String.format("Could not create a Project in '%s'", path) + e.getLocalizedMessage());
Messages.getString("Main.anErrorOccurred"),
Messages.getString("newProject.couldNotCreateProject.header"),
String.format(Messages.getString("newProject.couldNotCreateProject.content"), path) +
e.getLocalizedMessage());
alert.showAndWait();
return;
}
Expand All @@ -146,9 +145,10 @@ public void newProjectAction(final Event event) {
projectService.deleteProject(project);
final Alert alert = Alerts.buildErrorAlert(
dialog.getOwner(),
"An Error occurred",
"Could not create the Template.",
String.format("Could not create a Template in '%s'", path) + e.getLocalizedMessage());
Messages.getString("Main.anErrorOccurred"),
Messages.getString("newProject.couldNotCreateTemplate.header"),
String.format(Messages.getString("newProject.couldNotCreateTemplate.content"), path) +
e.getLocalizedMessage());
alert.showAndWait();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void initialize() {
}

/**
* Inject a project whose best compression ruleset is shown.
* Inject a project whose best compression rule set is shown.
*
* @param project
*/
Expand All @@ -107,7 +107,7 @@ public void setProject(final Project project) throws IOException {
}

/**
* Shows the compression ruleset of a specified project.
* Shows the compression rule set of a specified project.
*
* @param project
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ public void startMining() {
}
keepTaskRunning = true;
task = () -> {
final Path modTargetFile;
try {
long bestSize;
final ModD mod = gameService.getModData(project.getGameType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ public final class ErrorTabController {
private static final String TAB_TEXT_COLOR_WHITE = "-tab-text-color: white;";
private final boolean colorizeTitle;
private final boolean showResultIcon;
private boolean encounteredError;
private boolean running;
private boolean encounteredWarning;
private State state = State.NOT_STARTED;
@Getter
private final Tab tab;
@Getter
private final TextFlow textArea;
private boolean encounteredError;
private boolean running;
private boolean encounteredWarning;
private State state = State.NOT_STARTED;
@Getter
@Setter
private boolean errorPreventsExit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public class TabPaneController implements Updateable, FxmlController {

private ProgressController progressController;

@Getter
@FXML
private TabPane tabPane;
Expand Down
Loading

0 comments on commit 2a48d61

Please sign in to comment.