Exemple #1
0
        public static async Task DownloadCarAsync([NotNull] string id, string version = null)
        {
            try {
                var entry = await CmApiProvider.GetContentAsync <AcContentEntry>($"car/{id}");

                if (entry != null)
                {
                    if (version != null && entry.UiVersion != version && entry.OriginVersion != version)
                    {
                        throw new InformativeException($"Can’t download car “{id}”",
                                                       $"Not the required version: indexed is {entry.UiVersion ?? entry.OriginVersion}, while required is {version}.");
                    }

                    if (!entry.ImmediateDownload && entry.OriginUrl != null && (Keyboard.Modifiers & ModifierKeys.Control) == 0)
                    {
                        WindowsHelper.ViewInBrowser(entry.OriginUrl);
                    }
                    else
                    {
                        await ContentInstallationManager.Instance.InstallAsync(entry.DownloadUrl, new ContentInstallationParams(false) {
                            DisplayName    = entry.UiName,
                            Version        = entry.UiVersion,
                            InformationUrl = entry.OriginUrl
                        });
                    }
                }
                else
                {
                    throw new InformativeException($"Can’t download car “{id}”", "Attempt to find a description failed.");
                }
            } catch (Exception e) {
                NonfatalError.Notify($"Can’t download car “{id}”", e);
            }
        }
Exemple #2
0
        private static void ManualInstallation([CanBeNull] Exception e, string directory)
        {
            var downloadUrl = @"https://drive.google.com/uc?id=1vPW58x0AsD3XzSSq8MzN9FEuZt6vGTLq";

            NonfatalError.Notify("Can’t download the package",
                                 $"You can try to [url={BbCodeBlock.EncodeAttribute(downloadUrl)}]download[/url] and install it manually. Don’t forget to restart CM after it was installed.",
                                 e, new[] {
                new NonfatalErrorSolution("Open destination folder", null, t => {
                    WindowsHelper.ViewDirectory(directory);
                    return(Task.Delay(0));
                }, "FolderIconData"),
            });
        }
Exemple #3
0
        private static async Task DownloadAndInstall(CancellationToken token)
        {
            var directory = _directory ?? MainExecutingFile.Directory;

            try {
                var data = await CmApiProvider.GetStaticDataAsync("visual_cpp", TimeSpan.FromDays(1), cancellation : token);

                if (data == null)
                {
                    ManualInstallation(null, directory);
                }
                else
                {
                    await Task.Run(() => {
                        using (var archive = ZipFile.OpenRead(data.Item1)) {
                            foreach (var file in archive.Entries)
                            {
                                var completeFileName = Path.Combine(directory, file.FullName);
                                if (file.Name == "" || File.Exists(completeFileName))
                                {
                                    continue;
                                }
                                FileUtils.EnsureFileDirectoryExists(completeFileName);
                                file.ExtractToFile(completeFileName, true);
                            }
                        }
                    });

                    FileUtils.TryToDelete(data.Item1);
                    if (ModernDialog.ShowMessage("The package is installed. Now, app needs to be restarted. Restart it now?", "The package is installed",
                                                 MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                    {
                        WindowsHelper.RestartCurrentApplication();
                    }
                }
            } catch (Exception e) when(e.IsCancelled())
            {
            } catch (Exception e) {
                ManualInstallation(e, directory);
            }
        }
Exemple #4
0
        private static async Task ResetService()
        {
            var secondResponse = ActionExtension.InvokeInMainThread(() => MessageDialog.Show(
                                                                        "Would you like to reset FTH system to make sure changes are applied? Otherwise, you would need to restart Windows.[br][br]It’ll need to run this command:[br][mono]Rundll32.exe fthsvc.dll,FthSysprepSpecialize[/mono][br][br]Or, Content Manager can simply prepare a .bat-file for you to inspect and run manually. [url=\"https://docs.microsoft.com/en-us/windows/win32/win7appqual/fault-tolerant-heap\"]Learn more[/url].",
                                                                        "One more thing",
                                                                        new MessageDialogButton(MessageBoxButton.YesNo, MessageBoxResult.Yes)
            {
                [MessageBoxResult.Yes] = "Reset automatically",
                [MessageBoxResult.No]  = "Prepare a .bat-file only"
            }));

            if (secondResponse == MessageBoxResult.Cancel)
            {
                return;
            }

            var filename = FilesStorage.Instance.GetTemporaryFilename("RunElevated", "FixFTH.bat");

            File.WriteAllText(filename, @"@echo off
:: More info: https://docs.microsoft.com/en-us/windows/win32/win7appqual/fault-tolerant-heap
echo Running rundll32.exe fthsvc.dll,FthSysprepSpecialize...
cd %windir%\system32
%windir%\system32\rundll32.exe fthsvc.dll,FthSysprepSpecialize
echo Done
pause");

            if (secondResponse == MessageBoxResult.Yes)
            {
                var procRunDll32 = ProcessExtension.Start("explorer.exe", new[] { filename }, new ProcessStartInfo {
                    Verb = "runas"
                });
                await procRunDll32.WaitForExitAsync().ConfigureAwait(false);

                Logging.Debug("Done: " + procRunDll32.ExitCode);
            }
            else if (secondResponse == MessageBoxResult.No)
            {
                WindowsHelper.ViewFile(filename);
            }
        }