예제 #1
0
        /// <summary>
        /// Combines all of the InputFiles and writes it to disk.
        /// </summary>
        /// <returns>The final video's output path.</returns>
        public VideoMergeOutput CombineAndWrite()
        {
            var output = new VideoMergeOutput();

            try
            {
                output.FileOutputPath = Path.Combine(InputFiles.First().DirectoryName, Store.Data.Record.LastVideoName + ".mp4");

                if (InputFiles.Count == 1)
                {
                    // Remove _part 1 from the file name, but don't concatenate
                    InputFiles.First().MoveTo(output.FileOutputPath);
                    OutputFile = new FileInfo(output.FileOutputPath);

                    return(output);
                }

                TempFileList = new FileInfo(Path.GetTempFileName());
                using (var sw = new StreamWriter(TempFileList.FullName))
                {
                    foreach (FileInfo file in InputFiles)
                    {
                        sw.WriteLine($"file '{file.FullName}'");
                    }
                }

                FFMpegConverter ffMpegConverter = new FFMpegConverter();

                OutputFile = new FileInfo(output.FileOutputPath);

                string ffmpegArgs = $"-f concat -safe 0 -i \"{TempFileList.FullName}\" -movflags +faststart -c copy \"{OutputFile.FullName}\"";
                ffMpegConverter.Invoke(ffmpegArgs);

                DeleteInputFiles();
                DeleteTemporaryFiles();
            }
            catch (Exception ex)
            {
                DeleteTemporaryFiles();
                output.IsSuccessful       = false;
                output.MergeFailureReason = ex.Message;
            }

            return(output);
        }
예제 #2
0
        internal List <string> GetAbsoluteInputFiles()
        {
            List <string> files   = new List <string>();
            string        folder  = new DirectoryInfo(Path.GetDirectoryName(FileName)).FullName;
            string        ext     = Path.GetExtension(InputFiles.First());
            Options       options = new Options {
                AllowWindowsPaths = true
            };

            foreach (string inputFile in InputFiles.Where(f => !f.StartsWith("!", StringComparison.Ordinal)))
            {
                int globIndex = inputFile.IndexOf('*');

                if (globIndex > -1)
                {
                    string relative = string.Empty;
                    int    last     = inputFile.LastIndexOf('/', globIndex);

                    if (last > -1)
                    {
                        relative = inputFile.Substring(0, last + 1);
                    }

                    var output    = GetAbsoluteOutputFile();
                    var outputMin = BundleFileProcessor.GetMinFileName(output);

                    string searchDir = new FileInfo(Path.Combine(folder, relative).Replace("/", "\\")).FullName;
                    var    allFiles  = Directory.EnumerateFiles(searchDir, "*" + ext, SearchOption.AllDirectories).Select(f => f.Replace(folder + "\\", ""));

                    var matches = Minimatcher.Filter(allFiles, inputFile, options).Select(f => Path.Combine(folder, f));
                    matches = matches.Where(match => match != output && match != outputMin);
                    files.AddRange(matches.Where(f => !files.Contains(f)));
                }
                else
                {
                    string fullPath = Path.Combine(folder, inputFile).Replace("/", "\\");

                    if (Directory.Exists(fullPath))
                    {
                        DirectoryInfo dir      = new DirectoryInfo(fullPath);
                        SearchOption  search   = SearchOption.TopDirectoryOnly;
                        var           dirFiles = dir.GetFiles("*" + Path.GetExtension(OutputFileName), search);
                        files.AddRange(dirFiles.Select(f => f.FullName).Where(f => !files.Contains(f)));
                    }
                    else
                    {
                        files.Add(fullPath);
                    }
                }
            }

            // Remove files starting with a !
            foreach (string inputFile in InputFiles)
            {
                int globIndex = inputFile.IndexOf('!');

                if (globIndex == 0)
                {
                    var allFiles = files.Select(f => f.Replace(folder + "\\", ""));
                    var matches  = Minimatcher.Filter(allFiles, inputFile, options).Select(f => Path.Combine(folder, f));
                    files = matches.ToList();
                }
            }

            return(files);
        }
