Пример #1
0
        /// <inheritdoc />
        public override async Task InstallByond(string path, Version version, CancellationToken cancellationToken)
        {
            async Task SetNoPromptTrusted()
            {
                var configPath = IOManager.ConcatPath(path, ByondConfigDir);
                await IOManager.CreateDirectory(configPath, cancellationToken).ConfigureAwait(false);

                await IOManager.WriteAllBytes(IOManager.ConcatPath(configPath, ByondDDConfig), Encoding.UTF8.GetBytes(ByondNoPromptTrustedMode), cancellationToken).ConfigureAwait(false);
            }

            var setNoPromptTrustedModeTask = SetNoPromptTrusted();

            // after this version lummox made DD depend of directx lol
            // but then he became amazing and not only fixed it but also gave us 30s compiles \[T]/
            // then he readded it again so -_-
            if (!installedDirectX)
            {
                using (await SemaphoreSlimContext.Lock(semaphore, cancellationToken).ConfigureAwait(false))
                    if (!installedDirectX)
                    {
                        // ^check again because race conditions
                        // always install it, it's pretty fast and will do better redundancy checking than us
                        var rbdx = IOManager.ConcatPath(path, ByondDXDir);

                        // noShellExecute because we aren't doing runas shennanigans
                        IProcess directXInstaller;
                        try
                        {
                            directXInstaller = processExecutor.LaunchProcess(IOManager.ConcatPath(rbdx, "DXSETUP.exe"), rbdx, "/silent", noShellExecute: true);
                        }
                        catch (Exception e)
                        {
                            throw new JobException("Unable to start DirectX installer process! Is the server running with admin privileges?", e);
                        }

                        using (directXInstaller)
                        {
                            int exitCode;
                            using (cancellationToken.Register(() => directXInstaller.Terminate()))
                                exitCode = await directXInstaller.Lifetime.ConfigureAwait(false);
                            cancellationToken.ThrowIfCancellationRequested();

                            if (exitCode != 0)
                            {
                                throw new JobException(String.Format(CultureInfo.InvariantCulture, "Failed to install included DirectX! Exit code: {0}", exitCode));
                            }
                            installedDirectX = true;
                        }
                    }
            }

            await setNoPromptTrustedModeTask.ConfigureAwait(false);
        }
        /// <summary>
        /// Creates the BYOND cfg file that prevents the trusted mode dialog from appearing when launching DreamDaemon.
        /// </summary>
        /// <param name="path">The path to the BYOND installation.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
        /// <returns>A <see cref="Task"/> representing the running operation.</returns>
        async Task SetNoPromptTrusted(string path, CancellationToken cancellationToken)
        {
            var configPath = IOManager.ConcatPath(path, ByondConfigDir);
            await IOManager.CreateDirectory(configPath, cancellationToken).ConfigureAwait(false);

            var configFilePath = IOManager.ConcatPath(configPath, ByondDDConfig);

            Logger.LogTrace("Disabling trusted prompts in {0}...", configFilePath);
            await IOManager.WriteAllBytes(
                configFilePath,
                Encoding.UTF8.GetBytes(ByondNoPromptTrustedMode),
                cancellationToken)
            .ConfigureAwait(false);
        }