listener.sendMessage(DcResources.getText("msgClosingDb"));
DatabaseManager.closeDatabases(false);
boolean success = true;
while (list.hasMoreElements()) {
ZipEntry ze = list.nextElement();
String filename = ze.getName();
try {
if (isVersion(filename))
continue;
boolean isImage = isImage(filename);
boolean isReport = isReport(filename);
boolean isModule = isModule(filename);
boolean isResource = isResource(filename);
boolean isData = !isImage && !isReport && !isModule && !isResource;
boolean restore = true;
if (isImage && restoreDatabase) {
filename = DataCrow.imageDir + filename.substring(filename.lastIndexOf("/") + 1, filename.length());
} else if (isResource && restoreDatabase) {
filename = DataCrow.resourcesDir + filename.substring(filename.lastIndexOf("/") + 1, filename.length());
} else if (isReport && restoreReports) {
filename = filename.substring(filename.lastIndexOf("/reports") + 1, filename.length());
filename = DataCrow.installationDir + filename;
} else if (isModule && restoreModules) {
filename = filename.substring(filename.lastIndexOf("/modules") + 1, filename.length());
filename = DataCrow.installationDir + filename;
} else if (isData && restoreDatabase) {
filename = DataCrow.dataDir + filename.substring(filename.lastIndexOf("/") + 1, filename.length());
} else {
if (logger.isDebugEnabled())
logger.debug("Skipping " + filename);
restore = false;
}
if (restore) {
try {
new File(filename.substring(0, filename.lastIndexOf("/"))).mkdirs();
} catch (Exception e) {
logger.warn("Unable to create directories for " + filename, e);
}
InputStream istr = zf.getInputStream(ze);
BufferedInputStream bis = new BufferedInputStream(istr);
FileOutputStream fos = new FileOutputStream(filename);
int sz = (int)ze.getSize();
final int N = 1024;
byte buf[] = new byte[N];
int ln = 0;
while (sz > 0 && // workaround for bug
(ln = bis.read(buf, 0, Math.min(N, sz))) != -1) {