public void ReCreateAllThumbnails()
        {
            if (backgroundWorker.IsBusy)
            {
                return;
            }

            this.sema = new Semaphore(1, 1);
            statusDisplay.WorkFinished();

            if (!CurrentPath.StartsWith("::"))
            {
                backgroundWorker.RunWorkerAsync();
            }
        }
Esempio n. 2
0
        //controller
        private void buttonSaveAll_Click(object sender, EventArgs e)
        {
            IStatusDisplay statusDisplay = (IStatusDisplay)this.FindForm();
            List <string>  filenames     = this.GetAllFileList(this.chkSubdirs.Checked);

            PauseOtherWorker();

            statusDisplay.WorkStart(filenames.Count);

            foreach (string filename in filenames)
            {
                PictureMetaData pmd;
                if (this.currentPicture != null &&
                    this.currentPicture.Filename == filename)
                {
                    pmd = currentPicture;
                }
                else
                {
                    if (File.Exists(filename))
                    {
                        pmd = new PictureMetaData(filename);
                    }
                    else
                    {
                        continue;
                    }
                }


                bool breakForeach = SaveToPicture(pmd, true) == false;

                if (pmd != currentPicture)
                {
                    pmd.Close();
                }

                if (breakForeach)
                {
                    break;
                }

                statusDisplay.WorkNextPart();
            }

            FireDataChanged();

            statusDisplay.WorkFinished();

            RestartOtherWorker();
        }
