protected override void Prepare() { base.Prepare(); _logActivateChange = new LogActivateChange(AcRoot); _skins = Directory.GetDirectories(AcPaths.GetCarSkinsDirectory(AcRoot, CarId)) .Select(Path.GetFileName).ToArray(); }
public bool TestChild(string carId, string key, IFilter filter) { if (key != "s" && key != "skin") { return(false); } if (!_skinsPerCar.TryGetValue(carId, out var skins)) { skins = Directory.GetDirectories(AcPaths.GetCarSkinsDirectory(_acRoot, carId)).Select(Path.GetFileName).ToArray(); _skinsPerCar[carId] = skins; } return(skins.Any(x => filter.Test(SkinTester.Instance, x))); }
private static int MainInner(string[] args) { var options = new Options(); if (!Parser.Default.ParseArguments(args, options) || options.Ids.Count == 0) { return(1); } var acRoot = Path.GetFullPath(options.AcRoot); var magick = _helper.GetFilename("Magick.NET-x86"); if (magick != null && File.Exists(magick)) { try { ImageUtils.MagickResolver.Initialize(Path.GetDirectoryName(magick) ?? ""); } catch (Exception e) { Console.Error.WriteLine("Can’t load ImageMagick assembly: " + e.Message); } } IFilter <string> filter; try { filter = Filter.Create(new CarTester(acRoot), options.Ids.Select(x => "(" + (x.EndsWith("/") ? x.Substring(0, x.Length - 1) : x) + ")").JoinToString("|"), true); if (options.FilterTest) { Console.WriteLine(Directory.GetDirectories(AcPaths.GetCarsDirectory(options.AcRoot)) .Select(Path.GetFileName).Where(x => filter.Test(x)).JoinToString(", ")); return(0); } if (options.Verbose) { Console.WriteLine("Filter: " + filter); } } catch (Exception e) { Console.Error.WriteLine("Can’t parse filter: " + e); return(2); } if (options.Verbose) { Console.WriteLine("ImageMagick: " + (ImageUtils.IsMagickSupported ? "Available" : "Not available")); Console.WriteLine("AC root: " + options.AcRoot); Console.WriteLine("Showroom: " + options.Showroom); Console.WriteLine("Filter: " + options.Filter); Console.WriteLine("Camera position: " + options.CameraPosition); Console.WriteLine("Look at: " + options.LookAt); Console.WriteLine("FOV: " + options.Fov); Console.WriteLine("Exposure: " + options.Exposure); Console.WriteLine("FXAA: " + options.Fxaa); Console.WriteLine("4K Resolution: " + options.SpecialResolution); Console.WriteLine("Maximize video: " + options.MaximizeVideo); Console.WriteLine("Starting shoting..."); } foreach (var id in Directory.GetDirectories(AcPaths.GetCarsDirectory(options.AcRoot)) .Select(Path.GetFileName).Where(x => filter.Test(x))) { string[] skinIds = options.WithoutPreviews ? Directory.GetDirectories(AcPaths.GetCarSkinsDirectory(acRoot, id)) .Where(x => !File.Exists(Path.Combine(x, "preview.jpg"))) .Select(Path.GetFileName) .ToArray() : null; if (options.Verbose) { Console.WriteLine("Processing: " + id); if (options.WithoutPreviews) { Console.WriteLine(" Shot only: " + skinIds?.JoinToString(", ")); } } int i; for (i = 0; i < options.MaxAttempts; i++) { try { var shotted = Showroom.Shot(new Showroom.ShotProperties { AcRoot = acRoot, CarId = id, ShowroomId = options.Showroom, SkinIds = skinIds, Filter = options.Filter, Fxaa = options.Fxaa, SpecialResolution = options.SpecialResolution, MaximizeVideoSettings = options.MaximizeVideo, Mode = Showroom.ShotMode.Fixed, UseBmp = true, DisableWatermark = true, DisableSweetFx = true, ClassicCameraDx = 0.0, ClassicCameraDy = 0.0, ClassicCameraDistance = 5.5, FixedCameraPosition = options.CameraPosition, FixedCameraLookAt = options.LookAt, FixedCameraFov = options.Fov, FixedCameraExposure = options.Exposure, }); if (shotted != null) { if (options.Verbose) { Console.WriteLine(" Applying previews from: " + shotted); } ImageUtils.ApplyPreviews(acRoot, id, shotted, true, null); } else { if (options.Verbose) { Console.WriteLine(" Nothing shotted"); } } break; } catch (ShotingCancelledException e) { if (!e.UserCancelled) { Console.Error.WriteLine(e.Message); } else if (options.Verbose) { Console.Error.WriteLine("Cancelled"); } return(3); } catch (Exception e) { Console.Error.WriteLine(e); } } if (i == options.MaxAttempts && !options.IgnoreErrors) { Console.Error.WriteLine("Attempts number exceeded, terminating"); return(2); } } return(0); }
private static int MainInner(string[] args) { Acd.Factory = new AcdFactory(); var presets = args.Where(x => x.EndsWith(".pu-preset")).ToList(); var actualList = new List <string>(); foreach (var preset in presets) { try { actualList.AddRange( File.ReadAllLines(preset) .Where(x => !x.StartsWith("#")) .Select(x => x.Split(new[] { " #" }, StringSplitOptions.None)[0].Trim()) .Where(x => x.Length > 0)); } catch (Exception e) { Console.Error.WriteLine($"Can't load preset {preset}: {e.Message}."); } } actualList.AddRange(args.ApartFrom(presets)); var options = new Options(); if (!Parser.Default.ParseArguments(actualList.ToArray(), options)) { return(1); } if (options.ColorGradingFilename != null && presets.Count > 0 && !File.Exists(options.ColorGradingFilename)) { var locations = presets.Select(Path.GetDirectoryName).ToList(); var current = Environment.CurrentDirectory; foreach (var location in locations) { Environment.CurrentDirectory = location; var path = Path.GetFullPath(options.ColorGradingFilename); if (File.Exists(path)) { options.ColorGradingFilename = path; } } Environment.CurrentDirectory = current; } var acRoot = options.AcRoot == null?AcRootFinder.TryToFind() : Path.GetFullPath(options.AcRoot); if (acRoot == null) { Console.Error.WriteLine("Can't find AC root directory, you need to specify it manually."); Console.ReadLine(); return(1); } var ids = options.Ids.ApartFrom(presets).ToList(); if (ids.Count == 0) { Console.Error.WriteLine("You forgot to specify what cars to update: either list their IDs or filters."); Console.Error.WriteLine("To process all cars, use filter \"*\"."); Console.ReadLine(); return(1); } IFilter <string> filter; try { filter = Filter.Create(new CarTester(acRoot), ids.Select(x => "(" + (x.EndsWith("/") ? x.Substring(0, x.Length - 1) : x) + ")").JoinToString("|"), true); if (options.FilterTest) { Console.WriteLine(Directory.GetDirectories(AcPaths.GetCarsDirectory(acRoot)) .Select(Path.GetFileName).Where(x => filter.Test(x)).JoinToString(", ")); return(0); } if (options.Verbose) { Console.WriteLine("Filter: " + filter); } } catch (Exception e) { Console.Error.WriteLine("Can't parse filter: " + e.Message + "."); Console.ReadLine(); return(2); } if (options.Verbose) { Console.WriteLine("AC root: " + acRoot); Console.WriteLine("ImageMagick: " + ImageUtils.IsMagickSupported); Console.WriteLine("Starting shoting..."); } var sw = Stopwatch.StartNew(); int i = 0, j = 0; using (var thing = new DarkPreviewsUpdater(acRoot, new DarkPreviewsOptions { PreviewName = options.FileName, Showroom = options.Showroom, AlignCar = options.AlignCar, AlignCameraHorizontally = options.AlignCamera, AlignCameraHorizontallyOffset = options.AlignCameraOffset.Split(',').Select(x => FlexibleParser.TryParseDouble(x) ?? 0d).ToArray()[0], // TODO SsaaMultiplier = options.SsaaMultiplier, UseFxaa = options.UseFxaa, UseMsaa = options.UseMsaa, SoftwareDownsize = options.SoftwareDownsize, MsaaSampleCount = options.MsaaSampleCount, PreviewWidth = options.PreviewWidth, PreviewHeight = options.PreviewHeight, BloomRadiusMultiplier = options.BloomRadiusMultiplier, FlatMirror = options.FlatMirror, WireframeMode = options.WireframeMode, MeshDebugMode = options.MeshDebugMode, SuspensionDebugMode = options.SuspensionDebugMode, HeadlightsEnabled = options.HeadlightsEnabled, BrakeLightsEnabled = options.BrakeLightsEnabled, LeftDoorOpen = options.LeftDoorOpen, RightDoorOpen = options.RightDoorOpen, SteerDeg = options.SteerAngle, CameraPosition = options.CameraPosition.Split(',').Select(x => FlexibleParser.TryParseDouble(x) ?? 0d).ToArray(), CameraLookAt = options.LookAt.Split(',').Select(x => FlexibleParser.TryParseDouble(x) ?? 0d).ToArray(), CameraFov = options.Fov, BackgroundColor = ParseColor(options.BackgroundColor), LightColor = ParseColor(options.LightColor), AmbientUp = ParseColor(options.AmbientUp), AmbientDown = ParseColor(options.AmbientDown), AmbientBrightness = options.AmbientBrightness, LightBrightness = options.LightBrightness, DelayedConvertation = !options.SingleThread, UseSslr = options.UseSslr, UseAo = options.UseSsao, UsePcss = options.UsePcss, EnableShadows = options.EnableShadows, ShadowMapSize = options.ShadowMapSize, MaterialsReflectiveness = options.ReflectionMultiplier, ReflectionCubemapAtCamera = options.ReflectionCubemapAtCamera, ReflectionsWithShadows = !options.NoShadowsWithReflections, FlatMirrorBlurred = options.FlatMirrorBlurred, FlatMirrorReflectiveness = options.FlatMirrorReflectiveness, LightDirection = options.LightDirection.Split(',').Select(x => FlexibleParser.TryParseDouble(x) ?? 0d).ToArray(), })) { foreach (var carId in Directory.GetDirectories(AcPaths.GetCarsDirectory(acRoot)) .Select(Path.GetFileName).Where(x => filter.Test(x))) { Console.WriteLine($" {carId}..."); j++; foreach (var skinId in Directory.GetDirectories(AcPaths.GetCarSkinsDirectory(acRoot, carId)) .Where(x => !options.WithoutPreviews || !File.Exists(Path.Combine(x, options.FileName))) .Select(Path.GetFileName)) { var success = false; for (var a = 0; a < options.AttemptsCount || a == 0; a++) { try { if (options.Verbose) { Console.Write($" {skinId}... "); } thing.Shot(carId, skinId); success = true; break; } catch (Exception e) { Console.Error.WriteLine(e.Message); if (options.Verbose) { Console.Error.WriteLine(e.StackTrace); } } } if (success) { i++; if (options.Verbose) { Console.WriteLine("OK"); } } } if (options.Verbose && j % 10 == 0) { Console.WriteLine( $"At this moment done: {i} skins ({sw.Elapsed.TotalMilliseconds / j:F1} ms per car; {sw.Elapsed.TotalMilliseconds / i:F1} ms per skin)"); Console.WriteLine($"Time taken: {ToMillisecondsString(sw.Elapsed)}"); } } Console.Write("Finishing convertation... "); } Console.WriteLine("OK"); Console.WriteLine($"Done: {i} skins ({sw.Elapsed.TotalMilliseconds / j:F1} ms per car; {sw.Elapsed.TotalMilliseconds / i:F1} ms per skin)"); Console.WriteLine($"Time taken: {ToMillisecondsString(sw.Elapsed)}"); return(0); }