Ticket #18462: 18462.patch

File 18462.patch, 2.4 KB (added by GerdP, 6 years ago)
  • src/org/openstreetmap/josm/data/Preferences.java

     
    607607                }
    608608            }
    609609        }
     610        File possiblyGoodBackupFile = new File(prefDir, "preferences.xml_backup");
    610611        try {
    611612            load();
    612613            initSuccessful = true;
     
    617618                JOptionPane.showMessageDialog(
    618619                        MainApplication.getMainFrame(),
    619620                        tr("<html>Preferences file had errors.<br> Making backup of old one to <br>{0}<br> " +
    620                                 "and creating a new default preference file.</html>",
    621                                 backupFile.getAbsoluteFile()),
     621                                "and trying to read last good preference file <br>{1}<br>.</html>",
     622                                backupFile.getAbsoluteFile(), possiblyGoodBackupFile.getAbsoluteFile()),
    622623                        tr("Error"),
    623624                        JOptionPane.ERROR_MESSAGE
    624625                );
    625626            }
    626627            PlatformManager.getPlatform().rename(preferenceFile, backupFile);
     628        }
     629        if (!initSuccessful) {
    627630            try {
     631                if (possiblyGoodBackupFile.exists() && possiblyGoodBackupFile.length() > 0) {
     632                    Utils.copyFile(possiblyGoodBackupFile, preferenceFile);
     633                }
     634
     635                load();
     636                initSuccessful = true;
     637            } catch (IOException | SAXException | XMLStreamException e) {
     638                Logging.error(e);
     639                Logging.warn(tr("Failed to initialize preferences. Failed to reset preference file to default: {0}", getPreferenceFile()));
     640            }
     641        }
     642        if (!initSuccessful) {
     643            try {
     644                if (!GraphicsEnvironment.isHeadless()) {
     645                    JOptionPane.showMessageDialog(
     646                            MainApplication.getMainFrame(),
     647                            tr("<html>Preferences file had errors.<br> Creating a new default preference file.</html>"),
     648                             tr("Error"),
     649                            JOptionPane.ERROR_MESSAGE
     650                    );
     651                }
    628652                resetToDefault();
    629653                save();
    630654            } catch (IOException e1) {