private void tbxSourceFile_MouseDown(Object sender, MouseButtonEventArgs e) { var result = FileDialog.OpenFileDialog(m_SourceFilePath); if (result != "") { tbxSourceFile.Text = "Pattern: " + result; m_SourceFilePath = result; if (File.Exists(m_SourceFilePath)) { m_SourceFileImage = ImageSourceExt.Load(m_SourceFilePath); iSourceFile.Source = m_SourceFileImage; } } else { tbxSourceFile.Text = ""; } }
/// <summary> /// Assume .\Thumbnail same name file is the thumbnail /// if not created, create, if exception throw and ignore and warning some load error /// if created, try load, if exception then create new one /// load success and that is /// </summary> private void MakeDirectoryPreview() { if (HasMakePreview) { return; } foreach (var libImage in m_LibraryImages) { if (libImage.ThumbnailChecked) { continue; } bool needToConstruct = true; if (File.Exists(libImage.ThumbnailPath)) { try { libImage.ThumbnailImage = ImageSourceExt.Load(libImage.ThumbnailPath); needToConstruct = false; } catch { // Load failed, change path to another path to prevent overwrite libImage.ThumbnailPath = PathEx.ChangeFileName(libImage.ThumbnailPath, fileName => fileName + "A_very_long_name_that_definitely_would_not_collide" // _because_I_dont_want_to_write_too_more_for_this_kind_of_homework_level_project" ); } } if (needToConstruct) { try { if (!Directory.Exists(Path.GetDirectoryName(libImage.ThumbnailPath))) { Directory.CreateDirectory(Path.GetDirectoryName(libImage.ThumbnailPath)); } ImageSourceExt.GetThumbnailImage(libImage.OriginalPath, libImage.ThumbnailPath, 0.1, 200, 200); libImage.ThumbnailImage = ImageSourceExt.Load(libImage.ThumbnailPath); } catch (Exception e) { e.ToString(); // Still construct or load or save failed // give warning and ignore this libImage.ExceptionedAndIgnored = true; } } } StringBuilder sb = new StringBuilder("Error loading these images, they are ignored then: \n"); bool hasAnyInvalid = false; foreach (var libImage in m_LibraryImages.FindAll(image => image.ExceptionedAndIgnored)) { sb.Append("\t"); sb.Append(libImage); sb.Append(Environment.NewLine); hasAnyInvalid = true; } if (hasAnyInvalid) { MessageBox.Show(sb.ToString(), "Warning"); m_LibraryImages.RemoveAll(image => image.ExceptionedAndIgnored); } HasMakePreview = true; }