private static void TestEvaluate(TemporaryDirectory directory, Glob glob, string[] expectedResult) { var items = glob.EnumerateFiles(directory.FullPath) .AsEnumerable() .Select(path => FullPath.FromPath(path).MakePathRelativeTo(directory.FullPath).Replace('\\', '/')) .Sort() .ToList(); Assert.Equal(expectedResult, items); }
RunResult Run() { // Sign on var assemblyVersion = ThisAssembly.AssemblyInformationalVersion; var toolNameAndVersion = $"Lottie for Windows Code Generator version {assemblyVersion}"; _reporter.WriteInfo(toolNameAndVersion); _reporter.WriteInfoNewLine(); if (_options.ErrorDescription != null) { // Failed to parse the command line. _reporter.WriteError("Invalid arguments."); _reporter.ErrorStream.WriteLine(_options.ErrorDescription); return(RunResult.InvalidUsage); } else if (_options.MinimumUapVersion.HasValue && _options.MinimumUapVersion < LottieToWinCompTranslator.MinimumTargetUapVersion) { // Unacceptable version. _reporter.WriteError($"Invalid minimum UAP version \"{_options.MinimumUapVersion}\". Must be 7 or above."); return(RunResult.InvalidUsage); } else if (_options.TargetUapVersion.HasValue) { if (_options.TargetUapVersion < 7) { // Unacceptable version. _reporter.WriteError($"Invalid target UAP version \"{_options.TargetUapVersion}\". Must be 7 or above."); return(RunResult.InvalidUsage); } if (_options.MinimumUapVersion.HasValue && _options.TargetUapVersion < _options.MinimumUapVersion) { // Unacceptable version. _reporter.WriteError($"Invalid target UAP version \"{_options.TargetUapVersion}\". Must be greater than the minimum UAP version specified ({_options.MinimumUapVersion})."); return(RunResult.InvalidUsage); } } else if (_options.HelpRequested) { ShowHelp(_reporter.InfoStream); return(RunResult.Success); } // Check for required args if (_options.InputFile == null) { _reporter.WriteError("Lottie file not specified."); return(RunResult.InvalidUsage); } // Validate the languages. if (!_options.Languages.Any()) { _reporter.WriteError("Language not specified."); return(RunResult.InvalidUsage); } foreach (var language in _options.Languages) { if (language == Lang.Unknown) { _reporter.WriteError("Invalid language."); return(RunResult.InvalidUsage); } } // Check that at least one file matches InputFile. var matchingInputFiles = Glob.EnumerateFiles(_options.InputFile).ToArray(); if (matchingInputFiles.Length == 0) { _reporter.WriteError($"File not found: {_options.InputFile}"); return(RunResult.Failure); } // Get the output folder as an absolute path, defaulting to the current directory // if no output folder was specified. var outputFolder = MakeAbsolutePath(_options.OutputFolder ?? Directory.GetCurrentDirectory()); // Assume success. var succeeded = true; try { #if DO_NOT_PROCESS_IN_PARALLEL foreach (var(file, relativePath) in matchingInputFiles) { if (!LottieFileProcessor.ProcessFile(_options, _reporter, file, System.IO.Path.Combine(outputFolder, relativePath))) { succeeded = false; } } #else Parallel.ForEach(matchingInputFiles, ((string path, string relativePath)inputFile) => { if (!LottieFileProcessor.ProcessFile(_options, _reporter, inputFile.path, System.IO.Path.Combine(outputFolder, inputFile.relativePath))) { succeeded = false; } }); #endif }
RunResult Run() { // Sign on var assemblyVersion = ThisAssembly.AssemblyInformationalVersion; var toolNameAndVersion = $"Lottie for Windows Code Generator version {assemblyVersion}"; _reporter.WriteInfo(InfoType.Signon, toolNameAndVersion); _reporter.WriteInfoNewLine(); if (_options.ErrorDescription != null) { // Failed to parse the command line. _reporter.WriteError("Invalid arguments."); _reporter.ErrorStream.WriteLine(_options.ErrorDescription); return RunResult.InvalidUsage; } else if (_options.WinUIVersion.Major >= 3 && (_options.MinimumUapVersion.HasValue || _options.TargetUapVersion.HasValue)) { // WinUI3 does not permit setting a minimum or target version because WinUI3 implies // the latest version only. _reporter.WriteError($"WinUI versions of 3 and above cannot be used with {nameof(_options.MinimumUapVersion)} or {nameof(_options.TargetUapVersion)}."); return RunResult.InvalidUsage; } else if (_options.MinimumUapVersion.HasValue && _options.MinimumUapVersion < LottieToWinCompTranslator.MinimumTargetUapVersion) { // Unacceptable version. _reporter.WriteError($"Invalid minimum UAP version \"{_options.MinimumUapVersion}\". Must be 7 or above."); return RunResult.InvalidUsage; } else if (_options.TargetUapVersion.HasValue) { if (_options.TargetUapVersion < 7) { // Unacceptable version. _reporter.WriteError($"Invalid target UAP version \"{_options.TargetUapVersion}\". Must be 7 or above."); return RunResult.InvalidUsage; } if (_options.MinimumUapVersion.HasValue && _options.TargetUapVersion < _options.MinimumUapVersion) { // Unacceptable version. _reporter.WriteError($"Invalid target UAP version \"{_options.TargetUapVersion}\". Must be greater than the minimum UAP version specified ({_options.MinimumUapVersion})."); return RunResult.InvalidUsage; } } else if (_options.HelpRequested) { ShowHelp(_reporter.InfoStream); return RunResult.Success; } // Check for required args. if (_options.InputFile is null) { _reporter.WriteError("Lottie file not specified."); return RunResult.InvalidUsage; } // Validate the languages. if (!_options.Languages.Any()) { _reporter.WriteError("Language not specified."); return RunResult.InvalidUsage; } foreach (var language in _options.Languages) { if (language == Lang.Unknown) { _reporter.WriteError("Invalid language."); return RunResult.InvalidUsage; } } // Check that at least one file matches InputFile. var matchingInputFiles = Glob.EnumerateFiles(_options.InputFile).ToArray(); if (matchingInputFiles.Length == 0) { _reporter.WriteError($"File not found: {_options.InputFile}"); return RunResult.Failure; } // Get the output folder as an absolute path, defaulting to the current directory // if no output folder was specified. var outputFolder = MakeAbsolutePath(_options.OutputFolder ?? Directory.GetCurrentDirectory()); // Get a timestamp to include in the output to help identify a particular // run on the tool. var timestamp = DateTime.UtcNow; // Assume success. var succeeded = true; try { #if DO_NOT_PROCESS_IN_PARALLEL foreach (var (file, relativePath) in matchingInputFiles) #else Parallel.ForEach(matchingInputFiles, ((string path, string relativePath) inputFile) => #endif // DO_NOT_PROCESS_IN_PARALLEL { if (!FileProcessor.ProcessFile( _options, _reporter, inputFile.path, Path.Combine(outputFolder, inputFile.relativePath), timestamp)) { succeeded = false; } }); }