Ignore:
Timestamp:
2009-11-28T17:05:44+01:00 (16 years ago)
Author:
pieren
Message:

Fix minor issues if Grab is called without layer (possible since projection rework)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CacheControl.java

    r18720 r18838  
    106106                // till here
    107107
    108                 if (reply == JOptionPane.OK_OPTION) {
    109                     return loadCache(file, wmsLayer.getLambertZone());
    110                 } else
    111                     file.delete();
     108                if (reply == JOptionPane.OK_OPTION && loadCache(file, wmsLayer.getLambertZone())) {
     109                    return true;
     110                } else {
     111                    delete(file);
     112                }
    112113            }
    113114        } catch (Exception e) {
     
    122123            if (Main.proj instanceof LambertCC9Zones)
    123124                extension = cLambertCC9Z + extension;
    124             File file = new File(CadastrePlugin.cacheDir + wmsLayer.getName() + "." + extension);
    125             if (file.exists())
    126                 file.delete();
     125            delete(new File(CadastrePlugin.cacheDir + wmsLayer.getName() + "." + extension));
    127126        } catch (Exception e) {
    128127            e.printStackTrace(System.out);
    129128        }
    130129    }
     130   
     131    private void delete(File file) {
     132        System.out.println("Delete file "+file);
     133        if (file.exists())
     134            file.delete();
     135        while (file.exists()) // wait until file is really gone (otherwise appends to existing one)
     136            CadastrePlugin.safeSleep(500);
     137    }
    131138
    132139    public boolean loadCache(File file, int currentLambertZone) {
     140        boolean successfulRead = false;
    133141        try {
    134142            FileInputStream fis = new FileInputStream(file);
    135143            ObjectInputStream ois = new ObjectInputStream(fis);
    136             if (wmsLayer.read(ois, currentLambertZone) == false)
    137                 return false;
     144            successfulRead = wmsLayer.read(ois, currentLambertZone);
    138145            ois.close();
    139146            fis.close();
    140147        } catch (Exception ex) {
    141148            ex.printStackTrace(System.out);
    142             JOptionPane.showMessageDialog(Main.parent, tr("Error loading file"), tr("Error"), JOptionPane.ERROR_MESSAGE);
     149            JOptionPane.showMessageDialog(Main.parent, tr("Error loading file.\nProbably an old version of the cache file."), tr("Error"), JOptionPane.ERROR_MESSAGE);
    143150            return false;
    144151        }
    145         if (wmsLayer.isRaster()) {
     152        if (successfulRead && wmsLayer.isRaster()) {
    146153            // serialized raster bufferedImage hangs-up on Java6. Recreate them here
    147154            wmsLayer.images.get(0).image = RasterImageModifier.fixRasterImage(wmsLayer.images.get(0).image);
    148155        }
    149         return true;
     156        return successfulRead;
    150157    }
    151158
Note: See TracChangeset for help on using the changeset viewer.