Untitled

 avatar
unknown
csharp
a year ago
3.3 kB
1
Indexable
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Windows.Forms;

namespace GameLauncher
{
    public partial class Launcher : Form
    {
        private string gameUrl = "http://example.com/game.zip";
        private string gameExe = "game.exe";
        private string updateUrl = "http://example.com/update.zip";

        public Launcher()
        {
            InitializeComponent();
        }

        private void btnPlay_Click(object sender, EventArgs e)
        {
            // Запускаем игру
            if (File.Exists(gameExe))
            {
                Process.Start(gameExe);
            }
            else
            {
                MessageBox.Show("Игра не найдена. Необходимо её скачать.");
            }
        }

        private void btnDownload_Click(object sender, EventArgs e)
        {
            // Скачиваем игру
            using (WebClient client = new WebClient())
            {
                client.DownloadFile(gameUrl, "game.zip");
            }
            UnzipGame();
        }

        private void UnzipGame()
        {
            // Разархивируем игру
            using (Process process = new Process())
            {
                ProcessStartInfo startInfo = new ProcessStartInfo
                {
                    WindowStyle = ProcessWindowStyle.Hidden,
                    FileName = "powershell.exe",
                    Arguments = $"-nologo -executionpolicy bypass -command \"Add-Type -A 'System.IO.Compression.FileSystem'; " +
                                $"[IO.Compression.ZipFile]::ExtractToDirectory('game.zip', '.')\"",
                    RedirectStandardOutput = true,
                    UseShellExecute = false
                };
                process.StartInfo = startInfo;
                process.Start();
                process.WaitForExit();
            }
            File.Delete("game.zip");
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            // Скачиваем обновление
            using (WebClient client = new WebClient())
            {
                client.DownloadFile(updateUrl, "update.zip");
            }
            ApplyUpdate();
        }

        private void ApplyUpdate()
        {
            // Применяем обновление
            using (Process process = new Process())
            {
                ProcessStartInfo startInfo = new ProcessStartInfo
                {
                    WindowStyle = ProcessWindowStyle.Hidden,
                    FileName = "powershell.exe",
                    Arguments = $"-nologo -executionpolicy bypass -command \"Add-Type -A 'System.IO.Compression.FileSystem'; " +
                                $"[IO.Compression.ZipFile]::ExtractToDirectory('update.zip', '.')\"",
                    RedirectStandardOutput = true,
                    UseShellExecute = false
                };
                process.StartInfo = startInfo;
                process.Start();
                process.WaitForExit();
            }
            File.Delete("update.zip");
        }
    }
}
Leave a Comment