/// <summary>
 /// Prepares the files of an existing job.
 /// </summary>
 /// <returns>A MediaEncoderSegments object containing the segments analysis.</returns>
 public MediaEncoderSegments PrepareExistingJob(MediaEncoderSettings settings) {
     settings.ResumePos = 0;
     settings.CompletionStatus = CompletionStatus.Success;
     if (File.Exists(settings.FinalFile)) {
         // Merging was completed.
         return null;
     } else {
         MediaEncoderSegments SegBusiness = new MediaEncoderSegments();
         SegBusiness.Analyze(settings);
         return SegBusiness;
     }
 }
        /// <summary>
        /// For files encoded in various segments (stop/resume), merge the various segments.
        /// </summary>
        private CompletionStatus MergeSegments(MediaEncoderSettings settings, string destination) {
            MediaEncoderSegments segBusiness = new MediaEncoderSegments();
            segBusiness.Analyze(settings);
            if (segBusiness.SegLeft.Count() > 0)
                return CompletionStatus.Error;

            List<string> SegmentList = new List<string>();
            foreach (SegmentInfo seg in segBusiness.SegDone) {
                SegmentList.Add(PathManager.GetOutputFile(settings.JobIndex, seg.Start, settings.Container));
            }

            CompletionStatus Result = CompletionStatus.Success;
            File.Delete(destination);
            if (SegmentList.Count == 1)
                File.Move(SegmentList[0], destination);
            else if (SegmentList.Count > 1) {
                Result = MediaMuxer.Concatenate(SegmentList, destination, new ProcessStartOptions(settings.JobIndex, "Merging Files", false));
            }
            settings.CompletionStatus = Result;
            return Result;
        }