Esempio n. 3
0
        private void buttonGetGpsData_Click(object sender, EventArgs e)
        {
            // a picture is need for the offset dialog
            if (this.currentPicture == null)
            {
                return;
            }

            // the filename of the gps log
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Title  = "Open gps nmea file";
            ofd.Filter = "*.txt|*.txt";
            if (ofd.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }

            this.lastGpsFile = ofd.FileName;

            // read the gps log
            GpsLog log = GpsLogFactory.FromFile(ofd.FileName);

            // empty log -> exit
            if (log.Count == 0)
            {
                return;
            }

            // ask for gps time offset
            PictureGpsOffsetDialog d = new PictureGpsOffsetDialog(currentPicture, log.FirstTime.Value, log.LastTime.Value);

            d.Offset = Settings.Default.GPSTimeOffset;
            if (d.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }

            // set offset to gps log
            Settings.Default.GPSTimeOffset = d.Offset;
            log.Offset = d.Offset;

            IStatusDisplay statusDisplay = (IStatusDisplay)this.FindForm();

            List <string> filenames = this.GetAllFileList(false);

            statusDisplay.WorkStart(filenames.Count);

            // compute the timespan of all pictures
            DateTime firstPicture           = new DateTime(4000, 1, 1);
            DateTime lastPicture            = new DateTime(1, 1, 1);
            List <PictureMetaData> pictures = new List <PictureMetaData>();

            foreach (string filename in filenames)
            {
                PictureMetaData pmd;
                if (this.currentPicture != null &&
                    this.currentPicture.Filename == filename)
                {
                    pmd = currentPicture;
                }
                else
                {
                    pmd = new PictureMetaData(filename);
                }

                if (pmd.ExifOriginalDateTime.HasValue)
                {
                    DateTime time = pmd.ExifOriginalDateTime.Value;

                    if (time > lastPicture)
                    {
                        lastPicture = time;
                    }
                    if (time < firstPicture)
                    {
                        firstPicture = time;
                    }

                    pictures.Add(pmd);
                }
                statusDisplay.WorkNextPart();
            }
            statusDisplay.WorkFinished();

            // ask the user: do it now?
            string text =
                String.Format(
                    "The GPS time is between {0} and {1}.\nThe picture time is between {2} and {3} ({4} and {5}).\n\nContinue?",
                    log.FirstTime,
                    log.LastTime,
                    firstPicture.Add(log.Offset),
                    lastPicture.Add(log.Offset),
                    firstPicture,
                    lastPicture);

            if (MessageBox.Show(text, "Continue?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                statusDisplay.WorkStart(pictures.Count);
                foreach (PictureMetaData pmd in pictures)
                {
                    UpdateGpsData(pmd, log);

                    if (pmd != currentPicture)
                    {
                        pmd.Close();
                    }
                    statusDisplay.WorkNextPart();
                }

                FireDataChanged();
                statusDisplay.WorkFinished();
            }
            else
            {
                foreach (PictureMetaData pmd in pictures)
                {
                    if (pmd != currentPicture)
                    {
                        pmd.Close();
                    }
                }
            }
        }
Esempio n. 4
0
        //TODO
        private void btnRename_Click(object sender, EventArgs e)
        {
            IStatusDisplay statusDisplay = (IStatusDisplay)this.FindForm();

            StopOtherWorker();

            List <string> filenames;

            if (this.chkFilename.Checked)
            {
                filenames = this.GetAllFileList(this.chkSubdirs.Checked);
            }
            else
            {
                filenames = new List <string>();
            }
            List <string> directories;

            if (this.chkDirectory.Checked)
            {
                directories = this.GetAllDirectoryList(this.chkSubdirs.Checked);
            }
            else
            {
                directories = new List <string>();
            }

            statusDisplay.WorkStart(filenames.Count + directories.Count);

            #region renaming files
            Features.Renamer.RenamerEngine renamer = new Features.Renamer.RenamerEngine(this.txtFilename.Text.Contains("%#"), !this.txtFilename.Text.Contains("%##"));

            filenames.Sort();
            foreach (string filename in filenames)
            {
                // get the new name form the metadata
                PictureMetaData pmd     = new PictureMetaData(filename);
                string          newname = FileNameFormater.FormatFilename(pmd, this.txtFilename.Text);
                newname = newname.Replace("%##", "%#");
                pmd.Close();

                if (newname != "")
                {
                    // open a file info
                    FileInfo fi = new FileInfo(filename);
                    newname = fi.DirectoryName + "\\" + newname;

                    // give the new name to the renamer
                    renamer.AddNewRenameItem(fi, newname);
                }

                // next
                statusDisplay.WorkNextPart();
            }

            // and now: do all the dirty working
            renamer.Rename();

            Settings.Default.FilenameFormats.AddIfGrowing(this.txtFilename.Text);
            #endregion

            string goToDir;
            #region renaming directories
            renamer = new Features.Renamer.RenamerEngine(this.txtDirectoryname.Text.Contains("%#"), !this.txtDirectoryname.Text.Contains("%##"));

            directories.Sort();
            foreach (string directory in directories)
            {
                // get the new name form the metadata
                PictureMetaData pmd;
                DirectoryInfo   di           = new DirectoryInfo(directory);
                bool            dontClosePmd = false;
                if (this.currentDirectory == di.FullName && this.currentPicture != null)
                {
                    pmd          = this.currentPicture;
                    dontClosePmd = true;
                }
                else
                {
                    pmd = GetPictureMetaDataFromDirectory(di);
                }

                if (pmd != null)
                {
                    string newname = FileNameFormater.FormatFilename(pmd, this.txtDirectoryname.Text);
                    newname = newname.Replace("%##", "%#");

                    if (!dontClosePmd)
                    {
                        pmd.Close();
                    }

                    if (newname != "")
                    {
                        // give the new name to the renamer
                        renamer.AddNewRenameItem(di, newname);
                    }
                }

                // next
                statusDisplay.WorkNextPart();
            }

            // and now: do all the dirty working
            DirectoryInfo curdi = new DirectoryInfo(this.currentDirectory);
            goToDir = curdi.Parent.FullName + "\\" + renamer.GetNewName(this.currentDirectory);
            renamer.Rename();

            Settings.Default.DirectorynameFormats.AddIfGrowing(this.txtDirectoryname.Text);
            #endregion

            if (this.chkDirectory.Checked)
            {
                if (Directory.Exists((goToDir)))
                {
                    this.FireDirectoryNameChanged(goToDir);
                }
            }
            else
            {
                this.FireDirectoryChanged();
            }

            statusDisplay.WorkFinished();
        }
Esempio n. 5
0
 void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     statusDisplay.WorkFinished();
 }