Changeset 873 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2008-08-26T22:35:52+02:00 (16 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/Preferences.java
r812 r873 72 72 */ 73 73 public String getPreferencesDir() { 74 final String path = getPreferencesDirFile().getPath(); 75 if (path.endsWith(File.separator)) 76 return path; 77 return path + File.separator; 78 } 79 80 public File getPreferencesDirFile() { 74 81 if (System.getenv("APPDATA") != null) 75 return System.getenv("APPDATA")+"/JOSM/"; 76 return System.getProperty("user.home")+"/.josm/"; 82 return new File(System.getenv("APPDATA"), "JOSM"); 83 return new File(System.getProperty("user.home"), ".josm"); 84 } 85 86 public File getPluginsDirFile() { 87 return new File(getPreferencesDirFile(), "plugins"); 77 88 } 78 89 … … 85 96 String s; 86 97 if ((s = System.getenv("JOSM_RESOURCES")) != null) { 87 if (!s.endsWith( "/") && !s.endsWith("\\"))88 s = s + "/";98 if (!s.endsWith(File.separator)) 99 s = s + File.separator; 89 100 locations.add(s); 90 101 } 91 102 if ((s = System.getProperty("josm.resources")) != null) { 92 if (!s.endsWith( "/") && !s.endsWith("\\"))93 s = s + "/";103 if (!s.endsWith(File.separator)) 104 s = s + File.separator; 94 105 locations.add(s); 95 106 } 96 107 String appdata = System.getenv("APPDATA"); 97 if (System.getenv("ALLUSERSPROFILE") != null && appdata != null && appdata.lastIndexOf("\\") != -1) { 98 appdata = appdata.substring(appdata.lastIndexOf("\\")); 99 locations.add(System.getenv("ALLUSERSPROFILE")+appdata+"/JOSM/"); 108 if (System.getenv("ALLUSERSPROFILE") != null && appdata != null 109 && appdata.lastIndexOf(File.separator) != -1) { 110 appdata = appdata.substring(appdata.lastIndexOf(File.separator)); 111 locations.add(new File(new File(System.getenv("ALLUSERSPROFILE"), 112 appdata), "JOSM").getPath()); 100 113 } 101 114 locations.add("/usr/local/share/josm/"); -
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r795 r873 22 22 23 23 import org.openstreetmap.josm.Main; 24 import org.openstreetmap.josm.plugins.PluginDownloader; 24 25 import org.openstreetmap.josm.tools.BugReportExceptionHandler; 25 26 /** … … 84 85 final File prefDir = new File(Main.pref.getPreferencesDir()); 85 86 // check if preferences directory has moved (TODO: Update code. Remove this after some time) 86 File oldPrefDir = new File(System.getProperty("user.home") +"/.josm");87 File oldPrefDir = new File(System.getProperty("user.home"), ".josm"); 87 88 if (!prefDir.isDirectory() && oldPrefDir.isDirectory()) { 88 89 if (oldPrefDir.renameTo(prefDir)) { … … 119 120 } 120 121 122 if (!PluginDownloader.moveUpdatedPlugins()) { 123 JOptionPane.showMessageDialog(null, 124 tr("Activating the updated plugins failed."), 125 tr("Plugins"), JOptionPane.ERROR_MESSAGE); 126 } 127 121 128 // load the early plugins 122 129 Main.loadPlugins(true); -
trunk/src/org/openstreetmap/josm/gui/preferences/PluginPreference.java
r627 r873 102 102 public void actionPerformed(ActionEvent e) { 103 103 update(); 104 refreshPluginPanel(gui); 104 105 } 105 106 … … 168 169 169 170 private void update() { 171 // refresh description 172 PluginDownloader.downloadDescription(); 173 170 174 Set<PluginDescription> toUpdate = new HashSet<PluginDescription>(); 171 175 StringBuilder toUpdateStr = new StringBuilder(); … … 212 216 for (final PluginDescription plugin : availablePlugins) { 213 217 boolean enabled = enabledPlugins.contains(plugin.name); 214 final JCheckBox pluginCheck = new JCheckBox(plugin.name+(plugin.version != null && !plugin.version.equals("") ? " Version: "+plugin.version : ""), enabled); 218 String remoteversion = plugin.version; 219 if(remoteversion == null || remoteversion.equals("")) 220 remoteversion = tr("unknown"); 221 222 String localversion; 223 PluginInformation p = PluginInformation.findPlugin(plugin.name); 224 if(p != null) 225 { 226 if(p.version != null && !p.version.equals("")) 227 localversion = p.version; 228 else 229 localversion = tr("unknown"); 230 localversion = " (" + localversion + ")"; 231 } 232 else 233 localversion = ""; 234 235 final JCheckBox pluginCheck = new JCheckBox(tr("{0}: Version {1}{2}", plugin.name, remoteversion, localversion), enabled); 215 236 pluginPanel.add(pluginCheck); 216 237 -
trunk/src/org/openstreetmap/josm/plugins/Plugin.java
r627 r873 53 53 */ 54 54 public final String getPluginDir() { 55 return Main.pref.getPreferencesDir()+"plugins/"+info.name+"/";55 return new File(Main.pref.getPluginsDirFile(), info.name).getPath(); 56 56 } 57 57 -
trunk/src/org/openstreetmap/josm/plugins/PluginDownloader.java
r627 r873 13 13 import java.io.FileOutputStream; 14 14 import java.io.FileWriter; 15 import java.io.FilenameFilter; 15 16 import java.io.IOException; 16 17 import java.io.InputStream; … … 54 55 55 56 @Override protected void realRun() throws SAXException, IOException { 57 File pluginDir = Main.pref.getPluginsDirFile(); 58 if (!pluginDir.exists()) 59 pluginDir.mkdirs(); 56 60 for (PluginDescription d : toUpdate) { 57 File tempFile = new File(Main.pref.getPreferencesDir()+"temp.jar"); 58 if (download(d.resource, tempFile)) { 59 tempFile.renameTo(new File(Main.pref.getPreferencesDir()+"plugins/"+d.name+".jar")); 61 File pluginFile = new File(pluginDir, d.name + ".jar.new"); 62 if (download(d.resource, pluginFile)) 60 63 count++; 61 }else64 else 62 65 errors += d.name + "\n"; 63 66 } 67 PluginDownloader.moveUpdatedPlugins(); 64 68 } 65 69 } … … 79 83 r.close(); 80 84 new File(Main.pref.getPreferencesDir()+"plugins").mkdir(); 81 FileWriter out = new FileWriter(Main.pref.getPreferencesDir()+"plugins/"+count+"-site-"+site.replaceAll("[/:\\\\ <>|]", "_")+".xml"); 85 FileWriter out = new FileWriter(new File(Main.pref 86 .getPluginsDirFile(), count + "-site-" 87 + site.replaceAll("[/:\\\\ <>|]", "_") + ".xml")); 82 88 out.append(txt); 83 89 out.close(); … … 123 129 124 130 public static boolean downloadPlugin(PluginDescription pd) { 125 File file = new File(Main.pref.getP referencesDir()+"plugins/"+pd.name+".jar");131 File file = new File(Main.pref.getPluginsDirFile(), pd.name + ".jar"); 126 132 if (!download(pd.resource, file)) { 127 133 JOptionPane.showMessageDialog(Main.parent, tr("Could not download plugin: {0} from {1}", pd.name, pd.resource)); … … 163 169 Main.worker.execute(new UpdateTask(update)); 164 170 } 171 172 public static boolean moveUpdatedPlugins() { 173 File pluginDir = Main.pref.getPluginsDirFile(); 174 boolean ok = true; 175 if (pluginDir.exists() && pluginDir.isDirectory()) { 176 final File[] files = pluginDir.listFiles(new FilenameFilter() { 177 public boolean accept(File dir, String name) { 178 return name.endsWith(".new"); 179 }}); 180 for (File updatedPlugin : files) { 181 final String filePath = updatedPlugin.getPath(); 182 File plugin = new File(filePath.substring(0, filePath.length() - 4)); 183 ok = plugin.delete() && updatedPlugin.renameTo(plugin) && ok; 184 } 185 } 186 return ok; 187 } 165 188 } -
trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java
r627 r873 196 196 197 197 for (String s : locations) { 198 File pluginFile = new File(s +"/"+pluginName+".jar");198 File pluginFile = new File(s, pluginName + ".jar"); 199 199 if (pluginFile.exists()) { 200 200 PluginInformation info = new PluginInformation(pluginFile);
Note:
See TracChangeset
for help on using the changeset viewer.