Search in sources :

Example 1 with Type

use of se.light.assembly64.Support.Type in project assembly64fx by freabemania.

the class SearchService method search2.

public List<SearchResultItem> search2(String name, String group, String year, String handle, String event, String rating, String category, String searchFromStart, String d64, String t64, String d71, String d81, String prg, String tap, String crt, String sid, String bin, String g64, String orSearch, int days) throws SearchException {
    Response response = null;
    try {
        boolean anyCat = d64.equals("Y") || t64.equals("Y") || d71.equals("Y") || d81.equals("Y") || prg.equals("Y") || tap.equals("Y") || crt.equals("Y") || sid.equals("Y") || bin.equals("Y") || g64.equals("Y");
        boolean anyField = !name.equals("***") || !group.equals("***") || !handle.equals("***") || !event.equals("***");
        if (!(days > -1 || anyField) && anyCat) {
            GenericMessageDialogController.withErrorProps("Oops", "Please enter valid searchcriterias").showAndWait();
            return Collections.<SearchResultItem>emptyList();
        }
        response = getClient().target(getBackendServer()).path("/leet/search/get/" + urlEncode(name) + "/" + urlEncode(group) + "/" + urlEncode(year) + "/" + urlEncode(handle) + "/" + urlEncode(event) + "/" + urlEncode(rating) + "/" + urlEncode(category) + "/" + searchFromStart + "/" + d64 + "/" + t64 + "/" + d71 + "/" + d81 + "/" + prg + "/" + tap + "/" + crt + "/" + sid + "/" + bin + "/" + g64 + "/" + orSearch + "/" + Integer.toString(days)).request().header("Content-Type", "application/json").header("email", getSessionInfo().getEmail()).header("token", getSessionInfo().getToken()).get();
        if (response.getStatus() == 200) {
            return response.readEntity(new GenericType<List<SearchResultItem>>() {
            });
        } else if (response.getStatus() == 425) {
            throw SearchException.ofRefineSearch();
        } else if (response.getStatus() == 424) {
            throw SearchException.ofSearchesExceeded();
        } else {
            throw new RuntimeException("Unknown");
        }
    } finally {
        if (response != null) {
            response.close();
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) SearchResultItem(se.light.assembly64.model.SearchResultItem) List(java.util.List)

Example 2 with Type

use of se.light.assembly64.Support.Type in project assembly64fx by freabemania.

the class Main method setupTree.

public static void setupTree() {
    GuiLocation rootsLocations = GuiLocation.builder().id(-1).type(TYPE.ROOT).name("Installations").build();
    ImageView iconR = new ImageView();
    iconR.setFitWidth(40);
    iconR.setFitHeight(20);
    iconR.setImage(ImageResolveService.getInstance().getImage("image-root-base.png"));
    rootItemBase = new TreeItem<GuiLocation>(rootsLocations, iconR);
    rootItemBase.setExpanded(true);
    tree = new TreeView<GuiLocation>(rootItemBase);
    tree.setMinWidth(topContainer.getWidth());
    tree.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
    tree.setOnScrollStarted((event) -> {
        tree.getSelectionModel().clearSelection();
    });
    tree.addEventHandler(MouseEvent.MOUSE_PRESSED, event -> handleMouseClicked(event));
    Image searchImage = new Image(Main.class.getResourceAsStream("button-magnifiersmall.png"), 30, 30, false, false);
    searchView = new ImageView();
    searchView.setImage(searchImage);
    sidifyView = new ImageView();
    sidifyView.setImage(new Image(Main.class.getResourceAsStream("button-sidify.png"), 30, 30, false, false));
    downloadLatestDbView = new ImageView();
    downloadLatestDbView.setImage(new Image(Main.class.getResourceAsStream("button-latestdb.png"), 30, 30, false, false));
    searchView.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> {
        executeIfPremium((Runnable) -> {
            Analytics.sendEvent("application_click", "open_search");
            GuiUtils.showDialog("searchMain.fxml", "Assembly64 search", Artifact.nullArtifact());
        }, "open_search");
    });
    setMagnifierAndSidify();
    treeAndComponents.getChildren().addAll(tree, searchView, sidifyView, downloadLatestDbView);
    topContainer.getChildren().add(treeAndComponents);
}
Also used : GuiLocation(se.light.assembly64.model.GuiLocation) ImageView(javafx.scene.image.ImageView) Image(javafx.scene.image.Image)

Example 3 with Type

use of se.light.assembly64.Support.Type in project assembly64fx by freabemania.

the class Main method refreshTree.

public static void refreshTree() {
    Platform.runLater(new Runnable() {

        @Override
        public void run() {
            try {
                ProgressbarEnhanced progressBar = (ProgressbarEnhanced) GlobalRepoService.getInstance().get("pbar");
                if (progressBar != null) {
                    topContainer.getChildren().remove(progressBar);
                }
                rootItemBase.getChildren().clear();
                for (WorkLocation location : userService.getLocations()) {
                    List<Artifact> artifactsDb = artifactsService.getArtifactsDb();
                    Set<LatestInstalledItemInfo> lastestAdditions = null;
                    if (location.exists()) {
                        lastestAdditions = InstallationService.getInstance().resolveLatestInstalledByLocation(location.toLocationAndInstallation());
                    } else {
                        lastestAdditions = lastestAdditionsNotFound;
                    }
                    ImageView icon = new ImageView();
                    icon.setFitWidth(20);
                    icon.setFitHeight(20);
                    if (location.exists()) {
                        if (userService.isInstallationPrimary(location.getId())) {
                            icon.setImage(ImageResolveService.getInstance().getImage("image-root-primary.png"));
                        } else {
                            icon.setImage(ImageResolveService.getInstance().getImage("image-root.png"));
                        }
                        TreeItem<GuiLocation> rootItem = new TreeItem<GuiLocation>(GuiLocation.builder().id(location.getId()).type(TYPE.INSTALLATION_ROOT).name(Support.removeEndingSlash(location.getPath())).build(), icon);
                        rootItem.setExpanded(localDbService.getBooleanLocalDBSetting(resolveInstallationExpandedKey(location.getId()), false));
                        rootItemBase.getChildren().add(rootItem);
                        TreeItem<GuiLocation> leaf = rootItem;
                        for (Artifact entry : artifactsDb) {
                            String node = entry.getPrefix();
                            if (node != null) {
                                String[] path = node.split("/");
                                String leafKey = "";
                                for (String pathItem : path) {
                                    leafKey += pathItem + "/";
                                    ImageView testIcon = new ImageView();
                                    testIcon.setFitWidth(20);
                                    testIcon.setFitHeight(20);
                                    if (checkIfFolderNeedsUpdate(leafKey, location) && userService.isPremium()) {
                                        testIcon.setImage(ImageResolveService.getInstance().getImage("image-folder-updateneeded.png"));
                                    } else {
                                        testIcon.setImage(ImageResolveService.getInstance().getImage("image-folder.png"));
                                    }
                                    Optional<TreeItem<GuiLocation>> categoryItem = leaf.getChildren().stream().filter(item -> item.getValue().getName() != null && item.getValue().getName().equals(pathItem)).findFirst();
                                    if (!categoryItem.isPresent()) {
                                        TreeItem<GuiLocation> depNode = new TreeItem<GuiLocation>(GuiLocation.builder().id(location.getId()).type(TYPE.LEAF).name(pathItem).leafKey(leafKey).build(), testIcon);
                                        leaf.getChildren().add(depNode);
                                        leaf = depNode;
                                    } else {
                                        leaf = categoryItem.get();
                                    }
                                    leaf.setExpanded(localDbService.getBooleanLocalDBSetting(resolveLeafInInstallationExpandedKey(leaf.getValue()), false));
                                }
                                // we're at thre position in the list now with the correct leaf
                                if (!localDbService.hasLocalDBSetting("exclude_" + location.getId() + "_" + entry.getName())) {
                                    ImageView itemIcon = new ImageView();
                                    itemIcon.setFitWidth(16);
                                    itemIcon.setFitHeight(16);
                                    if (entry.getCurrentInstallingId() != null && entry.getCurrentInstallingId().equals(location.getId())) {
                                        if (entry.isMarkedForUpdate() && !entry.isUpdating()) {
                                            itemIcon.setImage(ImageResolveService.getInstance().getImage("image-waiting.png"));
                                        } else if (entry.isUpdating()) {
                                            itemIcon.setImage(ImageResolveService.getInstance().getImage("image-install2.png"));
                                        }
                                    } else {
                                        if (entry.getHero() && userService.isFreemium()) {
                                            itemIcon.setImage(ImageResolveService.getInstance().getImage("image-notavailable.png"));
                                        } else if (entry.getType() == ArtifactType.LOCAL && !artifactsService.isPrivateDirAvailable()) {
                                            itemIcon.setImage(ImageResolveService.getInstance().getImage("image-notavailable.png"));
                                        } else if (!artifactsService.isInstalled(location.toLocationAndInstallation(), entry)) {
                                            itemIcon.setImage(ImageResolveService.getInstance().getImage("image-notinstalled2bw.png"));
                                        } else if (artifactsService.needsUpdate(location.toLocationAndInstallation(), entry)) {
                                            itemIcon.setImage(ImageResolveService.getInstance().getImage("image-needsupdatebw.png"));
                                        } else {
                                            Optional<LatestInstalledItemInfo> findFirst = lastestAdditions.stream().filter(item -> item.getId().equals(entry.getName())).findFirst();
                                            if (findFirst.isPresent() && userService.isPremium()) {
                                                itemIcon.setImage(ImageResolveService.getInstance().getImage("image-updated-new.png"));
                                            } else {
                                                itemIcon.setImage(ImageResolveService.getInstance().getImage("image-updated2.png"));
                                            }
                                        }
                                    }
                                    TreeItem<GuiLocation> depNode = new TreeItem<GuiLocation>(GuiLocation.builder().id(location.getId()).type(TYPE.INSTALLATION).artifact(entry).build(), itemIcon);
                                    leaf.getChildren().add(depNode);
                                }
                                // reset
                                leaf = rootItem;
                            }
                        }
                    } else {
                        icon.setImage(ImageResolveService.getInstance().getImage("image-root-invalid.png"));
                        TreeItem<GuiLocation> rootItem = new TreeItem<GuiLocation>(GuiLocation.builder().id(location.getId()).type(TYPE.INSTALLATION_ROOT).name(Support.removeEndingSlash(location.getPath())).build(), icon);
                        rootItemBase.getChildren().add(rootItem);
                    }
                }
                if (Scheduler.getInstance() != null && Scheduler.getInstance().isWorking() && ProgressControlWrapper.getInstance().isClosed()) {
                    int height = 25;
                    progressBar = new ProgressbarEnhanced();
                    progressBar.setMinWidth(300);
                    progressBar.setMinHeight(height);
                    progressBar.addEventHandler(MouseEvent.MOUSE_CLICKED, (MouseEvent event) -> handleMouseClicked2(event));
                    topContainer.getChildren().add(1, progressBar);
                    GlobalRepoService.getInstance().put("pbar", progressBar);
                    tree.setMinHeight(topContainer.getHeight() - menuBar.getHeight() - height);
                } else {
                    tree.setMinHeight(topContainer.getHeight() - menuBar.getHeight());
                }
            } catch (Exception e) {
                LOGGER.error("Unable to refresh view", e);
                GenericMessageDialogController.withErrorProps("Ooops", "Unable to refresh view").showAndWait();
            }
        }
    });
}
Also used : EventHandler(javafx.event.EventHandler) StageStyle(javafx.stage.StageStyle) RandomAccessFile(java.io.RandomAccessFile) Scheduler(se.light.assembly64.Scheduler) TYPE(se.light.assembly64.model.GuiLocation.TYPE) LoggerFactory(org.slf4j.LoggerFactory) PathService(se.light.assembly64.service.PathService) VBox(javafx.scene.layout.VBox) StringUtils(org.apache.commons.lang3.StringUtils) FileLock(java.nio.channels.FileLock) Application(javafx.application.Application) ArtifactType(se.light.assembly64.model.ArtifactType) LogConfig(se.light.assembly64.LogConfig) ContextMenu(javafx.scene.control.ContextMenu) Type(se.light.assembly64.Support.Type) WindowEvent(javafx.stage.WindowEvent) WorkLocation(se.light.assembly64.model.WorkLocation) Pane(javafx.scene.layout.Pane) Rectangle2D(javafx.geometry.Rectangle2D) MenuItem(javafx.scene.control.MenuItem) ButtonType(se.light.assembly64.fx.GenericMessageDialogController.ButtonType) Set(java.util.Set) Screen(javafx.stage.Screen) Artifact(se.light.assembly64.model.Artifact) LocalStorageUtil(se.light.assembly64.util.LocalStorageUtil) Collectors(java.util.stream.Collectors) TreeView(javafx.scene.control.TreeView) UserService(se.light.assembly64.service.UserService) Platform(javafx.application.Platform) Duration(javafx.util.Duration) List(java.util.List) PlatformInfoService(se.light.assembly64.service.PlatformInfoService) Optional(java.util.Optional) InstallationService(se.light.assembly64.service.InstallationService) Autoupgrade(se.light.assembly64.Autoupgrade) ReturningTask(se.light.assembly64.model.ReturningTask) Scene(javafx.scene.Scene) MouseButton(javafx.scene.input.MouseButton) TreeItem(javafx.scene.control.TreeItem) GuiLocation(se.light.assembly64.model.GuiLocation) MouseEvent(javafx.scene.input.MouseEvent) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GlobalRepoService(se.light.assembly64.service.GlobalRepoService) GenericMessageDialogController.heroesOnlyFeatureDialog(se.light.assembly64.fx.GenericMessageDialogController.heroesOnlyFeatureDialog) ArrayList(java.util.ArrayList) LatestInstalledItemInfo(se.light.assembly64.model.LatestInstalledItemInfo) ViceService(se.light.assembly64.service.ViceService) UpgradeOptions(se.light.assembly64.Support.UpgradeOptions) FadeTransition(javafx.animation.FadeTransition) GuiUtils(se.light.assembly64.util.GuiUtils) Support(se.light.assembly64.Support) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Support.resolveInstallationExpandedKey(se.light.assembly64.Support.resolveInstallationExpandedKey) DirectoryChooser(javafx.stage.DirectoryChooser) Color(javafx.scene.paint.Color) Analytics(se.light.assembly64.Analytics) Logger(org.slf4j.Logger) MenuBar(javafx.scene.control.MenuBar) ExecutorUtil(se.light.assembly64.util.ExecutorUtil) FileUtils(org.apache.commons.io.FileUtils) ArtifactsService(se.light.assembly64.service.ArtifactsService) File(java.io.File) Menu(javafx.scene.control.Menu) Consumer(java.util.function.Consumer) FileChooser(javafx.stage.FileChooser) ActionEvent(javafx.event.ActionEvent) SelectionMode(javafx.scene.control.SelectionMode) Stage(javafx.stage.Stage) PlatformInfo(se.light.assembly64.model.PlatformInfo) ImageView(javafx.scene.image.ImageView) LocalDBService(se.light.assembly64.service.LocalDBService) ObservableValue(javafx.beans.value.ObservableValue) ChangeListener(javafx.beans.value.ChangeListener) Support.resolveLeafInInstallationExpandedKey(se.light.assembly64.Support.resolveLeafInInstallationExpandedKey) Image(javafx.scene.image.Image) FileChannel(java.nio.channels.FileChannel) Collections(java.util.Collections) LocationAndInstallationStatus(se.light.assembly64.model.LocationAndInstallationStatus) Set(java.util.Set) MouseEvent(javafx.scene.input.MouseEvent) Optional(java.util.Optional) TreeItem(javafx.scene.control.TreeItem) WorkLocation(se.light.assembly64.model.WorkLocation) GuiLocation(se.light.assembly64.model.GuiLocation) Artifact(se.light.assembly64.model.Artifact) LatestInstalledItemInfo(se.light.assembly64.model.LatestInstalledItemInfo) List(java.util.List) ArrayList(java.util.ArrayList) ImageView(javafx.scene.image.ImageView)

Example 4 with Type

use of se.light.assembly64.Support.Type in project assembly64fx by freabemania.

the class DiskImage method readImage.

/**
 * Load image from disk
 * @param filename file name of disk image
 * @param expectedFileSize if uncompressed image is smaller, then throw CbmException. If larger, print warning message.
 * @param type the type of image to load. Used for logging.
 * @throws CbmException
 */
protected void readImage(String filename, int expectedFileSize, String type) throws CbmException {
    feedbackMessage = new StringBuffer();
    FileInputStream input;
    int magic = 0;
    feedbackMessage.append("Trying to load " + type + " image ").append(filename).append("\n");
    this.cbmDisk = null;
    try {
        magic = getFileMagic(filename) & 0xffff;
    } catch (Exception e) {
        throw new CbmException("Failed to open header. " + e.getMessage());
    }
    if (magic == GZIPInputStream.GZIP_MAGIC) {
        feedbackMessage.append("GZIP compressed file detected.\n");
        readZippedFile(filename);
    } else {
        File file = new File(filename);
        if (file.isFile() == false) {
            throw new CbmException("File is not a regular file.");
        } else if (file.length() <= 0) {
            throw new CbmException("File is empty.");
        } else if (file.length() > Integer.MAX_VALUE) {
            throw new CbmException("File is too large.");
        } else if (file.length() < expectedFileSize) {
            throw new CbmException("File smaller than normal size. A " + type + " file should be " + expectedFileSize + " bytes.");
        } else if (file.length() > expectedFileSize) {
            feedbackMessage.append("Warning: File larger than normal size. A " + type + " file should be ").append(expectedFileSize).append(" bytes.\n");
        }
        try {
            input = new FileInputStream(filename);
        } catch (Exception e) {
            throw new CbmException("Failed to open file. " + e.getMessage());
        }
        try {
            this.cbmDisk = new byte[(int) file.length()];
            for (int i = 0; i < cbmDisk.length; i++) {
                cbmDisk[i] = 0;
            }
            input.read(cbmDisk);
        } catch (Exception e) {
            try {
                input.close();
            } catch (Exception e2) {
            }
            throw new CbmException("Failed to read file. " + e.getMessage());
        }
        try {
            input.close();
        } catch (Exception e) {
            throw new CbmException("Failed to close file. " + e.getMessage());
        }
    }
    feedbackMessage.append(type + " disk image was loaded.\n");
}
Also used : File(java.io.File) DiskFile(se.light.assembly64.d64.db.DiskFile) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

File (java.io.File)2 List (java.util.List)2 Image (javafx.scene.image.Image)2 ImageView (javafx.scene.image.ImageView)2 GuiLocation (se.light.assembly64.model.GuiLocation)2 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 RandomAccessFile (java.io.RandomAccessFile)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 FileChannel (java.nio.channels.FileChannel)1 FileLock (java.nio.channels.FileLock)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Optional (java.util.Optional)1 Set (java.util.Set)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1