/// <summary> /// The entry point of the program, where the program control starts and ends. /// </summary> /// <param name="args">The command-line arguments.</param> public static void Main(string[] args) { Assembly a = Assembly.GetExecutingAssembly(); String location = a.Location; location = location.Remove(location.LastIndexOf(Path.DirectorySeparatorChar)); Logger = new ConsoleFileLogger(Path.Combine(location, "logs")); var options = new Options(); if (Parser.Default.ParseArguments(args, options)) { Logger.Info("Starting test suite for CCExtractor - If you encounter any issues using this program, don't hesitate to ask questions or report problems on GitHub. Please don't forget to attach logs (enable extensive logging using the -debug flag)."); Logger.Info("Test suite version: " + a.GetName().Version.ToString()); if (options.Debug) { Logger.ActivateDebug(); Logger.Debug("Debug activated"); } Logger.Info(""); Logger.Info("If you want to see the available flags, run this program with --help. Press ctrl-c to abort if necessary."); Logger.Info(""); // Loading configuration ConfigManager config = null; if (!String.IsNullOrEmpty(options.ConfigFile) && options.ConfigFile.EndsWith(".xml") && File.Exists(options.ConfigFile)) { Logger.Info("Loading provided configuration (" + options.ConfigFile + ")"); XmlDocument doc = new XmlDocument(); doc.Load(options.ConfigFile); config = ConfigManager.CreateFromXML(Logger, doc); } else { Logger.Warn("Provided no config or an invalid one; reverting to default config (" + a.GetName().Name + ".exe.config)"); config = ConfigManager.CreateFromAppSettings(Logger); } if (config == null || !config.IsValidConfig()) { Logger.Error("Fatal error - config not valid. Please check. Exiting application"); return; } String temporaryFolder = Path.Combine(location, "tmpFiles"); if (!String.IsNullOrEmpty(options.TempFolder) && IsValidDirectory(options.TempFolder)) { temporaryFolder = options.TempFolder; } else { if (!Directory.Exists(temporaryFolder)) { Logger.Warn(temporaryFolder + " does not exist; trying to create it"); DirectoryInfo di = Directory.CreateDirectory(temporaryFolder); if (!di.Exists) { Logger.Error("Failed to create the directory! Exiting"); return; } } } config.TemporaryFolder = temporaryFolder; Logger.Info("Generated result files will be stored in " + temporaryFolder + "(when running multiple tests after another, files might be overwritten)"); // See what overrides are specified if (!String.IsNullOrEmpty(options.CCExtractorExecutable)) { if (File.Exists(options.CCExtractorExecutable)) { config.CCExctractorLocation = options.CCExtractorExecutable; Logger.Info("Overriding CCExtractorLocation with given version (located at: " + options.CCExtractorExecutable + ")"); } else { Logger.Error("Given CCExtractor executable path does not exist. Exiting application"); return; } } if (options.TimeOut > 60 && options.TimeOut != 180) { config.TimeOut = options.TimeOut; Logger.Info("Overriding timeout with: " + options.TimeOut); } if (!String.IsNullOrEmpty(options.Comparer)) { try { config.Comparer = CompareTypeParser.parseString(options.Comparer); Logger.Info("Overriding Comparer with: " + options.Comparer); } catch (ArgumentOutOfRangeException) { Logger.Warn("Provided value for comparer invalid; ignoring it."); } } if (!String.IsNullOrEmpty(options.ReportFolder)) { config.ReportFolder = options.ReportFolder; Logger.Info("Overriding ReportFolder with: " + options.ReportFolder); } if (!String.IsNullOrEmpty(options.ResultFolder)) { config.ResultFolder = options.ResultFolder; Logger.Info("Overriding ResultFolder with: " + options.ResultFolder); } if (!String.IsNullOrEmpty(options.SampleFolder)) { config.SampleFolder = options.SampleFolder; Logger.Info("Overriding SampleFolder with: " + options.SampleFolder); } config.BreakOnChanges = options.BreakOnChanges; if (config.BreakOnChanges) { Logger.Info("If there's a sample that doesn't match, we will exit instead of running them all."); } if (!String.IsNullOrEmpty(options.FFMpegExecutable)) { if (File.Exists(options.FFMpegExecutable)) { config.FFMpegLocation = options.FFMpegExecutable; Logger.Info("Overriding FFMpeg executable with given version (located at: " + options.FFMpegExecutable + ")"); } else { Logger.Error("Given CCExtractor executable path does not exist. Exiting application"); return; } } config.TestType = options.RunMethod; if (options.UseValgrind) { Logger.Info("Valgrind will be used to run tests with."); config.UseValgrind = true; } // Continue with parameter parsing switch (config.TestType) { case RunType.Matrix: Logger.Info("Running in report mode, generating matrix"); if (IsValidDirectory(options.EntryFile)) { StartMatrixGenerator(Logger, config, options.EntryFile); } else { Logger.Error("Invalid directory provided for matrix generation!"); } break; case RunType.Server: // Check if the URL was set if (!String.IsNullOrEmpty(options.ReportURL)) { Logger.Info("Setting report URL to provided value!"); config.ReportUrl = options.ReportURL; } if (String.IsNullOrEmpty(config.ReportUrl)) { Logger.Error("Server reporting mode selected, but no URL configured! Exiting."); break; } if (IsValidPotentialSampleFile(options.EntryFile)) { Logger.Info("Running provided file"); StartTester(Logger, config, options.EntryFile, location); } else { Logger.Error("No file (or invalid file) provided!"); } break; case RunType.Report: if (IsValidPotentialSampleFile(options.EntryFile)) { Logger.Info("Running provided file"); StartTester(Logger, config, options.EntryFile, location); } else { Logger.Error("No file (or invalid file) provided!"); } break; default: Logger.Error("Unknown RunType!"); break; } } }