/// <summary> /// Refresh the current list of pics and reload them if there is some missing or changes. /// </summary> internal static void Reload(bool fromBackup = false) { if (fromBackup && string.IsNullOrWhiteSpace(BackupPath)) { Unload(); return; } string s; if (Pics != null && Pics.Count > 0) { s = fromBackup ? BackupPath : Pics[FolderIndex]; } else { // TODO extract url from path or get alternative method s = Path.GetFileName(ConfigureWindows.GetMainWindow.TitleText.Text); } if (File.Exists(s)) { // Force reloading values by setting freshStartup to true FreshStartup = true; // Clear Preloader, to avoid errors by FolderIndex changing location because of re-sorting Preloader.Clear(); // Need a sort method instead GalleryFunctions.Clear(); Pic(s); // Reset if (Flipped) { Flip(); } if (Rotateint != 0) { Rotate(0); } } else if (Clipboard.ContainsImage() || Base64.IsBase64String(s)) { return; } else if (Uri.IsWellFormedUriString(s, UriKind.Absolute)) // Check if from web { LoadFromWeb.PicWeb(s); } else { Unload(); ShowTooltipMessage(Application.Current.Resources["UnexpectedError"]); } }
/// <summary> /// Loads a picture from a given file path and does extra error checking /// </summary> /// <param name="path"></param> internal static async void Pic(string path) { // Set Loading SetLoadingString(); // Handle if from web if (!File.Exists(path)) { if (Uri.IsWellFormedUriString(path, UriKind.Absolute)) { LoadFromWeb.PicWeb(path); return; } else if (Directory.Exists(path)) { ChangeFolder(true); await GetValues(path).ConfigureAwait(true); } else { Unload(); return; } } // If count not correct or just started, get values if (Pics.Count <= FolderIndex || FolderIndex < 0 || FreshStartup) { await GetValues(path).ConfigureAwait(true); } // If the file is in the same folder, navigate to it. If not, start manual loading procedure. else if (!string.IsNullOrWhiteSpace(Pics[FolderIndex]) && Path.GetDirectoryName(path) != Path.GetDirectoryName(Pics[FolderIndex])) { // Reset old values and get new ChangeFolder(true); await GetValues(path).ConfigureAwait(true); } FolderIndex = Pics.IndexOf(path); // Fix large archive extraction error if (FolderIndex == -1) { var recovery = await RecoverFailedArchiveAsync().ConfigureAwait(true); if (!recovery) { Reload(true); return; } else { LoadWindows.GetMainWindow.TitleText.Text = Application.Current.Resources["Unzipping"] as string; LoadWindows.GetMainWindow.TitleText.ToolTip = LoadWindows.GetMainWindow.TitleText.Text; FolderIndex = 0; } LoadWindows.GetMainWindow.Focus(); } if (!FreshStartup) { Preloader.Clear(); } #if DEBUG if (FreshStartup) { Trace.WriteLine("Pic(string path) entering Pic(int x)"); } #endif // Navigate to picture using obtained index Pic(FolderIndex); // Load new gallery values, if changing folder if (GetPicGallery != null && Properties.Settings.Default.PicGallery == 2 && !GalleryFunctions.IsLoading) { await GalleryLoad.Load().ConfigureAwait(false); } }
/// <summary> /// Loads a picture from a given file path and does extra error checking /// </summary> /// <param name="path"></param> internal static async Task LoadPiFrom(string path) { // Set Loading SetLoadingString(); // Handle if from web if (!File.Exists(path)) { if (Uri.IsWellFormedUriString(path, UriKind.Absolute)) { LoadFromWeb.PicWeb(path); return; } else if (Directory.Exists(path)) { ChangeFolder(true); await GetValues(path).ConfigureAwait(true); } else { Unload(); return; } } // If count not correct or just started, get values if (Pics.Count <= FolderIndex || FolderIndex < 0 || FreshStartup) { await GetValues(path).ConfigureAwait(true); } // If the file is in the same folder, navigate to it. If not, start manual loading procedure. else if (!string.IsNullOrWhiteSpace(Pics[FolderIndex]) && Path.GetDirectoryName(path) != Path.GetDirectoryName(Pics[FolderIndex])) { // Reset old values and get new ChangeFolder(true); await GetValues(path).ConfigureAwait(true); } FolderIndex = Pics.IndexOf(path); if (!FreshStartup) { Preloader.Clear(); } if (FolderIndex != -1) // if it is -1, it means it being extracted and need to wait for it instead { // Navigate to picture using obtained index await LoadPicAt(FolderIndex).ConfigureAwait(false); } await ConfigureWindows.GetMainWindow.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, (Action)(async() => { // Load new gallery values, if changing folder if (GetPicGallery != null && Properties.Settings.Default.FullscreenGallery) { if (GetPicGallery.Container.Children.Count == 0) { await GalleryLoad.Load().ConfigureAwait(false); } } })); }
/// <summary> /// Loads a picture from a given file path and does extra error checking /// </summary> /// <param name="path"></param> internal static async void Pic(string path) { // Set Loading SetLoadingString(); // Handle if from web if (!File.Exists(path)) { if (Uri.IsWellFormedUriString(path, UriKind.Absolute)) { LoadFromWeb.PicWeb(path); return; } else if (Directory.Exists(path)) { ChangeFolder(true); await GetValues(path).ConfigureAwait(true); } else { Unload(); return; } } // If count not correct or just started, get values if (Pics.Count <= FolderIndex || FolderIndex < 0 || FreshStartup) { await GetValues(path).ConfigureAwait(true); } // If the file is in the same folder, navigate to it. If not, start manual loading procedure. else if (!string.IsNullOrWhiteSpace(Pics[FolderIndex]) && Path.GetDirectoryName(path) != Path.GetDirectoryName(Pics[FolderIndex])) { // Reset old values and get new ChangeFolder(true); await GetValues(path).ConfigureAwait(true); } FolderIndex = Pics.IndexOf(path); if (!FreshStartup) { Preloader.Clear(); } #if DEBUG if (FreshStartup) { Trace.WriteLine("Pic(string path) entering Pic(int x)"); } #endif // Navigate to picture using obtained index Pic(FolderIndex == -1 ? 0 : FolderIndex); // Load new gallery values, if changing folder if (GetPicGallery != null && Properties.Settings.Default.PicGallery == 2) { if (GetPicGallery.Container.Children.Count == 0) { await GalleryLoad.Load().ConfigureAwait(false); } } }