Ejemplo n.º 1
0
        /// <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
            mainWindow.Title       = mainWindow.Bar.Text = Loading;
            mainWindow.Bar.ToolTip = Loading;
            if (mainWindow.img.Source == null)
            {
                AjaxLoadingStart();
            }

            // Handle if from web
            if (!File.Exists(path))
            {
                if (Uri.IsWellFormedUriString(path, UriKind.Absolute))
                {
                    LoadFromWeb.PicWeb(path);
                }
                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 zipped values
                //if (!string.IsNullOrWhiteSpace(TempZipPath))
                //{
                //    DeleteTempFiles();
                //    TempZipPath = string.Empty;
                //    RecentFiles.SetZipped(string.Empty, false);
                //}

                // Reset old values and get new
                ChangeFolder(true);
                await GetValues(path).ConfigureAwait(true);
            }

            // If no need to reset values, get index
            else if (Pics != null)
            {
                FolderIndex = Pics.IndexOf(path);
            }

            if (Pics != null)
            {
                // Fix large archive extraction error
                if (Pics.Count == 0)
                {
                    var recovery = await RecoverFailedArchiveAsync().ConfigureAwait(true);

                    if (!recovery)
                    {
                        if (sexyToolTip.Opacity == 0)
                        {
                            ToolTipStyle("Archive could not be processed");
                        }

                        Reload(true);
                        return;
                    }
                    mainWindow.Focus();
                }
            }
            else
            {
                Reload(true);
                return;
            }

            if (File.Exists(Pics[FolderIndex]))
            {
                if (!freshStartup)
                {
                    Preloader.Clear();
                }

                // Navigate to picture using obtained index
                Pic(FolderIndex);
            }
            else
            {
                Reload(true);
                return;
            }

            // Load images for PicGallery if enabled
            if (Properties.Settings.Default.PicGallery > 0)
            {
                if (!PicGalleryLogic.IsLoading)
                {
                    await PicGalleryLoad.Load().ConfigureAwait(true);
                }
            }

            prevPicResource = null; // Make sure to not waste memory
        }
Ejemplo n.º 2
0
        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");
            }
        }