Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Improved handling of null workDir.

  • Loading branch information...
commit 11249a870701aef56c405362bba8719337bcb06a 1 parent d456221
@IsmAvatar authored
View
49 org/lateralgm/jedit/GMLKeywords.java
@@ -9,12 +9,7 @@
package org.lateralgm.jedit;
-import java.io.BufferedInputStream;
import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -23,8 +18,6 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.lateralgm.main.LGM;
-
public final class GMLKeywords
{
public static Construct[] CONSTRUCTS;
@@ -35,18 +28,7 @@
static
{
- final String fn = "gmlkeywords.properties";
- InputStream is;
- File dir = LGM.workDir;
- if (!dir.isDirectory()) dir = dir.getParentFile();
- try
- {
- is = new BufferedInputStream(new FileInputStream(new File(dir,fn)));
- }
- catch (FileNotFoundException e1)
- {
- is = GMLKeywords.class.getResourceAsStream(fn);
- }
+ InputStream is = GMLKeywords.class.getResourceAsStream("gmlkeywords.properties");
Properties p = new Properties();
try
{
@@ -75,20 +57,9 @@
p.clear();
//read functions
-
- final String fn2 = "functions.txt";
- BufferedReader br2 = null;
- try
- {
- br2 = new BufferedReader(new FileReader(new File(dir,fn2)));
- }
- catch (FileNotFoundException e)
- {
- InputStream is2 = GMLKeywords.class.getResourceAsStream(fn2);
- br2 = new BufferedReader(new InputStreamReader(is2));
- }
-
- ArrayList<Function> list = new ArrayList<Function>();
+ InputStream is2 = GMLKeywords.class.getResourceAsStream("functions.txt");
+ BufferedReader br2 = new BufferedReader(new InputStreamReader(is2));
+ ArrayList<Function> funcList = new ArrayList<Function>();
try
{
@@ -97,7 +68,7 @@
{
String args = br2.readLine();
String desc = br2.readLine();
- list.add(new Function(func,args,desc));
+ funcList.add(new Function(func,args,desc));
}
}
catch (IOException e)
@@ -105,7 +76,7 @@
e.printStackTrace();
}
- FUNCTIONS = list.toArray(new Function[0]);
+ FUNCTIONS = funcList.toArray(new Function[0]);
}
private GMLKeywords()
@@ -146,11 +117,11 @@ public Operator(String input)
public Variable(String input)
{
Matcher m = Pattern.compile("(\\w+)(\\[(\\d+)])?(\\*)?").matcher(input);
- if (!m.matches()) System.err.println("Invalid variable: " + input);
+ if (!m.matches()) System.err.println("Invalid variable: " + input); //$NON-NLS-1$
name = m.group(1);
String s = m.group(3);
arraySize = s != null ? Integer.valueOf(m.group(3)) : 0;
- readOnly = "*".equals(m.group(4));
+ readOnly = "*".equals(m.group(4)); //$NON-NLS-1$
}
}
@@ -177,7 +148,7 @@ public Function(String input)
// fun ( arg, arg { 0 , 9 } , arg )
String re = "(\\w+)\\(((\\w+,)*)((\\w+)\\{(\\d+),(\\d+)}((?=\\))|,))?(\\w+)?\\)";
Matcher m = Pattern.compile(re).matcher(input);
- if (!m.matches()) System.err.println("Invalid function: " + input);
+ if (!m.matches()) System.err.println("Invalid function: " + input); //$NON-NLS-1$
name = m.group(1); //the function name
String a1 = m.group(2); //plain arguments with commas
String da = m.group(5); //argument with range
@@ -201,7 +172,7 @@ public Function(String input)
arguments[aa1.length] = da;
}
if (a2 != null) arguments[arguments.length - 1] = a2;
- description = "";
+ description = ""; //$NON-NLS-1$
}
public Function(String func, String args, String desc)
View
5 org/lateralgm/main/LGM.java
@@ -97,9 +97,9 @@
{
workDir = new File(LGM.class.getProtectionDomain().getCodeSource().getLocation().toURI());
}
- catch (URISyntaxException e1)
+ catch (Exception e)
{
- e1.printStackTrace();
+ System.err.println(Messages.format("LGM.NO_WORKDIR",e.getClass(),e.getLocalizedMessage()));
}
}
public static JFrame frame;
@@ -285,6 +285,7 @@ private static JComponent createMDI()
public static void loadPlugins()
{
+ if (workDir == null) return;
File dir = new File(workDir.getParent(),"plugins"); //$NON-NLS-1$
if (!dir.exists()) dir = new File(workDir.getParent(),"Plugins"); //$NON-NLS-1$
File[] ps = dir.listFiles(new CustomFileFilter(null,".jar")); //$NON-NLS-1$
View
3  org/lateralgm/messages/messages.properties
@@ -235,6 +235,9 @@ LGM.SPLASH_LOGO=Reticulating Splines
LGM.SPLASH_TREE=Populating Tree
LGM.SPLASH_PLUGINS=Loading Plugins
+LGM.NO_WORKDIR=Unable to determine the Working Directory. \
+ Plugins and default User Libraries directory will be unavailable. \
+ Caused by: {0}: {1}
LGM.PLUGIN_MISSING_ENTRY=No plugin entry point ({0})
LGM.PLUGIN_LOAD_ERROR=Info: {0} is not an LGM plugin: {1}: {2}
View
8 org/lateralgm/resources/library/LibManager.java
@@ -63,8 +63,12 @@ public static LibAction getLibAction(int libraryId, int libActionId)
public static void autoLoad()
{
File defdir = new File(Prefs.defaultLibraryPath);
- if (!defdir.exists()) defdir = new File(LGM.workDir,Prefs.defaultLibraryPath);
- if (!defdir.exists()) defdir = LGM.workDir;
+ if (!defdir.exists())
+ {
+ if (LGM.workDir == null) return;
+ defdir = new File(LGM.workDir,Prefs.defaultLibraryPath);
+ if (!defdir.exists()) defdir = LGM.workDir;
+ }
codeAction = null;
Please sign in to comment.
Something went wrong with that request. Please try again.