Esempio n. 1
0
        /// <summary>
        /// Gets the passed list of argument and analyzes it by using an Analyze instance.
        /// </summary>
        /// <param name="args">A string array that includes all filelist view arguments.</param>
        /// <param name="analyzeData">The Analyze instance to use.</param>
        public ProgressForm(string[] args, Analyze analyzeData)
        {
            this.args = args;
              this.analyzeData = analyzeData;

              InitializeComponent();
        }
Esempio n. 2
0
        //BackgroundWorker - Main analyze process for files
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            var previousData = analyzeData;

            analyzeData = new Analyze(backgroundWorker1);

            analyzeData.process(args);

            if (backgroundWorker1.CancellationPending)
            {
                e.Cancel = true;
                return;
            }

            if (previousData == MainWindow.projectManager.analyze)
            {
                MainWindow.projectManager.analyze = analyzeData;
            }

            e.Result = analyzeData;
        }
Esempio n. 3
0
        private void backgroundWorker4_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            DialogResult result = new DialogResult();

            // Check to see if an error occurred in the
            // background process.
            if (e.Error != null)
            {
                MessageBox.Show(e.Error.Message);
            }
            else

            // Check to see if the background process was cancelled.
            if (e.Cancelled)
            {
                MessageBox.Show("Processing cancelled.");
            }
            // If shutdownDevice is true, shutdown the computer.
            else if (Config.Configure.ConvertConfigure.shutdownDevice)
            {
                Program.ShutdownDevice();
            }
            else
            {
                // Everything completed normally.
                // process the response using e.Result
                Analyze processor = e.Result as Analyze;
                result = MessageBox.Show("Conversion complete! View output files?", "Confirm", MessageBoxButtons.YesNo);

                if (result == DialogResult.Yes)
                {
                    processor.LaunchInExplorer();
                }
            }

            this.Close();
        }
Esempio n. 4
0
        /// <summary>
        /// Create a ProgressForm with different modes, with the default ProjectManager Analyze instance.
        /// </summary>
        /// <param name="mode">Modes: 0 for XML creation (deprecated), 1 for merge, 2 for convert.</param>
        public ProgressForm(int mode)
        {
            switch (mode)
            {
            case 0:
                this.doMakeXml = true;
                break;

            case 1:
                this.doMerge = true;
                break;

            case 2:
                this.doConvert = true;
                break;

            default:
                break;
            }

            analyzeData = MainWindow.projectManager.analyze;

            InitializeComponent();
        }
Esempio n. 5
0
        /// <summary>
        /// Create a ProgressForm with different modes, and a custom Analyze instance.
        /// </summary>
        /// <param name="mode">Modes: 0 for XML creation (deprecated), 1 for merge, 2 for convert.</param>
        /// <param name="analyzeData">The Analyze instance to use for the mode.</param>
        public ProgressForm(int mode, Analyze analyzeData)
        {
            switch (mode)
            {
            case 0:
                this.doMakeXml = true;
                break;

            case 1:
                this.doMerge = true;
                break;

            case 2:
                this.doConvert = true;
                break;

            default:
                break;
            }

            this.analyzeData = analyzeData;

            InitializeComponent();
        }
 /// <summary>
 /// Clears the projectManager of any file data.
 /// </summary>
 public void ClearProject()
 {
     this.projectFileName = "";
       this.argumentList.Clear();
       /*
       if (this.analyze.fileLists.Count > 0)
     this.analyze.fileLists.Clear();
       this.analyze.hasOrdered = false;
        * */
       this.analyze = null;
 }
        /// <summary>
        /// Processes files to create File Objects for the main tasks of this program.
        /// Every tasks are denoted on each comment lines inside the method.
        /// </summary>
        /// <param name="list">The list that contains the fullpaths of the actual files.</param>
        /// <param name="listname">Name for the FileObjectCollection to be created.</param>
        /// <param name="processor">The Analyze object for progression report.</param>
        /// <param name="path">The path used as a working directory merge commands.</param>
        /// <param name="totalArguments">Optional. For progress report. The total number of lists to process.</param>
        public void processList(List<string> list, string listname, Analyze processor, string path = "C:\\", int totalArguments = 0)
        {
            FileObjectCollection fileList = new FileObjectCollection();
              TrackLister tracklist = new TrackLister();
              MakeFile makeFile = new MakeFile();
              ChapterGenerator chapterGet = new ChapterGenerator();
              ProgressState progressState = new ProgressState();

              fileList.folderPath = path;
              fileList.name = listname;

              progressState.listName = fileList.name;

              progress = 1;
              processPercent = 0;

              foreach (string s in list)
              {

            progressState.progressDetail = "Creating file entry...";

            Analyze.backgroundWorker.ReportProgress(processor.progressArg, progressState);

            FileObject file = new FileObject(s);

            processPercent = progress.ToPercentage(list.Count);
            progressState.progressPercent = processPercent;
            progressState.fileName = file.filename;
            Analyze.backgroundWorker.ReportProgress(processor.progressArg, progressState);

              //Routine after splitting
              //Checks if current backgroundWorker operation is cancelled
              //Stops this program if true
            if (Analyze.backgroundWorker.CancellationPending)
            {
              return;
            }

            if (file.extension == ".mkv")
            {
              try
              {
            file = InfoDumper.infoDump(file);
              }
              catch (Exception ex)
              {
            Program.Message("Error:\r\n\r\n" + ex.Message, "Error");
              }

              progressState.progressDetail = "Dumping MKV info...";

              Analyze.backgroundWorker.ReportProgress(processor.progressArg, progressState);

              file = chapterGet.chapterDump(file);

              if (!Config.Configure.includeMkvInfoOnFiles)
            file.mkvInfo = null;

              if (!Config.Configure.includeMediaInfoOnFiles)
            file.ffInfo = null;

              progressState.progressDetail = "Getting chapters' info...";

              Analyze.backgroundWorker.ReportProgress(processor.progressArg, progressState);

              fileList.hasMKV = true;
            }

            if (Program.hasFFmpeg)
            {

              progressState.progressDetail = "Dumping media info...";

              Analyze.backgroundWorker.ReportProgress(processor.progressArg, progressState);

              try
              {
            file = InfoDumper.ffInfoDump(file);
              }
              catch (Exception ex)
              {
            Program.Message("Error:\r\n\r\n" + ex.Message, "Error");
              }

              if (!String.IsNullOrEmpty(file.ffInfo)) file = chapterGet.mediaDump(file);

            }

            fileList.addFile(file);

            progress++;
              }

              if (fileList.hasMKV)
              {
            SuidLister suidList = CreateSuidLister(fileList);

            progressState.progressDetail = "Creating SUID list...";
            Analyze.backgroundWorker.ReportProgress(processor.progressArg, progressState);

            fileList = tracklist.arrangeTrack(fileList, suidList, processor);

            progressState.progressDetail = "Arranging new tracklist for every file...";
            Analyze.backgroundWorker.ReportProgress(processor.progressArg, progressState);

            //For Diagnostic purposes only
            if (Config.Configure.diagnose >= 30)
            {
              foreach (Suid suid in suidList.suidList)
              {

            {
              Console.WriteLine("SUID filename: " + suid.fileName);
              Console.WriteLine("SUID: " + suid.suid);
              Console.WriteLine("\n");
            }
              }

              Console.WriteLine("fileList.fileList.Count: " + fileList.fileList.Count + "\n");

              foreach (FileObject file in fileList.fileList)
              {

            //Console.WriteLine("Merge Argument count: {0}\n", file.mergeArgument.Count);

            foreach (MergeArgument merge in file.mergeArgument)
            {

              Console.WriteLine("Merge Argument:\nFile name: {0}\nTime Code: {1}\nFile Argument: {2}\nChapter Number: {3}\n",
                  file.filename,
                  merge.timeCode,
                  merge.fileName,
                  merge.chapterNum);

            }

            foreach (TimeCode time in file.timeCode)
            {
              Console.WriteLine("Time Code Argument: {0}\n", time.timeCode);
            }

            foreach (DelArgument del in file.delArgument)
            {
              Console.WriteLine("Del Argument: {0}\n", del.fileName);
            }

              }
            }

            if (Config.Configure.doMakeScript)
            {
              makeFile.makeFile(fileList, processor);

              progressState.progressDetail = "Creating Merge Script...";
              Analyze.backgroundWorker.ReportProgress(processor.progressArg, progressState);
            }

              }

              if (Config.Configure.doMakeXml)
              {
            makeFile.makeXML(fileList, processor);

            progressState.progressDetail = "Dumping XML file...";
            Analyze.backgroundWorker.ReportProgress(processor.progressArg, progressState);
              }

              processor.fileLists.Add(fileList);
        }
