public AlbumNode(string name, string albumPath) : base(name) { if (albumPath == null) { throw new ArgumentNullException("albumPath"); } if (!File.Exists(albumPath)) { throw new ArgumentException("albumPath is not a valid path"); } _manager = null; _albumPath = Path.GetFullPath(albumPath); this.Nodes.Add("child"); if (AlbumStorage.IsEncrypted(albumPath)) { this.ImageKey = "AlbumLock"; this.SelectedImageKey = "AlbumLock"; } else { this.ImageKey = "Album"; this.SelectedImageKey = "AlbumSelect"; } }
private void mnuOpen_Click(object sender, EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Title = "Open Photo"; dlg.Filter = "jpg files (*.jpg)|*.jpg" + "|All files (*.*)|*.*"; dlg.InitialDirectory = AlbumManager.DefaultPath; dlg.RestoreDirectory = true; if (dlg.ShowDialog() == DialogResult.OK) { string path = dlg.FileName; string pwd = null; // Get password if encrypted if (AlbumStorage.IsEncrypted(path)) { using (AlbumPasswordDialog pwdDlg = new AlbumPasswordDialog()) { pwdDlg.Album = path; if (pwdDlg.ShowDialog() != DialogResult.OK) { return; // Open cancelled } pwd = pwdDlg.Password; } } // Close any existing album if (!SaveAndCloseAlbum()) { return; // Close canceled } try { // Open the new album Manager = new AlbumManager(path, pwd); } catch (AlbumStorageException aex) { string msg = String.Format( "Unable to open album file {0}\n({1})", path, aex.Message); MessageBox.Show(msg, "Unable to Open"); Manager = new AlbumManager(); } DisplayAlbum(); } dlg.Dispose(); }
public AlbumManager GetManager(bool interactive) { if (_manager == null) { string path = AlbumPath; string pwd = null; try { if (AlbumStorage.IsEncrypted(path)) { DialogResult result = DialogResult.None; if (interactive) { result = MessageBox.Show("The album " + path + " is encrypted. " + "Do you wish to open this album?", "Encrypted Album", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); } if (result != DialogResult.Yes || !AlbumController.CheckAlbumPassword(path, ref pwd)) { return(null); // cancelled } } _manager = new AlbumManager(path, pwd); this.ImageKey = "Album"; this.SelectedImageKey = "AlbumSelect"; } catch (AlbumStorageException ex) { if (interactive) { MessageBox.Show("The album could not " + "be opened [" + ex.Message + "]"); } this.ImageKey = "AlbumError"; this.SelectedImageKey = "AlbumError"; _manager = null; } } return(_manager); }
public static bool CheckAlbumPassword(string path, ref string password) { // Get password if encrypted if (AlbumStorage.IsEncrypted(path)) { using (AlbumPasswordDialog pwdDlg = new AlbumPasswordDialog()) { pwdDlg.Album = path; if (pwdDlg.ShowDialog() != DialogResult.OK) { return(false); } password = pwdDlg.Password; } } return(true); }
protected override void OnLoad(EventArgs e) { ComponentResourceManager resources = new ComponentResourceManager(typeof(MainForm)); Image newImage = (Image)resources.GetObject("mnuFileNew.Image"); Image openImage = (Image)resources.GetObject("mnuFileOpen.Image"); mnuFileNew.Image = newImage; mnuFileOpen.Image = openImage; tsbNew.Image = newImage; tsbOpen.Image = openImage; PixelDialog.GlobalMdiParent = this; SetTitleBar(); string name = Settings.Default.LastAlbumPath; if (!string.IsNullOrEmpty(name) && !AlbumStorage.IsEncrypted(name)) { CreateMdiChild(new MainForm(name, null)); } base.OnLoad(e); }