SDK Manager: Display error when saving settings

SDK BUG 2226029

Change-Id: I568c71b80bddb5c4409df0bd1b02e35b82d6d1ba
This commit is contained in:
Raphael
2009-10-29 21:20:41 -07:00
parent be4cbcc226
commit d3f9eb79c7
2 changed files with 49 additions and 11 deletions

View File

@@ -18,9 +18,15 @@ package com.android.sdkuilib.internal.repository;
import com.android.prefs.AndroidLocation; import com.android.prefs.AndroidLocation;
import com.android.prefs.AndroidLocation.AndroidLocationException; import com.android.prefs.AndroidLocation.AndroidLocationException;
import com.android.sdklib.ISdkLog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Properties; import java.util.Properties;
@@ -40,7 +46,10 @@ public class SettingsController {
private ISettingsPage mSettingsPage; private ISettingsPage mSettingsPage;
public SettingsController() { private final UpdaterData mUpdaterData;
public SettingsController(UpdaterData updaterData) {
mUpdaterData = updaterData;
} }
//--- Access to settings ------------ //--- Access to settings ------------
@@ -144,9 +153,11 @@ public class SettingsController {
*/ */
public void loadSettings() { public void loadSettings() {
FileInputStream fis = null; FileInputStream fis = null;
String path = null;
try { try {
String folder = AndroidLocation.getFolder(); String folder = AndroidLocation.getFolder();
File f = new File(folder, SETTINGS_FILENAME); File f = new File(folder, SETTINGS_FILENAME);
path = f.getPath();
if (f.exists()) { if (f.exists()) {
fis = new FileInputStream(f); fis = new FileInputStream(f);
@@ -157,10 +168,11 @@ public class SettingsController {
setSetting(ISettingsPage.KEY_ASK_ADB_RESTART, getAskBeforeAdbRestart()); setSetting(ISettingsPage.KEY_ASK_ADB_RESTART, getAskBeforeAdbRestart());
} }
} catch (AndroidLocationException e) { } catch (Exception e) {
e.printStackTrace(); ISdkLog log = mUpdaterData.getSdkLog();
} catch (IOException e) { if (log != null) {
e.printStackTrace(); log.error(e, "Failed to load settings from '%1$s'", path);
}
} finally { } finally {
if (fis != null) { if (fis != null) {
try { try {
@@ -177,18 +189,42 @@ public class SettingsController {
public void saveSettings() { public void saveSettings() {
FileOutputStream fos = null; FileOutputStream fos = null;
String path = null;
try { try {
String folder = AndroidLocation.getFolder(); String folder = AndroidLocation.getFolder();
File f = new File(folder, SETTINGS_FILENAME); File f = new File(folder, SETTINGS_FILENAME);
path = f.getPath();
fos = new FileOutputStream(f); fos = new FileOutputStream(f);
mProperties.store( fos, "## Settings for Android Tool"); //$NON-NLS-1$ mProperties.store( fos, "## Settings for Android Tool"); //$NON-NLS-1$
} catch (AndroidLocationException e) { } catch (Exception e) {
e.printStackTrace(); ISdkLog log = mUpdaterData.getSdkLog();
} catch (IOException e) {
e.printStackTrace(); if (log != null) {
log.error(e, "Failed to save settings at '%1$s'", path);
}
// This is important enough that we want to really nag the user about it
String reason = null;
if (e instanceof FileNotFoundException) {
reason = "File not found";
} else if (e instanceof AndroidLocationException) {
reason = ".android folder not found, please define ANDROID_SDK_HOME";
} else if (e.getMessage() != null) {
reason = String.format("%1$s: %2$s", e.getClass().getSimpleName(), e.getMessage());
} else {
reason = e.getClass().getName();
}
MessageDialog.openInformation(mUpdaterData.getWindowShell(),
"SDK Manager Settings",
String.format(
"The Android SDK and AVD Manager failed to save its settings (%1$s) at %2$s",
reason, path));
} finally { } finally {
if (fos != null) { if (fos != null) {
try { try {
@@ -202,7 +238,7 @@ public class SettingsController {
/** /**
* When settings have changed: retrieve the new settings, apply them and save them. * When settings have changed: retrieve the new settings, apply them and save them.
* *
* This updats Java system properties for the HTTP proxy. * This updates Java system properties for the HTTP proxy.
*/ */
private void onSettingsChanged() { private void onSettingsChanged() {
if (mSettingsPage == null) { if (mSettingsPage == null) {

View File

@@ -64,7 +64,7 @@ class UpdaterData {
private ImageFactory mImageFactory; private ImageFactory mImageFactory;
private final SettingsController mSettingsController = new SettingsController(); private final SettingsController mSettingsController;
private final ArrayList<ISdkListener> mListeners = new ArrayList<ISdkListener>(); private final ArrayList<ISdkListener> mListeners = new ArrayList<ISdkListener>();
@@ -74,6 +74,8 @@ class UpdaterData {
mOsSdkRoot = osSdkRoot; mOsSdkRoot = osSdkRoot;
mSdkLog = sdkLog; mSdkLog = sdkLog;
mSettingsController = new SettingsController(this);
initSdk(); initSdk();
} }