use of com.biglybt.core.custom.CustomizationException in project BiglyBT by BiglySoftware.
the class CustomizationManagerImpl method exportCustomization.
protected void exportCustomization(CustomizationImpl cust, File to_file) throws CustomizationException {
if (to_file.isDirectory()) {
to_file = new File(to_file, VuzeFileHandler.getVuzeFileName(cust.getName() + "_" + cust.getVersion()));
}
if (!VuzeFileHandler.isAcceptedVuzeFileName(to_file.getName())) {
to_file = new File(to_file.getParentFile(), VuzeFileHandler.getVuzeFileName(to_file.getName()));
}
try {
Map contents = new HashMap();
byte[] data = FileUtil.readFileAsByteArray(cust.getContents());
contents.put("name", cust.getName());
contents.put("version", cust.getVersion());
contents.put("data", data);
VuzeFile vf = VuzeFileHandler.getSingleton().create();
vf.addComponent(VuzeFileComponent.COMP_TYPE_CUSTOMIZATION, contents);
vf.write(to_file);
} catch (Throwable e) {
throw (new CustomizationException("Failed to export customization", e));
}
}
use of com.biglybt.core.custom.CustomizationException in project BiglyBT by BiglySoftware.
the class CustomizationManagerImpl method importCustomization.
protected void importCustomization(Map map) throws CustomizationException {
try {
String name = new String((byte[]) map.get("name"), "UTF-8");
String version = new String((byte[]) map.get("version"), "UTF-8");
if (!Constants.isValidVersionFormat(version)) {
throw (new CustomizationException("Invalid version specification: " + version));
}
byte[] data = (byte[]) map.get("data");
File user_dir = FileUtil.getUserFile("custom");
if (!user_dir.exists()) {
user_dir.mkdirs();
}
File target = new File(user_dir, name + "_" + version + ".zip");
if (!target.exists()) {
if (!FileUtil.writeBytesAsFile2(target.getAbsolutePath(), data)) {
throw (new CustomizationException("Failed to save customization to " + target));
}
}
} catch (CustomizationException e) {
throw (e);
} catch (Throwable e) {
throw (new CustomizationException("Failed to import customization", e));
}
}
Aggregations