1 /* 2 * Created on May 29, 2006 2:13:41 PM 3 * Copyright (C) Azureus Software, Inc, All Rights Reserved. 4 * 5 * This program is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU General Public License 7 * as published by the Free Software Foundation; either version 2 8 * of the License, or (at your option) any later version. 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * You should have received a copy of the GNU General Public License 14 * along with this program; if not, write to the Free Software 15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16 */ 17 package com.aelitis.azureus.ui.swt; 18 19 import java.io.File; 20 import java.io.IOException; 21 import java.util.Iterator; 22 import java.util.List; 23 24 import org.eclipse.swt.SWT; 25 import org.eclipse.swt.graphics.Point; 26 import org.eclipse.swt.graphics.Rectangle; 27 import org.eclipse.swt.widgets.Display; 28 import org.eclipse.swt.widgets.Shell; 29 import org.gudy.azureus2.core3.config.COConfigurationManager; 30 import org.gudy.azureus2.core3.download.DownloadManager; 31 import org.gudy.azureus2.core3.global.GlobalManager; 32 import org.gudy.azureus2.core3.internat.MessageText; 33 import org.gudy.azureus2.core3.security.SESecurityManager; 34 import org.gudy.azureus2.core3.util.*; 35 import org.gudy.azureus2.plugins.PluginEvent; 36 import org.gudy.azureus2.plugins.PluginEventListener; 37 import org.gudy.azureus2.plugins.utils.DelayedTask; 38 import org.gudy.azureus2.pluginsimpl.local.PluginInitializer; 39 import org.gudy.azureus2.pluginsimpl.local.utils.UtilitiesImpl; 40 import org.gudy.azureus2.ui.swt.*; 41 import org.gudy.azureus2.ui.swt.auth.AuthenticatorWindow; 42 import org.gudy.azureus2.ui.swt.auth.CertificateTrustWindow; 43 import org.gudy.azureus2.ui.swt.auth.CryptoWindow; 44 import org.gudy.azureus2.ui.swt.mainwindow.*; 45 import org.gudy.azureus2.ui.swt.networks.SWTNetworkSelection; 46 import org.gudy.azureus2.ui.swt.pluginsinstaller.InstallPluginWizard; 47 import org.gudy.azureus2.ui.swt.progress.ProgressWindow; 48 import org.gudy.azureus2.ui.swt.shells.MessageBoxShell; 49 import org.gudy.azureus2.ui.swt.update.UpdateMonitor; 50 import org.gudy.azureus2.ui.swt.updater2.PreUpdateChecker; 51 import org.gudy.azureus2.ui.swt.updater2.SWTUpdateChecker; 52 53 import com.aelitis.azureus.core.*; 54 import com.aelitis.azureus.core.messenger.ClientMessageContext; 55 import com.aelitis.azureus.core.messenger.PlatformMessenger; 56 import com.aelitis.azureus.core.messenger.config.PlatformConfigMessenger; 57 import com.aelitis.azureus.core.torrent.PlatformTorrentUtils; 58 import com.aelitis.azureus.core.util.CopyOnWriteList; 59 import com.aelitis.azureus.core.versioncheck.VersionCheckClient; 60 import com.aelitis.azureus.core.versioncheck.VersionCheckClientListener; 61 import com.aelitis.azureus.ui.IUIIntializer; 62 import com.aelitis.azureus.ui.InitializerListener; 63 import com.aelitis.azureus.ui.UIFunctions; 64 import com.aelitis.azureus.ui.UIFunctionsManager; 65 import com.aelitis.azureus.ui.UserPrompterResultListener; 66 import com.aelitis.azureus.ui.swt.browser.listener.*; 67 import com.aelitis.azureus.ui.swt.browser.msg.MessageDispatcherSWT; 68 import com.aelitis.azureus.ui.swt.devices.DeviceManagerUI; 69 import com.aelitis.azureus.ui.swt.feature.FeatureManagerUI; 70 import com.aelitis.azureus.ui.swt.shells.main.MainWindowFactory; 71 import com.aelitis.azureus.ui.swt.subscriptions.SubscriptionManagerUI; 72 import com.aelitis.azureus.ui.swt.utils.UIMagnetHandler; 73 import com.aelitis.azureus.util.InitialisationFunctions; 74 75 /** 76 * @author TuxPaper 77 * @created May 29, 2006 78 * 79 * @notes 80 * The old Initializer would store up LogEvents if the UI had the console set 81 * to auto-open, and send the events to the mainwindow when it was initialized 82 * This Initializer doesn't do this (yet) 83 final ArrayList logEvents = new ArrayList(); 84 ILogEventListener logListener = null; 85 if (COConfigurationManager.getBooleanParameter("Open Console", false)) { 86 logListener = new ILogEventListener() { 87 public void log(LogEvent event) { 88 logEvents.add(event); 89 } 90 }; 91 Logger.addListener(logListener); 92 } 93 final ILogEventListener finalLogListener = logListener; 94 * 95 * The old initializer sets a semaphore when it starts loading IPFilters, 96 * and on AzureusCoreListener.coreStarted would: 97 IpFilterManager ipFilterManager = azureus_core.getIpFilterManager(); 98 if (ipFilterManager != null) { 99 String s = MessageText.getString("splash.loadIpFilters"); 100 do { 101 reportCurrentTask(s); 102 s += "."; 103 } while (!semFilterLoader.reserve(3000)); 104 } 105 */ 106 public class Initializer 107 implements IUIIntializer 108 { 109 // Whether to initialize the UI before the core has been started 110 private static boolean STARTUP_UIFIRST = System.getProperty("ui.startfirst", "1").equals("1"); 111 112 // Used in debug to find out how long initialization took 113 public static final long startTime = System.currentTimeMillis(); 114 115 private StartServer startServer; 116 117 private final AzureusCore core; 118 119 private final String[] args; 120 121 private CopyOnWriteList listeners = new CopyOnWriteList(); 122 123 private AEMonitor listeners_mon = new AEMonitor("Initializer:l"); 124 125 private int curPercent = 0; 126 127 private AESemaphore semFilterLoader = new AESemaphore("filter loader"); 128 129 private AESemaphore init_task = new AESemaphore("delayed init"); 130 131 private MainWindowFactory.MainWindowInitStub windowInitStub;; 132 133 private static Initializer lastInitializer; 134 135 /** 136 * Main Initializer. Usually called by reflection via 137 * org.gudy.azureus2.ui.swt.Main(String[]) 138 * @param core 139 * @param args 140 */ Initializer(final AzureusCore core, StartServer startServer, String[] args)141 public Initializer(final AzureusCore core, StartServer startServer, String[] args) { 142 this.core = core; 143 this.args = args; 144 this.startServer = startServer; 145 lastInitializer = this; 146 147 Thread filterLoaderThread = new AEThread("filter loader", true) { 148 public void runSupport() { 149 try { 150 core.getIpFilterManager().getIPFilter(); 151 } finally { 152 semFilterLoader.releaseForever(); 153 } 154 } 155 }; 156 filterLoaderThread.setPriority(Thread.MIN_PRIORITY); 157 filterLoaderThread.start(); 158 159 try { 160 SWTThread.createInstance(this); 161 } catch(SWTThreadAlreadyInstanciatedException e) { 162 Debug.printStackTrace( e ); 163 } 164 } 165 cleanupOldStuff()166 private void cleanupOldStuff() { 167 File v3Shares = new File(SystemProperties.getUserPath(), "v3shares"); 168 if (v3Shares.isDirectory()) { 169 FileUtil.recursiveDeleteNoCheck(v3Shares); 170 } 171 File dirFriends = new File(SystemProperties.getUserPath(), "friends"); 172 if (dirFriends.isDirectory()) { 173 FileUtil.recursiveDeleteNoCheck(dirFriends); 174 } 175 File dirMedia = new File(SystemProperties.getUserPath(), "media"); 176 if (dirMedia.isDirectory()) { 177 FileUtil.recursiveDeleteNoCheck(dirMedia); 178 } 179 deleteConfig("v3.Friends.dat"); 180 deleteConfig("unsentdata.config"); 181 AzureusCoreFactory.addCoreRunningListener(new AzureusCoreRunningListener() { 182 public void azureusCoreRunning(final AzureusCore core) { 183 new AEThread2("cleanupOldStuff", true) { 184 public void run() { 185 GlobalManager gm = core.getGlobalManager(); 186 List dms = gm.getDownloadManagers(); 187 for (Object o : dms) { 188 DownloadManager dm = (DownloadManager) o; 189 if (dm != null) { 190 String val = PlatformTorrentUtils.getContentMapString( 191 dm.getTorrent(), "Ad ID"); 192 if (val != null) { 193 try { 194 gm.removeDownloadManager(dm, true, true); 195 } catch (Exception e) { 196 } 197 } 198 } 199 } 200 } 201 }.start(); 202 } 203 }); 204 } 205 deleteConfig(String name)206 private void deleteConfig(String name) { 207 try { 208 File file = new File(SystemProperties.getUserPath(), name); 209 if (file.exists()) { 210 file.delete(); 211 } 212 } catch (Exception e) { 213 } 214 try { 215 File file = new File(SystemProperties.getUserPath(), name + ".bak"); 216 if (file.exists()) { 217 file.delete(); 218 } 219 } catch (Exception e) { 220 } 221 } 222 runInSWTThread()223 public void runInSWTThread() { 224 UISwitcherUtil.calcUIMode(); 225 226 try { 227 initializePlatformClientMessageContext(); 228 } catch (Exception e) { 229 Debug.out(e); 230 } 231 new AEThread2("cleanupOldStuff", true) { 232 public void run() { 233 cleanupOldStuff(); 234 } 235 }.start(); 236 237 boolean uiClassic = COConfigurationManager.getStringParameter("ui").equals("az2"); 238 239 if (!uiClassic) { 240 PlatformConfigMessenger.login(0); 241 } 242 243 VersionCheckClient.getSingleton().addVersionCheckClientListener(true, 244 new VersionCheckClientListener() { 245 public void versionCheckStarted(String reason) { 246 if (VersionCheckClient.REASON_UPDATE_CHECK_START.equals(reason) 247 || VersionCheckClient.REASON_UPDATE_CHECK_PERIODIC.equals(reason)) { 248 PlatformConfigMessenger.sendVersionServerMap(VersionCheckClient.constructVersionCheckMessage(reason)); 249 } 250 } 251 }); 252 253 FeatureManagerUI.registerWithFeatureManager(); 254 255 COConfigurationManager.setBooleanDefault("ui.startfirst", true); 256 STARTUP_UIFIRST = STARTUP_UIFIRST 257 && COConfigurationManager.getBooleanParameter("ui.startfirst", true); 258 259 if (!STARTUP_UIFIRST) { 260 return; 261 } 262 263 // Ensure colors initialized 264 Colors.getInstance(); 265 266 UIConfigDefaultsSWT.initialize(); 267 268 UIConfigDefaultsSWTv3.initialize(core); 269 270 checkInstallID(); 271 272 windowInitStub = MainWindowFactory.createAsync( Display.getDefault(), this ); 273 } 274 275 /** 276 * 277 * 278 * @since 4.4.0.5 279 */ checkInstallID()280 private void checkInstallID() { 281 String storedInstallID = COConfigurationManager.getStringParameter("install.id", null); 282 String installID = ""; 283 File file = FileUtil.getApplicationFile("installer.log"); 284 if (file != null) { 285 try { 286 String s = FileUtil.readFileAsString(file, 1024); 287 String[] split = s.split("[\r\n]"); 288 for (int i = 0; i < split.length; i++) { 289 int posEquals = split[i].indexOf('='); 290 if (posEquals > 0 && split[i].length() > posEquals + 1) { 291 installID = split[i].substring(posEquals + 1); 292 } 293 } 294 } catch (IOException e) { 295 } 296 } 297 298 if (storedInstallID == null || !storedInstallID.equals(installID)) { 299 COConfigurationManager.setParameter("install.id", installID); 300 } 301 } 302 run()303 public void run() { 304 305 DelayedTask delayed_task = UtilitiesImpl.addDelayedTask( "SWT Initialisation", new Runnable() 306 { 307 public void 308 run() 309 { 310 init_task.reserve(); 311 } 312 }); 313 314 delayed_task.queueFirst(); 315 316 // initialise the SWT locale util 317 long startTime = SystemTime.getCurrentTime(); 318 319 new LocaleUtilSWT(core); 320 321 final Display display = SWTThread.getInstance().getDisplay(); 322 323 new UIMagnetHandler(core); 324 325 if (!STARTUP_UIFIRST) { 326 // Ensure colors initialized 327 Colors.getInstance(); 328 329 UIConfigDefaultsSWT.initialize(); 330 UIConfigDefaultsSWTv3.initialize(core); 331 } else { 332 COConfigurationManager.setBooleanDefault("Show Splash", false); 333 } 334 335 if (COConfigurationManager.getBooleanParameter("Show Splash")) { 336 display.asyncExec(new AERunnable() { 337 public void runSupport() { 338 new SplashWindow(display, Initializer.this); 339 } 340 }); 341 } 342 343 System.out.println("Locale Initializing took " 344 + (SystemTime.getCurrentTime() - startTime) + "ms"); 345 startTime = SystemTime.getCurrentTime(); 346 347 core.addListener(new AzureusCoreListener() { 348 int fakePercent = Math.min(70, 100 - curPercent); 349 350 long startTime = SystemTime.getCurrentTime(); 351 long lastTaskTimeSecs = startTime / 500; 352 353 String sLastTask; 354 355 public void reportCurrentTask(AzureusCoreOperation op, String currentTask) { 356 if (op.getOperationType() != AzureusCoreOperation.OP_INITIALISATION) { 357 return; 358 } 359 360 Initializer.this.reportCurrentTask(currentTask); 361 362 long now = SystemTime.getCurrentTime(); 363 if (fakePercent > 0 && lastTaskTimeSecs != now / 200) { 364 lastTaskTimeSecs = SystemTime.getCurrentTime() / 200; 365 fakePercent--; 366 Initializer.this.reportPercent(curPercent + 1); 367 } 368 369 if (Constants.IS_CVS_VERSION && sLastTask != null && !sLastTask.startsWith("Loading Torrent")) { 370 371 long diff = now - startTime; 372 if (diff > 10 && diff < 1000 * 60 * 5) { 373 System.out.println(TimeFormatter.milliStamp() + " Core: " + diff + "ms for activity between '" + sLastTask + "' and '" + currentTask + "'"); 374 } 375 startTime = SystemTime.getCurrentTime(); 376 } 377 sLastTask = currentTask; 378 //System.out.println(currentTask); 379 } 380 381 public void reportPercent(AzureusCoreOperation op, int percent) { 382 /* 383 if (op.getOperationType() != AzureusCoreOperation.OP_INITIALISATION) { 384 return; 385 } 386 if (percent == 100) { 387 long now = SystemTime.getCurrentTime(); 388 long diff = now - startTime; 389 if (diff > 10 && diff < 1000 * 60 * 5) { 390 System.out.println(" Core: " + diff + "ms for " + sLastTask); 391 } 392 } 393 */ 394 // TODO Auto-generated method stub 395 } 396 397 }); 398 399 core.addLifecycleListener(new AzureusCoreLifecycleAdapter() { 400 private GlobalManager gm; 401 402 public void 403 componentCreated( 404 AzureusCore core, 405 AzureusCoreComponent component ) 406 { 407 Initializer.this.reportPercent(curPercent + 1); 408 409 if (component instanceof GlobalManager){ 410 411 reportCurrentTaskByKey("splash.initializePlugins"); 412 413 gm = (GlobalManager) component; 414 415 InitialisationFunctions.earlyInitialisation(core); 416 417 } 418 } 419 420 // @see com.aelitis.azureus.core.AzureusCoreLifecycleAdapter#started(com.aelitis.azureus.core.AzureusCore) 421 public void started(AzureusCore core) { 422 boolean main_window_will_report_complete = false; 423 424 try { 425 426 InitialisationFunctions.lateInitialisation(core); 427 if (gm == null) { 428 return; 429 } 430 431 // Ensure colors initialized 432 Colors.getInstance(); 433 434 Initializer.this.reportPercent(curPercent + 1); 435 new UserAlerts(gm); 436 437 reportCurrentTaskByKey("splash.initializeGui"); 438 439 Initializer.this.reportPercent(curPercent + 1); 440 441 main_window_will_report_complete = true; 442 443 if (STARTUP_UIFIRST) { 444 windowInitStub.init(core); 445 } else { 446 MainWindowFactory.create( core, Display.getDefault(), Initializer.this ); 447 } 448 449 reportCurrentTaskByKey("splash.openViews"); 450 451 SWTUpdateChecker.initialize(); 452 453 PreUpdateChecker.initialize(core, 454 COConfigurationManager.getStringParameter("ui")); 455 456 UpdateMonitor.getSingleton(core); // setup the update monitor 457 458 //Tell listeners that all is initialized : 459 Alerts.initComplete(); 460 461 //Finally, open torrents if any. 462 for (int i = 0; i < args.length; i++) { 463 464 String arg = args[i]; 465 466 if ( arg.equalsIgnoreCase( "--open" )){ 467 468 // can get this here so skip as not a torrent! 469 470 }else{ 471 try { 472 TorrentOpener.openTorrent( arg ); 473 474 } catch (Throwable e) { 475 476 Debug.printStackTrace(e); 477 } 478 } 479 } 480 } 481 finally{ 482 483 if ( !main_window_will_report_complete ){ 484 init_task.release(); 485 } 486 } 487 488 } 489 490 public void stopping(AzureusCore core) { 491 Alerts.stopInitiated(); 492 } 493 494 public void stopped(AzureusCore core) { 495 } 496 497 public boolean syncInvokeRequired() { 498 return (true); 499 } 500 501 public boolean 502 requiresPluginInitCompleteBeforeStartedEvent() 503 { 504 return( false ); 505 } 506 507 public boolean stopRequested(AzureusCore _core) 508 throws AzureusCoreException { 509 return handleStopRestart(false); 510 } 511 512 public boolean restartRequested(final AzureusCore core) { 513 return handleStopRestart(true); 514 } 515 516 }); 517 518 reportCurrentTaskByKey("splash.initializeCore"); 519 520 boolean uiClassic = COConfigurationManager.getStringParameter("ui").equals("az2"); 521 522 try{ 523 new SubscriptionManagerUI(); 524 525 }catch( Throwable e ){ 526 527 Debug.printStackTrace(e); 528 } 529 530 531 if (!uiClassic) { 532 try{ 533 new DeviceManagerUI( core ); 534 535 }catch( Throwable e ){ 536 537 Debug.printStackTrace(e); 538 } 539 } 540 541 if ( core.canStart()){ 542 543 core.start(); 544 545 reportPercent(50); 546 547 System.out.println("Core Initializing took " 548 + (SystemTime.getCurrentTime() - startTime) + "ms"); 549 startTime = SystemTime.getCurrentTime(); 550 551 reportCurrentTaskByKey("splash.initializeUIElements"); 552 553 // Ensure colors initialized 554 Colors.getInstance(); 555 556 reportPercent(curPercent + 1); 557 Alerts.init(); 558 559 reportPercent(curPercent + 1); 560 ProgressWindow.register(core); 561 562 reportPercent(curPercent + 1); 563 new SWTNetworkSelection(); 564 565 reportPercent(curPercent + 1); 566 new AuthenticatorWindow(); 567 new CryptoWindow(); 568 569 reportPercent(curPercent + 1); 570 new CertificateTrustWindow(); 571 572 InstallPluginWizard.register(core, display); 573 574 // finally check if an explicit open has been requested in case hidden in tray atm 575 576 for (int i = 0; i < args.length; i++) { 577 578 String arg = args[i]; 579 580 if ( arg.equalsIgnoreCase( "--open" )){ 581 582 UIFunctions uif = UIFunctionsManager.getUIFunctions(); 583 584 if ( uif != null ){ 585 586 uif.bringToFront(); 587 } 588 589 break; 590 } 591 } 592 }else{ 593 594 final AESemaphore sem = new AESemaphore( "waiter" ); 595 596 Utils.execSWTThread( 597 new Runnable() 598 { 599 public void 600 run() 601 { 602 MessageBoxShell mb = 603 new MessageBoxShell( 604 MessageText.getString( "msgbox.force.close.title" ), 605 MessageText.getString( 606 "msgbox.force.close.text", 607 new String[]{ core.getLockFile().getAbsolutePath() }), 608 new String[]{ MessageText.getString("Button.ok") }, 609 0 ); 610 611 mb.setIconResource( "error" ); 612 613 mb.setModal( true ); 614 615 mb.open( 616 new UserPrompterResultListener() 617 { 618 619 public void 620 prompterClosed( 621 int result ) 622 { 623 sem.releaseForever(); 624 } 625 }); 626 } 627 }); 628 629 sem.reserve(); 630 631 SESecurityManager.exitVM( 1 ); 632 } 633 } 634 stopIt(boolean isForRestart, boolean isCloseAreadyInProgress)635 public void stopIt(boolean isForRestart, boolean isCloseAreadyInProgress) 636 throws AzureusCoreException { 637 if (core != null && !isCloseAreadyInProgress) { 638 639 if (isForRestart) { 640 641 core.checkRestartSupported(); 642 } 643 } 644 645 try { 646 647 // Cursors.dispose(); 648 649 try { 650 UIFunctionsManager.getUIFunctions().getUIUpdater().stopIt(); 651 } catch (Exception e) { 652 Debug.out(e); 653 } 654 655 if (false) { 656 // No Unix as it will dispose before isTerminated is set, causing 657 // a 'user close' flag to be incorrectly set and used 658 Utils.execSWTThread(new AERunnable() { 659 public void runSupport() { 660 SWTThread instance = SWTThread.getInstance(); 661 if (instance == null || instance.isTerminated()) { 662 return; 663 } 664 Shell anyShell = Utils.findAnyShell(); 665 Point location = null; 666 if (anyShell != null) { 667 Rectangle bounds = anyShell.getBounds(); 668 location = new Point(bounds.x, bounds.y); 669 } 670 Shell[] shells = instance.getDisplay().getShells(); 671 for (Shell shell : shells) { 672 if (!shell.isDisposed()) { 673 shell.dispose(); 674 } 675 } 676 Shell shell = new Shell(instance.getDisplay(), SWT.BORDER | SWT.TITLE); 677 Utils.setShellIcon(shell); 678 shell.setText("Shutting Down Vuze.."); 679 shell.setSize(200, 0); 680 if (location != null) { 681 shell.setLocation(location); 682 } 683 shell.open(); 684 } 685 }); 686 } 687 688 } finally { 689 690 try{ 691 if ( core != null && !isCloseAreadyInProgress) { 692 693 try { 694 if (isForRestart) { 695 696 core.restart(); 697 698 } else { 699 700 long lStopStarted = System.currentTimeMillis(); 701 System.out.println("core.stop"); 702 core.stop(); 703 System.out.println("core.stop done in " 704 + (System.currentTimeMillis() - lStopStarted)); 705 } 706 } catch (Throwable e) { 707 708 // don't let any failure here cause the stop operation to fail 709 710 Debug.out(e); 711 } 712 } 713 }finally{ 714 715 // do this after closing core to minimise window when the we aren't 716 // listening and therefore another Azureus start can potentially get 717 // in and screw things up 718 719 if (startServer != null) { 720 startServer.stopIt(); 721 } 722 } 723 724 Utils.execSWTThread(new AERunnable() { 725 public void runSupport() { 726 SWTThread.getInstance().terminate(); 727 } 728 }); 729 730 } 731 } 732 733 // @see com.aelitis.azureus.ui.IUIIntializer#addListener(org.gudy.azureus2.ui.swt.mainwindow.InitializerListener) addListener(InitializerListener listener)734 public void addListener(InitializerListener listener) { 735 try { 736 listeners_mon.enter(); 737 738 listeners.add(listener); 739 } finally { 740 741 listeners_mon.exit(); 742 } 743 } 744 745 // @see com.aelitis.azureus.ui.IUIIntializer#removeListener(org.gudy.azureus2.ui.swt.mainwindow.InitializerListener) removeListener(InitializerListener listener)746 public void removeListener(InitializerListener listener) { 747 try { 748 listeners_mon.enter(); 749 750 listeners.remove(listener); 751 } finally { 752 753 listeners_mon.exit(); 754 } 755 } 756 reportCurrentTask(String currentTaskString)757 public void reportCurrentTask(String currentTaskString) { 758 try { 759 listeners_mon.enter(); 760 761 Iterator iter = listeners.iterator(); 762 while (iter.hasNext()) { 763 InitializerListener listener = (InitializerListener) iter.next(); 764 try { 765 listener.reportCurrentTask(currentTaskString); 766 } catch (Exception e) { 767 // ignore 768 } 769 } 770 } finally { 771 772 listeners_mon.exit(); 773 } 774 } 775 reportCurrentTaskByKey(String key)776 private void reportCurrentTaskByKey(String key) { 777 reportCurrentTask(MessageText.getString(key)); 778 } 779 increaseProgress()780 public void increaseProgress() { 781 if (curPercent < 100) { 782 reportPercent(curPercent + 1); 783 } 784 } 785 786 // @see com.aelitis.azureus.ui.IUIIntializer#abortProgress() abortProgress()787 public void abortProgress() { 788 reportPercent(101); 789 } 790 reportPercent(int percent)791 public void reportPercent(int percent) { 792 if (curPercent > percent) { 793 return; 794 } 795 796 curPercent = percent; 797 try { 798 listeners_mon.enter(); 799 800 Iterator iter = listeners.iterator(); 801 while (iter.hasNext()) { 802 InitializerListener listener = (InitializerListener) iter.next(); 803 try { 804 listener.reportPercent(percent); 805 } catch (Exception e) { 806 // ignore 807 } 808 } 809 810 if (percent > 100) { 811 listeners.clear(); 812 } 813 } finally { 814 815 listeners_mon.exit(); 816 } 817 } 818 819 public void initializationComplete()820 initializationComplete() 821 { 822 core.getPluginManager().firePluginEvent( PluginEvent.PEV_INITIALISATION_UI_COMPLETES ); 823 824 // Old Initializer would delay 8500 825 826 AzureusCoreFactory.addCoreRunningListener(new AzureusCoreRunningListener() { 827 public void azureusCoreRunning(AzureusCore core) { 828 new DelayedEvent( 829 "SWTInitComplete:delay", 830 500, 831 new AERunnable() 832 { 833 public void 834 runSupport() 835 { 836 /* 837 try { 838 String captureSnapshot = new Controller().captureSnapshot(ProfilingModes.SNAPSHOT_WITH_HEAP); 839 System.out.println(captureSnapshot); 840 } catch (Exception e) { 841 // TODO Auto-generated catch block 842 e.printStackTrace(); 843 } 844 */ 845 //System.out.println("Release Init. Task"); 846 init_task.release(); 847 } 848 }); 849 } 850 }); 851 } 852 853 /** 854 * 855 * 856 * @since 3.0.5.3 857 */ initializePlatformClientMessageContext()858 private void initializePlatformClientMessageContext() { 859 ClientMessageContext clientMsgContext = PlatformMessenger.getClientMessageContext(); 860 if (clientMsgContext != null) { 861 clientMsgContext.setMessageDispatcher(new MessageDispatcherSWT(clientMsgContext)); 862 clientMsgContext.addMessageListener(new TorrentListener()); 863 clientMsgContext.addMessageListener(new VuzeListener()); 864 clientMsgContext.addMessageListener(new DisplayListener(null)); 865 clientMsgContext.addMessageListener(new ConfigListener(null)); 866 } 867 PluginInitializer.getDefaultInterface().addEventListener(new PluginEventListener() { 868 public void handleEvent(PluginEvent ev) { 869 try { 870 int type = ev.getType(); 871 String event = null; 872 if (type == PluginEvent.PEV_PLUGIN_INSTALLED) { 873 event = "installed"; 874 } else if (type == PluginEvent.PEV_PLUGIN_UNINSTALLED) { 875 event = "uninstalled"; 876 } 877 if (event != null && (ev.getValue() instanceof String)) { 878 PlatformConfigMessenger.logPlugin(event, (String) ev.getValue()); 879 } 880 } catch (Exception e) { 881 Debug.out(e); 882 } 883 } 884 }); 885 } 886 887 public static boolean handleStopRestart( final boolean restart )888 handleStopRestart( 889 final boolean restart ) 890 { 891 UIFunctionsSWT functionsSWT = UIFunctionsManagerSWT.getUIFunctionsSWT(); 892 if (functionsSWT != null) { 893 return functionsSWT.dispose(restart, true); 894 } 895 896 return false; 897 } 898 getLastInitializer()899 public static Initializer getLastInitializer() { 900 return lastInitializer; 901 } 902 } 903