Skip to content

Commit

Permalink
Save settings to the correct location
Browse files Browse the repository at this point in the history
  • Loading branch information
Redande committed Mar 24, 2017
1 parent b18a40f commit f594b3a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
33 changes: 33 additions & 0 deletions tmc-plugin/src/fi/helsinki/cs/tmc/actions/MigrateSettings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package fi.helsinki.cs.tmc.actions;

import fi.helsinki.cs.tmc.core.configuration.TmcSettings;
import fi.helsinki.cs.tmc.coreimpl.TmcCoreSettingsImpl;
import fi.helsinki.cs.tmc.model.PersistableSettings;

import java.util.logging.Logger;
import java.util.prefs.BackingStoreException;

public class MigrateSettings {

private static Logger logger = Logger.getLogger(MigrateSettings.class.getName());

public static void run() {
PersistableSettings rightSettings = PersistableSettings.forModule(TmcCoreSettingsImpl.class);
PersistableSettings wrongSettings = PersistableSettings.forModule(TmcSettings.class);
try {
final String[] keys = wrongSettings.getPreferences().keys();
for (String key : keys) {
String wrongValue = wrongSettings.get(key, null);
if (wrongValue == null) {
continue;
}
rightSettings.put(key, wrongValue);
wrongSettings.remove(key);
}
wrongSettings.saveAll();
rightSettings.saveAll();
} catch (BackingStoreException ex) {
logger.fine("Could not migrate wrong settings.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public void restored() {
WindowManager.getDefault().invokeWhenUIReady(new Runnable() {
@Override
public void run() {
MigrateSettings.run();

CheckForOutdatedNetbeans.run();

TmcCore.setInstance(new TmcCore());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class TmcCoreSettingsImpl implements TmcSettings {
private static final String PREF_RESOLVE_DEPENDENCIES = "resolveDependencies";
private static final String PREF_SEND_DIAGNOSTICS = "sendDiagnostics";

private static PersistableSettings settings = PersistableSettings.forModule(TmcSettings.class);
private static PersistableSettings settings = PersistableSettings.forModule(TmcCoreSettingsImpl.class);

private Tailoring tailoring = SelectedTailoring.get();
private TmcEventBus eventBus = TmcEventBus.getDefault();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ public void cancel() {
transients.clear();
}

public Preferences getPreferences() {
return prefs;
}

private void flushPrefsOrThrow() {
try {
prefs.flush();
Expand Down

0 comments on commit f594b3a

Please sign in to comment.