private async void Application_Startup(object o1, StartupEventArgs e1) { DispatcherUnhandledException += (o2, e2) => LogTo.Error(e2.Exception, "Unhandled exception"); _taskbarIcon = (TaskbarIcon)FindResource("TbIcon"); var selectionWdw = new CollectionSelectionWindow(); selectionWdw.ShowDialog(); var selectedCol = selectionWdw.Collection; if (selectionWdw.Collection != null) { SMA.SMA.Instance.OnSMStoppedEvent += Instance_OnSMStoppedEvent; if (await SMA.SMA.Instance.Start(selectedCol).ConfigureAwait(true) == false) { await Show.Window().For( new Alert( $"SMA failed to start. Please check the logs in '{SMAFileSystem.LogDir.FullPath}' for details.", "Error") ); Shutdown(); } } else { Shutdown(); } }
private void Application_Startup(object sender, StartupEventArgs e) { SyncContext = new DispatcherSynchronizationContext(); SynchronizationContext.SetSynchronizationContext(SyncContext); var selectionWdw = new CollectionSelectionWindow(); selectionWdw.ShowDialog(); var selectedCol = selectionWdw.Collection; if (selectionWdw.Collection != null) { if (SMA.Instance.Start(selectedCol)) { SMA.Instance.OnSMStoppedEvent += Instance_OnSMStoppedEvent; } } else { Shutdown(); } }
private async Task LoadApp(SMAParameters args) { // // Installer events if (SMAInstaller.HandleEvent(args, out var firstRun)) { if (firstRun) { await "SuperMemo Assistant has been successfully installed.".MsgBox("Installation"); } Shutdown(); return; } // // Make sure assemblies are available, and SMA is installed in "%LocalAppData%\SuperMemoAssistant" if (AssemblyCheck.CheckRequired(out var errMsg) == false || CheckSMALocation(out errMsg) == false) { LogTo.Warning(errMsg); await errMsg.ErrorMsgBox(); Shutdown(SMAExitCodes.ExitCodeDependencyError); return; } // // Load system configs if (await LoadConfigs(out var nativeDataCfg, out var startupCfg) == false) { errMsg = $"At least one essential config file could not be loaded: nativeDataCfg ? {nativeDataCfg == null} ; startupCfg ? {startupCfg == null}"; LogTo.Warning(errMsg); await errMsg.ErrorMsgBox(); Shutdown(SMAExitCodes.ExitCodeConfigError); return; } // // Make sure SuperMemo exe path is correct. Prompt user to input the path otherwise. if (SMASetup.ShouldFindSuperMemo(startupCfg, nativeDataCfg)) { var smFinder = new Setup.SuperMemoFinder(nativeDataCfg, startupCfg); smFinder.ShowDialog(); if (smFinder.DialogResult == null || smFinder.DialogResult == false) { LogTo.Warning(errMsg); Shutdown(SMAExitCodes.ExitCodeSMExeError); return; } } // // (Optional) Start the debug Key logger (logs key strokes with modifiers, e.g. ctrl, alt, ..) if (args.KeyLogger) { SMA.Core.KeyboardHotKey.MainCallback = hk => LogTo.Debug($"Key pressed: {hk}"); } // // Determine which collection to open SMCollection smCollection = null; var selectionWdw = new CollectionSelectionWindow(startupCfg); // Try to open command line collection, if one was passed if (args.CollectionKnoPath != null && selectionWdw.ValidateSuperMemoPath()) { smCollection = new SMCollection(args.CollectionKnoPath, DateTime.Now); if (selectionWdw.ValidateCollection(smCollection) == false) { smCollection = null; } } // No valid collection passed, show selection window if (smCollection == null) { selectionWdw.ShowDialog(); smCollection = selectionWdw.Collection; } // // If a collection was defined, start SMA if (smCollection != null) { SMA.Core.SMA.OnSMStoppedEvent += OnSMStoppedEvent; if (await SMA.Core.SMA.Start(nativeDataCfg, startupCfg, smCollection).ConfigureAwait(true) == false) { await $"SMA failed to start. Please check the logs in '{SMAFileSystem.LogDir.FullPath}' for details.".ErrorMsgBox(); Shutdown(SMAExitCodes.ExitCodeSMAStartupError); return; } if (SMAExecutableInfo.Instance.IsDev == false) { await SMAInstaller.Instance.Update(); } } else { Shutdown(); } }
private async Task LoadApp(SMAParameters args) { if (CheckAssemblies(out var errMsg) == false || CheckSMALocation(out errMsg) == false) { LogTo.Warning(errMsg); await Show.Window().For(new Alert(errMsg, "Error")); Shutdown(); return; } if (args.KeyLogger) { Core.KeyboardHotKey.MainCallback = LogHotKeys; } _taskbarIcon = (TaskbarIcon)FindResource("TbIcon"); SMCollection smCollection = null; var selectionWdw = new CollectionSelectionWindow(); // Try to open command line collection, if one was passed if (args.CollectionKnoPath != null && selectionWdw.ValidateSuperMemoPath()) { smCollection = new SMCollection(args.CollectionKnoPath, DateTime.Now); if (selectionWdw.ValidateCollection(smCollection) == false) { smCollection = null; } } // No valid collection passed, show selection window if (smCollection == null) { selectionWdw.ShowDialog(); smCollection = selectionWdw.Collection; } // If a collection was selected, start SMA if (smCollection != null) { Core.SMA.OnSMStoppedEvent += Instance_OnSMStoppedEvent; if (await Core.SMA.Start(smCollection).ConfigureAwait(true) == false) { await Show.Window().For( new Alert( $"SMA failed to start. Please check the logs in '{SMAFileSystem.LogDir.FullPath}' for details.", "Error") ); Shutdown(); } } else { Shutdown(); } }
private async Task LoadAppAsync(SMAParameters args) { // // Installer events https://github.com/Squirrel/Squirrel.Windows/blob/master/docs/using/custom-squirrel-events.md if (SMAInstaller.HandleEvent(args, out var firstRun)) { if (firstRun) { MessageBox.Show("SuperMemo Assistant has been successfully installed.", "Installation success"); } Shutdown(); return; } // // Make sure assemblies are available, and SMA is installed in "%LocalAppData%\SuperMemoAssistant" if (AssemblyCheck.CheckRequired(out var errMsg) == false || CheckSMALocation(out errMsg) == false) { LogTo.Warning(errMsg); await errMsg.ErrorMsgBox().ConfigureAwait(false); Shutdown(SMAExitCodes.ExitCodeDependencyError); return; } // // Load main configuration files var(success, nativeDataCfg, coreCfg) = await LoadConfigs().ConfigureAwait(true); if (success == false) { errMsg = $"At least one essential config file could not be loaded: nativeDataCfg ? {nativeDataCfg == null} ; startupCfg ? {coreCfg == null}"; LogTo.Warning(errMsg); await errMsg.ErrorMsgBox().ConfigureAwait(false); Shutdown(SMAExitCodes.ExitCodeConfigError); return; } SMA.Core.CoreConfig = coreCfg; // // Setup Windows Toast notifications DesktopNotificationManager.RegisterAumidAndComServer <SMANotificationActivator>(SMANotificationActivator.AppUserModelId); DesktopNotificationManager.RegisterActivator <SMANotificationActivator>(); // // Initialize the plugin manager await SMAPluginManager.Instance.InitializeAsync().ConfigureAwait(true); // // Check if SMA is setup, and run the setup wizard if it isn't if (SMASetup.Run(nativeDataCfg, coreCfg) == false) { LogTo.Warning("SMA Setup canceled. Exiting."); Shutdown(SMAExitCodes.ExitCodeSMASetupError); return; } // // Start plugins var pluginStartTask = SMAPluginManager.Instance.StartPlugins().ConfigureAwait(true); // // (Optional) Start the debugging tool Key logger (logs key strokes with modifiers, e.g. ctrl, alt, ..) if (args.KeyLogger) { SMA.Core.KeyboardHotKey.MainCallback = hk => LogTo.Debug("Key pressed: {Hk}", hk); } // // Show the change logs if necessary ChangeLogWindow.ShowIfUpdated(coreCfg); // // Determine which collection to open SMCollection smCollection = null; var selectionWdw = new CollectionSelectionWindow(coreCfg); // Try to open command line collection, if one was passed if (args.CollectionKnoPath != null && selectionWdw.ValidateSuperMemoPath()) { smCollection = new SMCollection(args.CollectionKnoPath, DateTime.Now); if (selectionWdw.ValidateCollection(smCollection) == false) { smCollection = null; } } // No valid collection passed, show selection window if (smCollection == null) { selectionWdw.ShowDialog(); smCollection = selectionWdw.Collection; } // // If a collection was selected, start SMA if (smCollection != null) { _splashScreen = new SplashScreenWindow(); _splashScreen.Show(); SMA.Core.SMA.OnSMStartingInternalEvent += OnSMStartingEventAsync; SMA.Core.SMA.OnSMStoppedInternalEvent += OnSMStoppedEvent; // Wait for plugins to start await pluginStartTask; Exception ex; if ((ex = await SMA.Core.SMA.StartAsync(nativeDataCfg, smCollection).ConfigureAwait(true)) != null) { _splashScreen?.Close(); _splashScreen = null; await $"SMA failed to start: {ex.Message}".ErrorMsgBox().ConfigureAwait(false); Shutdown(SMAExitCodes.ExitCodeSMAStartupError); return; } if (SMAExecutableInfo.Instance.IsDev == false) { await SMAInstaller.Instance.Update().ConfigureAwait(false); } } else { Shutdown(); } }
private async Task LoadApp(SMAParameters args) { _taskbarIcon = (TaskbarIcon)FindResource("TbIcon"); // // Make sure assemblies are available, and SMA is installed in "%AppData%\SuperMemoAssistant" if (CheckAssemblies(out var errMsg) == false || CheckSMALocation(out errMsg) == false) { LogTo.Warning(errMsg); await errMsg.ErrorMsgBox(); Shutdown(1); return; } // // Load system configs if (await LoadConfigs(out var nativeDataCfg, out var startupCfg) == false) { return; } // // Make sure SuperMemo exe path is correct. Prompt user to input the path otherwise. if (ShouldFindSuperMemo(startupCfg, nativeDataCfg)) { var smFinder = new SuperMemoFinder(nativeDataCfg, startupCfg); smFinder.ShowDialog(); if (smFinder.DialogResult == null || smFinder.DialogResult == false) { LogTo.Warning("No valid SM executable file path defined. SMA cannot run."); Shutdown(1); return; } } // // (Optional) Start the debug Key logger (logs key strokes with modifiers, e.g. ctrl, alt, ..) if (args.KeyLogger) { SMA.Core.KeyboardHotKey.MainCallback = LogHotKeys; } // // Determine which collection to open SMCollection smCollection = null; var selectionWdw = new CollectionSelectionWindow(startupCfg); // Try to open command line collection, if one was passed if (args.CollectionKnoPath != null && selectionWdw.ValidateSuperMemoPath()) { smCollection = new SMCollection(args.CollectionKnoPath, DateTime.Now); if (selectionWdw.ValidateCollection(smCollection) == false) { smCollection = null; } } // No valid collection passed, show selection window if (smCollection == null) { selectionWdw.ShowDialog(); smCollection = selectionWdw.Collection; } // // If a collection was defined, start SMA if (smCollection != null) { SMA.Core.SMA.OnSMStoppedEvent += Instance_OnSMStoppedEvent; if (await SMA.Core.SMA.Start(nativeDataCfg, startupCfg, smCollection).ConfigureAwait(true) == false) { await $"SMA failed to start. Please check the logs in '{SMAFileSystem.LogDir.FullPath}' for details.".ErrorMsgBox(); Shutdown(); } } else { Shutdown(); } }