private void UpdateSelectedFolder() { if (listBoxLocations.SelectedIndex != -1) { currentFolder = foldersToIndex[listBoxLocations.SelectedIndex]; spinFolderDepth.Value = currentFolder.Depth; listBoxExtensions.DataSource = currentFolder.Extensions; } else { currentFolder = null; spinFolderDepth.Value = defaultFolderDepth; listBoxExtensions.DataSource = null; } spinFolderDepth.Enabled = btnAddExt.Enabled = btnRemoveExt.Enabled = currentFolder != null; }
private static void RebuildIndex() { if (Properties.Settings.Default.FoldersToIndex == null) { return; } ClearDB(indexDbInfo); var folderStack = new Stack <FolderToIndex>(); foreach (var item in Properties.Settings.Default.FoldersToIndex) { var folder = new FolderToIndex(item); if (folder.Extensions.Count > 0) { folderStack.Push(folder); } } IEnumerable <string> currentFiles; var failedToIndex = new List <string>(); while (folderStack.Count > 0) { var currentFolder = folderStack.Pop(); if (Properties.Settings.Default.FoldersToExclude != null && Properties.Settings.Default.FoldersToExclude.Contains(currentFolder.Path)) { continue; } try { currentFiles = Directory.EnumerateFiles(currentFolder.Path, "*.*").Where(file => currentFolder.Extensions.Contains(Path.GetExtension(file))); } catch (Exception ex) { failedToIndex.Add(string.Join(" - ", currentFolder.Path, ex.Message)); continue; } UpdateIndex(currentFiles); if (currentFolder.Depth == 0) { break; } foreach (var currentSubFolder in Directory.EnumerateDirectories(currentFolder.Path)) { folderStack.Push(new FolderToIndex() { Path = currentSubFolder, Depth = currentFolder.Depth - 1, Extensions = currentFolder.Extensions }); } } Properties.Settings.Default.DateLastIndexed = DateTime.Now; if (failedToIndex.Count > 0) { MessageBox.Show($"The following directories were not indexed: \n{string.Join("\n", failedToIndex)}", "Indexing finished", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } //// remove items for history that are no longer in the index //using (var connection = GetDbConnection(historyDb)) //{ // (new SQLiteCommand($"ATTACH '{indexDb}' as CATALOG", connection)).ExecuteNonQuery(); // var command = new SQLiteCommand("delete from HISTORY where FULLPATH no in (select FULLPATH FROM CATALOG)", connection); // command.ExecuteNonQuery(); //} }