コード例 #1
0
    private void launch() {
        try {
            final Instance instance = launcher.getInstances().get(instancesTable.getSelectedRow());
            boolean update = updateCheck.isSelected() && instance.isUpdatePending();

            // Store last access date
            Date now = new Date();
            instance.setLastAccessed(now);
            Persistence.commitAndForget(instance);

            // Perform login
            final Session session = LoginDialog.showLoginRequest(this, launcher);
            if (session == null) {
                return;
            }

            // If we have to update, we have to update
            if (!instance.isInstalled()) {
                update = true;
            }

            if (update) {
                // Execute the updater
                Updater updater = new Updater(launcher, instance);
                updater.setOnline(session.isOnline());
                ObservableFuture<Instance> future = new ObservableFuture<Instance>(
                        launcher.getExecutor().submit(updater), updater);

                // Show progress
                ProgressDialog.showProgress(
                        this, future, _("launcher.updatingTitle"), _("launcher.updatingStatus", instance.getTitle()));
                SwingHelper.addErrorDialogCallback(this, future);

                // Update the list of instances after updating
                future.addListener(new Runnable() {
                    @Override
                    public void run() {
                        instancesModel.update();
                    }
                }, SwingExecutor.INSTANCE);

                // On success, launch also
                Futures.addCallback(future, new FutureCallback<Instance>() {
                    @Override
                    public void onSuccess(Instance result) {
                        launch(instance, session);
                    }

                    @Override
                    public void onFailure(Throwable t) {
                    }
                }, SwingExecutor.INSTANCE);
            } else {
                launch(instance, session);
            }
        } catch (ArrayIndexOutOfBoundsException e) {
            SwingHelper.showErrorDialog(this, _("launcher.noInstanceError"), _("launcher.noInstanceTitle"));
        }
    }
コード例 #2
0
  @Override
  public List<ManifestEntry> apply(List<ManifestEntry> entries) {
    File[] files =
        searchDir.listFiles(
            f ->
                f.isFile()
                    && f.getName().toLowerCase().endsWith(".json")
                    && !f.getName().startsWith("packages."));

    if (files != null) {
      for (File file : files) {
        String location = file.getName();
        Manifest manifest = Persistence.read(file, Manifest.class, true);

        if (manifest != null) {
          ManifestInfo info = new ManifestInfo();
          info.setName(manifest.getName());
          info.setTitle(manifest.getTitle());
          info.setVersion(manifest.getVersion());
          info.setPriority(0);
          info.setLocation(location);

          boolean found = false;

          for (ManifestEntry entry : entries) {
            if (entry.getManifestInfo().getLocation().equals(location)) {
              info.setPriority(entry.getManifestInfo().getPriority());
              entry.setManifestInfo(info);
              found = true;
              break;
            }
          }

          if (!found) {
            ManifestEntry entry = new ManifestEntry();
            entry.setManifestInfo(info);
            entries.add(entry);
          }
        }
      }
    }

    return entries;
  }
コード例 #3
0
ファイル: LauncherFrame.java プロジェクト: idem-id/Launcher
    private void launch() {
        boolean offlineOnly = false;

        if(LauncherFrame.this.updateUrl != null) {
            SwingHelper.showMessageDialog(
                    LauncherFrame.this,
                    _("launcher.selfUpdateComplete"),
                    _("errors.launchImpossible"),
                   null,
                    JOptionPane.ERROR_MESSAGE);
            return;
        }

        if(LauncherFrame.this.updateRequired) {
            offlineOnly = true;
            if(!SwingHelper.confirmDialog(
                    LauncherFrame.this,
                    _("errors.offlineOnly"),
                    _("errors.genericError"))) return;
        }
        try {
            final Instance instance = launcher.getInstances().get(instancesTable.getSelectedRow());

            // Store last access date
            Date now = new Date();
            instance.setLastAccessed(now);
            Persistence.commitAndForget(instance);

            // Perform login
            final Session session = offlineOnly
                ? (new OfflineSession(launcher.getProperties().getProperty("offlinePlayerName")))
                : LoginDialog.showLoginRequest(this, launcher);
            if (session == null) {
                return;
            }

            // Execute the updater
            Updater updater = new Updater(launcher, instance);
            updater.setSelectFeatures(configureFeaturesCheck.isSelected());
            updater.setOnline(session.isOnline());
            ObservableFuture<Instance> future = new ObservableFuture<Instance>(
                    launcher.getExecutor().submit(updater), updater);

            // Show progress
            ProgressDialog.showProgress(
                    this, future, _("launcher.updatingTitle"), _("launcher.updatingStatus", instance.getTitle()));
            SwingHelper.addErrorDialogCallback(this, future);

            // Update the list of instances after updating
            future.addListener(new Runnable() {
                @Override
                public void run() {
                    instancesModel.update();
                }
            }, SwingExecutor.INSTANCE);

            // On success, launch also
            Futures.addCallback(future, new FutureCallback<Instance>() {
                @Override
                public void onSuccess(Instance result) {
                    launch(instance, session);
                }

                @Override
                public void onFailure(Throwable t) {
                }
            }, SwingExecutor.INSTANCE);
        } catch (ArrayIndexOutOfBoundsException e) {
            SwingHelper.showErrorDialog(this, _("launcher.noInstanceError"), _("launcher.noInstanceTitle"));
        }
    }