use of se.light.assembly64.Support.flush in project assembly64fx by freabemania.
the class InstallationService method unpackDynamic.
private void unpackDynamic(File content, LocationAndInstallationStatus location, Artifact entry, ArtifactDelta delta) throws Exception {
CancelableTask cancelTask = CancelableTask.of();
LocalStorageUtil.createDir(pathService.getTmpDynFolder());
unzipService.extractZip(content, pathService.getTmpDynFolder(), entry);
if (cancelTask.isCancelled()) {
return;
}
File[] files = LocalStorageUtil.getSubdirOrFile(pathService.getTmpDynFolder(), entry.getFolder()).listFiles();
File base = LocalStorageUtil.getSubdirOrFile(location.getLocation(), entry.getPrefix() + "/" + entry.getFolder());
Optional<File> releaseLogFile = Arrays.stream(files).filter(item -> item.getName().equals("releaselog.json")).findFirst();
List<ReleaseInfo> releaseInfoList = null;
List<ReleaseInfo> matchedReleaseInfoList = new ArrayList<>();
if (releaseLogFile.isPresent()) {
releaseInfoList = Support.readList(ReleaseInfo.class, releaseLogFile.get()).stream().collect(Collectors.toList());
for (ReleaseInfo item : releaseInfoList) {
String p = item.getPath();
int start = p.indexOf("/", p.indexOf("/") + 1);
item.setPath(entry.getPrefix() + "/" + entry.getFolder() + "/" + p.substring(start + 1));
item.setStrippedPath(entry.getFolder() + "/" + p.substring(start + 1));
}
}
for (File f : files) {
if (f.isDirectory()) {
String dirname = f.getName().toUpperCase();
char firstChar = dirname.charAt(0);
boolean isDigit = Character.isDigit(firstChar);
boolean isAlpha = Character.isAlphabetic(firstChar);
String target = findDestination(firstChar, dirname, base);
if (target != null) {
File t = null;
if (isDigit) {
t = new File(base.getAbsolutePath() + "/0-9/" + target + "/" + f.getName());
} else if (isAlpha) {
t = new File(base.getAbsolutePath() + "/" + String.valueOf(firstChar) + "/" + target + "/" + f.getName());
} else {
t = new File(base.getAbsolutePath() + "/___MISC___/" + target + "/" + f.getName());
}
FileUtils.forceMkdir(t);
FileUtils.copyDirectory(f, t);
if (releaseInfoList != null) {
ReleaseInfo matchedReleaseInfo = null;
for (ReleaseInfo item : releaseInfoList) {
File[] subdirs = f.listFiles(File::isDirectory);
for (File dir : subdirs) {
if (dir.getPath().contains(item.getStrippedPath())) {
matchedReleaseInfo = item;
break;
}
}
}
if (matchedReleaseInfo != null) {
matchedReleaseInfo.setPath(t.getAbsolutePath().substring(base.getAbsolutePath().length() + 1));
matchedReleaseInfoList.add(matchedReleaseInfo);
}
}
ProgressControlWrapper.getInstance().setProgressLabel("Moved " + f.getName() + " to " + t.getAbsolutePath());
if (cancelTask.isCancelled()) {
break;
}
} else {
LOGGER.info("Unable to install " + dirname);
}
}
}
ProgressControlWrapper.getInstance().increaseProgress();
if (releaseLogFile.isPresent()) {
File t = new File(base.getAbsolutePath() + "/releaselog.json");
LOGGER.info("Flushing rebuildt releaselog.json to " + t.getAbsolutePath());
Support.flush(matchedReleaseInfoList, t);
}
}
Aggregations