예제 #3
0
        /// <summary>
        /// Returns a list of absolute file paths of all matching input files.
        /// </summary>
        /// <param name="notifyOnPatternMiss">Writes to the Console if any input file is missing on disk.</param>
        public List <string> GetAbsoluteInputFiles(bool notifyOnPatternMiss = false)
        {
            List <string> files = new List <string>();

            if (!InputFiles.Any())
            {
                return(files);
            }

            string  folder  = new DirectoryInfo(Path.GetDirectoryName(FileName)).FullName;
            string  ext     = Path.GetExtension(InputFiles.First());
            Options options = new Options {
                AllowWindowsPaths = true
            };

            foreach (string inputFile in InputFiles.Where(f => !f.StartsWith("!", StringComparison.Ordinal)))
            {
                int globIndex = inputFile.IndexOf('*');

                if (globIndex > -1)
                {
                    string relative = string.Empty;
                    int    last     = inputFile.LastIndexOf('/', globIndex);

                    if (last > -1)
                    {
                        relative = inputFile.Substring(0, last + 1);
                    }

                    var output    = GetAbsoluteOutputFile();
                    var outputMin = BundleMinifier.GetMinFileName(output);

                    string searchDir = new FileInfo(Path.Combine(folder, relative).NormalizePath()).FullName;
                    var    allFiles  = Directory.EnumerateFiles(searchDir, "*" + ext, SearchOption.AllDirectories).Select(f => f.Replace(folder + FileHelpers.PathSeparatorChar, ""));

                    var matches = Minimatcher.Filter(allFiles, inputFile, options).Select(f => Path.Combine(folder, f));
                    matches = matches.Where(match => match != output && match != outputMin).ToList();

                    if (notifyOnPatternMiss && !matches.Any())
                    {
                        Console.WriteLine($"  No files matched the pattern {inputFile}".Orange().Bright());
                    }

                    files.AddRange(matches.Where(f => !files.Contains(f)));
                }
                else
                {
                    string fullPath = Path.Combine(folder, inputFile.NormalizePath());

                    if (Directory.Exists(fullPath))
                    {
                        DirectoryInfo dir       = new DirectoryInfo(fullPath);
                        SearchOption  search    = SearchOption.TopDirectoryOnly;
                        var           dirFiles  = dir.GetFiles("*" + Path.GetExtension(OutputFileName), search);
                        var           collected = dirFiles.Select(f => f.FullName).Where(f => !files.Contains(f)).ToList();

                        if (notifyOnPatternMiss && collected.Count == 0)
                        {
                            Console.WriteLine($"  No files were found in {inputFile}".Orange().Bright());
                        }

                        files.AddRange(collected);
                    }
                    else
                    {
                        files.Add(fullPath);

                        if (notifyOnPatternMiss && !File.Exists(fullPath))
                        {
                            Console.WriteLine($"  {inputFile} was not found".Orange().Bright());
                        }
                    }
                }
            }

            // Remove files starting with a !
            foreach (string inputFile in InputFiles)
            {
                int globIndex = inputFile.IndexOf('!');

                if (globIndex == 0)
                {
                    var allFiles = files.Select(f => f.Replace(folder + FileHelpers.PathSeparatorChar, ""));
                    var matches  = Minimatcher.Filter(allFiles, inputFile, options).Select(f => Path.Combine(folder, f));
                    files = matches.ToList();
                }
            }

            return(files);
        }
