Esempio n. 1
0
        public async Task <byte[]> GetModel(string key)
        {
            if (key != ExtraModels.KeyCrewExtra)
            {
                return(null);
            }

            using (var dialog = new WaitingDialog()) {
                dialog.Report(ControlsStrings.Common_Downloading);

                var data = await CmApiProvider.GetStaticDataBytesAsync("cs_crew", TimeSpan.FromDays(3), dialog, dialog.CancellationToken);

                if (data == null)
                {
                    return(null);
                }

                return(await Task.Run(() => {
                    using (var stream = new MemoryStream(data, false))
                        using (var archive = new ZipArchive(stream)) {
                            return archive.GetEntry("Crew.kn5")?.Open().ReadAsBytesAndDispose();
                        }
                }));
            }
        }
Esempio n. 2
0
        public static async Task Play(BeepingNoiseType type)
        {
            switch (type)
            {
            case BeepingNoiseType.Disabled:
                break;

            case BeepingNoiseType.System:
                SystemSounds.Exclamation.Play();
                break;

            case BeepingNoiseType.Custom:
                try {
                    var data = await CmApiProvider.GetStaticDataBytesAsync("audio_error", TimeSpan.FromDays(3));

                    if (data != null)
                    {
                        using (var stream = new MemoryStream(data))
                            using (var zip = ZipArchive.Open(stream)) {
                                var entry = zip.Entries.FirstOrDefault(x => x.Key == @"error.wav");
                                if (entry == null)
                                {
                                    throw new Exception("Invalid data");
                                }
                                using (var s = entry.OpenEntryStream()) {
                                    new SoundPlayer(s).Play();
                                }
                            }
                    }
                } catch (Exception e) {
                    Logging.Warning(e);
                }
                break;
            }
        }
Esempio n. 3
0
        public static async Task FixMissingDefaultPpFilter(CancellationToken cancellation)
        {
            var original = await CmApiProvider.GetStaticDataBytesAsync("pp_default", TimeSpan.FromDays(3), cancellation : cancellation);

            if (cancellation.IsCancellationRequested)
            {
                return;
            }

            await Task.Run(() => {
                cancellation.ThrowIfCancellationRequested();
                if (original == null)
                {
                    throw new InformativeException("Can’t load original filter");
                }

                using (var stream = new MemoryStream(original))
                    using (var zip = ZipArchive.Open(stream)) {
                        var entry = zip.Entries.FirstOrDefault(x => x.Key == @"default.ini");
                        if (entry == null)
                        {
                            throw new Exception("Invalid data");
                        }

                        File.WriteAllBytes(PpFiltersManager.Instance.DefaultFilename, entry.OpenEntryStream().ReadAsBytesAndDispose());
                    }
            }, cancellation);
        }
Esempio n. 4
0
        private async Task LoadBackgroundAsync()
        {
            var data = await CmApiProvider.GetStaticDataBytesAsync("damagedisplayer_bg", TimeSpan.MaxValue);

            if (data != null)
            {
                using (var stream = new MemoryStream(data))
                    using (var zip = new ZipArchive(stream, ZipArchiveMode.Read)) {
                        BackgroundImageProgress.IsActive = false;
                        BackgroundImage.Source           = zip.GetEntry(@"image.jpg")?.Open().ReadAsBytesAndDispose();
                    }
            }
        }
Esempio n. 5
0
        private async Task LoadBackgroundAsync()
        {
            var data = await CmApiProvider.GetStaticDataBytesAsync("patch_img_about", TimeSpan.MaxValue);

            if (data != null)
            {
                using (var stream = new MemoryStream(data))
                    using (var zip = new ZipArchive(stream, ZipArchiveMode.Read)) {
                        _imageData    = zip.GetEntry(@"image.jpg")?.Open().ReadAsBytesAndDispose();
                        _imageMessage = zip.GetEntry(@"about.txt")?.Open().ReadAsBytesAndDispose().ToUtf8String();
                        BackgroundImageProgress.IsActive = false;
                        BackgroundImage.Source           = _imageData;
                    }
            }
        }
Esempio n. 6
0
        private static async Task <byte[]> GetFlamesTexturesAsync(IProgress <AsyncProgressEntry> progress = null,
                                                                  CancellationToken cancellation          = default(CancellationToken))
        {
            if (_flamesTextures == null)
            {
                progress?.Report(AsyncProgressEntry.FromStringIndetermitate("Loading flames textures…"));
                _flamesTextures = await CmApiProvider.GetStaticDataBytesAsync("flames", TimeSpan.FromDays(3), cancellation : cancellation);

                if (cancellation.IsCancellationRequested)
                {
                    return(null);
                }
            }

            return(_flamesTextures);
        }
        private static async Task InstallShowroom(string showroomName, string showroomId, CarUpdatePreviewsDialog instance = null)
        {
            if (instance != null)
            {
                instance._mode = UpdatePreviewMode.Options;
                await Task.Delay(100);
            }

            using (var dialog = new WaitingDialog(showroomName)) {
                dialog.Report(ControlsStrings.Common_Downloading);

                var destination = FileUtils.GetShowroomsDirectory(AcRootDirectory.Instance.Value);
                var data        = await CmApiProvider.GetStaticDataBytesAsync(showroomId, dialog, dialog.CancellationToken);

                if (data == null)
                {
                    dialog.Close();
                    NonfatalError.Notify(string.Format(AppStrings.CarPreviews_CannotDownloadShowroom, showroomName), ToolsStrings.Common_CannotDownloadFile_Commentary);
                    return;
                }

                dialog.Content = ControlsStrings.Common_Installing;
                try {
                    await Task.Run(() => {
                        using (var stream = new MemoryStream(data, false))
                            using (var archive = new ZipArchive(stream)) {
                                archive.ExtractToDirectory(destination);
                            }
                    });
                } catch (Exception e) {
                    dialog.Close();
                    NonfatalError.Notify(string.Format(AppStrings.CarPreviews_CannotInstallShowroom, showroomName), e);
                    return;
                }

                await Task.Delay(1000);

                if (instance != null)
                {
                    instance.SelectedShowroom = ShowroomsManager.Instance.GetById(showroomId) ?? instance.SelectedShowroom;
                }
            }
        }