Esempio n. 8
0
        /// <summary>
        /// Processes files to create File Objects for the main tasks of this program.
        /// Every tasks are denoted on each comment lines inside the method.
        /// </summary>
        /// <param name="list">The list that contains the fullpaths of the actual files.</param>
        /// <param name="listname">Name for the FileObjectCollection to be created.</param>
        /// <param name="processor">The Analyze object for progression report.</param>
        /// <param name="path">The path used as a working directory merge commands.</param>
        /// <param name="totalArguments">Optional. For progress report. The total number of lists to process.</param>
        public void processList(List <string> list, string listname, Analyze processor, string path = "C:\\", int totalArguments = 0)
        {
            FileObjectCollection fileList      = new FileObjectCollection();
            TrackLister          tracklist     = new TrackLister();
            MakeFile             makeFile      = new MakeFile();
            ChapterGenerator     chapterGet    = new ChapterGenerator();
            ProgressState        progressState = new ProgressState();

            fileList.folderPath = path;
            fileList.name       = listname;

            progressState.listName = fileList.name;

            progress       = 1;
            processPercent = 0;

            foreach (string s in list)
            {
                progressState.progressDetail = "Creating file entry...";

                Analyze.backgroundWorker.ReportProgress(processor.progressArg, progressState);

                FileObject file = new FileObject(s);

                processPercent = progress.ToPercentage(list.Count);
                progressState.progressPercent = processPercent;
                progressState.fileName        = file.filename;
                Analyze.backgroundWorker.ReportProgress(processor.progressArg, progressState);

                //Routine after splitting
                //Checks if current backgroundWorker operation is cancelled
                //Stops this program if true
                if (Analyze.backgroundWorker.CancellationPending)
                {
                    return;
                }

                if (file.extension == ".mkv")
                {
                    try
                    {
                        file = InfoDumper.infoDump(file);
                    }
                    catch (Exception ex)
                    {
                        Program.Message("Error:\r\n\r\n" + ex.Message, "Error");
                    }

                    progressState.progressDetail = "Dumping MKV info...";

                    Analyze.backgroundWorker.ReportProgress(processor.progressArg, progressState);

                    file = chapterGet.chapterDump(file);

                    if (!Config.Configure.includeMkvInfoOnFiles)
                    {
                        file.mkvInfo = null;
                    }

                    if (!Config.Configure.includeMediaInfoOnFiles)
                    {
                        file.ffInfo = null;
                    }

                    progressState.progressDetail = "Getting chapters' info...";

                    Analyze.backgroundWorker.ReportProgress(processor.progressArg, progressState);

                    fileList.hasMKV = true;
                }

                if (Program.hasFFmpeg)
                {
                    progressState.progressDetail = "Dumping media info...";

                    Analyze.backgroundWorker.ReportProgress(processor.progressArg, progressState);

                    try
                    {
                        file = InfoDumper.ffInfoDump(file);
                    }
                    catch (Exception ex)
                    {
                        Program.Message("Error:\r\n\r\n" + ex.Message, "Error");
                    }

                    if (!String.IsNullOrEmpty(file.ffInfo))
                    {
                        file = chapterGet.mediaDump(file);
                    }
                }

                fileList.addFile(file);

                progress++;
            }

            if (fileList.hasMKV)
            {
                SuidLister suidList = CreateSuidLister(fileList);

                progressState.progressDetail = "Creating SUID list...";
                Analyze.backgroundWorker.ReportProgress(processor.progressArg, progressState);

                fileList = tracklist.arrangeTrack(fileList, suidList, processor);

                progressState.progressDetail = "Arranging new tracklist for every file...";
                Analyze.backgroundWorker.ReportProgress(processor.progressArg, progressState);

                //For Diagnostic purposes only
                if (Config.Configure.diagnose >= 30)
                {
                    foreach (Suid suid in suidList.suidList)
                    {
                        {
                            Console.WriteLine("SUID filename: " + suid.fileName);
                            Console.WriteLine("SUID: " + suid.suid);
                            Console.WriteLine("\n");
                        }
                    }

                    Console.WriteLine("fileList.fileList.Count: " + fileList.fileList.Count + "\n");

                    foreach (FileObject file in fileList.fileList)
                    {
                        //Console.WriteLine("Merge Argument count: {0}\n", file.mergeArgument.Count);

                        foreach (MergeArgument merge in file.mergeArgument)
                        {
                            Console.WriteLine("Merge Argument:\nFile name: {0}\nTime Code: {1}\nFile Argument: {2}\nChapter Number: {3}\n",
                                              file.filename,
                                              merge.timeCode,
                                              merge.fileName,
                                              merge.chapterNum);
                        }

                        foreach (TimeCode time in file.timeCode)
                        {
                            Console.WriteLine("Time Code Argument: {0}\n", time.timeCode);
                        }

                        foreach (DelArgument del in file.delArgument)
                        {
                            Console.WriteLine("Del Argument: {0}\n", del.fileName);
                        }
                    }
                }

                if (Config.Configure.doMakeScript)
                {
                    makeFile.makeFile(fileList, processor);

                    progressState.progressDetail = "Creating Merge Script...";
                    Analyze.backgroundWorker.ReportProgress(processor.progressArg, progressState);
                }
            }

            if (Config.Configure.doMakeXml)
            {
                makeFile.makeXML(fileList, processor);

                progressState.progressDetail = "Dumping XML file...";
                Analyze.backgroundWorker.ReportProgress(processor.progressArg, progressState);
            }

            processor.fileLists.Add(fileList);
        }
