public void Load(TagQueryCriteria tagQueryCriteria = null, bool newAdditionsOnly = false) { FileNames.Clear(); currentQuery = tagQueryCriteria ?? new TagQueryCriteria(); var sourcePath = PersistanceUtil.RetreiveSetting(Setting.SourceDirectory); if (!Directory.Exists(sourcePath)) { sourcePath = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures); PersistanceUtil.RecordSetting(Setting.SourceDirectory, sourcePath); } if (newAdditionsOnly) { FileNames.Add(NewFiles); } else { FileNames.Add(ImageFileUtil.GetImageFilenames(sourcePath, currentQuery)); } if (currentQuery.orderDirection == OrderDirection.RANDOM) { FileNames.Shuffle(); } watcher.Path = sourcePath; watcher.EnableRaisingEvents = true; FilesLoaded(null, new EventArgs()); }
private void SetDestination_MenuItem_Click(object sender, RoutedEventArgs e) { var success = ImageFileUtil.GetDirectoryFromDialog(out string result, PersistanceUtil.RetreiveSetting(Setting.DestinationDirectory)); if (success) { PersistanceUtil.RecordSetting(Setting.DestinationDirectory, result); } }
private void SetSource_MenuItem_Click(object sender, RoutedEventArgs e) { var result = ""; var success = ImageFileUtil.GetDirectoryFromDialog(out result, PersistanceUtil.RetreiveSetting(Setting.SourceDirectory)); if (success) { PersistanceUtil.RecordSetting(Setting.SourceDirectory, result); main.ImageFiles.Load(main.ImageFiles.currentQuery); } }
public static async void Load() { foreach (var category in TagsRecord.Keys) { TagsRecord[category].Clear(); } ImageTagger.TagManipulation.Internal.MyTagsRecord.Load(ref TagsRecord); foreach (var category in TagsRecord.Keys) { OnProcessedNewCategory(null, new AddedCategoryEventArgs(category)); foreach (var tag in TagsRecord[category]) { OnProcessedNewTag(null, new AddedTagEventArgs(category, tag)); } } OnPreviewTagsLoaded(null, new EventArgs()); loadState = LoadState.Loading; var source = PersistanceUtil.RetreiveSetting(Setting.SourceDirectory); await LoadTagsFromFileAsynch(source); loadState = LoadState.Loaded; OnTagsLoaded(null, new EventArgs()); }
} //, "jpeg", "gif", "png", }; public static List <string> GetImageFilenames(string sourcePath = null, TagQueryCriteria tagQueryCriteria = null) { sourcePath = sourcePath ?? PersistanceUtil.RetreiveSetting(Setting.SourceDirectory); if (!Directory.Exists(sourcePath)) { sourcePath = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures); } tagQueryCriteria = tagQueryCriteria ?? new TagQueryCriteria(); var result = new List <string>(); var query = tagQueryCriteria.GetQueryClause(sourcePath, out bool randomize); var windowsSearchConnection = @"Provider=Search.CollatorDSO.1;Extended Properties=""Application=Windows"""; using (OleDbConnection connection = new OleDbConnection(windowsSearchConnection)) { connection.Open(); var command = new OleDbCommand(query, connection); try { using (var r = command.ExecuteReader()) { var cont = true; var context = new CancelDialogDataContext(); var dialogue = new CancelDialog(context); context.OnCancel = (n, m) => cont = false; context.OnClosed = (n, m) => context.OnCancel(n, null); dialogue.Show(); while (cont) { try { cont = r.Read(); var filepath = $"{r[0]}"; if (IsJpg(filepath)) { result.Add(filepath); } } catch (Exception e) { Debug.WriteLine(e); } finally { dialogue.Close(); } } } } catch (Exception e) { Debug.WriteLine(e); var dialogue = new CancelDialog(); var context = new CancelDialogDataContext(); int i; var files = Directory.GetFiles(sourcePath, "*.*", SearchOption.AllDirectories); context.MaxValue = files.Length; context.PerformAction = () => { for (i = 0; i < files.Length; i++) { var fileName = files[i]; if (IsJpg(fileName) && MatchesCriteria(fileName, tagQueryCriteria)) { result.Add(fileName); } context.CurrentValue++; } }; context.OnCancel = (n, m) => { i = files.Length; dialogue.Close(); }; context.OnClosed = (n, m) => context.OnCancel(n, null); dialogue.SetContext(context); dialogue.ShowDialog(); } finally { connection.Close(); } } if (randomize) { result.Shuffle(); } return(result); }