public CollectionSelectionWindow() { try { _config = Core.Configuration.Load <StartupCfg>().Result ?? new StartupCfg(); } catch (SMAException) { Forge.Forms.Show.Window().For(new Alert("Failed to open StartupCfg.json. Make sure file is unlocked and try again.", "Error")); Environment.Exit(1); return; } SavedCollections = _config.Collections; InitializeComponent(); if (SavedCollections.Count > 0) { lbCollections.SelectedIndex = 0; } Loaded += CollectionSelectionWindow_Loaded; }
// // Collection loading management public async Task <bool> Start( NativeDataCfg nativeDataCfg, StartupCfg startupCfg, SMCollection collection) { try { if (_sm != null) { throw new InvalidOperationException("_sm is already instantiated"); } await LoadConfig(collection, startupCfg); var nativeData = CheckSuperMemoExecutable(nativeDataCfg); _sm = InstantiateSuperMemo(collection, nativeData.SMVersion); // TODO: Move somewhere else _sm.UI.ElementWdw.OnAvailable += OnSuperMemoWindowsAvailable; await _sm.Start(nativeData); // TODO: Ensure opened collection (windows title) matches parameter } catch (Exception ex) { if (ex is SMAException) { LogTo.Warning(ex, "Failed to start SM."); } else { LogTo.Error(ex, "Failed to start SM."); } _sm?.Dispose(); _sm = null; try { if (OnSMStoppedEvent != null) { await OnSMStoppedEvent.InvokeAsync(this, new SMProcessArgs(_sm, null)).ConfigureAwait(true); } } catch (Exception pluginEx) { LogTo.Error(pluginEx, "Exception while notifying plugins OnSMStoppedEvent."); } // TODO: Handle exception return(false); } return(true); }
private async Task LoadConfig(SMCollection collection, StartupCfg startupCfg) { Core.CollectionConfiguration = new CollectionConfigurationService(collection, "Core"); StartupConfig = startupCfg; // CollectionsCfg CollectionConfig = await Core.CollectionConfiguration.Load <CollectionCfg>() ?? new CollectionCfg(); }
public static bool ShouldFindSuperMemo(StartupCfg startupCfg, NativeDataCfg nativeDataCfg) { return(string.IsNullOrWhiteSpace(startupCfg.SMBinPath) || SuperMemoFinderUtil.CheckSuperMemoExecutable( nativeDataCfg, startupCfg.SMBinPath, out _, out _) == false); }
private Task <bool> LoadConfigs(out NativeDataCfg nativeDataCfg, out StartupCfg startupCfg) { nativeDataCfg = LoadNativeDataConfig().Result; startupCfg = LoadStartupConfig().Result; if (nativeDataCfg == null || startupCfg == null) { return(Task.FromResult(false)); } return(Task.FromResult(true)); }
public CollectionSelectionWindow(StartupCfg startupCfg) { _startupCfg = startupCfg; SavedCollections = startupCfg.Collections; InitializeComponent(); if (SavedCollections.Count > 0) { lbCollections.SelectedIndex = 0; } Loaded += CollectionSelectionWindow_Loaded; }
public CollectionSelectionWindow() { _config = Svc.Configuration.Load <StartupCfg>().Result ?? new StartupCfg(); SavedCollections = _config.Collections; InitializeComponent(); if (SavedCollections.Count > 0) { lbCollections.SelectedIndex = 0; } Loaded += CollectionSelectionWindow_Loaded; }
public SuperMemoFinder(NativeDataCfg nativeDataCfg, StartupCfg startupCfg) { _nativeDataCfg = nativeDataCfg; _startupCfg = startupCfg; SMExeFilePath = new SuperMemoFilePath(startupCfg.SMBinPath, nativeDataCfg); SMExeSuggestedFilePaths = SuperMemoFinderUtil.SearchSuperMemoInDefaultLocations() .Select(fp => fp.FullPathWin) .ToHashSet(); AcceptCommand = new RelayCommand(Accept, CanAcceptExecute); BrowseCommand = new RelayCommand(Browse); BuildDescriptionText(); Task.Run(SearchForSuperMemo).RunAsync(); InitializeComponent(); }
private void LoadConfig(SMCollection collection) { var knoPath = collection.GetKnoFilePath(); // StartupCfg StartupConfig = Core.Configuration.Load <StartupCfg>().Result ?? new StartupCfg(); // CollectionsCfg _collectionsCfg = Core.Configuration.Load <CollectionsCfg>().Result ?? new CollectionsCfg(); CollectionConfig = _collectionsCfg.CollectionsConfig.SafeGet(knoPath); if (CollectionConfig == null) { CollectionConfig = new CollectionCfg(); _collectionsCfg.CollectionsConfig[knoPath] = CollectionConfig; } }