Example #1
0
        private static int MainInner(string[] args) {
            var options = new Options();
            if (!Parser.Default.ParseArguments(args, options)) return 1;

            var filename = Assembly.GetEntryAssembly().Location;
            if (options.Verbose || filename.IndexOf("log", StringComparison.OrdinalIgnoreCase) != -1
                    || filename.IndexOf("debug", StringComparison.OrdinalIgnoreCase) != -1) {
                var log = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) ?? "", "Log.txt");
                try {
                    File.WriteAllBytes(log, new byte[0]);
                    RenderLogging.Initialize(log);
                } catch (Exception e) {
                    MessageBox.Show("Can’t setup logging: " + e, @"Oops!", MessageBoxButtons.OK);
                }
            }

            var inputItems = options.Items;
#if DEBUG
            inputItems = inputItems.Any() ? inputItems : new[] { DebugHelper.GetCarKn5(), DebugHelper.GetShowroomKn5() };
#endif

            if (inputItems.Count == 0) {
                var dialog = new OpenFileDialog {
                    Title = @"Select KN5",
                    Filter = @"KN5 Files (*.kn5)|*.kn5"
                };
                if (dialog.ShowDialog() != DialogResult.OK) return 2;

                inputItems = new[] { dialog.FileName };
            }

            var kn5File = inputItems.ElementAtOrDefault(0);
            if (kn5File == null || !File.Exists(kn5File)) {
                MessageBox.Show(@"File is missing", @"Custom Showroom", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return 3;
            }

            if (options.Mode == Mode.UpdateAmbientShadows) {
                UpdateAmbientShadows(kn5File);
                return 0;
            }

            if (options.Mode == Mode.ExtractUv) {
                if (string.IsNullOrWhiteSpace(options.ExtractUvTexture)) {
                    MessageBox.Show(@"Texture to extract is not specified", @"Custom Showroom", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return 4;
                }
                ExtractUv(kn5File, options.ExtractUvTexture);
                return 0;
            }

            var showroomKn5File = inputItems.ElementAtOrDefault(1);
            if (showroomKn5File == null && options.ShowroomId != null) {
                showroomKn5File = Path.Combine(
                        Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(kn5File))) ?? "",
                        "showroom", options.ShowroomId, options.ShowroomId + ".kn5");
            }

            if (!File.Exists(showroomKn5File)) {
                showroomKn5File = null;
            }
            
            if (options.Mode == Mode.Lite) {
                using (var renderer = new ForwardKn5ObjectRenderer(kn5File)) {
                    renderer.UseMsaa = options.UseMsaa;
                    renderer.UseFxaa = options.UseFxaa;
                    new LiteShowroomWrapper(renderer).Run();
                }
            } else {
                using (var renderer = new Kn5ObjectRenderer(kn5File, showroomKn5File)) {
                    renderer.UseFxaa = options.UseFxaa;
                    new FancyShowroomWrapper(renderer).Run();
                }
            }

            GC.Collect();
            GC.WaitForPendingFinalizers();
            return 0;
        }