Exemplo n.º 1
0
    private void selfUpdate() {
        URL url = updateUrl;
        if (url != null) {
            SelfUpdater downloader = new SelfUpdater(launcher, url);
            ObservableFuture<File> future = new ObservableFuture<File>(
                    launcher.getExecutor().submit(downloader), downloader);

            Futures.addCallback(future, new FutureCallback<File>() {
                @Override
                public void onSuccess(File result) {
                    SwingHelper.showMessageDialog(
                            LauncherFrame.this,
                            _("launcher.selfUpdateComplete"),
                            _("launcher.selfUpdateCompleteTitle"),
                            null,
                            JOptionPane.INFORMATION_MESSAGE);
                    LauncherFrame.this.updateRequired = false;
                }

                @Override
                public void onFailure(Throwable t) {
                }
            }, SwingExecutor.INSTANCE);

            ProgressDialog.showProgress(this, future, _("launcher.selfUpdatingTitle"), _("launcher.selfUpdatingStatus"));
            SwingHelper.addErrorDialogCallback(this, future);
        } else {
            SwingHelper.showMessageDialog(
                    LauncherFrame.this,
                    _("launcher.selfUpdateCheckError"),
                    _("launcher.genericError"),
                    null,
                    JOptionPane.INFORMATION_MESSAGE);
        }
    }
Exemplo n.º 2
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"));
        }
    }
  public void actionPerformed(ActionEvent e) {
    Object source = e.getSource();

    if (source == okButton) {
      dispose();

      // Starts copying files
      ProgressDialog progressDialog =
          new ProgressDialog(mainFrame, Translator.get("progress_dialog.processing_files"));
      ChangeFileAttributesJob job =
          new ChangeFileAttributesJob(
              progressDialog, mainFrame, files, getPermInt(), recurseDirCheckBox.isSelected());
      progressDialog.start(job);
    } else if (source == cancelButton) {
      dispose();
    }
  }
Exemplo n.º 4
0
    private void launch(Instance instance, Session session) {
        final File extractDir = launcher.createExtractDir();

        // Get the process
        Runner task = new Runner(launcher, instance, session, extractDir);
        ObservableFuture<Process> processFuture = new ObservableFuture<Process>(
                launcher.getExecutor().submit(task), task);

        // Show process for the process retrieval
        ProgressDialog.showProgress(
                this, processFuture, _("launcher.launchingTItle"), _("launcher.launchingStatus", instance.getTitle()));

        // If the process is started, get rid of this window
        Futures.addCallback(processFuture, new FutureCallback<Process>() {
            @Override
            public void onSuccess(Process result) {
                dispose();
            }

            @Override
            public void onFailure(Throwable t) {
            }
        });

        // Watch the created process
        ListenableFuture<?> future = Futures.transform(
                processFuture, new LaunchProcessHandler(launcher), launcher.getExecutor());
        SwingHelper.addErrorDialogCallback(null, future);

        // Clean up at the very end
        future.addListener(new Runnable() {
            @Override
            public void run() {
                try {
                    log.info("Process ended; cleaning up " + extractDir.getAbsolutePath());
                    FileUtils.deleteDirectory(extractDir);
                } catch (IOException e) {
                    log.log(Level.WARNING, "Failed to clean up " + extractDir.getAbsolutePath(), e);
                }
                instancesModel.update();
            }
        }, sameThreadExecutor());
    }
Exemplo n.º 5
0
    private void loadInstances() {
        InstanceList.Enumerator loader = launcher.getInstances().createEnumerator();
        ObservableFuture<InstanceList> future = new ObservableFuture<InstanceList>(
                launcher.getExecutor().submit(loader), loader);

        future.addListener(new Runnable() {
            @Override
            public void run() {
                instancesModel.update();
                if (instancesTable.getRowCount() > 0) {
                    instancesTable.setRowSelectionInterval(0, 0);
                }
                requestFocus();
            }
        }, SwingExecutor.INSTANCE);

        ProgressDialog.showProgress(this, future, _("launcher.checkingTitle"), _("launcher.checkingStatus"));
        SwingHelper.addErrorDialogCallback(this, future);
    }
