/// <summary> /// returns true if it could actually find something to display /// </summary> /// <returns></returns> private bool preview() { bool ret = false; disableButtons(); // Create an Image object from the specified file. try { m_wpt = PhotoWaypoints.CurrentWaypoint(); if (m_wpt != null) { PhotoDescr photoDescr = PhotoDescr.FromThumbnail(m_wpt.ThumbSource); photoViewerControl.photoDescr = m_photoDescr = photoDescr; setPhotoDetail(); if (m_keepInView) { PictureManager.This.CameraManager.keepInView(m_wpt.Location); } PictureManager.This.CameraManager.MarkLocation(m_wpt.Location, 0); ret = true; } else { photoViewerControl.photoDescr = m_photoDescr = null; } } // An invalid image will throw an OutOfMemoryException // exception catch (OutOfMemoryException) { throw new InvalidOperationException("'" + m_wpt.ThumbSource + "' is not a valid image file."); } if (ret) { setupButtons(); } DlgPhotoManager.sync(false); this.BringToFront(); return(ret); }
private void deleteButton_Click(object sender, System.EventArgs e) { if (m_photoDescr != null && m_photoDescr.imageSourceIsLocal) { string imageSource = m_photoDescr.imageSource; try { string msg; int pos = imageSource.IndexOf("|"); if (pos > 0) { // this is a .zip or .gpz file string zipFileName = imageSource.Substring(0, pos); string photoFileName = imageSource.Substring(pos + 1); msg = "Will permanently delete entry '" + photoFileName + "' from the zip archive '" + zipFileName + "'.\n\nThe zip archive file will NOT be deleted.\n\nAre you sure?"; } else { // plain file msg = "Will permanently delete file '" + imageSource + "' from disk.\n\nAre you sure?"; } string fileToDelete = null; if (Project.YesNoBox(this, msg)) { if (m_wpt != null) { if (m_wpt.TrackId == -1) { WaypointsCache.RemoveWaypointById(m_wpt.Id); } PhotoWaypoints.RemoveWaypoint(m_wpt); // from track too, if any photoViewerControl.photoDescr = null; fileToDelete = m_photoDescr.deleteFromDisk(); if (preview()) // will find current waypoint, if any, and set m_photoDescr { setPhotoDetail(); photoViewerControl.Refresh(); } else { // no image to display, need to wrap up m_photoDescr = null; this.Close(); } PictureManager.This.Refresh(); } else { PhotoWaypoints.RemoveUnrelatedById(m_photoDescr.Id); fileToDelete = m_photoDescr.deleteFromDisk(); if (PhotoWaypoints.PhotosUnrelated.Count > 0) { photoViewerControl.photoDescr = m_photoDescr = (PhotoDescr)PhotoWaypoints.PhotosUnrelated.GetByIndex(0); setPhotoDetail(); photoViewerControl.Refresh(); this.setupButtons(); this.BringToFront(); } else { photoViewerControl.photoDescr = m_photoDescr = null; this.Close(); } } DlgPhotoManager.sync(true); if (fileToDelete != null) { GC.Collect(); FileInfo fi = new FileInfo(fileToDelete); fi.Delete(); } } } catch (Exception exc) { Project.ErrorBox(this, "Failed to delete " + imageSource + "\n\nException: " + exc.Message); this.Close(); } } }