Search in sources :

Example 1 with ReleaseInfo

use of se.light.assembly64.model.ReleaseInfo 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);
    }
}
Also used : ArtifactDelta(se.light.assembly64.model.ArtifactDelta) ReturningTask(se.light.assembly64.model.ReturningTask) Arrays(java.util.Arrays) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Support.isRemoteArtifact(se.light.assembly64.Support.isRemoteArtifact) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LatestInstalledItemInfo(se.light.assembly64.model.LatestInstalledItemInfo) Support.getVersionAsInteger(se.light.assembly64.Support.getVersionAsInteger) ArtifactType(se.light.assembly64.model.ArtifactType) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ProgressDBController(se.light.assembly64.fx.ProgressDBController) GuiUtils(se.light.assembly64.util.GuiUtils) Map(java.util.Map) Support(se.light.assembly64.Support) Support.flush(se.light.assembly64.Support.flush) CancelableTask(se.light.assembly64.model.CancelableTask) TrueFileFilter(org.apache.commons.io.filefilter.TrueFileFilter) Support.getObjectMapper(se.light.assembly64.Support.getObjectMapper) ContentEntry(se.light.assembly64.model.ContentEntry) GenericMessageDialogController(se.light.assembly64.fx.GenericMessageDialogController) Analytics(se.light.assembly64.Analytics) Logger(org.slf4j.Logger) ExecutorUtil(se.light.assembly64.util.ExecutorUtil) Set(java.util.Set) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Artifact(se.light.assembly64.model.Artifact) Collectors(java.util.stream.Collectors) LocalStorageUtil(se.light.assembly64.util.LocalStorageUtil) File(java.io.File) ReleaseInfo(se.light.assembly64.model.ReleaseInfo) Platform(javafx.application.Platform) ProgressControlWrapper(se.light.assembly64.fx.ProgressControlWrapper) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) SearchResultItem(se.light.assembly64.model.SearchResultItem) NullWindowOwner(se.light.assembly64.fx.NullWindowOwner) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) Optional(java.util.Optional) DOWNLOAD_STATUS(se.light.assembly64.service.FTPService.DOWNLOAD_STATUS) ProgressMessageBox(se.light.assembly64.ProgressMessageBox) FILE_ACTION(se.light.assembly64.Support.FILE_ACTION) Support.getTodayDateAsBasicIsoString(se.light.assembly64.Support.getTodayDateAsBasicIsoString) LocationAndInstallationStatus(se.light.assembly64.model.LocationAndInstallationStatus) ArrayList(java.util.ArrayList) ReleaseInfo(se.light.assembly64.model.ReleaseInfo) Support.getTodayDateAsBasicIsoString(se.light.assembly64.Support.getTodayDateAsBasicIsoString) File(java.io.File) CancelableTask(se.light.assembly64.model.CancelableTask)

Example 2 with ReleaseInfo

use of se.light.assembly64.model.ReleaseInfo in project assembly64fx by freabemania.

the class ShowInstalledContentController method init.

public void init(String base) {
    File releaseLog = new File(base + "/releaselog.json");
    releaseList.setPlaceholder(new Label("No content"));
    name.setCellValueFactory(new PropertyValueFactory<ReleaseInfo, String>("name"));
    group.setCellValueFactory(new PropertyValueFactory<ReleaseInfo, String>("group"));
    year.setCellValueFactory(new PropertyValueFactory<ReleaseInfo, String>("year"));
    newReleases = Support.readList(ReleaseInfo.class, releaseLog);
    releaseList.setItems(items);
    releaseList.getSelectionModel().select(0);
    releaseList.getFocusModel().focus(0);
    releaseList.setOnMousePressed(event -> {
        ReleaseInfo selectedItem = releaseList.getSelectionModel().getSelectedItem();
        String path = base + "/" + selectedItem.getPath();
        if (event.getButton() == MouseButton.SECONDARY || event.isControlDown()) {
            final ContextMenu contextMenu = new ContextMenu();
            MenuItem infoItem = new MenuItem("Open folder");
            infoItem.setOnAction((ActionEvent event2) -> {
                PlatformInfoService.getInstance().openFolder(path);
            });
            contextMenu.getItems().add(infoItem);
            releaseList.setContextMenu(contextMenu);
        } else if (event.getClickCount() == 2) {
            File target = new File(path);
            SearchResultItem searchResult = ReleaseInfo.toSearchResult(selectedItem);
            if (target.exists()) {
                List<ContentEntry> cEntries = FileUtils.listFiles(new File(base + "/" + selectedItem.getPath()), null, true).stream().map(item -> new ContentEntry(item.getPath(), item.getName())).collect(Collectors.toList());
                ContentEntryInfo searchItems = new ContentEntryInfo(cEntries, false);
                GuiUtils.showDialogBare("searchViewFiles.fxml", "Files and info for '" + selectedItem.getName() + "'", searchResult, searchItems, false);
            } else {
                GenericMessageDialogController.withErrorProps("Oopss...", "Was not able to find the directory").showAndWait();
            }
        }
    });
    populateList();
}
Also used : ActionEvent(javafx.event.ActionEvent) ContentEntry(se.light.assembly64.model.ContentEntry) Label(javafx.scene.control.Label) SearchResultItem(se.light.assembly64.model.SearchResultItem) ReleaseInfo(se.light.assembly64.model.ReleaseInfo) ContextMenu(javafx.scene.control.ContextMenu) MenuItem(javafx.scene.control.MenuItem) List(java.util.List) ObservableList(javafx.collections.ObservableList) File(java.io.File) ContentEntryInfo(se.light.assembly64.model.ContentEntryInfo)

Aggregations

File (java.io.File)2 List (java.util.List)2 ContentEntry (se.light.assembly64.model.ContentEntry)2 IOException (java.io.IOException)1 LocalDate (java.time.LocalDate)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 ChronoUnit (java.time.temporal.ChronoUnit)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Collectors (java.util.stream.Collectors)1 Platform (javafx.application.Platform)1 ObservableList (javafx.collections.ObservableList)1 ActionEvent (javafx.event.ActionEvent)1 ContextMenu (javafx.scene.control.ContextMenu)1