blob: ed9c92970f6f6dcb3829887908d417ac4d162320 [file] [log] [blame]
package org.eclipse.epp.installer.internal.win32.core.operations;
import java.text.MessageFormat;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.epp.installer.core.IErrorConstants;
import org.eclipse.epp.installer.core.Win32;
import org.eclipse.epp.installer.core.model.Context;
import org.eclipse.epp.installer.core.model.InstallOperation;
import com.ice.jni.registry.RegStringValue;
import com.ice.jni.registry.Registry;
import com.ice.jni.registry.RegistryException;
import com.ice.jni.registry.RegistryKey;
import com.ice.jni.registry.RegistryValue;
public class RegistryGetValueOperation extends InstallOperation {
/**
* Registry path in HKEY_LOCAL_MACHINE.
*/
private String path;
/**
* Registry key name.
*/
private String name;
/**
* Value to set.
*/
private String[] result;
/**
* Construct new instance of RegistrySetValueOperation, with path, key name and value.
*
* @param path registry path, in HKEY_LOCAL_MACHINE section of registry.
* @param name key name.
* @param value value to set.
*/
public RegistryGetValueOperation(String path, String name, String[] result) {
this.path = path;
this.name = name;
this.result = result;
}
/**
* Run specified operation.
*
* To successful perform of this operation, user must have rights to write
* into HKEY_LOCAL_MACHINE section of registry.
*
* @return execution status code. If operation coul'd not be performed then
* error status with ERROR_REGISTRY_ERROR code are returned. See
* {@link org.eclipse.epp.installer.core.IErrorConstants } for
* details.
*/
protected IStatus run(Context installer) {
RegistryKey key = Registry.openSubkey(Registry.HKEY_LOCAL_MACHINE,
path, RegistryKey.ACCESS_READ);
if (key == null)
return new Status(IStatus.ERROR, Win32.PLUGIN_ID,
IErrorConstants.ERROR_REGISTRY_ERROR,
"Can't open key for reading: " + path, null);
try {
RegistryValue v = key.getValue(name);
if(v instanceof RegStringValue) {
result[0] = ((RegStringValue) v).getData();
}
else {
return new Status(IStatus.ERROR, Win32.PLUGIN_ID,
IErrorConstants.ERROR_REGISTRY_ERROR,
"Unable to read not string registry value: " + path + "." + name, null);
}
return Status.OK_STATUS;
} catch(RegistryException e) {
return new Status(IStatus.ERROR, Win32.PLUGIN_ID,
IErrorConstants.ERROR_REGISTRY_ERROR, "Registry error",
e);
} finally {
try {
key.closeKey();
} catch(RegistryException e) {
return new Status(IStatus.ERROR, Win32.PLUGIN_ID,
IErrorConstants.ERROR_REGISTRY_ERROR, "Registry error",
e);
}
}
}
/**
* Return operation name.
*/
public String toString() {
return MessageFormat.format("Reading registry value {0}.", new Object[] {name});
}
}