Skip to content

Commit

Permalink
Patch Legacy Recent File Paths
Browse files Browse the repository at this point in the history
Fixes exception caused by 986260d
Apply a quick fix to convert raw filepaths in recent files to new URI
syntax at startup. This allows you to bring recent files from legacy
versions of LGM like 1.5.7.1 into the newer versions without any errors.
Perhaps later we will allow both filepaths and URIs from the command
line and recent files eliminating this patch.
  • Loading branch information
RobertBColton committed Feb 23, 2021
1 parent 9345ae8 commit 385f7f2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
5 changes: 4 additions & 1 deletion org/lateralgm/main/LGM.java
Expand Up @@ -131,7 +131,7 @@

public final class LGM
{
public static final String version = "1.8.225"; //$NON-NLS-1$
public static final String version = "1.8.226"; //$NON-NLS-1$

// TODO: This list holds the class loader for any loaded plugins which should be
// cleaned up and closed when the application closes.
Expand Down Expand Up @@ -1217,6 +1217,9 @@ public static void main(final String[] args)
if (javaVersion < 10700)
System.out.println("Some program functionality will be limited due to your outdated Java version"); //$NON-NLS-1$

// Fix up raw filepaths from 1.5.7.1 into file URI format.
PrefsStore.patchRecentFiles();

// Create the main window on the EDT for safety.
// https://docs.oracle.com/javase/tutorial/uiswing/concurrency/initial.html
SwingUtilities.invokeLater(new Runnable()
Expand Down
24 changes: 23 additions & 1 deletion org/lateralgm/main/PrefsStore.java
Expand Up @@ -10,6 +10,7 @@
package org.lateralgm.main;

import java.awt.Rectangle;
import java.io.File;
import java.util.ArrayList;
import java.util.Locale;
import java.util.prefs.BackingStoreException;
Expand Down Expand Up @@ -52,7 +53,6 @@ public static ArrayList<String> getRecentFiles()
for (String name : array)
list.add(Util.urlDecode(name));
return list;

}

public static void addRecentFile(String name)
Expand All @@ -67,6 +67,28 @@ public static void addRecentFile(String name)
PREFS.put("FILE_RECENT",newList);
}

/**
* Updates raw filepaths from 1.5.7.1 to proper URI format.
*/
public static void patchRecentFiles()
{
String value = PREFS.get("FILE_RECENT",null);
if (value == null) return;
String[] array = value.split(" ");
if (array.length < 1) return;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < array.length; ++i)
{
if (i > 0) sb.append(" ");
String str = array[i];
if (!str.startsWith("file%3A%2F"))
sb.append(Util.urlEncode(new File(Util.urlDecode(str)).toURI().toString()));
else
sb.append(str);
}
PREFS.put("FILE_RECENT",sb.toString());
}

public static Rectangle getWindowBounds(Rectangle def)
{
return Util.stringToRectangle(PREFS.get("WINDOW_BOUNDS",null),def);
Expand Down

0 comments on commit 385f7f2

Please sign in to comment.