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 604 by alloc, Sat Jan 12 22:48:33 2013 UTC vs.
Revision 605 by alloc, Sun Jan 13 19:11:07 2013 UTC

# Line 1 | Line 1
1   package net.oni2.aeinstaller.gui;
2  
3   import java.io.File;
4 + import java.io.IOException;
5   import java.util.ArrayList;
6 + import java.util.HashMap;
7 + import java.util.HashSet;
8   import java.util.List;
9   import java.util.ResourceBundle;
10   import java.util.TreeMap;
11   import java.util.TreeSet;
12 + import java.util.Vector;
13  
14   import javax.swing.JButton;
15   import javax.swing.JComboBox;
# Line 41 | Line 45 | import net.oni2.aeinstaller.backend.mods
45   import net.oni2.aeinstaller.backend.oni.InstallProgressListener;
46   import net.oni2.aeinstaller.backend.oni.Installer;
47   import net.oni2.aeinstaller.gui.about.AboutDialog;
48 + import net.oni2.aeinstaller.gui.downloadwindow.Downloader;
49   import net.oni2.aeinstaller.gui.modtable.DownloadSizeListener;
50   import net.oni2.aeinstaller.gui.modtable.ModTableFilter;
51   import net.oni2.aeinstaller.gui.modtable.ModTableModel;
# Line 96 | Line 101 | public class MainWin extends JFrame impl
101                  }
102  
103                  getRootPane().setDefaultButton(btnInstall);
104 +                lblDownloadSizeVal.setText(SizeFormatter.format(0, 2));
105          }
106  
107          private void initModTypeBox() {
# Line 159 | Line 165 | public class MainWin extends JFrame impl
165                  // }
166          }
167  
162        private boolean askClose() {
163                int res = JOptionPane.showConfirmDialog(this,
164                                bundle.getString("askClose.text"),
165                                bundle.getString("askClose.title"), JOptionPane.YES_NO_OPTION,
166                                JOptionPane.QUESTION_MESSAGE);
167                return res == JOptionPane.YES_OPTION;
168        }
169
168          private void exit() {
169                  setVisible(false);
170                  dispose();
# Line 318 | Line 316 | public class MainWin extends JFrame impl
316                                                  @Override
317                                                  public void updateStatus(ModDownloader source,
318                                                                  State state, int filesDown, int filesTotal,
319 <                                                                int bytesDown, int bytesTotal) {
319 >                                                                int bytesDown, int bytesTotal, int duration,
320 >                                                                int remaining, int speed) {
321                                                          evt.setProgressEnd(filesTotal);
322                                                          evt.setProgressValue(filesDown);
323                                                  }
# Line 338 | Line 337 | public class MainWin extends JFrame impl
337  
338          @DoInBackground(progressMessage = "installing.title", cancelable = false, indeterminateProgress = false)
339          private void install(final BackgroundEvent evt) {
341                // TODO: Conflicts/Dependencies
342
340                  TreeSet<Mod> mods = new TreeSet<Mod>();
341                  mods.addAll(ModManager.getInstance().getMandatoryMods());
342                  mods.addAll(model.getSelectedMods());
343  
344 <                System.out.println("Install mods:");
348 <                for (Mod m : mods) {
349 <                        System.out.println("  " + m.getPackageNumberString() + ": "
350 <                                        + m.getName());
351 <                }
344 >                boolean instReady = false;
345  
346 <                Installer.install(mods, new InstallProgressListener() {
347 <                        @Override
348 <                        public void installProgressUpdate(int done, int total, String step) {
349 <                                evt.setProgressEnd(total);
350 <                                evt.setProgressValue(done);
351 <                                evt.setProgressMessage(step);
346 >                while (!instReady) {
347 >                        System.out.println("Checking downloads:");
348 >                        TreeSet<Mod> toDownload = new TreeSet<Mod>();
349 >                        for (Mod m : mods) {
350 >                                if (!m.isLocalAvailable())
351 >                                        toDownload.add(m);
352                          }
353 <                });
353 >                        if (toDownload.size() > 0) {
354 >                                System.out.println("Download files: " + toDownload.toString());
355 >                                Downloader dl = new Downloader(toDownload);
356 >                                dl.setVisible(true);
357 >                                if (!dl.isFinished())
358 >                                        break;
359 >                        }
360 >                        HashMap<Mod, HashSet<Mod>> dependencies = ModManager.getInstance()
361 >                                        .checkDependencies(mods);
362 >                        if (dependencies.size() > 0) {
363 >                                System.out.println("Unmet dependencies: "
364 >                                                + dependencies.toString());
365 >                                for (Mod m : dependencies.keySet()) {
366 >                                        for (Mod mDep : dependencies.get(m))
367 >                                                mods.add(mDep);
368 >                                }
369 >                        } else {
370 >                                HashMap<Mod, HashSet<Mod>> conflicts = ModManager.getInstance()
371 >                                                .checkConflicts(mods);
372 >                                if (conflicts.size() > 0) {
373 >                                        System.err.println("Conflicting mods: "
374 >                                                        + conflicts.toString());
375 >                                        break;
376 >                                } else {
377 >                                        instReady = true;
378 >                                }
379 >                        }
380 >                }
381 >
382 >                if (instReady) {
383 >                        Installer.install(mods, new InstallProgressListener() {
384 >                                @Override
385 >                                public void installProgressUpdate(int done, int total,
386 >                                                String step) {
387 >                                        evt.setProgressEnd(total);
388 >                                        evt.setProgressValue(done);
389 >                                        evt.setProgressMessage(step);
390 >                                }
391 >                        });
392 >                }
393 >
394 >                JOptionPane.showMessageDialog(this,
395 >                                bundle.getString("installDone.text"),
396 >                                bundle.getString("installDone.title"),
397 >                                JOptionPane.INFORMATION_MESSAGE);
398          }
399  
400          private void modSelection(Mod m) {
# Line 408 | Line 445 | public class MainWin extends JFrame impl
445                          }
446                  }
447          }
448 +        
449 +        private Vector<String> getBasicOniLaunchParams() {
450 +                Vector<String> params = new Vector<String>();
451 +                switch (Settings.getPlatform()) {
452 +                        case WIN:
453 +                                params.add(new File(Paths.getEditionBasePath(), "Oni.exe")
454 +                                                .getPath());
455 +                                break;
456 +                        case MACOS:
457 +                                params.add(new File(Paths.getEditionBasePath(), "Oni")
458 +                                                .getPath());
459 +                                break;
460 +                        case LINUX:
461 +                                String wine = Settings.getWinePath();
462 +                                if (wine != null) {
463 +                                        params.add(wine);
464 +                                        params.add(new File(Paths.getEditionBasePath(), "Oni.exe")
465 +                                                        .getPath());
466 +                                }
467 +                                break;
468 +                        default:
469 +                }
470 +                if (params.size() > 0) {
471 +                        params.add("-debugfiles");
472 +                }
473 +                return params;
474 +        }
475 +
476 +        @SuppressWarnings("unused")
477 +        private void oniFull() {
478 +                Vector<String> params = getBasicOniLaunchParams();
479 +                if (params.size() > 0) {
480 +                        try {
481 +                                new ProcessBuilder(params).start();
482 +                        } catch (IOException e) {
483 +                                // TODO Auto-generated catch block
484 +                                e.printStackTrace();
485 +                        }
486 +                }
487 +        }
488 +
489 +        @SuppressWarnings("unused")
490 +        private void oniWin() {
491 +                Vector<String> params = getBasicOniLaunchParams();
492 +                if (params.size() > 0) {
493 +                        params.add("-noswitch");
494 +                        try {
495 +                                new ProcessBuilder(params).start();
496 +                        } catch (IOException e) {
497 +                                // TODO Auto-generated catch block
498 +                                e.printStackTrace();
499 +                        }
500 +                }
501 +        }
502  
503          @Override
504          public void handleAbout(ApplicationEvent event) {
# Line 434 | Line 525 | public class MainWin extends JFrame impl
525  
526          @Override
527          public void handleQuit(ApplicationEvent event) {
528 <                if (askClose()) {
529 <                        event.setHandled(true);
530 <                        saveLocalData();
440 <                        exit();
441 <                } else {
442 <                        event.setHandled(false);
443 <                }
528 >                event.setHandled(true);
529 >                saveLocalData();
530 >                exit();
531          }
532  
533          @Override

Diff Legend

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