private int OnExecute() { InputFile = Path.GetFullPath(InputFile); if (OutputFile != null) { OutputFile = Path.GetFullPath(OutputFile); OutputFile = FixPathSlashes(OutputFile); } if (FileFilter != null) { FileFilter = FixPathSlashes(FileFilter); } if (ExtFilter != null) { ExtFilterList = ExtFilter.Split(','); } var paths = new List <string>(); if (Directory.Exists(InputFile)) { if (OutputFile != null && File.Exists(OutputFile)) { Console.Error.WriteLine("Output path is an existing file, but input is a folder."); return(1); } paths.AddRange(Directory.EnumerateFiles(InputFile, "*.*", RecursiveSearch ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly).Where(s => s.EndsWith("_c") || s.EndsWith(".vcs"))); } else if (File.Exists(InputFile)) { RecursiveSearch = false; paths.Add(InputFile); } if (paths.Count == 0) { Console.Error.WriteLine("No such file \"{0}\" or directory is empty. Did you mean to include --recursive parameter?", InputFile); return(1); } CurrentFile = 0; TotalFiles = paths.Count; if (MaxParallelismThreads > 1) { Console.WriteLine("Will use {0} threads concurrently.", MaxParallelismThreads); Parallel.ForEach(paths, new ParallelOptions { MaxDegreeOfParallelism = MaxParallelismThreads }, (path, state) => { ProcessFile(path); }); } else { foreach (var path in paths) { ProcessFile(path); } } if (CollectStats) { Console.WriteLine(); Console.WriteLine("Processed resource stats:"); foreach (var stat in stats.OrderByDescending(x => x.Value.Count).ThenBy(x => x.Key)) { var info = stat.Value.Info != string.Empty ? string.Format(" ({0})", stat.Value.Info) : string.Empty; Console.WriteLine($"{stat.Value.Count,5} resources of version {stat.Value.Version} and type {stat.Value.Type}{info}"); foreach (var file in stat.Value.FilePaths) { Console.WriteLine($"\t\t{file}"); } } Console.WriteLine(); Console.WriteLine("Unique special dependancies:"); foreach (var stat in uniqueSpecialDependancies) { Console.WriteLine("{0} in {1}", stat.Key, stat.Value); } Console.WriteLine(); Console.WriteLine("Particle classes:"); foreach (var stat in uniqueParticleClasses.OrderByDescending(x => x.Value)) { Console.WriteLine("{0} in {1}", stat.Key, stat.Value); } } return(0); }
private int OnExecute() { InputFile = Path.GetFullPath(InputFile); if (OutputFile != null) { OutputFile = Path.GetFullPath(OutputFile); OutputFile = FixPathSlashes(OutputFile); } if (FileFilter != null) { FileFilter = FixPathSlashes(FileFilter); } if (ExtFilter != null) { ExtFilterList = ExtFilter.Split(','); } if (GltfExportFormat != "gltf" && GltfExportFormat != "glb") { Console.Error.WriteLine("glTF export format must be either 'gltf' or 'glb'."); return(1); } var paths = new List <string>(); if (Directory.Exists(InputFile)) { if (OutputFile != null && File.Exists(OutputFile)) { Console.Error.WriteLine("Output path is an existing file, but input is a folder."); return(1); } IsInputFolder = true; var dirs = Directory .EnumerateFiles(InputFile, "*.*", RecursiveSearch ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly) .Where(s => s.EndsWith("_c") || s.EndsWith(".vcs")); if (!dirs.Any()) { Console.Error.WriteLine( "Unable to find any \"_c\" compiled files in \"{0}\" folder.{1}", InputFile, RecursiveSearch ? " Did you mean to include --recursive parameter?" : string.Empty); return(1); } paths.AddRange(dirs); } else if (File.Exists(InputFile)) { if (RecursiveSearch) { Console.Error.WriteLine("File passed in with --recursive option. Either pass in a folder or remove --recursive."); return(1); } paths.Add(InputFile); } else { Console.Error.WriteLine("Input \"{0}\" is not a file or a folder.", InputFile); return(1); } CurrentFile = 0; TotalFiles = paths.Count; if (MaxParallelismThreads > 1) { Console.WriteLine("Will use {0} threads concurrently.", MaxParallelismThreads); var queue = new ConcurrentQueue <string>(paths); var tasks = new List <Task>(); ThreadPool.GetMinThreads(out var workerThreads, out var completionPortThreads); if (workerThreads < MaxParallelismThreads) { ThreadPool.SetMinThreads(MaxParallelismThreads, MaxParallelismThreads); } for (var n = 0; n < MaxParallelismThreads; n++) { tasks.Add(Task.Run(() => { while (queue.TryDequeue(out var path)) { ProcessFile(path); } })); } Task.WhenAll(tasks).GetAwaiter().GetResult(); } else { foreach (var path in paths) { ProcessFile(path); } } if (CollectStats) { Console.WriteLine(); Console.WriteLine("Processed resource stats:"); foreach (var stat in stats.OrderByDescending(x => x.Value.Count).ThenBy(x => x.Key)) { var info = string.IsNullOrEmpty(stat.Value.Info) ? string.Empty : $" ({stat.Value.Info})"; Console.WriteLine($"{stat.Value.Count,5} resources of version {stat.Value.Version} and type {stat.Value.Type}{info}"); foreach (var file in stat.Value.FilePaths) { Console.WriteLine($"\t\t{file}"); } } Console.WriteLine(); Console.WriteLine("Unique special dependancies:"); foreach (var stat in uniqueSpecialDependancies) { Console.WriteLine("{0} in {1}", stat.Key, stat.Value); } } return(0); }
private int OnExecute() { InputFile = Path.GetFullPath(InputFile); if (OutputFile != null) { OutputFile = Path.GetFullPath(OutputFile); OutputFile = FixPathSlashes(OutputFile); } if (FileFilter != null) { FileFilter = FixPathSlashes(FileFilter); } if (ExtFilter != null) { ExtFilterList = ExtFilter.Split(','); } var paths = new List <string>(); if (Directory.Exists(InputFile)) { if (OutputFile != null && File.Exists(OutputFile)) { Console.Error.WriteLine("Output path is an existing file, but input is a folder."); return(1); } IsInputFolder = true; var dirs = Directory .EnumerateFiles(InputFile, "*.*", RecursiveSearch ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly) .Where(s => s.EndsWith("_c") || s.EndsWith(".vcs")); if (!dirs.Any()) { Console.Error.WriteLine( "Unable to find any \"_c\" compiled files in \"{0}\" folder.{1}", InputFile, RecursiveSearch ? " Did you mean to include --recursive parameter?" : string.Empty); return(1); } paths.AddRange(dirs); } else if (File.Exists(InputFile)) { if (RecursiveSearch) { Console.Error.WriteLine("File passed in with --recursive option. Either pass in a folder or remove --recursive."); return(1); } paths.Add(InputFile); } else { Console.Error.WriteLine("Input \"{0}\" is not a file or a folder.", InputFile); return(1); } CurrentFile = 0; TotalFiles = paths.Count; if (MaxParallelismThreads > 1) { Console.WriteLine("Will use {0} threads concurrently.", MaxParallelismThreads); var partitioner = Partitioner.Create(paths, EnumerablePartitionerOptions.NoBuffering); Parallel.ForEach(partitioner, new ParallelOptions { MaxDegreeOfParallelism = MaxParallelismThreads }, (path, state) => { ProcessFile(path); }); } else { foreach (var path in paths) { ProcessFile(path); } } if (CollectStats) { Console.WriteLine(); Console.WriteLine("Processed resource stats:"); foreach (var stat in stats.OrderByDescending(x => x.Value.Count).ThenBy(x => x.Key)) { var info = stat.Value.Info != string.Empty ? string.Format(" ({0})", stat.Value.Info) : string.Empty; Console.WriteLine($"{stat.Value.Count,5} resources of version {stat.Value.Version} and type {stat.Value.Type}{info}"); foreach (var file in stat.Value.FilePaths) { Console.WriteLine($"\t\t{file}"); } } Console.WriteLine(); Console.WriteLine("Unique special dependancies:"); foreach (var stat in uniqueSpecialDependancies) { Console.WriteLine("{0} in {1}", stat.Key, stat.Value); } } return(0); }