use of se.light.assembly64.util.LocalStorageUtil.getSubdirOrFile in project assembly64fx by freabemania.
the class InstallationService method findDestination.
private static String findDestination(char prefix, String dirname, File root) {
String sourceDir = formatDir(dirname);
String[] subdirs;
if (Character.isDigit(prefix)) {
subdirs = getImmedateSubdirs(LocalStorageUtil.getSubdirOrFile(root, NBR_FOLDER));
} else {
subdirs = getImmedateSubdirs(LocalStorageUtil.getSubdirOrFile(root, String.valueOf(prefix)));
}
if (subdirs == null) {
return null;
}
for (int i = 0; i < subdirs.length - 1; i++) {
String from = getFirstPartOfDir(subdirs[i]);
String to = getFirstPartOfDir(subdirs[i + 1]);
for (int c = 1; c < CHUNCK_LENGTH; c++) {
int startOrd = from.charAt(c);
int endOrd = to.charAt(c);
int curr = sourceDir.charAt(c);
String res = checkMatch(curr, startOrd, endOrd, sourceDir, from, to, i, c, subdirs);
if (res.equals(CONT)) {
continue;
} else if (res == BRK) {
break;
} else {
return res;
}
}
}
if (subdirs.length == 0) {
return "AAAA - ZZZZ";
} else {
return subdirs[subdirs.length - 1];
}
}
use of se.light.assembly64.util.LocalStorageUtil.getSubdirOrFile 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);
}
}
use of se.light.assembly64.util.LocalStorageUtil.getSubdirOrFile in project assembly64fx by freabemania.
the class InstallationService method housekeep.
public void housekeep(File base) {
GenericMessageDialogController.withInfoProps("Scan was started", "Scanning " + base.getAbsolutePath()).show();
ReturningTask<Void> task = () -> {
final AtomicInteger emptyDirs = new AtomicInteger();
final AtomicInteger emptyFiles = new AtomicInteger();
for (Artifact entry : artifactsService.getArtifactsDb()) {
if (artifactsService.isInstalled(base, entry)) {
boolean emptyDirFound = true;
while (emptyDirFound) {
emptyDirFound = false;
for (File f : FileUtils.listFilesAndDirs(LocalStorageUtil.getSubdirOrFile(base, entry), TrueFileFilter.TRUE, TrueFileFilter.TRUE)) {
if (!f.isDirectory()) {
if (f.length() == 0) {
emptyFiles.incrementAndGet();
FileUtils.deleteQuietly(f);
emptyDirFound = true;
}
} else {
if (f.list().length == 0 || f.getName().toUpperCase().equals("__MACOSX")) {
emptyDirs.incrementAndGet();
FileUtils.deleteQuietly(f);
emptyDirFound = true;
}
}
}
}
}
}
GenericMessageDialogController.withInfoProps("Housekeeping finished", "Removed " + emptyFiles.get() + " empty files and " + emptyDirs.get() + " dirs", true).showAndWait();
return null;
};
ExecutorUtil.executeAsyncWithRetry(task, 3);
}
use of se.light.assembly64.util.LocalStorageUtil.getSubdirOrFile in project assembly64fx by freabemania.
the class InstallationService method installDelta.
private void installDelta(LocationAndInstallationStatus location, Artifact entry) throws Exception {
LOGGER.info("Updating " + entry.getName());
if (entry.isCreateDelta()) {
Integer latestUpdated = getVersionAsInteger(artifactsService.getLatestVersion(artifactsService.resolveDB(location, entry)));
List<ArtifactDelta> entries = entry.getDeltas().stream().filter(item -> {
return getVersionAsInteger(item.getVersion()) > latestUpdated;
}).collect(Collectors.toList());
CancelableTask cancelTask = CancelableTask.of();
for (ArtifactDelta e : entries) {
if (cancelTask.isRunning()) {
if (entry.isDynamicImport()) {
File file = installEntry(location, entry, entry.getBaseDir() + "/delta", e.getFile(), e.getVersion(), true, true);
unpackDynamic(file, location, entry, e);
if (!cancelTask.isCancelled()) {
updateDb(location, entry, e.getVersion());
} else {
break;
}
} else {
installEntry(location, entry, entry.getBaseDir() + "/delta", e.getFile(), e.getVersion());
}
} else {
ProgressControlWrapper.getInstance().setProgressLabel("Cancelling");
return;
}
}
} else {
ProgressControlWrapper.getInstance().setProgressLabel("Will delete current folder " + entry.getName() + ", please wait...");
FileUtils.deleteQuietly(LocalStorageUtil.getSubdirOrFile(location.getLocation(), entry.getAbsoluteInstallationPath()));
ProgressControlWrapper.getInstance().setProgressLabel("Installing new version");
installEntry(location, entry, entry.getBaseDir(), entry.getFile(), entry.getVersion());
}
}
use of se.light.assembly64.util.LocalStorageUtil.getSubdirOrFile in project assembly64fx by freabemania.
the class InstallationService method install.
public void install(LocationAndInstallationStatus location, Artifact entry, boolean updateProgressWindow) throws Exception {
CancelableTask cancelTask = CancelableTask.of();
if (isRemoteArtifact(entry)) {
if (!artifactsService.isInstalled(location, entry)) {
Analytics.sendEvent("install_item", "artifact_" + entry.getName());
installFull(location, entry);
} else if (artifactsService.needsUpdate(location, entry)) {
Analytics.sendEvent("update_item", "artifact_" + entry.getName());
installDelta(location, entry);
}
} else {
ProgressControlWrapper.getInstance().setProgressLabel("Installing local folder!!!");
artifactsService.updateChecksumInPrivateFolder();
FileUtils.copyDirectory(new File(localDbService.getPrivateDir()), LocalStorageUtil.getSubdirOrFile(LocalStorageUtil.getSubdirOrFile(location.getLocation(), "Misc"), localDbService.getPrivateDirName()));
artifactsService.updateChecksumInInstallation(location);
}
if (updateProgressWindow) {
updateProgressDialog(cancelTask);
}
}
Aggregations