Esempio n. 1
0
        private static async Task StartAsyncInner(string kn5, string skinId = null, string presetFilename = null)
        {
            if (_starting)
            {
                return;
            }
            _starting = true;

            await FormWrapperBase.PrepareAsync();

            ForwardKn5ObjectRenderer renderer = null;

            Logging.Write("Custom Showroom: Magick.NET IsSupported=" + ImageUtils.IsMagickSupported);

            try {
                var carDirectory = Path.GetDirectoryName(kn5);
                if (Path.GetFileName(Path.GetDirectoryName(carDirectory)) == @"..")
                {
                    carDirectory = Path.GetDirectoryName(Path.GetDirectoryName(carDirectory));
                }

                var carObject   = CarsManager.Instance.GetById(Path.GetFileName(carDirectory) ?? "");
                var toolboxMode = IsSameDirectories(carObject?.Location, carDirectory);

                LiteShowroomFormWrapper formWrapper;
                using (var waiting = new WaitingDialog()) {
                    waiting.Report(ControlsStrings.CustomShowroom_Loading);

                    var description = new CarDescription(kn5, carDirectory, carObject?.AcdData);
                    if (toolboxMode)
                    {
                        ExtraModelProvider.Initialize();
                        var toolsRenderer = await Task.Run(() => SettingsHolder.CustomShowroom.UseOldLiteShowroom?
                                                           new ToolsKn5ObjectRenderer(description) {
                            UseMsaa      = SettingsHolder.CustomShowroom.LiteUseMsaa,
                            UseFxaa      = SettingsHolder.CustomShowroom.LiteUseFxaa,
                            UseBloom     = SettingsHolder.CustomShowroom.LiteUseBloom,
                            SoundFactory = new AcCarSoundFactory()
                        } :
                                                           new DarkKn5ObjectRenderer(description)
                        {
                            SoundFactory = new AcCarSoundFactory()
                        });

                        formWrapper = new LiteShowroomFormWrapperWithTools(toolsRenderer, carObject, skinId, presetFilename);
                        renderer    = toolsRenderer;
                    }
                    else
                    {
                        Logging.Warning($"Can’t find CarObject for “{carDirectory}”");
                        Logging.Warning($"Found location: “{carObject?.Location ?? @"NULL"}”");

                        renderer = await Task.Run(() => SettingsHolder.CustomShowroom.UseOldLiteShowroom?
                                                  new ForwardKn5ObjectRenderer(description) {
                            UseMsaa  = SettingsHolder.CustomShowroom.LiteUseMsaa,
                            UseFxaa  = SettingsHolder.CustomShowroom.LiteUseFxaa,
                            UseBloom = SettingsHolder.CustomShowroom.LiteUseBloom
                        } :
                                                  new DarkKn5ObjectRenderer(description)
                        {
                            FlatMirror = true,
                            VisibleUi  = true,
                            UseSprite  = true
                        });

                        formWrapper = new LiteShowroomFormWrapper(renderer);
                        if (skinId != null)
                        {
                            renderer.SelectSkin(skinId);
                        }
                    }

                    SetProperties(formWrapper, renderer);
                    formWrapper.Form.Icon = AppIconService.GetAppIcon();
                }

                formWrapper.Run(() => _starting = false);
            } catch (Exception e) {
                NonfatalError.Notify(ControlsStrings.CustomShowroom_CannotStart, e);
            } finally {
                try {
                    renderer?.Dispose();
                } catch (Exception e) {
                    NonfatalError.Notify("Can’t close Custom Showroom", e);
                } finally {
                    _starting = false;
                }
            }
        }
Esempio n. 2
0
        private static async Task StartAsyncInner([CanBeNull] CarObject carObject, string kn5, IEnumerable <CustomShowroomLodDefinition> lodDefinitions = null,
                                                  string skinId = null, string presetFilename = null, bool forceToolboxMode = false)
        {
            if (_starting)
            {
                return;
            }
            _starting = true;

            await FormWrapperBase.PrepareAsync();

            ForwardKn5ObjectRenderer renderer = null;

            Logging.Write("Custom Showroom: Magick.NET IsSupported=" + ImageUtils.IsMagickSupported);

            if (!_interopSet)
            {
                _interopSet = true;
                Task.Delay(TimeSpan.FromSeconds(1d)).ContinueWithInMainThread(r => {
                    DpiAwareWindow.NewWindowCreated += (sender, args) => ElementHost.EnableModelessKeyboardInterop((DpiAwareWindow)sender);
                    foreach (Window window in Application.Current.Windows)
                    {
                        ElementHost.EnableModelessKeyboardInterop(window);
                    }
                }).Ignore();
            }

            try {
                var kn5Directory = Path.GetDirectoryName(kn5);
                var toolboxMode  = forceToolboxMode || lodDefinitions != null || IsSameDirectories(carObject?.Location, kn5Directory);

                LiteShowroomFormWrapper formWrapper;
                using (var waiting = new WaitingDialog()) {
                    waiting.Report(ControlsStrings.CustomShowroom_Loading);

                    var description = new CarDescription(kn5, carObject?.Location ?? kn5Directory, carObject?.AcdData);
                    if (toolboxMode)
                    {
                        ExtraModelProvider.Initialize();
                        var toolsRenderer = await Task.Run(() => SettingsHolder.CustomShowroom.UseOldLiteShowroom?
                                                           new ToolsKn5ObjectRenderer(description) {
                            UseMsaa      = SettingsHolder.CustomShowroom.LiteUseMsaa,
                            UseFxaa      = SettingsHolder.CustomShowroom.LiteUseFxaa,
                            UseBloom     = SettingsHolder.CustomShowroom.LiteUseBloom,
                            SoundFactory = new AcCarSoundFactory()
                        } :
                                                           new DarkKn5ObjectRenderer(description)
                        {
                            SoundFactory = new AcCarSoundFactory()
                        });

                        formWrapper = new LiteShowroomFormWrapperWithTools(toolsRenderer, carObject, skinId, presetFilename, lodDefinitions);
                        renderer    = toolsRenderer;
                    }
                    else
                    {
                        Logging.Warning($"Can’t find CarObject for “{kn5Directory}”");
                        Logging.Warning($"Found location: “{carObject?.Location ?? @"NULL"}”");

                        renderer = await Task.Run(() => SettingsHolder.CustomShowroom.UseOldLiteShowroom?
                                                  new ForwardKn5ObjectRenderer(description) {
                            UseMsaa  = SettingsHolder.CustomShowroom.LiteUseMsaa,
                            UseFxaa  = SettingsHolder.CustomShowroom.LiteUseFxaa,
                            UseBloom = SettingsHolder.CustomShowroom.LiteUseBloom
                        } :
                                                  new DarkKn5ObjectRenderer(description)
                        {
                            FlatMirror = true,
                            VisibleUi  = true,
                            UseSprite  = true
                        });

                        formWrapper = new LiteShowroomFormWrapper(renderer);
                        if (skinId != null)
                        {
                            renderer.SelectSkin(skinId);
                        }
                    }

                    SetProperties(formWrapper, renderer);
                    formWrapper.Form.Icon = AppIconService.GetAppIcon();
                }

                formWrapper.Run(() => _starting = false);
            } catch (Exception e) {
                NonfatalError.Notify(ControlsStrings.CustomShowroom_CannotStart, e);
            } finally {
                try {
                    renderer?.Dispose();
                } catch (Exception e) {
                    NonfatalError.Notify("Can’t close Custom Showroom", e);
                } finally {
                    _starting = false;
                }
            }
        }