1
0
mirror of https://github.com/RipMeApp/ripme.git synced 2025-08-23 14:02:54 +02:00

shorten path uses nio, fixes #85.

This commit is contained in:
soloturn
2022-04-25 09:01:42 +02:00
parent e3550d6f68
commit e0e58c1435
3 changed files with 17 additions and 16 deletions

View File

@@ -536,7 +536,7 @@ public final class MainWindow implements Runnable, RipStatusHandler {
setLogLevel(configLogLevelCombobox.getSelectedItem().toString()); setLogLevel(configLogLevelCombobox.getSelectedItem().toString());
configSaveDirLabel = new JLabel(); configSaveDirLabel = new JLabel();
try { try {
String workingDir = (Utils.shortenPath(Utils.getWorkingDirectory().toString())); String workingDir = (Utils.shortenPath(Utils.getWorkingDirectory()));
configSaveDirLabel.setText(workingDir); configSaveDirLabel.setText(workingDir);
configSaveDirLabel.setForeground(Color.BLUE); configSaveDirLabel.setForeground(Color.BLUE);
configSaveDirLabel.setCursor(new Cursor(Cursor.HAND_CURSOR)); configSaveDirLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
@@ -920,21 +920,21 @@ public final class MainWindow implements Runnable, RipStatusHandler {
configSaveDirButton.addActionListener(arg0 -> { configSaveDirButton.addActionListener(arg0 -> {
UIManager.put("FileChooser.useSystemExtensionHiding", false); UIManager.put("FileChooser.useSystemExtensionHiding", false);
JFileChooser jfc = new JFileChooser(Utils.getWorkingDirectory().toString()); JFileChooser jfc = new JFileChooser(Utils.getWorkingDirectory().toString());
LOGGER.debug("select save directory, current is:" + Utils.getWorkingDirectory());
jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int returnVal = jfc.showDialog(null, "select directory"); int returnVal = jfc.showDialog(null, "select directory");
if (returnVal != JFileChooser.APPROVE_OPTION) { if (returnVal != JFileChooser.APPROVE_OPTION) {
return; return;
} }
File chosenFile = jfc.getSelectedFile(); Path chosenPath;
String chosenPath;
try { try {
chosenPath = chosenFile.getCanonicalPath(); chosenPath = jfc.getSelectedFile().toPath();
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("Error while getting selected path: ", e); LOGGER.error("Error while getting selected path: ", e);
return; return;
} }
configSaveDirLabel.setText(Utils.shortenPath(chosenPath)); configSaveDirLabel.setText(Utils.shortenPath(chosenPath));
Utils.setConfigString("rips.directory", chosenPath); Utils.setConfigString("rips.directory", chosenPath.toString());
}); });
configUrlFileChooserButton.addActionListener(arg0 -> { configUrlFileChooserButton.addActionListener(arg0 -> {
UIManager.put("FileChooser.useSystemExtensionHiding", false); UIManager.put("FileChooser.useSystemExtensionHiding", false);
@@ -1471,7 +1471,7 @@ public final class MainWindow implements Runnable, RipStatusHandler {
statusProgress.setVisible(false); statusProgress.setVisible(false);
openButton.setVisible(true); openButton.setVisible(true);
Path f = rsc.dir; Path f = rsc.dir;
String prettyFile = Utils.shortenPath(f.toFile()); String prettyFile = Utils.shortenPath(f);
openButton.setText(Utils.getLocalizedString("open") + prettyFile); openButton.setText(Utils.getLocalizedString("open") + prettyFile);
mainFrame.setTitle("RipMe v" + UpdateUtils.getThisJarVersion()); mainFrame.setTitle("RipMe v" + UpdateUtils.getThisJarVersion());
try { try {

View File

@@ -168,11 +168,10 @@ public class UpdateUtils {
logger.error("Error while updating: ", e); logger.error("Error while updating: ", e);
} }
} else { } else {
logger.debug("This version (" + UpdateUtils.getThisJarVersion() logger.info("Running version (" + UpdateUtils.getThisJarVersion()
+ ") is the same or newer than the website's version (" + latestVersion + ")"); + ") is not older than release (" + latestVersion + ")");
configUpdateLabel.setText("<html><font color=\"green\">v" + UpdateUtils.getThisJarVersion() configUpdateLabel.setText("<html><font color=\"green\">v" + UpdateUtils.getThisJarVersion()
+ " is the latest version</font></html>"); + " is the latest version</font></html>");
logger.debug("Running latest version: " + UpdateUtils.getThisJarVersion());
} }
} }

View File

@@ -438,21 +438,23 @@ public class Utils {
* @return The simplified path to the file. * @return The simplified path to the file.
*/ */
public static String shortenPath(String path) { public static String shortenPath(String path) {
return shortenPath(new File(path)); return shortenPath(path);
} }
/** /**
* Shortens the path to a file * Shortens the path to a file
* *
* @param file File object that you want the shortened path of. * @param path File object that you want the shortened path of.
* @return The simplified path to the file. * @return The simplified path to the file.
*/ */
public static String shortenPath(File file) { public static String shortenPath(Path path) {
String path = removeCWD(file.toPath()); Path prettyPath = path.normalize();
if (path.length() < SHORTENED_PATH_LENGTH * 2) { if (prettyPath.toString().length() < SHORTENED_PATH_LENGTH * 2) {
return path; return prettyPath.toString();
} }
return path.substring(0, SHORTENED_PATH_LENGTH) + "..." + path.substring(path.length() - SHORTENED_PATH_LENGTH); return prettyPath.toString().substring(0, SHORTENED_PATH_LENGTH)
+ "..."
+ prettyPath.toString().substring(prettyPath.toString().length() - SHORTENED_PATH_LENGTH);
} }
/** /**