use of se.light.assembly64.model.Settings in project assembly64fx by freabemania.
the class SearchViewFilesController method openFile.
private void openFile(boolean launchExplorerEvenIfOneFile, boolean loadStar) {
ContentEntry selectedItem = table.getSelectionModel().getSelectedItem();
try {
File file = null;
if (fromSearch) {
file = downloadService.downloadItem(searchedItem.getId(), searchedItem.getCategory(), selectedItem.getId(), searchedItem.getName(), selectedItem.getName(), searchedItem.getCategoryShortName(), FILE_ACTION.TMPDOWNLOAD);
} else {
// we're using the id as pathfield
file = new File(selectedItem.getId());
}
String path = file.getAbsolutePath().toLowerCase();
if (path.endsWith(".d64") || path.endsWith(".d71") || path.endsWith(".d81")) {
GuiUtils.showDialogWithOwner("viewimage.fxml", "Browsing diskimage for " + selectedItem.getName(), getStage(), new Object[] { file, launchExplorerEvenIfOneFile, loadStar });
} else if (path.endsWith(".sid")) {
GuiUtils.showDialog("sidifyPlaySid.fxml", true, "Sidplay", getStage(), file);
} else {
if (StringUtils.isNotEmpty(localDb.getLocalDBSetting("vicepath"))) {
Analytics.sendEvent("search", "viceopen");
if (fromSearch) {
downloadService.downloadItem(searchedItem.getId(), searchedItem.getCategory(), selectedItem.getId(), searchedItem.getName(), selectedItem.getName(), searchedItem.getCategoryShortName(), FILE_ACTION.EXECUTE);
} else {
viceService.execVice(file);
}
} else {
Analytics.sendEvent("search", "novice");
GenericMessageDialogController.withErrorProps("Specify vicepath", "In order to run files you need to specify Vicepath in settings").showAndWait();
}
}
} catch (Exception e) {
GenericMessageDialogController.withErrorProps("Specify vicepath", "Unable to view files").showAndWait();
}
}
use of se.light.assembly64.model.Settings in project assembly64fx by freabemania.
the class UserService method storeSettings.
public void storeSettings() throws HttpException {
Response response = null;
try {
response = getClient().target(getBackendServer()).path("/leet/user3/settings").request().header("email", getSessionInfo().getEmail()).header("token", getSessionInfo().getToken()).post(Entity.json(settings));
} finally {
response.close();
}
invalidateUserDb();
if (response.getStatus() != 200) {
throw new HttpException(response.getStatus());
}
}
use of se.light.assembly64.model.Settings in project assembly64fx by freabemania.
the class Main method viewPrimary.
public void viewPrimary() {
primaryStage = new Stage();
primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
public void handle(WindowEvent we) {
System.exit(1);
}
});
if (!userService.isPremium()) {
userService.deleteExcludesFromLocalDbQuiet();
}
// Setting the saved windowsize
if (localDbService.hasLocalDBSetting("screenHeight")) {
primaryStage.setHeight(Double.valueOf(localDbService.getLocalDBSetting("screenHeight")));
}
if (localDbService.hasLocalDBSetting("screenWidth")) {
primaryStage.setWidth(Double.valueOf(localDbService.getLocalDBSetting("screenWidth")));
}
GuiUtils.attachIconToStage(primaryStage);
LOGGER.info("Assembly64 v." + version + " is starting up...");
try {
if (userService.isPremium()) {
primaryStage.setTitle("Assembly64 - Hero edition");
} else {
primaryStage.setTitle("Assembly64 - Free edition");
}
// menuBar = new MenuBar();
Menu menuFile = new Menu("Assembly64");
Menu menuLogs = new Menu("Logs");
Menu menuMisc = new Menu("Misc");
// A64
MenuItem openFile = new MenuItem("Open D64/D71/D81/TAP/G64/T64/BIN/CRT/SID");
menuFile.getItems().add(openFile);
MenuItem settingsItem = new MenuItem("Preferences");
menuFile.getItems().add(settingsItem);
MenuItem exitItem = new MenuItem("Exit");
menuFile.getItems().add(exitItem);
// logsmenu
MenuItem viewLogItem = new MenuItem("Systemlog");
menuLogs.getItems().add(viewLogItem);
MenuItem changelog = new MenuItem("Changelog");
menuLogs.getItems().add(changelog);
MenuItem instructions = new MenuItem("Instructions");
menuMisc.getItems().add(instructions);
// misc
MenuItem backers = new MenuItem("Backers");
menuMisc.getItems().add(backers);
MenuItem donations = new MenuItem("Donations");
menuMisc.getItems().add(donations);
MenuItem feedbackItem = new MenuItem("Feedback & Feature requests");
menuMisc.getItems().add(feedbackItem);
MenuItem aboutItem = new MenuItem("About");
menuMisc.getItems().add(aboutItem);
menuBar = new MenuBar();
menuBar.getMenus().addAll(menuFile, menuLogs, menuMisc);
feedbackItem.setOnAction((item) -> {
GuiUtils.showDialogBare("feedback.fxml", "Submit feedback");
});
exitItem.setOnAction((item) -> {
System.exit(1);
});
openFile.setOnAction((item) -> {
Analytics.sendEvent("application_click", "open_file");
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Open Resource File");
fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("All", "*.*"), new FileChooser.ExtensionFilter("PRG", "*.d64"), new FileChooser.ExtensionFilter("D64", "*.d64"), new FileChooser.ExtensionFilter("D71", "*.d71"), new FileChooser.ExtensionFilter("T64", "*.t64"), new FileChooser.ExtensionFilter("TAP", "*.d71"), new FileChooser.ExtensionFilter("G64", "*.g64"), new FileChooser.ExtensionFilter("G64", "*.tap"), new FileChooser.ExtensionFilter("D71", "*.d71"), new FileChooser.ExtensionFilter("D81", "*.d81"), new FileChooser.ExtensionFilter("BIN", "*.bin"), new FileChooser.ExtensionFilter("CRT", "*.crt"));
launchViceOrImageView(fileChooser.showOpenDialog(primaryStage));
});
settingsItem.setOnAction((item) -> {
try {
GuiUtils.showDialogBare("mainSettings.fxml", "Settings", new Object[] {});
} catch (Exception e) {
LOGGER.error("Unable to view settings", e);
GenericMessageDialogController.withErrorProps("Oops", "Unable to view settings").showAndWait();
}
});
viewLogItem.setOnAction((item) -> {
try {
Analytics.sendEvent("application_click", "view_logs");
GuiUtils.showDialogBare("viewFileFromDisk.fxml", "View log", new File(LogConfig.getLogFileAsString()), "Systemlog");
} catch (Exception e) {
LOGGER.error("Unable to view logs", e);
GenericMessageDialogController.withErrorProps("Oops", "Unable to view logs").showAndWait();
}
});
donations.setOnAction((i) -> {
String linebreak = System.getProperty("line.separator");
String donStr = userService.getDonations().stream().map(item -> item.dateFormatted() + linebreak + item.getName()).collect(Collectors.joining(linebreak + linebreak));
GuiUtils.showDialogBare("viewFileFromDisk.fxml", "Donations by heroes", donStr, "Donationshistory");
});
backers.setOnAction((item) -> {
try {
String[] bck = userService.getBackers();
int start = ThreadLocalRandom.current().nextInt(0, bck.length - 1);
StringBuffer names = new StringBuffer();
for (int i = 0; i < bck.length - 1; i++) {
int pos = (start + i) % (bck.length - 1);
names.append(bck[pos] + "\n");
}
Analytics.sendEvent("application_click", "view_backers");
GuiUtils.showDialogBare("viewFileFromDisk.fxml", "Backing heroes of Assembly64", names.toString(), "List of backers");
} catch (Exception e) {
GenericMessageDialogController.withErrorProps("Oops", "Unable to view backers").showAndWait();
LOGGER.error("Unable to view logs", e);
}
});
instructions.setOnAction((item) -> {
try {
Analytics.sendEvent("application_click", "view_instructions");
GuiUtils.showDialogBare("viewFileFromDisk.fxml", "This is the way", getClass().getResourceAsStream("instructions.txt"), "Instructions");
} catch (Exception e) {
GenericMessageDialogController.withErrorProps("Oops", "Unable to view instructions").showAndWait();
LOGGER.error("Unable to view instructions", e);
}
});
changelog.setOnAction((item) -> {
Analytics.sendEvent("application_click", "view_changelog");
try {
GuiUtils.showDialogBare("viewFileFromDisk.fxml", "Haxxing haxxing haxxing", getClass().getResourceAsStream("changelog.txt"), "Changelog");
} catch (Exception e) {
GenericMessageDialogController.withErrorProps("Oops", "Unable to view changelog").showAndWait();
LOGGER.error("Unable to view logs", e);
}
});
aboutItem.setOnAction((item) -> {
try {
Analytics.sendEvent("application_click", "view_about");
showAboutDia();
} catch (Exception e) {
LOGGER.error("Unable to view about", e);
GenericMessageDialogController.withErrorProps("Oops", "Unable to view about").showAndWait();
}
});
topContainer.getChildren().addAll(menuBar);
topContainer.setStyle("-fx-background: #222222;");
Scene scene = new Scene(topContainer, 300, maxHeight);
scene.getStylesheets().add(getClass().getResource("css-psidplayer.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.setResizable(true);
GlobalRepoService.getInstance().put("primarystage", primaryStage);
if (!localDbService.getBooleanLocalDBSetting(Support.SIDIFYASDEFAULT) || userService.isFreemium()) {
primaryStage.show();
} else {
ReturningTask<Void> task = () -> {
Platform.runLater(() -> {
primaryStage.hide();
executeIfPremium((Runnable) -> {
GuiUtils.showDialog("sidifyMain.fxml", false, "Sidify Heroium", NullWindowOwner.of(), new Object[] { Boolean.TRUE });
}, "open_sidify_default");
});
return null;
};
ExecutorUtil.executeAsyncWithRetry(task);
}
scene.heightProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observableValue, Number oldSceneHeight, Number newSceneHeight) {
tree.setMinHeight(topContainer.getHeight() - menuBar.getHeight());
setMagnifierAndSidify();
}
});
scene.widthProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observableValue, Number oldSceneHeight, Number newSceneHeight) {
tree.setMinWidth(treeAndComponents.getWidth());
setMagnifierAndSidify();
}
});
// bootstrapping
GlobalRepoService.getInstance().put("rootscene", scene);
for (WorkLocation location : userService.getExistingLocations()) {
artifactsService.assertCorrectTargetFolderNames(location.asFile());
}
setupTree();
sidifyView.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> {
Analytics.sendEvent("application_click", "open_sidify");
executeIfPremium((Runnable) -> {
// Platform.runLater(() -> primaryStage.hide());
GuiUtils.showDialog("sidifyMain.fxml", false, "Sidify Heroium", NullWindowOwner.of(), new Object[] { Boolean.FALSE });
}, "open_sidify");
});
downloadLatestDbView.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> {
executeIfPremium((Runnable) -> {
if (userService.getPrimaryInstallation().exists()) {
InstallationService.getInstance().downloadLatestFromDatabase();
} else {
GenericMessageDialogController.withErrorProps("Ooops..", "No valid downloadlocation is present").showAndWait();
}
}, "download_latest");
});
userService.locationsAssert();
if (!localDbService.hasLocalDBSetting(Support.LAST_VERSION)) {
localDbService.addLocalDBSetting(Support.LAST_VERSION, "0.00");
}
if (localDbService.getBooleanLocalDBSetting(Support.SHOWDIA_ON_STARTUP) || !version.equals(localDbService.getLocalDBSetting(Support.LAST_VERSION))) {
ReturningTask<Void> task = () -> {
Thread.sleep(300);
Platform.runLater(() -> showAboutDia());
return null;
};
ExecutorUtil.executeAsyncWithRetry(task);
}
ReturningTask<Void> deleteTmpTask = () -> {
LocalStorageUtil.deleteOldFiles(PathService.getInstance().getTmpFolderAsString(), Support.ONE_WEEK_IN_MILLIS);
LocalStorageUtil.deleteOldFiles(PathService.getInstance().getDownloadTmpFolderAsString(), Support.ONE_MONTH_IN_MILLIS);
return null;
};
ExecutorUtil.executeAsyncWithRetry(deleteTmpTask);
// migrate db to .db
for (WorkLocation location : userService.getLocations()) {
PathService.getInstance().renameDbFolder(location);
}
if (userService.getExistingLocations().size() == 0 && localDbService.hasLocalDBSetting(WORKDIR)) {
addLocation(new File(localDbService.getLocalDBSetting(WORKDIR)));
localDbService.deleteLocalDBSetting(WORKDIR);
}
if (userService.isPremium() && !localDbService.getBooleanLocalDBSetting(Support.SIDIFYASDEFAULT)) {
ExecutorUtil.executeAsync(() -> {
Platform.runLater(() -> {
examineContent();
});
});
}
refreshTree();
} catch (Exception e) {
LOGGER.error("Unable to delete cached items", e);
GenericMessageDialogController.withErrorProps("OOoops", "Unable to startup properly").showAndWait();
}
}
use of se.light.assembly64.model.Settings in project assembly64fx by freabemania.
the class SettingsController method storeSettings.
@FXML
protected void storeSettings(MouseEvent event) {
try {
Settings settings = userService.getSettings();
if (settings.getNotificationOnNewContent() != notifyOnNewContent.isSelected() || !settings.getCountry().equals(countries.getSelectionModel().getSelectedItem()) || !settings.getName().equals(username.getText()) || !settings.getAnonymous().equals(anonymous.isSelected())) {
settings.setNotificationOnNewContent(notifyOnNewContent.isSelected());
settings.setCountry(countries.getSelectionModel().getSelectedItem());
settings.setName(username.getText());
settings.setAnonymous(anonymous.isSelected());
userService.storeSettings();
Analytics.sendEvent("application_click", "store_settings");
LOGGER.info("Settings were stored");
}
localDb.setSidifyAsDefault(sidifyAsDefault.isSelected());
if (userService.isPremium()) {
int tmp = workers.getSelectionModel().getSelectedIndex();
if (tmp != initialWorkers) {
localDb.addLocalDBSetting("instances", String.valueOf(workers.getSelectionModel().getSelectedIndex()));
Scheduler.reinitIfNotWorking();
}
localDb.addLocalDBSetting("vicepath", vicePath.getText());
localDb.setRunScriptInsteadOfVice(executeAsCommand.isSelected());
if (executeAsCommand.isSelected()) {
localDb.setViceStyleFormatOnArgs(viceStyleFormatOnArgs.isSelected());
} else {
localDb.setViceStyleFormatOnArgs(false);
}
}
localDb.addLocalDBSetting("maxage", String.valueOf(latestMaxAge.getSelectionModel().getSelectedItem()));
if (latestMaxAge.getSelectionModel().getSelectedIndex() > currMaxAgeIndex) {
for (WorkLocation location : userService.getExistingLocations()) {
FileUtils.deleteQuietly(new File(location.asFile().getAbsolutePath() + "/.db/latest"));
}
}
getStage().close();
} catch (Exception e) {
if (e instanceof HttpException) {
GenericMessageDialogController.withErrorProps("Oops", "Unable to store. Invalid length of name").showAndWait();
}
LOGGER.error("Unable to store settings", e);
}
}
use of se.light.assembly64.model.Settings in project assembly64fx by freabemania.
the class SettingsController method init.
public void init() throws Exception {
localDb = LocalDBService.getInstance();
userService = UserService.getInstance();
addTextLimiter(username, 48);
Settings settings = userService.getSettings();
if (userService.isPremium()) {
String[] tkns = Support.readStringResourceFromFile("countries.txt", getClass()).split(System.getProperty("line.separator"));
initialWorkers = getWorkersIndex();
workers.getSelectionModel().clearAndSelect(initialWorkers);
notifyOnNewContent.setSelected(settings.getNotificationOnNewContent());
Arrays.stream(tkns).forEach(item -> countries.getItems().add(item));
countries.getSelectionModel().select(settings.getCountry());
username.setText(settings.getName());
anonymous.setSelected(settings.getAnonymous());
} else {
sidifyAsDefault.setDisable(true);
latestMaxAge.setDisable(true);
anonymous.setDisable(true);
username.setDisable(true);
countries.setDisable(true);
workers.getSelectionModel().select(0);
workers.setDisable(true);
notifyOnNewContent.setDisable(true);
}
sidifyAsDefault.setSelected(localDb.getSidifyAsDefault());
latestMaxAge.getSelectionModel().select(LocalDBService.getInstance().getMagAgeIndex());
currMaxAgeIndex = latestMaxAge.getSelectionModel().getSelectedIndex();
if (localDb.hasLocalDBSetting("vicepath")) {
vicePath.setText(localDb.getLocalDBSetting("vicepath"));
}
if (localDb.getRunScriptInsteadOfVice()) {
viceStyleFormatOnArgs.setSelected(localDb.getViceStyleFormatOnArgs());
executeAsCommand.setSelected(true);
openFileImage.setVisible(false);
} else {
viceStyleFormatOnArgs.setDisable(true);
}
}
Aggregations