示例#1
0
        public void Execute(object parameter)
        {
            PasswordInput passwordInput = new PasswordInput();

            passwordInput.Owner = Application.Current.MainWindow;
            passwordInput.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            passwordInput.ShowDialog();
            Password = passwordInput.Password;
        }
示例#2
0
        void LoadImages()
        {
            var openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "Zip files|*.zip";

            if (!openFileDialog.ShowDialog() == true)
            {
                Application.Current.Shutdown();
                return;
            }

            var passwordSet = false;

            Images.Clear();
            Albums.Clear();

            using (var file = new ZipFile(openFileDialog.FileName))
            {
                AlbumModel currentAlbum = null;

                foreach (ZipEntry entry in file)
                {
                    if (entry.IsCrypted && !passwordSet)
                    {
                        var input = new PasswordInput();
                        if (!input.ShowDialog() == true)
                        {
                            Application.Current.Shutdown();
                            return;
                        }

                        file.Password = input.Password;
                        passwordSet = true;
                    }

                    if (!entry.IsFile)
                    {
                        var album = new AlbumModel(this);
                        album.Name = entry.Name;
                        currentAlbum = album;

                        Albums.Add(album);
                    }
                    else
                    {
                        var stream = file.GetInputStream(entry);
                        var buffer = new byte[4096];
                        var image = new BitmapImage();
                        var memoryStream = new MemoryStream();

                        try
                        {
                            StreamUtils.Copy(stream, memoryStream, buffer);

                            if (Path.GetExtension(entry.Name).ToLowerInvariant().Contains("jpg"))
                            {
                                var jpg = new Bitmap(memoryStream);

                                var stream2 = new MemoryStream();

                                jpg.Save(stream2, ImageFormat.Png);

                                memoryStream.Dispose();
                                memoryStream = stream2;
                            }

                            image.BeginInit();
                            image.CreateOptions = BitmapCreateOptions.IgnoreColorProfile;
                            image.CacheOption = BitmapCacheOption.OnLoad;
                            image.UriSource = null;
                            image.StreamSource = memoryStream;
                            image.EndInit();

                            Images.Add(new ImageModel()
                            {
                                Name = entry.Name,
                                Album = currentAlbum,
                                Image = image
                            });
                        }
                        finally
                        {
                            memoryStream.Dispose();
                        }
                    }
                }

                ImageIndex = 0;
            }
        }
示例#3
0
        private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            Form passwordForm = new PasswordInput(controller, dataGridView.SelectedRows[0].Cells[3].Value.ToString().Trim());

            passwordForm.ShowDialog();
        }