|
4 | 4 | import java.io.FileOutputStream; |
5 | 5 | import java.io.PrintStream; |
6 | 6 | import java.net.URISyntaxException; |
| 7 | +import java.util.ArrayList; |
7 | 8 | import java.util.Arrays; |
8 | 9 | import java.util.List; |
9 | 10 |
|
| 11 | +import processing.app.Platform; |
10 | 12 | import processing.core.PApplet; |
11 | 13 | import rprocessing.RunnableSketch; |
12 | 14 | import rprocessing.Runner; |
@@ -103,44 +105,26 @@ public StandaloneSketch(final String[] args) throws Exception { |
103 | 105 | this.code = RScriptReader.readText(sketchPath.toPath()); |
104 | 106 |
|
105 | 107 | // TODO: Support library in standalone sketch. |
106 | | - this.libraryDirs = null; |
107 | | - // { |
108 | | - // log("Populate library directories."); |
109 | | - // this.libraryDirs = new ArrayList<>(); |
110 | | - // final String buildProperties = "build.properties"; |
111 | | - // final String propsResource; |
112 | | - // try { |
113 | | - // propsResource = |
114 | | - // URLDecoder.decode(Runner.class.getResource(buildProperties).toString(), "UTF-8"); |
115 | | - // log(propsResource); |
116 | | - // } catch (final UnsupportedEncodingException e) { |
117 | | - // throw new RuntimeException("Impossible: " + e); |
118 | | - // } |
119 | | - // |
120 | | - // if (propsResource == null) { |
121 | | - // log("Could not get build.properties from Runner."); |
122 | | - // libraryDirs.add(new File("libraries")); |
123 | | - // return; |
124 | | - // } |
125 | | - // |
126 | | - // final Pattern jarResource = Pattern |
127 | | - // .compile("jar:file:(.+?)/RLangMode\\.jar!/rprocessing/" + Pattern.quote(buildProperties)); |
128 | | - // final Pattern fileResource = |
129 | | - // Pattern.compile("file:(.+?)/bin/rprocessing/" + Pattern.quote(buildProperties)); |
130 | | - // |
131 | | - // final Matcher jarMatcher = jarResource.matcher(propsResource); |
132 | | - // final Matcher fileMatcher = fileResource.matcher(propsResource); |
133 | | - // if (jarMatcher.matches()) { |
134 | | - // log("We're running from a JAR file."); |
135 | | - // libraryDirs.add(new File(jarMatcher.group(1), "libraries")); |
136 | | - // } else if (fileMatcher.matches()) { |
137 | | - // log("We're running from class files."); |
138 | | - // libraryDirs.add(new File(fileMatcher.group(1), "libraries")); |
139 | | - // } else { |
140 | | - // log("WARNING: I can't find my libraries directory!"); |
141 | | - // libraryDirs.add(new File("libraries")); |
142 | | - // } |
143 | | - // } |
| 108 | + final List<File> libraryDirs = new ArrayList<>(); |
| 109 | + libraryDirs.add(getLibraryDir()); |
| 110 | + log(getLibraryDir()); |
| 111 | + libraryDirs.add(sketchPath); |
| 112 | + this.libraryDirs = libraryDirs; |
| 113 | + } |
| 114 | + |
| 115 | + private File getLibraryDir() { |
| 116 | + if (Platform.isMacOS()) { |
| 117 | + String home = System.getProperty("user.home"); |
| 118 | + return new File(home + "/Documents/Processing/libraries"); |
| 119 | + } else if (Platform.isLinux()) { |
| 120 | + String home = System.getProperty("user.home"); |
| 121 | + return new File(home + "/sketchbook/libraries"); |
| 122 | + } else if (Platform.isWindows()) { |
| 123 | + String home = System.getProperty("user.home"); |
| 124 | + return new File(home + "\\Documents\\Processing\\modes"); |
| 125 | + } |
| 126 | + log("Operating System is not supported now."); |
| 127 | + return null; |
144 | 128 | } |
145 | 129 |
|
146 | 130 | @Override |
|
0 commit comments