Exemplo n.º 6
0
    private void confirmHardUpdate(Instance instance) {
        if (!SwingHelper.confirmDialog(this, _("instance.confirmHardUpdate"), _("confirmTitle"))) {
            return;
        }

        // Execute the resetter
        HardResetter resetter = new HardResetter(instance);
        ObservableFuture<Instance> future = new ObservableFuture<Instance>(
                launcher.getExecutor().submit(resetter), resetter);

        // Show progress
        ProgressDialog.showProgress( this, future, _("instance.resettingTitle"),
                _("instance.resettingStatus", instance.getTitle()));
        SwingHelper.addErrorDialogCallback(this, future);

        // Update the list of instances after updating
        future.addListener(new Runnable() {
            @Override
            public void run() {
                launch();
                instancesModel.update();
            }
        }, SwingExecutor.INSTANCE);
    }
Exemplo n.º 7
0
    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"));
        }
    }
 /**
  * Synchronize a local instance repository to the db repository. Calling this method may modify
  * deleteMap Map in the FileAdaptor object.
  *
  * @param fileAdaptor the PersistenceAdaptor for the local instance repository.
  * @param dbAdaptor the PersistenceAdaptor for the database instance repository.
  * @return Key: delete, deleteInDB, new and/or changed; Values: A list of instances
  *     <p>Sideeffect: changes typeMap.
  */
 private Map synchronize(final XMLFileAdaptor fileAdaptor, final MySQLAdaptor dbAdaptor) {
   // Need another thread to display the progress
   final ProgressDialog progDialog = new ProgressDialog((JFrame) getOwner());
   progDialog.setSize(300, 180);
   // GKApplicationUtilities.center(progDialog);
   progDialog.setLocationRelativeTo(progDialog.getOwner());
   progDialog.setModal(true);
   final List syncClassList = getSynchronizingClassList(fileAdaptor);
   // Get the total instance counter
   Schema schema = fileAdaptor.getSchema();
   SchemaClass cls = null;
   long total = 0;
   try {
     total = getTotalInstanceCount(fileAdaptor);
   } catch (Exception e) {
     System.err.println("SyncrhonizationEngine.synchronize(): " + e);
     e.printStackTrace();
   }
   progDialog.totalBar.setMaximum((int) total);
   progDialog.totalBar.setMinimum(0);
   // Let the synchronizing work in another thread.
   final Map map = new HashMap();
   Thread t =
       new Thread() {
         public void run() {
           java.util.List newInstances = new ArrayList();
           java.util.List changedInstances = new ArrayList();
           java.util.List deletedInDBInstances = new ArrayList();
           java.util.List localHasMoreIEInstances = new ArrayList();
           Schema schema = fileAdaptor.getSchema();
           SchemaClass schemaClass = null;
           Collection instances = null;
           GKInstance instance = null;
           GKInstance dbCopy = null;
           int index = 0;
           int total = 0;
           // For comparsing
           InstanceComparer comparer = new InstanceComparer();
           try {
             for (Iterator it = syncClassList.iterator(); it.hasNext(); ) {
               if (isCancelled) break;
               schemaClass = (SchemaClass) it.next();
               instances = fileAdaptor.fetchInstancesByClass(schemaClass, false);
               if (instances == null || instances.size() == 0) continue;
               progDialog.clsLabel.setText("Scan class " + schemaClass.getName() + "...");
               progDialog.clsBar.setMinimum(0);
               progDialog.clsBar.setMaximum(instances.size());
               List existedIDs = new ArrayList(instances.size());
               for (Iterator it1 = instances.iterator(); it1.hasNext(); ) {
                 instance = (GKInstance) it1.next();
                 if (instance.getDBID().longValue() < 0) {
                   newInstances.add(instance);
                   typeMap.put(instance, NEW_KEY);
                 } else // Shell instances should not be skipped since a shell instance can still
                   // be deleted locally so existence checking is needed.
                   existedIDs.add(instance.getDBID());
               }
               if (existedIDs.size() == 0) continue;
               Collection existences = dbAdaptor.fetchInstances(schemaClass.getName(), existedIDs);
               if (existences.size() > 0) {
                 // Load all modified attribute
                 SchemaAttribute att = schemaClass.getAttribute("modified");
                 // Load all atributes in a batch
                 dbAdaptor.loadInstanceAttributeValues(existences, att);
               }
               index = 0;
               for (Iterator it1 = instances.iterator(); it1.hasNext(); ) {
                 if (isCancelled) break;
                 instance = (GKInstance) it1.next();
                 if (instance.getDBID().longValue() < 0) { // Handled by the previous loop
                   continue;
                 }
                 // The schema class might be changed. Use the
                 // top-leve class to fetch instance
                 dbCopy = dbAdaptor.fetchInstance(instance.getDBID());
                 if (dbCopy == null) {
                   deletedInDBInstances.add(instance);
                   typeMap.put(instance, DELETE_IN_DB_KEY);
                 }
                 // Don't care a shell instance
                 else {
                   if (!instance.isShell()) {
                     int tmp = comparer.compare(instance, dbCopy);
                     String typeKey = mapCompareResultToString(tmp);
                     if (typeKey == LOCAL_HAS_MORE_IE_KEY) {
                       localHasMoreIEInstances.add(instance);
                       typeMap.put(instance, typeKey);
                     } else if (typeKey != IS_IDENTICAL_KEY) {
                       changedInstances.add(instance);
                       typeMap.put(instance, typeKey);
                     }
                   }
                 }
                 index++;
                 total++;
                 progDialog.clsBar.setValue(index);
                 progDialog.totalBar.setValue(total);
               }
             }
             if (deletedInDBInstances.size() > 0) map.put(DELETE_IN_DB_KEY, deletedInDBInstances);
             if (newInstances.size() > 0) map.put(NEW_KEY, newInstances);
             if (changedInstances.size() > 0) map.put(CHANGED_KEY, changedInstances);
             if (localHasMoreIEInstances.size() > 0)
               map.put(LOCAL_HAS_MORE_IE_KEY, localHasMoreIEInstances);
             // Check the delete instances
             Map deleteMap = getLocalDeleteMap(fileAdaptor, syncClassList);
             if (deleteMap != null && deleteMap.size() > 0) {
               java.util.List deleteInstances = new ArrayList();
               List clearingIDs = new ArrayList();
               for (Iterator it = deleteMap.keySet().iterator(); it.hasNext(); ) {
                 Long dbID = (Long) it.next();
                 String className = (String) deleteMap.get(dbID);
                 dbCopy = dbAdaptor.fetchInstance(className, dbID);
                 if (dbCopy != null) {
                   deleteInstances.add(dbCopy);
                   typeMap.put(dbCopy, DELETE_KEY);
                 } else clearingIDs.add(dbID);
               }
               if (deleteInstances.size() > 0) map.put(DELETE_KEY, deleteInstances);
               fileAdaptor.clearDeleteRecord(clearingIDs);
             }
             progDialog.dispose();
           } catch (Exception e) {
             System.err.println("SynchronizationEngine.synchronize() 1: " + e);
             e.printStackTrace();
             JOptionPane.showMessageDialog(
                 progDialog,
                 "Error in synchronizing: \n" + e,
                 "Error in Synchronizing",
                 JOptionPane.ERROR_MESSAGE);
             // Have to set this first to behavior correctly since thread issue.
             isCancelled = true;
             progDialog.dispose();
           }
         }
       };
   t.start();
   progDialog.setVisible(true);
   return map;
 }