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

View File

@@ -168,11 +168,10 @@ public class UpdateUtils {
logger.error("Error while updating: ", e);
}
} else {
logger.debug("This version (" + UpdateUtils.getThisJarVersion()
+ ") is the same or newer than the website's version (" + latestVersion + ")");
logger.info("Running version (" + UpdateUtils.getThisJarVersion()
+ ") is not older than release (" + latestVersion + ")");
configUpdateLabel.setText("<html><font color=\"green\">v" + UpdateUtils.getThisJarVersion()
+ " 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.
*/
public static String shortenPath(String path) {
return shortenPath(new File(path));
return shortenPath(path);
}
/**
* 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.
*/
public static String shortenPath(File file) {
String path = removeCWD(file.toPath());
if (path.length() < SHORTENED_PATH_LENGTH * 2) {
return path;
public static String shortenPath(Path path) {
Path prettyPath = path.normalize();
if (prettyPath.toString().length() < SHORTENED_PATH_LENGTH * 2) {
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);
}
/**