Ignore:
Timestamp:
2008-08-26T22:35:52+02:00 (16 years ago)
Author:
stoecker
Message:

cleanups in plugin handling

Location:
trunk/src/org/openstreetmap/josm/plugins
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/plugins/Plugin.java

    r627 r873  
    5353         */
    5454        public final String getPluginDir() {
    55                 return Main.pref.getPreferencesDir()+"plugins/"+info.name+"/";
     55                return new File(Main.pref.getPluginsDirFile(), info.name).getPath();
    5656        }
    5757
  • trunk/src/org/openstreetmap/josm/plugins/PluginDownloader.java

    r627 r873  
    1313import java.io.FileOutputStream;
    1414import java.io.FileWriter;
     15import java.io.FilenameFilter;
    1516import java.io.IOException;
    1617import java.io.InputStream;
     
    5455
    5556                @Override protected void realRun() throws SAXException, IOException {
     57                        File pluginDir = Main.pref.getPluginsDirFile();
     58                        if (!pluginDir.exists())
     59                                pluginDir.mkdirs();
    5660                        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))
    6063                                        count++;
    61                                 } else
     64                                else
    6265                                        errors += d.name + "\n";
    6366                        }
     67                        PluginDownloader.moveUpdatedPlugins();
    6468                }
    6569        }
     
    7983                                r.close();
    8084                                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"));
    8288                                out.append(txt);
    8389                                out.close();
     
    123129
    124130        public static boolean downloadPlugin(PluginDescription pd) {
    125                 File file = new File(Main.pref.getPreferencesDir()+"plugins/"+pd.name+".jar");
     131                File file = new File(Main.pref.getPluginsDirFile(), pd.name + ".jar");
    126132                if (!download(pd.resource, file)) {
    127133                        JOptionPane.showMessageDialog(Main.parent, tr("Could not download plugin: {0} from {1}", pd.name, pd.resource));
     
    163169                Main.worker.execute(new UpdateTask(update));
    164170        }
     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        }
    165188}
  • trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java

    r627 r873  
    196196
    197197        for (String s : locations) {
    198                 File pluginFile = new File(s+"/"+pluginName+".jar");
     198                File pluginFile = new File(s, pluginName + ".jar");
    199199                if (pluginFile.exists()) {
    200200                                PluginInformation info = new PluginInformation(pluginFile);
Note: See TracChangeset for help on using the changeset viewer.