예제 #4
0
        protected override void PostProcessSwitchList()
        {
            var firstFile = InputFiles.First();

            ToolExe = firstFile.GetMetadata("CompilerPath");

            ToolSwitch argument;

            argument = new ToolSwitch(ToolSwitchType.String)
            {
                MultipleValues = true
            };
            if (firstFile.GetMetadata("PointerSize") == "32")
            {
                argument.SwitchValue = "-32bits";
            }
            else if (firstFile.GetMetadata("PointerSize") == "64")
            {
                argument.SwitchValue = "-64bits";
            }
            ActiveToolSwitches["PointerSize"] = argument;

            ActiveToolSwitches["Definitions"] = new ToolSwitch(ToolSwitchType.StringArray)
            {
                StringList = firstFile.GetMetadata("Definitions").Split(';'), SwitchValue = "-D "
            };
            ActiveToolSwitches["IncludeFolders"] = new ToolSwitch(ToolSwitchType.StringPathArray)
            {
                StringList = firstFile.GetMetadata("IncludeFolders").Split(';'), SwitchValue = "-I "
            };

            argument = new ToolSwitch(ToolSwitchType.String)
            {
                MultipleValues = true
            };
            if (firstFile.GetMetadata("CallTrace") == "SingleThreaded")
            {
                argument.SwitchValue = "-call_trace 1";
            }
            else if (firstFile.GetMetadata("CallTrace") == "MSVC")
            {
                argument.SwitchValue = "-call_trace 2";
            }
            ActiveToolSwitches["CallTrace"] = argument;

            if (firstFile.GetMetadata("ShowMemoryUsage") != "true")
            {
                ActiveToolSwitches.Remove("ShowMemoryUsage");
            }
            else
            {
                ActiveToolSwitches["ShowMemoryUsage"] = new ToolSwitch(ToolSwitchType.String)
                {
                    MultipleValues = true, SwitchValue = "-debug_memory"
                }
            };

            ActiveToolSwitches["AdditionalDependencies"] = new ToolSwitch(ToolSwitchType.StringArray)
            {
                StringList = firstFile.GetMetadata("AdditionalDependencies").Split(';'), SwitchValue = "-linker_option /DEFAULTLIB:"
            };

            if (firstFile.GetMetadata("DisableDebugInfo") != "true")
            {
                ActiveToolSwitches.Remove("DisableDebugInfo");
            }
            else
            {
                ActiveToolSwitches["DisableDebugInfo"] = new ToolSwitch(ToolSwitchType.String)
                {
                    MultipleValues = true, SwitchValue = "-ndebug"
                }
            };

            ActiveToolSwitches["OutputFile"] = new ToolSwitch(ToolSwitchType.File)
            {
                SwitchValue = "-o ", Value = firstFile.GetMetadata("OutputFile")
            };

            if (firstFile.GetMetadata("PartialCompilation") != "true")
            {
                ActiveToolSwitches.Remove("PartialCompilation");
            }
            else
            {
                ActiveToolSwitches["PartialCompilation"] = new ToolSwitch(ToolSwitchType.String)
                {
                    MultipleValues = true, SwitchValue = "-part"
                }
            };

            if (firstFile.GetMetadata("RecursionDepthLimit") == "")
            {
                ActiveToolSwitches.Remove("RecursionDepthLimit");
            }
            else
            {
                ActiveToolSwitches["RecursionDepthLimit"] = new ToolSwitch(ToolSwitchType.Integer)
                {
                    IsValid = true, Number = int.Parse(firstFile.GetMetadata("RecursionDepthLimit")), SwitchValue = "-recursion_depth_limit "
                }
            };

            if (firstFile.GetMetadata("StaticLoopLimit") == "")
            {
                ActiveToolSwitches.Remove("StaticLoopLimit");
            }
            else
            {
                ActiveToolSwitches["StaticLoopLimit"] = new ToolSwitch(ToolSwitchType.Integer)
                {
                    IsValid = true, Number = int.Parse(firstFile.GetMetadata("StaticLoopLimit")), SwitchValue = "-static_loop_length_limit "
                }
            };

            AdditionalOptions = firstFile.GetMetadata("AdditionalOptions");
        }
    }
}