ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/java/installer2/src/net/oni2/aeinstaller/gui/MainWin.java
(Generate patch)

Comparing AE/installer2/src/net/oni2/aeinstaller/gui/MainWin.java (file contents):
Revision 619 by alloc, Tue Jan 15 02:28:53 2013 UTC vs.
Revision 621 by alloc, Tue Jan 15 20:02:01 2013 UTC

# Line 51 | Line 51 | import net.oni2.aeinstaller.backend.mods
51   import net.oni2.aeinstaller.backend.mods.download.ModDownloaderListener;
52   import net.oni2.aeinstaller.backend.oni.InstallProgressListener;
53   import net.oni2.aeinstaller.backend.oni.Installer;
54 + import net.oni2.aeinstaller.backend.oni.OniSplit;
55   import net.oni2.aeinstaller.gui.about.AboutDialog;
56   import net.oni2.aeinstaller.gui.downloadwindow.Downloader;
57   import net.oni2.aeinstaller.gui.modtable.DownloadSizeListener;
# Line 91 | Line 92 | public class MainWin extends JFrame impl
92          private JLabel lblCreatorVal;
93          private JLabel lblTypesVal;
94          private JLabel lblPlatformVal;
95 +        private JLabel lblPackageNumberVal;
96          private HTMLLinkLabel lblDescriptionVal;
97  
98          private JButton btnInstall;
99  
100 +        private TreeSet<Mod> execUpdates = null;
101 +
102 +        private enum EInstallResult {
103 +                DONE,
104 +                OFFLINE,
105 +                INCOMPATIBLE
106 +        };
107 +
108 +        private EInstallResult installDone = EInstallResult.DONE;
109 +
110          /**
111           * Constructor of main window.
112           */
# Line 227 | Line 239 | public class MainWin extends JFrame impl
239  
240          @DoInBackground(progressMessage = "updateDepot.title", cancelable = false, indeterminateProgress = false)
241          private void execDepotUpdate(final BackgroundEvent evt) {
242 <                try {
243 <                        DepotManager.getInstance().updateInformation(false,
244 <                                        new DepotCacheUpdateProgressListener() {
245 <
246 <                                                @Override
247 <                                                public void cacheUpdateProgress(String stepName,
248 <                                                                int current, int total) {
249 <                                                        evt.setProgressEnd(total);
250 <                                                        evt.setProgressValue(current);
251 <                                                        evt.setProgressMessage(stepName);
252 <                                                }
253 <                                        });
254 <                        ModManager.getInstance().init();
255 <                        initTable();
256 <                        initModTypeBox();
257 <
258 <                        tblMods.setVisible(true);
259 <                } catch (Exception e) {
260 <                        e.printStackTrace();
261 <                }
242 >                if (!Settings.getInstance().isOfflineMode()) {
243 >                        try {
244 >                                DepotManager.getInstance().updateInformation(false,
245 >                                                new DepotCacheUpdateProgressListener() {
246 >
247 >                                                        @Override
248 >                                                        public void cacheUpdateProgress(String stepName,
249 >                                                                        int current, int total) {
250 >                                                                evt.setProgressEnd(total);
251 >                                                                evt.setProgressValue(current);
252 >                                                                evt.setProgressMessage(stepName);
253 >                                                        }
254 >                                                });
255 >                        } catch (Exception e) {
256 >                                e.printStackTrace();
257 >                        }
258 >                }
259 >                ModManager.getInstance().init();
260 >                initTable();
261 >                initModTypeBox();
262 >
263 >                tblMods.setVisible(true);
264          }
265  
266          @SuppressWarnings("unused")
267 <        private void checkUpdates() {
268 <                if (Settings.getInstance().get("notifyupdates", true)) {
267 >        private void checkUpdates(Object evtSource) {
268 >                if ((evtSource != this)
269 >                                || Settings.getInstance().get("notifyupdates", true)) {
270 >                        if (Settings.getInstance().isOfflineMode()) {
271 >                                if (evtSource != this) {
272 >                                        JOptionPane.showMessageDialog(this,
273 >                                                        bundle.getString("offlineMode.text"),
274 >                                                        bundle.getString("offlineMode.title"),
275 >                                                        JOptionPane.WARNING_MESSAGE);
276 >                                }
277 >                        } else {
278 >                                TreeSet<Mod> mods = ModManager.getInstance().getUpdatableMods();
279 >                                TreeSet<Mod> tools = ModManager.getInstance()
280 >                                                .getUpdatableTools();
281 >                                int size = 0;
282 >                                String strMods = "";
283 >                                for (Mod m : mods) {
284 >                                        size += m.getZipSize();
285 >                                        if (strMods.length() > 0)
286 >                                                strMods += "<br>";
287 >                                        strMods += " - " + m.getName();
288 >                                }
289 >                                String strTools = "";
290 >                                for (Mod m : tools) {
291 >                                        size += m.getZipSize();
292 >                                        if (strTools.length() > 0)
293 >                                                strTools += "<br>";
294 >                                        strTools += " - " + m.getName();
295 >                                }
296 >                                String message = "<html>";
297 >                                message += String.format(
298 >                                                bundle.getString("updatesAvailable.text"), strMods,
299 >                                                strTools, SizeFormatter.format(size, 3));
300 >                                message += "</html>";
301 >                                int res = JOptionPane
302 >                                                .showConfirmDialog(this, message,
303 >                                                                bundle.getString("updatesAvailable.title"),
304 >                                                                JOptionPane.YES_NO_OPTION,
305 >                                                                JOptionPane.QUESTION_MESSAGE);
306 >                                if (res == JOptionPane.YES_OPTION) {
307 >                                        execUpdates = new TreeSet<Mod>();
308 >                                        execUpdates.addAll(mods);
309 >                                        execUpdates.addAll(tools);
310 >                                }
311 >                        }
312 >                }
313 >        }
314 >
315 >        @DoInBackground(progressMessage = "doUpdate.title", cancelable = false, indeterminateProgress = false)
316 >        private void doUpdate(final BackgroundEvent evt) {
317 >                if (execUpdates != null) {
318                          // TODO
319 +                        System.out.println("Update: " + execUpdates.toString());
320 +                        // TODO: install new tools if previously installed
321                  }
322 +                execUpdates = null;
323          }
324  
325          @SuppressWarnings("unused")
# Line 350 | Line 416 | public class MainWin extends JFrame impl
416  
417          @DoInBackground(progressMessage = "mandatoryFiles.title", cancelable = false, indeterminateProgress = false)
418          private void checkMandatoryFiles(final BackgroundEvent evt) {
419 <                TreeSet<Mod> mand = new TreeSet<Mod>();
420 <                for (Mod m : ModManager.getInstance().getMandatoryTools()) {
421 <                        if (m.isNewerAvailable()) {
422 <                                mand.add(m);
423 <                        }
424 <                }
425 <                for (Mod m : ModManager.getInstance().getMandatoryMods()) {
426 <                        if (m.isNewerAvailable()) {
427 <                                mand.add(m);
428 <                        }
429 <                }
430 <                if (mand.size() > 0) {
431 <                        ModDownloader m = new ModDownloader(mand,
432 <                                        new ModDownloaderListener() {
433 <                                                @Override
434 <                                                public void updateStatus(ModDownloader source,
435 <                                                                State state, int filesDown, int filesTotal,
436 <                                                                int bytesDown, int bytesTotal, int duration,
437 <                                                                int remaining, int speed) {
438 <                                                        evt.setProgressEnd(filesTotal);
439 <                                                        evt.setProgressValue(filesDown);
440 <                                                }
441 <                                        });
442 <                        while (!m.isFinished()) {
443 <                                try {
444 <                                        Thread.sleep(10);
445 <                                } catch (InterruptedException e) {
446 <                                        e.printStackTrace();
419 >                if (!Settings.getInstance().isOfflineMode()) {
420 >                        TreeSet<Mod> mand = new TreeSet<Mod>();
421 >                        for (Mod m : ModManager.getInstance().getMandatoryTools()) {
422 >                                if (m.isNewerAvailable()) {
423 >                                        mand.add(m);
424 >                                }
425 >                        }
426 >                        for (Mod m : ModManager.getInstance().getMandatoryMods()) {
427 >                                if (m.isNewerAvailable()) {
428 >                                        mand.add(m);
429 >                                }
430 >                        }
431 >                        if (mand.size() > 0) {
432 >                                ModDownloader m = new ModDownloader(mand,
433 >                                                new ModDownloaderListener() {
434 >                                                        @Override
435 >                                                        public void updateStatus(ModDownloader source,
436 >                                                                        State state, int filesDown, int filesTotal,
437 >                                                                        int bytesDown, int bytesTotal,
438 >                                                                        int duration, int remaining, int speed) {
439 >                                                                evt.setProgressEnd(filesTotal);
440 >                                                                evt.setProgressValue(filesDown);
441 >                                                        }
442 >                                                });
443 >                                while (!m.isFinished()) {
444 >                                        try {
445 >                                                Thread.sleep(10);
446 >                                        } catch (InterruptedException e) {
447 >                                                e.printStackTrace();
448 >                                        }
449                                  }
450                          }
451 +                        evt.setProgressMessage(bundle
452 +                                        .getString("mandatoryToolsInstall.title"));
453 +                        Installer
454 +                                        .installTools(ModManager.getInstance().getMandatoryTools());
455                  }
384                evt.setProgressMessage(bundle.getString("mandatoryToolsInstall.title"));
385                Installer.installTools(ModManager.getInstance().getMandatoryTools());
456          }
457  
458          @DoInBackground(progressMessage = "installing.title", cancelable = false, indeterminateProgress = false)
459 <        private boolean install(final BackgroundEvent evt) {
459 >        private void install(final BackgroundEvent evt) {
460                  TreeSet<Mod> mods = new TreeSet<Mod>();
461                  mods.addAll(ModManager.getInstance().getMandatoryMods());
462                  mods.addAll(model.getSelectedMods());
463  
464                  boolean instReady = false;
465 +                installDone = EInstallResult.DONE;
466  
467                  while (!instReady) {
397                        System.out.println("Checking downloads:");
468                          TreeSet<Mod> toDownload = new TreeSet<Mod>();
469                          for (Mod m : mods) {
470                                  if (!m.isLocalAvailable())
471                                          toDownload.add(m);
472                          }
473 +                        if (Settings.getInstance().isOfflineMode()) {
474 +                                installDone = EInstallResult.OFFLINE;
475 +                                break;
476 +                        }
477                          if (toDownload.size() > 0) {
404                                System.out.println("Download files: " + toDownload.toString());
478                                  Downloader dl = new Downloader(toDownload);
479                                  try {
480                                          dl.setVisible(true);
# Line 424 | Line 497 | public class MainWin extends JFrame impl
497                                  HashMap<Mod, HashSet<Mod>> conflicts = ModManager.getInstance()
498                                                  .checkIncompabitilites(mods);
499                                  if (conflicts.size() > 0) {
500 +                                        installDone = EInstallResult.INCOMPATIBLE;
501                                          System.err.println("Incompatible mods: "
502                                                          + conflicts.toString());
503                                          break;
# Line 434 | Line 508 | public class MainWin extends JFrame impl
508                  }
509  
510                  if (instReady) {
437                        System.out.println("Install mods: " + mods.toString());
438
511                          Installer.install(mods, new InstallProgressListener() {
512                                  @Override
513                                  public void installProgressUpdate(int done, int total,
# Line 445 | Line 517 | public class MainWin extends JFrame impl
517                                          evt.setProgressMessage(step);
518                                  }
519                          });
520 <                        return true;
520 >                        installDone = EInstallResult.DONE;
521                  }
450                return false;
522          }
523  
524          @SuppressWarnings("unused")
525          private void installDone() {
526 <                JOptionPane.showMessageDialog(this,
527 <                                bundle.getString("installDone.text"),
528 <                                bundle.getString("installDone.title"),
529 <                                JOptionPane.INFORMATION_MESSAGE);
526 >                switch (installDone) {
527 >                        case DONE:
528 >                                JOptionPane.showMessageDialog(this,
529 >                                                bundle.getString("installDone.text"),
530 >                                                bundle.getString("installDone.title"),
531 >                                                JOptionPane.INFORMATION_MESSAGE);
532 >                                break;
533 >                        case OFFLINE:
534 >                                JOptionPane.showMessageDialog(this,
535 >                                                bundle.getString("offlineMode.text"),
536 >                                                bundle.getString("offlineMode.title"),
537 >                                                JOptionPane.WARNING_MESSAGE);
538 >                                break;
539 >                        case INCOMPATIBLE:
540 >                                break;
541 >                }
542          }
543  
544          private void modSelection(Mod m) {
# Line 464 | Line 547 | public class MainWin extends JFrame impl
547                  lblDescriptionVal.setText("");
548                  lblTypesVal.setText("");
549                  lblPlatformVal.setText("");
550 +                lblPackageNumberVal.setText("");
551                  if (m != null) {
552                          lblSubmitterVal.setText(m.getName());
553                          lblCreatorVal.setText(m.getCreator());
# Line 477 | Line 561 | public class MainWin extends JFrame impl
561                          }
562                          lblTypesVal.setText(types);
563                          lblPlatformVal.setText(m.getPlatform().toString());
564 +                        lblPackageNumberVal.setText(m.getPackageNumberString());
565                  }
481                // TODO
566          }
567  
568          @SuppressWarnings("unused")
# Line 498 | Line 582 | public class MainWin extends JFrame impl
582          @SuppressWarnings("unused")
583          private void checkInitialize() {
584                  if (!Installer.isEditionInitialized()) {
585 <                        int res = JOptionPane.showConfirmDialog(this,
586 <                                        bundle.getString("askInitialize.text"),
587 <                                        bundle.getString("askInitialize.title"),
588 <                                        JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
589 <                        if (res == JOptionPane.NO_OPTION) {
506 <                                saveLocalData();
585 >                        if (!OniSplit.isOniSplitInstalled()) {
586 >                                JOptionPane.showMessageDialog(this,
587 >                                                bundle.getString("noOniSplit.text"),
588 >                                                bundle.getString("noOniSplit.title"),
589 >                                                JOptionPane.ERROR_MESSAGE);
590                                  exit();
591 +                        } else {
592 +                                int res = JOptionPane
593 +                                                .showConfirmDialog(this,
594 +                                                                bundle.getString("askInitialize.text"),
595 +                                                                bundle.getString("askInitialize.title"),
596 +                                                                JOptionPane.YES_NO_OPTION,
597 +                                                                JOptionPane.QUESTION_MESSAGE);
598 +                                if (res == JOptionPane.NO_OPTION) {
599 +                                        saveLocalData();
600 +                                        exit();
601 +                                }
602                          }
603                  }
604          }

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)