Skip to content

Commit

Permalink
Application: Extract dynamic library extension in a separate constant
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadelessFox committed Mar 24, 2024
1 parent d16d9f8 commit 3cd7ca6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.shade.decima.ui.data.viewer.shader.settings;

import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.util.SystemInfo;
import com.shade.decima.ui.controls.FileExtensionFilter;
import com.shade.decima.ui.controls.LabeledBorder;
import com.shade.decima.ui.controls.validators.ExistingFileValidator;
Expand All @@ -25,8 +24,7 @@ public class ShaderViewerSettingsPage implements SettingsPage {
@Override
public JComponent createComponent(@NotNull PropertyChangeListener listener) {
{
final String extension = SystemInfo.isMacOS ? "dylib" : SystemInfo.isLinux ? "so" : "dll";
final FileExtensionFilter filter = new FileExtensionFilter("Direct3D compiler library", extension);
final FileExtensionFilter filter = new FileExtensionFilter("Direct3D compiler library", FileExtensionFilter.LIBRARY);

d3dCompilerPath = new JTextField();
d3dCompilerPath.putClientProperty(FlatClientProperties.PLACEHOLDER_TEXT, "d3dcompiler.dll");
Expand All @@ -35,8 +33,7 @@ public JComponent createComponent(@NotNull PropertyChangeListener listener) {
}

{
final String extension = SystemInfo.isMacOS ? "dylib" : SystemInfo.isLinux ? "so" : "dll";
final FileExtensionFilter filter = new FileExtensionFilter("DirectX compiler library", extension);
final FileExtensionFilter filter = new FileExtensionFilter("DirectX compiler library", FileExtensionFilter.LIBRARY);

dxCompilerPath = new JTextField();
dxCompilerPath.putClientProperty(FlatClientProperties.PLACEHOLDER_TEXT, "dxcompiler.dll");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.shade.decima.ui.controls;

import com.formdev.flatlaf.util.SystemInfo;
import com.shade.platform.model.util.IOUtils;
import com.shade.platform.model.util.ReflectionUtils;
import com.shade.util.NotNull;
Expand All @@ -10,6 +11,16 @@
import java.util.stream.Collectors;

public class FileExtensionFilter extends FileFilter {
/**
* The dynamic library extension for the current platform.
* <ul>
* <li>On macOS, the extension is {@code dylib}</li>
* <li>On Linux, the extension is {@code so}</li>
* <li>On Windows, the extension is {@code dll}</li>
* </ul>
*/
public static final String LIBRARY = SystemInfo.isMacOS ? "dylib" : SystemInfo.isLinux ? "so" : "dll";

private final String description;
private final String[] extensions;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.shade.decima.ui.dialogs;

import com.formdev.flatlaf.util.SystemInfo;
import com.shade.decima.model.app.ProjectContainer;
import com.shade.decima.model.base.GameType;
import com.shade.decima.model.util.Oodle;
Expand Down Expand Up @@ -158,11 +157,10 @@ protected JComponent createContentsPane() {
}

{
final String extension = SystemInfo.isMacOS ? "dylib" : SystemInfo.isLinux ? "so" : "dll";
final FileExtensionFilter filter = new FileExtensionFilter("Oodle Library", extension);
final FileExtensionFilter filter = new FileExtensionFilter("Oodle Library", FileExtensionFilter.LIBRARY);

final JLabel label = new JLabel("Oodle library:");
label.setToolTipText("<html>Path to the oodle library used for compressing/decompressing game data.<br>For most games, it's a file in the game's root folder called <kbd>oo2core_XXX." + extension + "</kbd>.</html>");
label.setToolTipText("<html>Path to the oodle library used for compressing/decompressing game data.<br>For most games, it's a file in the game's root folder called <kbd>oo2core_XXX." + FileExtensionFilter.LIBRARY + "</kbd>.</html>");

panel.add(label, "gap ind");
panel.add(compressorPath, "wrap");
Expand Down Expand Up @@ -263,16 +261,15 @@ private void fillValuesBasedOnGameType(@NotNull GameType oldType, @NotNull GameT

private void fillValuesBasedOnGameExecutable(@NotNull Path path) {
final String newFilename = IOUtils.getBasename(path).toLowerCase(Locale.ROOT);
final String libExtension = SystemInfo.isMacOS ? "dylib" : SystemInfo.isLinux ? "so" : "dll";

switch (newFilename) {
case "ds" -> {
setIfEmptyOrOldValue(archiveFolderPath, Path.of(archiveFolderPath.getText()), path.resolveSibling("data"));
setIfEmptyOrOldValue(compressorPath, Path.of(compressorPath.getText()), path.resolveSibling("oo2core_7_win64." + libExtension));
setIfEmptyOrOldValue(compressorPath, Path.of(compressorPath.getText()), path.resolveSibling("oo2core_7_win64." + FileExtensionFilter.LIBRARY));
}
case "horizonzerodawn" -> {
setIfEmptyOrOldValue(archiveFolderPath, Path.of(archiveFolderPath.getText()), path.resolveSibling("Packed_DX12"));
setIfEmptyOrOldValue(compressorPath, Path.of(compressorPath.getText()), path.resolveSibling("oo2core_3_win64." + libExtension));
setIfEmptyOrOldValue(compressorPath, Path.of(compressorPath.getText()), path.resolveSibling("oo2core_3_win64." + FileExtensionFilter.LIBRARY));
}
}
}
Expand Down

0 comments on commit 3cd7ca6

Please sign in to comment.