public I18nService() { // Initialize Languages directories // -------------------------------- // Initialize variables this.builtinLanguagesDirectory = Path.Combine(ProcessExecutable.ExecutionFolder(), ApplicationPaths.BuiltinLanguagesFolder); this.customLanguagesDirectory = Path.Combine(SettingsClient.ApplicationFolder(), ApplicationPaths.CustomLanguagesFolder); // If the CustomLanguages subdirectory doesn't exist, create it if (!Directory.Exists(this.customLanguagesDirectory)) { Directory.CreateDirectory(System.IO.Path.Combine(this.customLanguagesDirectory)); } this.LoadLanguages(); // Configure the ColorSchemeTimer // ------------------------------ this.languageTimer.Interval = TimeSpan.FromSeconds(this.languageTimeoutSeconds).TotalMilliseconds; this.languageTimer.Elapsed += new ElapsedEventHandler(LanguageTimerElapsed); // Start the LanguageWatcher // ------------------------- this.languageWatcher = new FileSystemWatcher(this.customLanguagesDirectory) { EnableRaisingEvents = true }; this.languageWatcher.Changed += new FileSystemEventHandler(WatcherChangedHandler); this.languageWatcher.Deleted += new FileSystemEventHandler(WatcherChangedHandler); this.languageWatcher.Created += new FileSystemEventHandler(WatcherChangedHandler); this.languageWatcher.Renamed += new RenamedEventHandler(WatcherRenamedHandler); }
public UpdateService() { this.checkNewVersionTimer.Elapsed += new ElapsedEventHandler(this.CheckNewVersionTimerHandler); this.updatesSubDirectory = Path.Combine(SettingsClient.ApplicationFolder(), ApplicationPaths.UpdatesFolder); this.canCheckForUpdates = false; }
private LogClient() { this.logfolder = Path.Combine(SettingsClient.ApplicationFolder(), "Log"); this.logfile = System.IO.Path.Combine(this.logfolder, ProcessExecutable.Name() + ".log"); this.logEntries = new Queue <LogEntry>(); this.logTimer.Interval = 25; this.logTimer.Elapsed += LogTimer_Elapsed; }
public SettingsAppearanceViewModel(IPlaybackService playbackService, IEventAggregator eventAggregator) { this.playbackService = playbackService; this.eventAggregator = eventAggregator; this.ColorSchemesDirectory = System.IO.Path.Combine(SettingsClient.ApplicationFolder(), ApplicationPaths.ColorSchemesFolder); this.GetCheckBoxesAsync(); }
public ProviderService() { this.providersXmlPath = Path.Combine(SettingsClient.ApplicationFolder(), "Providers.xml"); // Create the XML containing the Providers this.CreateProvidersXml(); // Load the XML containing the Providers this.LoadProvidersXml(); }
public EqualizerService() { // Initialize the Equalizer directory // ---------------------------------- this.equalizerSubDirectory = Path.Combine(SettingsClient.ApplicationFolder(), ApplicationPaths.EqualizerFolder); // If the Equalizer subdirectory doesn't exist, create it if (!Directory.Exists(this.equalizerSubDirectory)) { Directory.CreateDirectory(Path.Combine(this.equalizerSubDirectory)); } }
public SettingsAppearanceViewModel(IPlaybackService playbackService, IEventAggregator eventAggregator) { this.playbackService = playbackService; this.eventAggregator = eventAggregator; this.ColorSchemesDirectory = System.IO.Path.Combine(SettingsClient.ApplicationFolder(), ApplicationPaths.ColorSchemesFolder); this.eventAggregator.GetEvent <SelectedSpectrumStyleChanged>().Subscribe((_) => this.SetSelectedSpectrumStyle()); this.GetCheckBoxesAsync(); this.GetSpectrumStylesAsync(); }
public CacheService() { string cacheFolderPath = Path.Combine(SettingsClient.ApplicationFolder(), ApplicationPaths.CacheFolder); this.coverArtCacheFolderPath = Path.Combine(SettingsClient.ApplicationFolder(), ApplicationPaths.CacheFolder, ApplicationPaths.CoverArtCacheFolder); this.temporaryCacheFolderPath = Path.Combine(SettingsClient.ApplicationFolder(), ApplicationPaths.CacheFolder, ApplicationPaths.TemporaryCacheFolder); // If it doesn't exist, create the cache folder. if (!Directory.Exists(cacheFolderPath)) { Directory.CreateDirectory(cacheFolderPath); } // If it doesn't exist, create the coverArt cache folder. if (!Directory.Exists(this.coverArtCacheFolderPath)) { Directory.CreateDirectory(this.coverArtCacheFolderPath); } // If it exists, delete the temporary cache folder and create it again (this makes sure it is cleaned from time to time) if (Directory.Exists(this.temporaryCacheFolderPath)) { try { Directory.Delete(this.temporaryCacheFolderPath, true); } catch (Exception ex) { LogClient.Error("Could not delete the temporary cache folder. Exception: {0}", ex.Message); } } // If the temporary cache folder doesn't exist, create it. if (!Directory.Exists(this.temporaryCacheFolderPath)) { Directory.CreateDirectory(this.temporaryCacheFolderPath); } temporaryCacheCleanupTimer = new Timer(); temporaryCacheCleanupTimer.Interval = temporaryCacheCleanupTimeout; temporaryCacheCleanupTimer.Elapsed += TemporaryCacheCleanupTimer_Elapsed; temporaryCacheCleanupTimer.Start(); }
public ConvertService() { this.musicFolder = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.MyMusic), ProductInformation.ApplicationDisplayName); this.workingFolder = Path.Combine(SettingsClient.ApplicationFolder(), "Working"); // Create the music folder. If this fails, we cannot continue (let it crash). this.CreateMusicFolder(); // Try to delete the working folder. If it fails: no problem. try { if (Directory.Exists(this.workingFolder)) { Directory.Delete(this.workingFolder, true); } } catch (Exception ex) { LogClient.Error("An error occurred while deleting the working folder {0}. Exception: {1}", this.workingFolder, ex.Message); } // Try to create the working folder. If this fails, we cannot continue (let it crash). try { if (!Directory.Exists(this.workingFolder)) { Directory.CreateDirectory(this.workingFolder); } } catch (Exception ex) { LogClient.Error("An error occurred while creating the music folder {0}. Exception: {1}", this.workingFolder, ex.Message); throw; } this.convertState = ConvertState.Idle; convertStateResetTimer.Elapsed += ConvertStateResetTimer_Elapsed; }
public SettingsAppearanceViewModel(IPlaybackService playbackService, IEventAggregator eventAggregator) { this.playbackService = playbackService; this.eventAggregator = eventAggregator; this.ColorSchemesDirectory = System.IO.Path.Combine(SettingsClient.ApplicationFolder(), ApplicationPaths.ColorSchemesFolder); this.OpenColorSchemesDirectoryCommand = new DelegateCommand <string>((colorSchemesDirectory) => { try { Actions.TryOpenPath(colorSchemesDirectory); } catch (Exception ex) { LogClient.Error("Could not open the ColorSchemes directory. Exception: {0}", ex.Message); } }); this.GetCheckBoxesAsync(); }
public SettingsAppearanceViewModel(IAppearanceService appearanceService, II18nService i18nService, INoteService noteService, IEventAggregator eventAggregator) { this.appearanceService = appearanceService; this.i18nService = i18nService; this.noteService = noteService; this.eventAggregator = eventAggregator; // ColorSchemes this.GetColorSchemes(); // Languages this.GetLanguagesAsync(); // CheckBoxStates this.LoadCheckBoxStates(); // Event handling this.appearanceService.ColorSchemesChanged += ColorSchemesChangedHandler; this.i18nService.LanguagesChanged += (sender, e) => this.GetLanguagesAsync(); this.ColorSchemesDirectory = System.IO.Path.Combine(SettingsClient.ApplicationFolder(), ApplicationPaths.ColorSchemesSubDirectory); }
public SQLiteConnectionFactory() { this.databaseFile = System.IO.Path.Combine(SettingsClient.ApplicationFolder(), ProductInformation.ApplicationAssemblyName + ".db"); }
public AppearanceService(IPlaybackService playbackService, IMetadataService metadataService) : base() { // Services // -------- this.playbackService = playbackService; this.metadataService = metadataService; playbackService.PlaybackSuccess += PlaybackService_PlaybackSuccess; // Initialize the ColorSchemes directory // ------------------------------------- this.colorSchemesSubDirectory = Path.Combine(SettingsClient.ApplicationFolder(), ApplicationPaths.ColorSchemesFolder); // If the ColorSchemes subdirectory doesn't exist, create it if (!Directory.Exists(this.colorSchemesSubDirectory)) { Directory.CreateDirectory(Path.Combine(this.colorSchemesSubDirectory)); } // Create the example ColorScheme // ------------------------------ string exampleColorSchemeFile = Path.Combine(this.colorSchemesSubDirectory, "Red.xml"); if (System.IO.File.Exists(exampleColorSchemeFile)) { System.IO.File.Delete(exampleColorSchemeFile); } XDocument exampleColorSchemeXml = XDocument.Parse("<ColorScheme><AccentColor>#E31837</AccentColor></ColorScheme>"); exampleColorSchemeXml.Save(exampleColorSchemeFile); // Create the "How to create ColorSchemes.txt" file // ------------------------------------------------ string howToFile = Path.Combine(this.colorSchemesSubDirectory, "How to create ColorSchemes.txt"); if (System.IO.File.Exists(howToFile)) { System.IO.File.Delete(howToFile); } string[] lines = { "How to create ColorSchemes?", "---------------------------", "", "1. Copy and rename the file Red.xml", "2. Open the file and edit the color code of AccentColor", "3. Your ColorScheme appears automatically in " + ProductInformation.ApplicationName }; System.IO.File.WriteAllLines(howToFile, lines, System.Text.Encoding.UTF8); // Configure the ColorSchemeTimer // ------------------------------ this.colorSchemeTimer.Interval = TimeSpan.FromSeconds(this.colorSchemeTimeoutSeconds).TotalMilliseconds; this.colorSchemeTimer.Elapsed += new ElapsedEventHandler(ColorSchemeTimerElapsed); // Start the ColorSchemeWatcher // ---------------------------- this.colorSchemeWatcher = new FileSystemWatcher(this.colorSchemesSubDirectory); this.colorSchemeWatcher.EnableRaisingEvents = true; this.colorSchemeWatcher.Changed += new FileSystemEventHandler(WatcherChangedHandler); this.colorSchemeWatcher.Deleted += new FileSystemEventHandler(WatcherChangedHandler); this.colorSchemeWatcher.Created += new FileSystemEventHandler(WatcherChangedHandler); this.colorSchemeWatcher.Renamed += new RenamedEventHandler(WatcherRenamedHandler); // Get the available ColorSchemes // ------------------------------ this.GetAllColorSchemes(); }
public UpdateService() { this.updatesSubDirectory = Path.Combine(SettingsClient.ApplicationFolder(), ApplicationPaths.UpdatesFolder); this.checkTimer.Elapsed += new ElapsedEventHandler(this.CheckTimerElapsedHandler); }
private async Task <bool> InitializeNoteStorageDirectoryAsync() { bool isSuccess = true; var migrator = new DbMigrator(); // Move the old "Knowte.db" database file to "Notes\Notes.db". TODO: remove this later (e.g. in version 1.2) try { string oldDatabaseFile = Path.Combine(SettingsClient.ApplicationFolder(), "Knowte.db"); if (File.Exists(oldDatabaseFile) && !File.Exists(migrator.DatabaseFile)) { File.Move(oldDatabaseFile, migrator.DatabaseFile); } } catch (Exception ex) { LogClient.Error("The old database file could not be moved. Exception: {0}", ex.Message); this.errorMessage = ex.Message; isSuccess = false; } // Make sure the default note storage location exists if (!Directory.Exists(ApplicationPaths.DefaultNoteStorageLocation)) { Directory.CreateDirectory(ApplicationPaths.DefaultNoteStorageLocation); } // Further verification is only needed when not using the default storage location if (ApplicationPaths.IsUsingDefaultStorageLocation) { return(true); } try { await Task.Run(() => { if (!Directory.Exists(ApplicationPaths.CurrentNoteStorageLocation)) { LogClient.Warning("Note storage location '{0}' could not be found.", ApplicationPaths.CurrentNoteStorageLocation); isSuccess = false; } if (!migrator.DatabaseExists()) { LogClient.Warning("Database file '{0}' could not be found.", migrator.DatabaseFile); isSuccess = false; } if (!isSuccess) { // Restore the default storage location SettingsClient.Set <string>("General", "NoteStorageLocation", ""); LogClient.Warning("Default note storage location was restored."); // Allow the application to start up after the default storage location was restored isSuccess = true; } }); } catch (Exception ex) { LogClient.Error("There was a problem initializing the note storage location. Exception: {0}", ex.Message); this.errorMessage = ex.Message; isSuccess = false; } return(isSuccess); }
public AppearanceService(IPlaybackService playbackService, IMetadataService metadataService) : base() { // Services // -------- this.playbackService = playbackService; this.metadataService = metadataService; playbackService.PlaybackSuccess += PlaybackService_PlaybackSuccess; // Initialize the ColorSchemes directory // ------------------------------------- this.colorSchemesSubDirectory = Path.Combine(SettingsClient.ApplicationFolder(), ApplicationPaths.ColorSchemesFolder); // If the ColorSchemes subdirectory doesn't exist, create it if (!Directory.Exists(this.colorSchemesSubDirectory)) { Directory.CreateDirectory(Path.Combine(this.colorSchemesSubDirectory)); } // Create the example ColorScheme // ------------------------------ string exampleColorSchemeFile = Path.Combine(this.colorSchemesSubDirectory, "Red.xml"); if (System.IO.File.Exists(exampleColorSchemeFile)) { System.IO.File.Delete(exampleColorSchemeFile); } XDocument exampleColorSchemeXml = XDocument.Parse("<ColorScheme><AccentColor>#E53935</AccentColor></ColorScheme>"); exampleColorSchemeXml.Save(exampleColorSchemeFile); // Create the "How to create ColorSchemes.txt" file // ------------------------------------------------ string howToFile = Path.Combine(this.colorSchemesSubDirectory, "How to create ColorSchemes.txt"); if (System.IO.File.Exists(howToFile)) { System.IO.File.Delete(howToFile); } string[] lines = { "How to create ColorSchemes?", "---------------------------", "", "1. Copy and rename the file Red.xml", "2. Open the file and edit the color code of AccentColor", "3. Your ColorScheme appears automatically in " + ProductInformation.ApplicationName }; System.IO.File.WriteAllLines(howToFile, lines, System.Text.Encoding.UTF8); // Watcher // ------- this.watcher = new GentleFolderWatcher(this.colorSchemesSubDirectory, false); this.watcher.FolderChanged += Watcher_FolderChanged; this.watcher.Resume(); // Get the available ColorSchemes // ------------------------------ this.GetAllColorSchemes(); }
public void Execute() { Console.WriteLine("Migrator"); Console.WriteLine("========"); string noteStudioFolder = Path.Combine(LegacyPaths.AppData(), "NoteStudio"); var migrator = new DbMigrator(); if (Directory.Exists(noteStudioFolder)) { if (!migrator.DatabaseExists()) { // Create the database if if doesn't exist migrator.InitializeNewDatabase(); } int noteCount = 0; int notebookCount = 0; using (var conn = this.factory.GetConnection()) { noteCount = conn.Table <Note>().Count(); notebookCount = conn.Table <Notebook>().Count(); } if (noteCount == 0 & notebookCount == 0) { Console.WriteLine(Environment.NewLine + "NoteStudio installation found! Do you want to start importing Notes and Notebooks? [Y/N]"); ConsoleKeyInfo info = Console.ReadKey(); if (info.Key == ConsoleKey.Y) { // Get the Notebooks from the xml String noteStudioXmlFilePath = System.IO.Path.Combine(noteStudioFolder, "NoteStudio.xml"); if (File.Exists(noteStudioXmlFilePath)) { XDocument doc = XDocument.Load(noteStudioXmlFilePath); List <Notebook> notebooks = null; List <Note> notes = null; long newNoteCount = 0; Console.WriteLine(Environment.NewLine + "Importing. Please wait..."); try { // Add to database newNoteCount = (from t in doc.Element("NoteStudio").Elements("Counters") select Convert.ToInt64(t.Attribute("UntitledCount").Value)).FirstOrDefault(); notebooks = (from t in doc.Element("NoteStudio").Element("Notebooks").Elements("Notebook") select new Notebook() { Id = t.Attribute("Id").Value, Title = t.Attribute("Title").Value, CreationDate = DateTime.Parse(t.Attribute("CreationDate").Value).Ticks, }).ToList(); notes = (from t in doc.Element("NoteStudio").Element("Notes").Elements("Note") select new Note() { NotebookId = t.Attribute("NotebookId").Value, Id = t.Attribute("Id").Value, Text = t.Attribute("Text") == null ? "" : t.Attribute("Text").Value, Title = t.Attribute("Title").Value, CreationDate = t.Attribute("CreationDate") == null ? DateTime.Now.Ticks : DateTime.Parse(t.Attribute("CreationDate").Value).Ticks, OpenDate = t.Attribute("OpenDate") == null ? DateTime.Now.Ticks : DateTime.Parse(t.Attribute("OpenDate").Value).Ticks, ModificationDate = t.Attribute("ModificationDate") == null ? DateTime.Now.Ticks : DateTime.Parse(t.Attribute("ModificationDate").Value).Ticks, Flagged = t.Attribute("Flagged") == null ? 0 : Convert.ToBoolean(t.Attribute("Flagged").Value) ? 1 : 0, Maximized = t.Attribute("Maximized") == null ? 0 : Convert.ToBoolean(t.Attribute("Maximized").Value) ? 1 : 0, Width = t.Attribute("Width") == null ? Defaults.DefaultNoteWidth : Convert.ToInt32(t.Attribute("Width").Value), Height = t.Attribute("Height") == null ? Defaults.DefaultNoteHeight : Convert.ToInt32(t.Attribute("Height").Value), Top = t.Attribute("Top") == null ? Defaults.DefaultNoteTop : Convert.ToInt32(t.Attribute("Top").Value), Left = t.Attribute("Left") == null ? Defaults.DefaultNoteLeft : Convert.ToInt32(t.Attribute("Left").Value) }).ToList(); using (var conn = this.factory.GetConnection()) { // NewNoteCount Knowte.Common.Database.Entities.Configuration newNoteCountConfiguration = conn.Table <Knowte.Common.Database.Entities.Configuration>().Where((c) => c.Key == "NewNoteCount").Select((c) => c).FirstOrDefault(); newNoteCountConfiguration.Value = newNoteCount.ToString(); conn.Update(newNoteCountConfiguration); // Notebooks foreach (Notebook notebook in notebooks) { conn.Insert(notebook); } // Notes foreach (Note note in notes) { conn.Insert(note); } } // Copy xaml files string noteStudioNotesSubFolder = System.IO.Path.Combine(noteStudioFolder, "Notes"); if (System.IO.Directory.Exists(noteStudioNotesSubFolder)) { // If the Notes subfolder doesn't exist, create it. string notesSubfolder = System.IO.Path.Combine(SettingsClient.ApplicationFolder(), "Notes"); if (!System.IO.Directory.Exists(notesSubfolder)) { System.IO.Directory.CreateDirectory(notesSubfolder); } foreach (var file in Directory.GetFiles(noteStudioNotesSubFolder)) { File.Copy(file, Path.Combine(notesSubfolder, Path.GetFileName(file))); } } } catch (Exception) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(Environment.NewLine + "An error occured. Import failed."); Console.ForegroundColor = ConsoleColor.Gray; } } Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(Environment.NewLine + "Import complete!"); Console.ForegroundColor = ConsoleColor.White; } } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(Environment.NewLine + "Import not allowed as the Knowte database is not empty."); Console.ForegroundColor = ConsoleColor.Gray; } } else { Console.WriteLine(Environment.NewLine + "NoteStudio installation not found."); } Console.WriteLine(Environment.NewLine + "Press any key to close this window..."); Console.ReadKey(); }