예제 #1
0
        private void EventPropertiesMarkersPaste_Invoked(object sender, EventArgs e)
        {
            object cbMarkers = Clipboard.GetData(Strings.ClipboardMarkersTag);

            if (cbMarkers == null)
            {
                return;
            }
            var markers = (Dictionary <double, string>)cbMarkers;

            List <TrackEvent> selected = myVegas.Project.GetSelectedEvents();

            using (var undo = new UndoBlock("Add markers to files (don't undo this)"))
            {
                foreach (TrackEvent ev in selected)
                {
                    string dir      = Path.GetDirectoryName(ev.ActiveTake.Media.FilePath) + Path.DirectorySeparatorChar;
                    string filename = Path.GetFileName(ev.ActiveTake.Media.FilePath);

                    if (filename != null && (!ev.IsAudio() || !filename.Contains(".wav")))                     // wav files only, right now
                    {
                        continue;
                    }

                    string tempFileName = dir + Path.GetFileNameWithoutExtension(filename) + "_take02" + Path.GetExtension(filename);
                    uint   counter      = 2;
                    while (File.Exists(tempFileName))
                    {
                        tempFileName = dir + Path.GetFileNameWithoutExtension(filename) + "_take" + counter++.ToString().PadLeft(2, '0') +
                                       Path.GetExtension(filename);
                    }

                    string fullpath = dir + filename;
                    File.Copy(fullpath, tempFileName);
                    ev.ActiveTake.Media.ReplaceWith(new Media(tempFileName));
                    myVegas.Project.MediaPool.Remove(fullpath);

                    try
                    {
                        var fileReader = new BinaryReader(new FileStream(fullpath, FileMode.Open), Encoding.ASCII);
                        fileReader.Close();
                    }
                    catch
                    {
                        MessageBox.Show("File could not be opened. Try reloading Vegas.");
                        undo.Cancel = true;
                        return;
                    }

                    WaveFile.AddMarkers(fullpath, markers);

                    ev.ActiveTake.Media.ReplaceWith(new Media(fullpath));
                    myVegas.Project.MediaPool.Remove(tempFileName);
                    File.Delete(tempFileName);
                }
            }
        }