Changeset 16241 in josm


Ignore:
Timestamp:
2020-04-06T07:59:36+02:00 (4 years ago)
Author:
GerdP
Message:

fix #18462: JOSM doesn't use preferences.xml_backup
Show a popup saying that JOSM tries to read the preferences.xml_backup.
It copies the content of preferences.xml_backup to preferences.xml and tries to load again.
If that fails also, the preferences are reset (as without the patch).

It improves the cases that preferences.xml is corrupted and preferences.xml_backup is good.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/Preferences.java

    r15606 r16241  
    608608            }
    609609        }
     610        File possiblyGoodBackupFile = new File(prefDir, "preferences.xml_backup");
    610611        try {
    611612            load();
     
    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
     
    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();
Note: See TracChangeset for help on using the changeset viewer.