/// <summary> /// Loads image based on overloaded int. /// </summary> /// <param name="x">The index of file to load from Pics</param> internal static async void Pic(int x) { BitmapSource pic; // Additional error checking if (Pics.Count <= x) { if (x == 0) { var recovery = await RecoverFailedArchiveAsync().ConfigureAwait(true); if (!recovery) { ToolTipStyle("Archive could not be processed"); Reload(true); return; } } // Untested code pic = await PicErrorFix(x).ConfigureAwait(true); if (pic == null) { Reload(true); return; } } if (x < 0) { pic = await PicErrorFix(x).ConfigureAwait(true); } //if (!canNavigate) //{ // Reload(true); // return; //} else { /// Add "pic" as local variable used for the image. /// Use the Load() function load image from memory if available /// if not, it will be null pic = Preloader.Load(Pics[x]); } if (pic == null) { mainWindow.Title = Loading; mainWindow.Bar.Text = Loading; mainWindow.Bar.ToolTip = Loading; TryZoomFit(Pics[x]); var thumb = GetThumb(); if (thumb != null) { mainWindow.img.Source = thumb; } // Dissallow changing image while loading canNavigate = false; if (freshStartup) { // Load new value manually await Task.Run(() => pic = RenderToBitmapSource(Pics[x])).ConfigureAwait(true); } else { do { // Try again while loading? await Task.Delay(20).ConfigureAwait(true); if (x < Pics.Count) { pic = Preloader.Load(Pics[x]); } } while (Preloader.IsLoading); } // If pic is still null, image can't be rendered if (pic == null) { // Attempt to load new image pic = await PicErrorFix(x).ConfigureAwait(true); if (pic == null) { if (Pics.Count <= 1) { Unload(); return; } DisplayBrokenImage(); canNavigate = true; return; } } } // Clear unsupported image window, if shown if (mainWindow.img.Source == null && !freshStartup) { if (mainWindow.topLayer.Children.Count > 0) { mainWindow.topLayer.Children.Clear(); } } // Show the image! :) mainWindow.img.Source = pic; ZoomFit(pic.PixelWidth, pic.PixelHeight); // Scroll to top if scroll enabled if (IsScrollEnabled) { mainWindow.Scroller.ScrollToTop(); } /// TODO Make it staying flipped a user preference //// Prevent picture from being flipped if previous is //if (Flipped) // Flip(); // Update values canNavigate = true; SetTitleString(pic.PixelWidth, pic.PixelHeight, x); FolderIndex = x; AjaxLoadingEnd(); if (Pics.Count > 0) { Progress(x, Pics.Count); // Preload images \\ if (Preloader.StartPreload()) { Preloader.Add(pic, Pics[FolderIndex]); await Preloader.PreLoad(x).ConfigureAwait(false); } } if (!freshStartup) { RecentFiles.Add(Pics[x]); } freshStartup = false; }
internal static void Paste() { // file if (Clipboard.ContainsFileDropList()) // If Clipboard has one or more files { var files = Clipboard.GetFileDropList().Cast <string>().ToArray(); if (files != null) { if (files.Length >= 1) { var x = files[0]; if (Pics.Count != 0) { // If from same folder if (!string.IsNullOrWhiteSpace(Pics[FolderIndex]) && Path.GetDirectoryName(x) == Path.GetDirectoryName(Pics[FolderIndex])) { if (!Preloader.Contains(x)) { PreloadCount = 4; Preloader.Add(x); } Pic(Pics.IndexOf(x)); } else { Pic(x); } } else { Pic(x); } if (files.Length > 1) { for (int i = 1; i < files.Length; i++) { using (var n = new Process()) { n.StartInfo.FileName = Assembly.GetExecutingAssembly().Location; n.StartInfo.Arguments = files[i]; n.Start(); } } } } return; } } // Clipboard Image if (Clipboard.ContainsImage()) { Pic(Clipboard.GetImage(), "Clipboard Image"); return; } // text/string/adddress var s = Clipboard.GetText(TextDataFormat.Text); if (string.IsNullOrEmpty(s)) { return; } if (FilePathHasInvalidChars(s)) { MakeValidFileName(s); } s = s.Replace("\"", ""); s = s.Trim(); if (File.Exists(s)) { Pic(s); } else if (Directory.Exists(s)) { ChangeFolder(); Pics = FileList(s); if (Pics.Count > 0) { Pic(Pics[0]); } else if (!string.IsNullOrWhiteSpace(Pics[FolderIndex])) { Pic(Pics[FolderIndex]); } else { Unload(); } } else if (Uri.IsWellFormedUriString(s, UriKind.Absolute)) // Check if from web { LoadFromWeb.PicWeb(s); } else { ToolTipStyle("An error occured while trying to paste file"); } }