private void BindScreenshots()
        {
            ScreenshotCollection.Clear();
            try
            {
                List <Screenshot> screenshotList = LoadScreenshotList();
                foreach (Screenshot screenshot in screenshotList)
                {
                    if (screenshotList.Count < 1)
                    {
                        return;
                    }
                    string pathNoExt = $@"{Globals.DirectoryPath}\Data\images\screenshots\{Globals.VnId}\thumbs\{Path.GetFileNameWithoutExtension(screenshot.Url)}";
                    string path      = $@"{Globals.DirectoryPath}\Data\images\screenshots\{Globals.VnId}\thumbs\{Path.GetFileName(screenshot.Url)}";

                    switch (screenshot.IsNsfw)
                    {
                    case true when File.Exists(pathNoExt):
                    {
                        BitmapImage bImage = Globals.NsfwEnabled ? Base64Converter.GetBitmapImageFromBytes(File.ReadAllText(pathNoExt))
                                : new BitmapImage(new Uri($@"{Globals.DirectoryPath}\Data\res\nsfw\thumb.jpg"));

                        _screenshotCollection.Add(new ScreenshotViewModelCollection
                            {
                                ScreenshotModel = new VnScreenshotModel {
                                    Screenshot = bImage
                                }
                            });
                        break;
                    }

                    case false when File.Exists(path):
                    {
                        BitmapImage bitmap = new BitmapImage();
                        using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
                        {
                            bitmap.BeginInit();
                            bitmap.CacheOption  = BitmapCacheOption.OnLoad;
                            bitmap.StreamSource = stream;
                            bitmap.EndInit();
                        }
                        _screenshotCollection.Add(new ScreenshotViewModelCollection
                            {
                                ScreenshotModel = new VnScreenshotModel {
                                    Screenshot = bitmap
                                }
                            });
                        break;
                    }
                    }
                }
            }
            catch (Exception ex)
            {
                Globals.Logger.Error(ex);
                throw;
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Get the collection of Snapshot instances fro all available windows
 /// </summary>
 /// <param name="minimized">Capture a window even it's Minimized</param>
 /// <param name="specialCapturring">use special capturing method to capture minmized windows</param>
 /// <returns>return collections of Snapshot instances</returns>
 public static ScreenshotCollection GetAllWindows(bool minimized, bool specialCapturring)
 {
     _snapshots = new ScreenshotCollection();
     _countMinimizedWindows = minimized; //set minimized flag capture
     _useSpecialCapturing = specialCapturring; //set specialcapturing flag
     EnumWindowsCallbackHandler callback = EnumWindowsCallback;
     NativeMethods.EnumWindows(callback, IntPtr.Zero);
     return new ScreenshotCollection(_snapshots.ToArray(), true);
 }