Esempio n. 1
0
        public MainWindowViewModel()
        {
            Settings = new FilerSettings();
            Debug.Assert(Settings != null);

            Settings.SessionLog = $"---Session Debug Log Started At {DateTime.Now.ToString()}---\n";

            LaunchItemChosenCommand   = new RelayCommand(_OnLaunchItemChosen);
            EnterPressedCommand       = new RelayCommand(_OnEnterPressed);
            ShowSettingsWindowCommand = new RelayCommand(_ShowSettingsWindow);
            ShowMoreResultsCommand    = new RelayCommand(_ShowMoreResults);

            _InitializeDatabase();

            m_limitedResultCollection = new ObservableCollection <Controls.SearchResultControl>();

            m_latestSearchResult = null;

            m_resultLock = new object();

            StatusMessage          = "Ready";
            m_enableShowMoreButton = false;

            m_directoryMonitor = new DirectoryMonitor();

            m_directoryMonitor.ScanCompleted             += _DirectoryMonitor_ScanCompleted;
            m_directoryMonitor.MonitoredDirectoryRemoved += _DirectoryMonitor_MonitoredDirectoryRemoved;
            m_directoryMonitor.StatusChanged             += _DirectoryMonitor_StatusChanged;
            m_directoryMonitor.ScanProgress         += _DirectoryMonitor_ScanProgress;
            m_directoryMonitor.ScanStarted          += _DirectoryMonitor_ScanStarted;
            m_directoryMonitor.MonitoredFileCreated += _DirectoryMonitor_MonitoredFileCreated;
            m_directoryMonitor.MonitoredFileDeleted += _DirectoryMonitor_MonitoredFileDeleted;
            m_directoryMonitor.MonitoredFileRenamed += _DirectoryMonitor_MonitoredFileRenamed;

            if (Settings.FirstRun)
            {
                //add the user's special folders as a default
                m_directoryMonitor.AddMonitoredDirectory(Environment.GetFolderPath(Environment.SpecialFolder.Desktop));
                m_directoryMonitor.AddMonitoredDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
                m_directoryMonitor.AddMonitoredDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyMusic));
                m_directoryMonitor.AddMonitoredDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures));
                m_directoryMonitor.AddMonitoredDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyVideos));
                m_directoryMonitor.AddMonitoredDirectory(Environment.GetFolderPath(Environment.SpecialFolder.Personal));
                m_directoryMonitor.AddMonitoredDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles));
                m_directoryMonitor.AddMonitoredDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86));
                m_directoryMonitor.AddMonitoredDirectory(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu));
                m_directoryMonitor.AddMonitoredDirectory(Environment.GetFolderPath(Environment.SpecialFolder.System), false);                 //just want top-level for calc, notepad, etc.

                Settings.MonitoredDirectories = m_directoryMonitor.GetFormattedStringFromDirectoryList();

                m_directoryMonitor.ScanMonitoredDirectories();
            }
            else
            {
                var extractedDirectories = DirectoryMonitor.GetDirectoryListFromFormattedString(Settings.MonitoredDirectories);
                foreach (DirectoryMonitor.Directory directory in extractedDirectories)
                {
                    m_directoryMonitor.AddMonitoredDirectory(directory);
                }
            }

            try
            {
                DatabaseItemCount = m_database.QueryDatabaseSize();
            }
            catch (Exception crap)
            {
                Settings.SessionLog += crap.Message + "\n";
                Debug.WriteLine(crap.Message);
            }
        }