Esempio n. 9
0
        /// <summary>
        /// Executes merge arguments after ListProcessor has done its job.
        /// </summary>
        /// <param name="fileList">The FileObjectCollection processed by TrackLister.</param>
        /// <param name="processor">The Analyze object for progress reporting.</param>
        /// <param name="useCmd">Deprecated - sets whether to use cmd or not for merge execution.</param>
        /// <param name="fileListPercent">The percentage of File Lists processed. Used for progress reporting.</param>
        public void Merge(FileObjectCollection fileList, Analyze processor, bool useCmd = false, int fileListPercent = 100)
        {
            List <string> cmdCommand    = new List <string>();
            string        splitArgument = "";
            string        mergeArgument = "";
            string        outputPath    = "";

            ProgressState progressState = new ProgressState();

            progressState.listName = fileList.name;

            progress       = 1;
            processPercent = 0;

            /*
             * Legacy code - since the command was just repeated twice below!
             *
             * if (fileList.hasOrdered)
             * {
             * Directory.CreateDirectory(Path.Combine(fileList.folderPath, "output"));
             * }
             *
             * */

            if (!Config.Configure.sourceOutputFolder)
            {
                outputPath = Program.defaultPath;
                if (!Directory.Exists(Path.Combine(outputPath, "merged")))
                {
                    Directory.CreateDirectory(Path.Combine(outputPath, "merged"));
                }
            }

            foreach (FileObject file in fileList.fileList)
            {
                //Routine after merging
                //Checks if current backgroundWorker operation is cancelled
                //Stops this program if true
                if (this.backgroundWorker.CancellationPending)
                {
                    return;
                }

                if (Config.Configure.sourceOutputFolder)
                {
                    outputPath = file.directoryname;
                }

                if (!Directory.Exists(Path.Combine(outputPath, "merged")))
                {
                    Directory.CreateDirectory(Path.Combine(outputPath, "merged"));
                }

                List <string> timeCodeList      = new List <string>();
                List <string> delArgumentList   = new List <string>();
                List <string> mergeArgumentList = new List <string>();
                List <string> chapterInfo       = new List <string>();

                progressState.fileName = file.filename;

                processPercent = progress.ToPercentage(fileList.fileList.Count);
                progressState.progressPercent = processPercent;

                progressState.progressDetail = "";
                this.backgroundWorker.ReportProgress(fileListPercent, progressState);



                /*
                 * Main process
                 * */
                if (file.mergeArgument.Count > 1)
                {
                    foreach (MergeArgument merge in file.mergeArgument)
                    {
                        if (merge.isExternalSuid)
                        {
                            mergeArgumentList.Add("\"" + merge.fullPath + "\"");
                        }
                        else
                        {
                            if (file.splitCount > 1)
                            {
                                mergeArgumentList.Add("\"" + Path.Combine(outputPath, merge.fileName) + "\"");
                            }
                            else
                            {
                                mergeArgumentList.Add("\"" + merge.originalFullPath + "\"");
                            }
                        }
                    }

                    foreach (TimeCode time in file.timeCode)
                    {
                        timeCodeList.Add(time.timeCode);
                    }

                    foreach (DelArgument del in file.delArgument)
                    {
                        delArgumentList.Add("\"" + del.fullPath + "\"");
                    }

                    string[] timeCode     = timeCodeList.ToArray();
                    string[] delString    = delArgumentList.ToArray();
                    string[] mergeString  = mergeArgumentList.ToArray();
                    string[] chaptersInfo = chapterInfo.ToArray();

                    string tempFileName     = "\"" + Config.Configure.tempfileprefix + file.filenameNoExtension + Config.Configure.tempfilesuffix + ".mkv\"";
                    string newFileName      = "\"merged\\" + Config.Configure.newfileprefix + file.filenameNoExtension + Config.Configure.newfilesuffix + ".mkv\"";
                    string originalFileName = "\"" + file.fullpath + "\"";

                    if (file.shouldJoin)
                    {
                        //processor.orderedGroups.Add(outputPath); //should be inside a check outside this loop, else it would add needless duplicates of outputPath


                        if (file.splitCount > 1)
                        {
                            splitArgument = "--no-chapters --split timecodes:" + String.Join(",", timeCode) + " -o " + tempFileName + " " + originalFileName;
                        }

                        mergeArgument = "--no-chapters -o " + newFileName + " " + String.Join(" +", mergeString);
                    }

                    progressState.progressDetail = "Building merge arguments...";
                    this.backgroundWorker.ReportProgress(fileListPercent, progressState);
                }

                //Routine after merge arguments
                //Checks if current backgroundWorker operation is cancelled
                //Stops this program if true
                if (this.backgroundWorker.CancellationPending)
                {
                    return;
                }

                if (file.shouldJoin)
                {
                    ProcessStartInfo mergeProcess = new ProcessStartInfo();

                    mergeProcess.FileName         = Program.mergeExe;
                    mergeProcess.UseShellExecute  = false;
                    mergeProcess.CreateNoWindow   = true;
                    mergeProcess.WorkingDirectory = file.directoryname;
                    mergeProcess.WindowStyle      = ProcessWindowStyle.Hidden;
                    //mergeProcess.RedirectStandardOutput = true;

                    if (file.splitCount > 1)
                    {
                        progressState.progressDetail = "Splitting file...";
                        this.backgroundWorker.ReportProgress(fileListPercent, progressState);

                        mergeProcess.Arguments = splitArgument;

                        using (Process process = Process.Start(mergeProcess))
                        {
                            process.WaitForExit();
                        }
                    }

                    //Routine after splitting
                    //Checks if current backgroundWorker operation is cancelled
                    //Stops this program if true
                    if (this.backgroundWorker.CancellationPending)
                    {
                        foreach (DelArgument del in file.delArgument)
                        {
                            File.Delete(del.fullPath);
                        }

                        return;
                    }

                    progressState.progressDetail = "Merging file...";
                    this.backgroundWorker.ReportProgress(fileListPercent, progressState);

                    mergeProcess.Arguments = mergeArgument;

                    using (Process process = Process.Start(mergeProcess))
                    {
                        process.WaitForExit();
                    }

                    progressState.progressDetail = "Deleting temporary files...";
                    this.backgroundWorker.ReportProgress(fileListPercent, progressState);

                    foreach (DelArgument del in file.delArgument)
                    {
                        File.Delete(del.fullPath);
                    }
                }

                progress++;
            }

            if (fileList.hasOrdered && !Analyze.outputGroups.Contains(outputPath))
            {
                Analyze.outputGroups.Add(outputPath + "\\merged");
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Rearranges chapter tracks to include the inserted external file determined by SUID.
        /// Also determines MergeArguments order.
        /// </summary>
        /// <param name="fileList">The FileObjectCollection processed by ChapterGenerator.</param>
        /// <param name="suid">The SuidLister that contains all SUIDs.</param>
        /// <param name="processor">The Analyze object for progression report.</param>
        /// <returns>The FileObjectCollection with FileObjects that has rearranged chapter tracks.</returns>
        public FileObjectCollection arrangeTrack(FileObjectCollection fileList, SuidLister suid, Analyze processor)
        {
            //string mergeargument = "";

              foreach (FileObject file in fileList.fileList)
              {

            int count = 0;
            string tempFileName = "";
            string tempFullPath = "";

              //First loop to determine which chapters have external suid attached
            foreach (ChapterAtom chaptera in file.chapterAtom)
            {
              foreach (Suid suidi in suid.suidList)
              {

            if (suidi.suid == chaptera.suid)
            {
              chaptera.suidFileName = suidi.fileName;
              chaptera.suidFullPath = suidi.fullPath;

              //Console.WriteLine("SUID match.");
            }

              }

              //mergeargument = mergeargument + chaptera.timeStart + chaptera.timeEnd + chaptera.suidFileName;
            }

              //Second loop that uses index to properly determine which chapter needs to be added as a MergeArgument
            for (int i = 0; i < file.chapterAtom.Count; i++)
            {

              var current = file.chapterAtom[i];

              var previous = current;
              var next = current;

              if (i > 0)
              {
            previous = file.chapterAtom.ElementAt(i - 1);
              }

              if (i < (file.chapterAtom.Count - 1))
              {
            next = file.chapterAtom.ElementAt(i + 1);
              }

              /*
               * Diagnostic purposes only
               *
               * Console.WriteLine("Arrange Track");
               * Console.WriteLine("Current: " + current.suidFileName);
               * Console.WriteLine("Previous: " + previous.suidFileName);
               * Console.WriteLine("Next: " + next.suidFileName);
               * Console.WriteLine("\n");
               * */

              //The following routine should correctly determine when to split the the chapters optimally to insert the external SUID file
              if (current.suidFileName != null)
              {
            file.addMergeArg(current.suidFullPath, current.chapterNum, true);
            if (!file.shouldJoin)
              file.shouldJoin = true;
            if (!fileList.hasOrdered)
              fileList.hasOrdered = true;
            if (!processor.hasOrdered)
              processor.hasOrdered = true;
              }
              else
              {

            string timeCode = "";

              //TimeEnd Split Mode
            if (Config.Configure.splitModeTimeEnd && (next.suidFileName != null || i == file.chapterAtom.Count - 1))
            {
              count++;

              file.splitCount = count;

              timeCode = current.timeEnd;

            //to change, should dynamically change digit format to "ddd"
            // done
              tempFileName = Config.Configure.tempfileprefix + file.filenameNoExtension + Config.Configure.tempfilesuffix + "-" + count.ToString("D3") + ".mkv";
              tempFullPath = Path.Combine(fileList.folderPath, Config.Configure.tempfileprefix + file.filenameNoExtension + Config.Configure.tempfilesuffix) + "-" + count.ToString("D3") + ".mkv";

              file.addMergeArg(tempFullPath, current.chapterNum, false, timeCode, tempFileName, file.fullpath);
              if (i != file.chapterAtom.Count - 1)
                file.addTimeCode(timeCode);
              file.addDelArg(tempFullPath, tempFileName);
            }
              //TimeStart Split Mode
            else if (Config.Configure.splitModeTimeStart && (previous.suidFileName != null || i == 0))
            {
              count++;

              file.splitCount = count;

              timeCode = current.timeStart;

              tempFileName = Config.Configure.tempfileprefix + file.filenameNoExtension + Config.Configure.tempfilesuffix + "-" + count.ToString("D3") + ".mkv";
              tempFullPath = Path.Combine(fileList.folderPath, Config.Configure.tempfileprefix + file.filenameNoExtension + Config.Configure.tempfilesuffix) + "-" + count.ToString("D3") + ".mkv";

              file.addMergeArg(tempFullPath, current.chapterNum, false, timeCode, tempFileName, file.fullpath);
              if (i > 0)
                file.addTimeCode(timeCode);
              file.addDelArg(tempFullPath, tempFileName);

            }

              }

            }

              }

              return fileList;
        }
Esempio n. 11
0
        /// <summary>
        /// Deprecated. Creates a script that executes mkvmerge commands to merge analyzed files
        /// </summary>
        /// <param name="fileList">The processed FileObjectCollection.</param>
        /// <param name="processor">The Analyze object</param>
        /// <param name="outputPathArg">Optional. Pass a different output path for the script.</param>
        public void makeFile(FileObjectCollection fileList, Analyze processor, string outputPathArg = null)
        {
            if (outputPathArg != null)
            {
                outputPath = outputPathArg;
            }
            else
            if (Config.Configure.sourceOutputFolder)
            {
                outputPath = Path.Combine(fileList.folderPath, Config.Configure.exportfilename);
            }
            else
            {
                outputPath = Path.Combine(outputPath, Config.Configure.exportfilename);
            }


            StringBuilder makeFileContent = new StringBuilder();

            if (Config.Configure.diagnoseMkvinfoDump | Config.Configure.diagnoseChapterinfoDump)
            {
                Directory.CreateDirectory(dumpPath);
            }

            foreach (FileObject file in fileList.fileList)
            {
                List <string> timeCodeList      = new List <string>();
                List <string> delArgumentList   = new List <string>();
                List <string> mergeArgumentList = new List <string>();
                List <string> chapterInfo       = new List <string>();

                /*
                 * Diagnostic purposes only
                 * */
                if (Config.Configure.diagnoseMkvinfoDump)
                {
                    using (StreamWriter writer = new StreamWriter(Path.Combine(dumpPath, file.filenameNoExtension + "_mkvinfo.txt")))
                    {
                        writer.Write(file.mkvInfo);
                    }
                }

                /*
                 * Main process
                 * */
                if (file.mergeArgument.Count > 1)
                {
                    foreach (MergeArgument merge in file.mergeArgument)
                    {
                        if (merge.isExternalSuid)
                        {
                            mergeArgumentList.Add("\"" + merge.fullPath + "\"");
                        }
                        else
                        {
                            if (file.splitCount > 1)
                            {
                                mergeArgumentList.Add("\"" + merge.fileName + "\"");
                            }
                            else
                            {
                                mergeArgumentList.Add("\"" + merge.originalFullPath + "\"");
                            }
                        }
                    }

                    foreach (TimeCode time in file.timeCode)
                    {
                        timeCodeList.Add(time.timeCode);
                    }

                    foreach (DelArgument del in file.delArgument)
                    {
                        delArgumentList.Add("\"" + del.fileName + "\"");
                    }

                    foreach (ChapterAtom chapter in file.chapterAtom)
                    {
                        chapterInfo.Add(chapter.chapterInfo);
                    }

                    string[] timeCode      = timeCodeList.ToArray();
                    string[] delArgument   = delArgumentList.ToArray();
                    string[] mergeArgument = mergeArgumentList.ToArray();
                    string[] chaptersInfo  = chapterInfo.ToArray();

                    string tempFileName     = "\"" + Config.Configure.tempfileprefix + file.filenameNoExtension + Config.Configure.tempfilesuffix + ".mkv\"";
                    string newFileName      = "\"output\\" + Config.Configure.newfileprefix + file.filenameNoExtension + Config.Configure.newfilesuffix + ".mkv\"";
                    string originalFileName = "\"" + file.fullpath + "\"";

                    if (file.shouldJoin)
                    {
                        doMakeFile = true;
                        makeFileContent.AppendLine("::" + file.filename);

                        if (file.splitCount > 1)
                        {
                            makeFileContent.AppendLine("mkvmerge --no-chapters --split timecodes:" + String.Join(",", timeCode) + " -o " + tempFileName + " " + originalFileName);
                        }

                        makeFileContent.AppendLine("mkvmerge --no-chapters -o " + newFileName + " " + String.Join(" +", mergeArgument) + "\r\n");
                        makeFileContent.AppendLine("DEL /Q " + String.Join(" ", delArgument) + "\r\n");
                    }

                    if (Config.Configure.diagnoseChapterinfoDump)
                    {
                        using (StreamWriter writer = new StreamWriter(Path.Combine(dumpPath, file.filenameNoExtension + "_chaptersinfo.txt")))
                        {
                            writer.WriteLine(String.Join("\n", chaptersInfo));
                        }
                    }
                }
            }

            if (doMakeFile)
            {
                using (StreamWriter writer = new StreamWriter(outputPath))
                {
                    writer.WriteLine("@echo off\r\ncls\r\n\r\npushd \"%~dp0\"\r\nif not exist output mkdir output\r\n");
                    writer.Write(makeFileContent);
                }
                Analyze.outputGroups.Add(outputPath);
            }
            else
            {
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Executes merge arguments after ListProcessor has done its job.
        /// </summary>
        /// <param name="fileList">The FileObjectCollection processed by TrackLister.</param>
        /// <param name="processor">The Analyze object for progress reporting.</param>
        /// <param name="useCmd">Deprecated - sets whether to use cmd or not for merge execution.</param>
        /// <param name="fileListPercent">The percentage of File Lists processed. Used for progress reporting.</param>
        public void Merge(FileObjectCollection fileList, Analyze processor, bool useCmd = false, int fileListPercent = 100)
        {
            List<string> cmdCommand = new List<string>();
              string splitArgument = "";
              string mergeArgument = "";
              string outputPath = "";

              ProgressState progressState = new ProgressState();
              progressState.listName = fileList.name;

              progress = 1;
              processPercent = 0;

              /*
               * Legacy code - since the command was just repeated twice below!
               *
              if (fileList.hasOrdered)
              {
            Directory.CreateDirectory(Path.Combine(fileList.folderPath, "output"));
              }
               *
               * */

              if (!Config.Configure.sourceOutputFolder)
              {
            outputPath = Program.defaultPath;
            if (!Directory.Exists(Path.Combine(outputPath, "merged")))
              Directory.CreateDirectory(Path.Combine(outputPath, "merged"));
              }

              foreach (FileObject file in fileList.fileList)
              {

              //Routine after merging
              //Checks if current backgroundWorker operation is cancelled
              //Stops this program if true
            if (this.backgroundWorker.CancellationPending)
            {
              return;
            }

            if (Config.Configure.sourceOutputFolder)
            {
              outputPath = file.directoryname;
            }

            if (!Directory.Exists(Path.Combine(outputPath, "merged")))
              Directory.CreateDirectory(Path.Combine(outputPath, "merged"));

            List<string> timeCodeList = new List<string>();
            List<string> delArgumentList = new List<string>();
            List<string> mergeArgumentList = new List<string>();
            List<string> chapterInfo = new List<string>();

            progressState.fileName = file.filename;

            processPercent = progress.ToPercentage(fileList.fileList.Count);
            progressState.progressPercent = processPercent;

            progressState.progressDetail = "";
            this.backgroundWorker.ReportProgress(fileListPercent, progressState);

            /*
              * Main process
              * */
            if (file.mergeArgument.Count > 1)
            {

              foreach (MergeArgument merge in file.mergeArgument)
              {

            if (merge.isExternalSuid)
              mergeArgumentList.Add("\"" + merge.fullPath + "\"");
            else
            {
              if (file.splitCount > 1)
              {
                mergeArgumentList.Add("\"" + Path.Combine(outputPath, merge.fileName) + "\"");
              }
              else
                mergeArgumentList.Add("\"" + merge.originalFullPath + "\"");

            }

              }

              foreach (TimeCode time in file.timeCode)
              {
            timeCodeList.Add(time.timeCode);
              }

              foreach (DelArgument del in file.delArgument)
              {
            delArgumentList.Add("\"" + del.fullPath + "\"");
              }

              string[] timeCode = timeCodeList.ToArray();
              string[] delString = delArgumentList.ToArray();
              string[] mergeString = mergeArgumentList.ToArray();
              string[] chaptersInfo = chapterInfo.ToArray();

              string tempFileName = "\"" + Config.Configure.tempfileprefix + file.filenameNoExtension + Config.Configure.tempfilesuffix + ".mkv\"";
              string newFileName = "\"merged\\" + Config.Configure.newfileprefix + file.filenameNoExtension + Config.Configure.newfilesuffix + ".mkv\"";
              string originalFileName = "\"" + file.fullpath + "\"";

              if (file.shouldJoin)
              {

            //processor.orderedGroups.Add(outputPath); //should be inside a check outside this loop, else it would add needless duplicates of outputPath

            if (file.splitCount > 1)
            {
              splitArgument = "--no-chapters --split timecodes:" + String.Join(",", timeCode) + " -o " + tempFileName + " " + originalFileName;

            }

            mergeArgument = "--no-chapters -o " + newFileName + " " + String.Join(" +", mergeString);

              }

              progressState.progressDetail = "Building merge arguments...";
              this.backgroundWorker.ReportProgress(fileListPercent, progressState);

            }

              //Routine after merge arguments
              //Checks if current backgroundWorker operation is cancelled
              //Stops this program if true
            if (this.backgroundWorker.CancellationPending)
            {
              return;
            }

            if (file.shouldJoin)
            {
              ProcessStartInfo mergeProcess = new ProcessStartInfo();

              mergeProcess.FileName = Program.mergeExe;
              mergeProcess.UseShellExecute = false;
              mergeProcess.CreateNoWindow = true;
              mergeProcess.WorkingDirectory = file.directoryname;
              mergeProcess.WindowStyle = ProcessWindowStyle.Hidden;
              //mergeProcess.RedirectStandardOutput = true;

              if (file.splitCount > 1)
              {
            progressState.progressDetail = "Splitting file...";
            this.backgroundWorker.ReportProgress(fileListPercent, progressState);

            mergeProcess.Arguments = splitArgument;

            using (Process process = Process.Start(mergeProcess))
            {
              process.WaitForExit();
            }

              }

            //Routine after splitting
            //Checks if current backgroundWorker operation is cancelled
            //Stops this program if true
              if (this.backgroundWorker.CancellationPending)
              {
            foreach (DelArgument del in file.delArgument)
              File.Delete(del.fullPath);

            return;
              }

              progressState.progressDetail = "Merging file...";
              this.backgroundWorker.ReportProgress(fileListPercent, progressState);

              mergeProcess.Arguments = mergeArgument;

              using (Process process = Process.Start(mergeProcess))
              {
            process.WaitForExit();
              }

              progressState.progressDetail = "Deleting temporary files...";
              this.backgroundWorker.ReportProgress(fileListPercent, progressState);

              foreach (DelArgument del in file.delArgument)
            File.Delete(del.fullPath);

            }

            progress++;

              }

              if (fileList.hasOrdered && !Analyze.outputGroups.Contains(outputPath))
              {
            Analyze.outputGroups.Add(outputPath + "\\merged");
              }
        }
Esempio n. 13
0
        /// <summary>
        /// Deprecated. There is no use for an xml file that holds fileList information.
        /// </summary>
        /// <param name="fileList">The FileObjectCollection to serialize into XML.</param>
        /// <param name="processor">The Processor object to get the file objects from.</param>
        public void makeXML(FileObjectCollection fileList, Analyze processor)
        {
            XmlSerializer xmlWrite = new XmlSerializer(typeof(FileObjectCollection));

              string fileListName = fileList.name + ".xml";

              FileStream xmlfile = File.Create(Path.Combine(outputPath, fileListName));

              xmlWrite.Serialize(xmlfile, fileList);

              xmlfile.Close();
        }
Esempio n. 14
0
        /// <summary>
        /// Create a ProgressForm with different modes, with the default ProjectManager Analyze instance.
        /// </summary>
        /// <param name="mode">Modes: 0 for XML creation (deprecated), 1 for merge, 2 for convert.</param>
        public ProgressForm(int mode)
        {
            switch (mode)
              {
            case 0:
              this.doMakeXml = true;
              break;
            case 1:
              this.doMerge = true;
              break;
            case 2:
              this.doConvert = true;
              break;
            default:
              break;
              }

              analyzeData = MainWindow.projectManager.analyze;

              InitializeComponent();
        }
Esempio n. 15
0
        /// <summary>
        /// Create a ProgressForm with different modes, and a custom Analyze instance.
        /// </summary>
        /// <param name="mode">Modes: 0 for XML creation (deprecated), 1 for merge, 2 for convert.</param>
        /// <param name="analyzeData">The Analyze instance to use for the mode.</param>
        public ProgressForm(int mode, Analyze analyzeData)
        {
            switch (mode)
              {
            case 0:
              this.doMakeXml = true;
              break;
            case 1:
              this.doMerge = true;
              break;
            case 2:
              this.doConvert = true;
              break;
            default:
              break;
              }

              this.analyzeData = analyzeData;

              InitializeComponent();
        }
Esempio n. 16
0
        private void backgroundWorker3_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            //var dialogComplete = new CustomDialog();

              DialogResult result = new DialogResult();

              // Check to see if an error occurred in the
              // background process.
              if (e.Error != null)
              {
            MessageBox.Show(e.Error.Message);
              }
              else

            // Check to see if the background process was cancelled.
            if (e.Cancelled)
            {
              MessageBox.Show("Processing cancelled.");
            }
            else
            {
              // Everything completed normally.
              // process the response using e.Result
              Analyze processor = e.Result as Analyze;

              var dialogComplete = new CustomDialog("Merging complete!", "Confirm", "OK", "Convert", "View in Explorer");

              result = dialogComplete.ShowDialog();

              //result = CustomDialog.Show("Merging complete!\n\nBut!\n\nWait!\n\nThere's more to it than it seems apparently through your boggling eyes (Yes, that's a new English word).\n\nOkay.", "Confirm", "OK", "Convert", "View in Explorer");

              if (result == DialogResult.OK)
              {

            if (dialogComplete.buttonPressed == "View in Explorer")
              processor.LaunchInExplorer();
            else if (dialogComplete.buttonPressed == "Convert")
            {

              Analyze analyzeMerged = new Analyze();

              var mergedAnalyze = new ProgressForm(Analyze.outputGroups.ToArray(), analyzeMerged);

              mergedAnalyze.ShowDialog();

              analyzeMerged = mergedAnalyze.analyzeData;

              var mergedConvert = new ProgressForm(2, analyzeMerged);

              mergedConvert.ShowDialog();

            }
            else
              this.Close();

              }
            }

              this.Close();
        }
Esempio n. 17
0
        //BackgroundWorker - Main analyze process for files
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            var previousData = analyzeData;

              analyzeData = new Analyze(backgroundWorker1);

              analyzeData.process(args);

              if (backgroundWorker1.CancellationPending)
              {
            e.Cancel = true;
            return;
              }

              if (previousData == MainWindow.projectManager.analyze)
            MainWindow.projectManager.analyze = analyzeData;

              e.Result = analyzeData;
        }
Esempio n. 18
0
        /// <summary>
        /// Deprecated. Creates a script that executes mkvmerge commands to merge analyzed files
        /// </summary>
        /// <param name="fileList">The processed FileObjectCollection.</param>
        /// <param name="processor">The Analyze object</param>
        /// <param name="outputPathArg">Optional. Pass a different output path for the script.</param>
        public void makeFile(FileObjectCollection fileList, Analyze processor, string outputPathArg = null)
        {
            if (outputPathArg != null)
              {
            outputPath = outputPathArg;
              }
              else
            if (Config.Configure.sourceOutputFolder)
              outputPath = Path.Combine(fileList.folderPath, Config.Configure.exportfilename);
            else
              outputPath = Path.Combine(outputPath, Config.Configure.exportfilename);

              StringBuilder makeFileContent = new StringBuilder();

              if (Config.Configure.diagnoseMkvinfoDump | Config.Configure.diagnoseChapterinfoDump)
            Directory.CreateDirectory(dumpPath);

              foreach (FileObject file in fileList.fileList)
              {

            List<string> timeCodeList = new List<string>();
            List<string> delArgumentList = new List<string>();
            List<string> mergeArgumentList = new List<string>();
            List<string> chapterInfo = new List<string>();

            /*
             * Diagnostic purposes only
             * */
            if (Config.Configure.diagnoseMkvinfoDump)
              using (StreamWriter writer = new StreamWriter(Path.Combine(dumpPath, file.filenameNoExtension + "_mkvinfo.txt")))
              {
            writer.Write(file.mkvInfo);
              }

            /*
             * Main process
             * */
            if (file.mergeArgument.Count > 1)
            {

              foreach (MergeArgument merge in file.mergeArgument)
              {

            if (merge.isExternalSuid)
              mergeArgumentList.Add("\"" + merge.fullPath + "\"");
            else
            {
              if (file.splitCount > 1)
                mergeArgumentList.Add("\"" + merge.fileName + "\"");
              else
                mergeArgumentList.Add("\"" + merge.originalFullPath + "\"");

            }

              }

              foreach (TimeCode time in file.timeCode)
              {
            timeCodeList.Add(time.timeCode);
              }

              foreach (DelArgument del in file.delArgument)
              {
            delArgumentList.Add("\"" + del.fileName + "\"");
              }

              foreach (ChapterAtom chapter in file.chapterAtom)
              {
            chapterInfo.Add(chapter.chapterInfo);
              }

              string[] timeCode = timeCodeList.ToArray();
              string[] delArgument = delArgumentList.ToArray();
              string[] mergeArgument = mergeArgumentList.ToArray();
              string[] chaptersInfo = chapterInfo.ToArray();

              string tempFileName = "\"" + Config.Configure.tempfileprefix + file.filenameNoExtension + Config.Configure.tempfilesuffix + ".mkv\"";
              string newFileName = "\"output\\" + Config.Configure.newfileprefix + file.filenameNoExtension + Config.Configure.newfilesuffix + ".mkv\"";
              string originalFileName = "\"" + file.fullpath + "\"";

              if (file.shouldJoin)
              {

            doMakeFile = true;
            makeFileContent.AppendLine("::" + file.filename);

            if (file.splitCount > 1)
            {
              makeFileContent.AppendLine("mkvmerge --no-chapters --split timecodes:" + String.Join(",", timeCode) + " -o " + tempFileName + " " + originalFileName);
            }

            makeFileContent.AppendLine("mkvmerge --no-chapters -o " + newFileName + " " + String.Join(" +", mergeArgument) + "\r\n");
            makeFileContent.AppendLine("DEL /Q " + String.Join(" ", delArgument) + "\r\n");

              }

              if (Config.Configure.diagnoseChapterinfoDump)
            using (StreamWriter writer = new StreamWriter(Path.Combine(dumpPath, file.filenameNoExtension + "_chaptersinfo.txt")))
            {
              writer.WriteLine(String.Join("\n", chaptersInfo));
            }

            }

              }

              if (doMakeFile)
              {
            using (StreamWriter writer = new StreamWriter(outputPath))
            {
              writer.WriteLine("@echo off\r\ncls\r\n\r\npushd \"%~dp0\"\r\nif not exist output mkdir output\r\n");
              writer.Write(makeFileContent);
            }
            Analyze.outputGroups.Add(outputPath);
              }
              else
              {

              }
        }
Esempio n. 19
0
        /// <summary>
        /// Rearranges chapter tracks to include the inserted external file determined by SUID.
        /// Also determines MergeArguments order.
        /// </summary>
        /// <param name="fileList">The FileObjectCollection processed by ChapterGenerator.</param>
        /// <param name="suid">The SuidLister that contains all SUIDs.</param>
        /// <param name="processor">The Analyze object for progression report.</param>
        /// <returns>The FileObjectCollection with FileObjects that has rearranged chapter tracks.</returns>
        public FileObjectCollection arrangeTrack(FileObjectCollection fileList, SuidLister suid, Analyze processor)
        {
            //string mergeargument = "";

            foreach (FileObject file in fileList.fileList)
            {
                int    count        = 0;
                string tempFileName = "";
                string tempFullPath = "";


                //First loop to determine which chapters have external suid attached
                foreach (ChapterAtom chaptera in file.chapterAtom)
                {
                    foreach (Suid suidi in suid.suidList)
                    {
                        if (suidi.suid == chaptera.suid)
                        {
                            chaptera.suidFileName = suidi.fileName;
                            chaptera.suidFullPath = suidi.fullPath;

                            //Console.WriteLine("SUID match.");
                        }
                    }

                    //mergeargument = mergeargument + chaptera.timeStart + chaptera.timeEnd + chaptera.suidFileName;
                }


                //Second loop that uses index to properly determine which chapter needs to be added as a MergeArgument
                for (int i = 0; i < file.chapterAtom.Count; i++)
                {
                    var current = file.chapterAtom[i];

                    var previous = current;
                    var next     = current;

                    if (i > 0)
                    {
                        previous = file.chapterAtom.ElementAt(i - 1);
                    }

                    if (i < (file.chapterAtom.Count - 1))
                    {
                        next = file.chapterAtom.ElementAt(i + 1);
                    }

                    /*
                     * Diagnostic purposes only
                     *
                     * Console.WriteLine("Arrange Track");
                     * Console.WriteLine("Current: " + current.suidFileName);
                     * Console.WriteLine("Previous: " + previous.suidFileName);
                     * Console.WriteLine("Next: " + next.suidFileName);
                     * Console.WriteLine("\n");
                     * */

                    //The following routine should correctly determine when to split the the chapters optimally to insert the external SUID file
                    if (current.suidFileName != null)
                    {
                        file.addMergeArg(current.suidFullPath, current.chapterNum, true);
                        if (!file.shouldJoin)
                        {
                            file.shouldJoin = true;
                        }
                        if (!fileList.hasOrdered)
                        {
                            fileList.hasOrdered = true;
                        }
                        if (!processor.hasOrdered)
                        {
                            processor.hasOrdered = true;
                        }
                    }
                    else
                    {
                        string timeCode = "";

                        //TimeEnd Split Mode
                        if (Config.Configure.splitModeTimeEnd && (next.suidFileName != null || i == file.chapterAtom.Count - 1))
                        {
                            count++;

                            file.splitCount = count;

                            timeCode = current.timeEnd;

                            //to change, should dynamically change digit format to "ddd"
                            // done
                            tempFileName = Config.Configure.tempfileprefix + file.filenameNoExtension + Config.Configure.tempfilesuffix + "-" + count.ToString("D3") + ".mkv";
                            tempFullPath = Path.Combine(fileList.folderPath, Config.Configure.tempfileprefix + file.filenameNoExtension + Config.Configure.tempfilesuffix) + "-" + count.ToString("D3") + ".mkv";

                            file.addMergeArg(tempFullPath, current.chapterNum, false, timeCode, tempFileName, file.fullpath);
                            if (i != file.chapterAtom.Count - 1)
                            {
                                file.addTimeCode(timeCode);
                            }
                            file.addDelArg(tempFullPath, tempFileName);
                        }
                        //TimeStart Split Mode
                        else if (Config.Configure.splitModeTimeStart && (previous.suidFileName != null || i == 0))
                        {
                            count++;

                            file.splitCount = count;

                            timeCode = current.timeStart;

                            tempFileName = Config.Configure.tempfileprefix + file.filenameNoExtension + Config.Configure.tempfilesuffix + "-" + count.ToString("D3") + ".mkv";
                            tempFullPath = Path.Combine(fileList.folderPath, Config.Configure.tempfileprefix + file.filenameNoExtension + Config.Configure.tempfilesuffix) + "-" + count.ToString("D3") + ".mkv";

                            file.addMergeArg(tempFullPath, current.chapterNum, false, timeCode, tempFileName, file.fullpath);
                            if (i > 0)
                            {
                                file.addTimeCode(timeCode);
                            }
                            file.addDelArg(tempFullPath, tempFileName);
                        }
                    }
                }
            }

            return(fileList);
        }