using System; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.IO; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using CasinoSetup; namespace PokerGameSetup; internal sealed class InstallerForm : Form { private readonly SetupPackage package; private readonly Panel content = new Panel(); private readonly CasinoButton back; private readonly CasinoButton next; private readonly CasinoButton cancel; private readonly CasinoStepper stepper = new CasinoStepper(); private readonly SlideShow slides; private readonly Label sizes; private readonly System.Windows.Forms.Timer timer; private readonly Stopwatch clock = Stopwatch.StartNew(); private readonly RouletteControl roulette = new RouletteControl(); private readonly CasinoProgressBar progress = new CasinoProgressBar(); private readonly Label status = new Label(); private readonly Label percentLabel = new Label(); private string target = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Assembler Casino"); private bool includeModel = true; private bool desktopShortcut = true; private bool installing; private int step; private CancellationTokenSource cancellation; private InstallProgress latest; private CheckBox launch; public static readonly Color Gold = Color.FromArgb(229, 190, 112); public static readonly Color GoldLight = Color.FromArgb(250, 222, 145); public static readonly Color Ink = Color.FromArgb(14, 17, 20); public static readonly Color Paper = Color.FromArgb(238, 233, 222); public InstallerForm(SetupPackage package, int initialStep = 0) { this.package = package; includeModel = package.HasModel; Text = "Assembler Casino — мастер установки"; ClientSize = new Size(1140, 720); AutoScaleMode = AutoScaleMode.Dpi; FormBorderStyle = FormBorderStyle.FixedSingle; MaximizeBox = false; StartPosition = FormStartPosition.CenterScreen; BackColor = Ink; ForeColor = Paper; Font = new Font("Segoe UI", 10f); DoubleBuffered = true; try { Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath); } catch { } // Header labels Label title = new Label { Text = "ASSEMBLER", Font = new Font("Georgia", 26f, FontStyle.Bold), ForeColor = GoldLight, Bounds = new Rectangle(32, 22, 380, 44), BackColor = Color.Transparent }; Controls.Add(title); Label subtitle = new Label { Text = "C A S I N O / M A S T E R S E T U P", ForeColor = Color.FromArgb(175, 170, 155), Bounds = new Rectangle(34, 68, 380, 22), Font = new Font("Segoe UI", 8.5f, FontStyle.Bold), BackColor = Color.Transparent }; Controls.Add(subtitle); // Modern Stepper stepper.Bounds = new Rectangle(32, 115, 375, 168); Controls.Add(stepper); // Dynamic content panel content.Bounds = new Rectangle(32, 298, 375, 304); Controls.Add(content); // Size / disk space label sizes = new Label { Bounds = new Rectangle(32, 606, 375, 36), ForeColor = Color.FromArgb(150, 160, 156), Font = new Font("Segoe UI", 8.8f), BackColor = Color.Transparent }; Controls.Add(sizes); // Buttons back = new CasinoButton { Text = "Назад", Bounds = new Rectangle(32, 650, 96, 42), IsPrimary = false }; next = new CasinoButton { Text = "Далее →", Bounds = new Rectangle(136, 650, 165, 42), IsPrimary = true }; cancel = new CasinoButton { Text = "Отмена", Bounds = new Rectangle(309, 650, 98, 42), IsPrimary = false }; Controls.Add(back); Controls.Add(next); Controls.Add(cancel); back.Click += (object s, EventArgs e) => { ShowStep(step - 1); }; next.Click += Next; cancel.Click += (object s, EventArgs e) => { if (installing) { CancelInstall(); } else { Close(); } }; // Slideshow on the right slides = new SlideShow { Bounds = new Rectangle(438, 0, 702, 720) }; Controls.Add(slides); // Animation Timer timer = new System.Windows.Forms.Timer { Interval = 30 }; timer.Tick += (object s, EventArgs e) => { slides.AdvanceTime(); if (installing) { double time = clock.Elapsed.TotalSeconds; roulette.Angle = time * 85.0; roulette.Invalidate(); progress.ShimmerPhase = time * 0.75; InstallProgress p = Interlocked.Exchange(ref latest, null); if (p != null) { progress.Value = Math.Max(progress.Value, Math.Min(100, p.Percent)); status.Text = p.Message; percentLabel.Text = $"{progress.Value}%"; } } }; timer.Start(); FormClosing += (object s, FormClosingEventArgs e) => { if (installing) { e.Cancel = true; CancelInstall(); } }; FormClosed += (object s, FormClosedEventArgs e) => { timer.Dispose(); slides.Dispose(); cancellation?.Dispose(); }; ShowStep(initialStep); } protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if ((keyData & Keys.Alt) == Keys.Alt) { Keys key = keyData & Keys.KeyCode; if (key >= Keys.D1 && key <= Keys.D5) { ShowStep((int)key - (int)Keys.D1); return true; } } return base.ProcessCmdKey(ref msg, keyData); } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics g = e.Graphics; g.SmoothingMode = SmoothingMode.AntiAlias; // Subtle luxury vignette gradient on left panel using (LinearGradientBrush bgGrad = new LinearGradientBrush( new Rectangle(0, 0, 438, Height), Color.FromArgb(16, 19, 22), Color.FromArgb(11, 13, 15), 90f)) { g.FillRectangle(bgGrad, 0, 0, 438, Height); } // Art Deco decorative divider below header using (Pen sepPen = new Pen(Color.FromArgb(60, 229, 190, 112), 1f)) { g.DrawLine(sepPen, 32, 98, 190, 98); g.DrawLine(sepPen, 218, 98, 395, 98); } // Diamond in the middle of divider using (SolidBrush dBrush = new SolidBrush(Gold)) { Point[] diamond = new Point[] { new Point(204, 95), new Point(208, 98), new Point(204, 101), new Point(200, 98) }; g.FillPolygon(dBrush, diamond); } } private Label CreateLabel(string text, int y, int height, float size, Color color, FontStyle style = FontStyle.Regular) { Label label = new Label { Text = text, Bounds = new Rectangle(0, y, 375, height), ForeColor = color, Font = new Font((size >= 16f) ? "Georgia" : "Segoe UI", size, style), BackColor = Color.Transparent }; content.Controls.Add(label); return label; } private void ShowStep(int value) { step = Math.Max(0, Math.Min(4, value)); content.Controls.Clear(); stepper.CurrentStep = step; back.Enabled = step > 0 && step < 3; next.Enabled = step != 3; if (step == 2) { next.Text = "Установить →"; } else if (step == 4) { next.Text = "Играть →"; } else { next.Text = "Далее →"; } cancel.Text = (step == 4) ? "Закрыть" : "Отмена"; if (step == 0) { // Step 0: Welcome CreateLabel("Ваш вечер\nначинается здесь", 0, 72, 22f, Paper, FontStyle.Bold); CreateLabel("Игровые столы, тайные комнаты и секреты подполья казино.", 78, 44, 10.5f, Color.FromArgb(195, 190, 180)); // 4 Feature Chips / Badges string[,] chips = new string[,] { { "♠ Pure x86 MASM", "Ассемблерный движок" }, { "✦ 3D Raycaster", "Зал казино от 1-го лица" }, { "◈ 100% Офлайн", "Полная автономность" }, { "🧠 Нейросеть Таро", "Локальный ИИ Qwen 4B" } }; int chipY = 128; for (int i = 0; i < 4; i++) { int cx = (i % 2 == 0) ? 0 : 190; int cy = chipY + (i / 2) * 54; Panel chipPanel = new Panel { Bounds = new Rectangle(cx, cy, 182, 48), BackColor = Color.FromArgb(22, 25, 28) }; chipPanel.Paint += (object s, PaintEventArgs pe) => { pe.Graphics.SmoothingMode = SmoothingMode.AntiAlias; Rectangle r = new Rectangle(0, 0, chipPanel.Width - 1, chipPanel.Height - 1); using Pen bp = new Pen(Color.FromArgb(70, 60, 45), 1f); pe.Graphics.DrawRectangle(bp, r); }; Label chipTitle = new Label { Text = chips[i, 0], Bounds = new Rectangle(8, 6, 166, 18), ForeColor = Gold, Font = new Font("Segoe UI", 9f, FontStyle.Bold), BackColor = Color.Transparent }; Label chipSub = new Label { Text = chips[i, 1], Bounds = new Rectangle(8, 25, 166, 18), ForeColor = Color.FromArgb(145, 155, 150), Font = new Font("Segoe UI", 8f), BackColor = Color.Transparent }; chipPanel.Controls.Add(chipTitle); chipPanel.Controls.Add(chipSub); content.Controls.Add(chipPanel); } // Offline note card Panel notePanel = new Panel { Bounds = new Rectangle(0, 244, 375, 56), BackColor = Color.FromArgb(20, 24, 26) }; notePanel.Paint += (object s, PaintEventArgs pe) => { pe.Graphics.SmoothingMode = SmoothingMode.AntiAlias; Rectangle r = new Rectangle(0, 0, notePanel.Width - 1, notePanel.Height - 1); using Pen bp = new Pen(Color.FromArgb(85, 72, 50), 1f); pe.Graphics.DrawRectangle(bp, r); }; Label noteLabel = new Label { Text = package.HasModel ? "Вся игра и локальная нейросеть (2.5 ГБ) уже внутри дистрибутива. Интернет для установки и игры не требуется." : "Дистрибутив без встроенной нейросети. Интернет не требуется.", Bounds = new Rectangle(10, 8, 355, 40), ForeColor = Color.FromArgb(170, 180, 175), Font = new Font("Segoe UI", 8.8f), BackColor = Color.Transparent }; notePanel.Controls.Add(noteLabel); content.Controls.Add(notePanel); } else if (step == 1) { // Step 1: Folder Selection CreateLabel("Место для казино", 0, 36, 21f, Paper, FontStyle.Bold); CreateLabel("Выберите отдельную папку. Права администратора не требуются.", 38, 38, 9.8f, Color.FromArgb(185, 180, 170)); // Folder Path Container Panel folderContainer = new Panel { Bounds = new Rectangle(0, 84, 375, 36), BackColor = Color.FromArgb(25, 29, 32) }; folderContainer.Paint += (object s, PaintEventArgs pe) => { pe.Graphics.SmoothingMode = SmoothingMode.AntiAlias; Rectangle r = new Rectangle(0, 0, folderContainer.Width - 1, folderContainer.Height - 1); using Pen bp = new Pen(Color.FromArgb(90, 78, 55), 1.2f); pe.Graphics.DrawRectangle(bp, r); }; TextBox box = new TextBox { Text = target, Bounds = new Rectangle(8, 8, 359, 24), BackColor = Color.FromArgb(25, 29, 32), ForeColor = Paper, BorderStyle = BorderStyle.None, Font = new Font("Segoe UI", 9.5f) }; box.TextChanged += (object s, EventArgs e) => { target = box.Text; UpdateSizes(); }; folderContainer.Controls.Add(box); content.Controls.Add(folderContainer); CasinoButton browseBtn = new CasinoButton { Text = "Выбрать папку…", Bounds = new Rectangle(0, 128, 160, 36), IsPrimary = false }; browseBtn.Click += (object s, EventArgs e) => { using FolderBrowserDialog dlg = new FolderBrowserDialog(); dlg.Description = "Родительская папка для установки Assembler Casino"; if (Directory.Exists(target)) { dlg.SelectedPath = target; } if (dlg.ShowDialog(this) == DialogResult.OK) { box.Text = Path.Combine(dlg.SelectedPath, "Assembler Casino"); } }; content.Controls.Add(browseBtn); // Info card about saves and portability Panel infoCard = new Panel { Bounds = new Rectangle(0, 176, 375, 114), BackColor = Color.FromArgb(20, 24, 27) }; infoCard.Paint += (object s, PaintEventArgs pe) => { pe.Graphics.SmoothingMode = SmoothingMode.AntiAlias; Rectangle r = new Rectangle(0, 0, infoCard.Width - 1, infoCard.Height - 1); using Pen bp = new Pen(Color.FromArgb(75, 65, 48), 1f); pe.Graphics.DrawRectangle(bp, r); }; Label cardTitle = new Label { Text = "✦ Сохранения и автономность", Bounds = new Rectangle(12, 10, 350, 20), ForeColor = Gold, Font = new Font("Segoe UI", 9.5f, FontStyle.Bold), BackColor = Color.Transparent }; Label cardBody = new Label { Text = "Все профили игроков, баланс фишек и открытые сюжетные достижения сохраняются в AppData. При обновлении или повторной установке прогресс полностью сохраняется.", Bounds = new Rectangle(12, 34, 350, 48), ForeColor = Color.FromArgb(160, 172, 168), Font = new Font("Segoe UI", 8.8f), BackColor = Color.Transparent }; Label cardCheck = new Label { Text = "✓ На диске достаточно свободного места для игры", Bounds = new Rectangle(12, 86, 350, 20), ForeColor = Color.FromArgb(140, 210, 160), Font = new Font("Segoe UI", 8.8f, FontStyle.Bold), BackColor = Color.Transparent }; infoCard.Controls.Add(cardTitle); infoCard.Controls.Add(cardBody); infoCard.Controls.Add(cardCheck); content.Controls.Add(infoCard); } else if (step == 2) { // Step 2: Components selection CreateLabel("Соберите свой вечер", 0, 34, 21f, Paper, FontStyle.Bold); // Card 1: Core Game CasinoCardCheck gameCard = new CasinoCardCheck { Bounds = new Rectangle(0, 44, 375, 64), Title = "Основная игра", Badge = "Обязательно", Description = "3D-зал, 12 классических игр, подполье, бар и ограбление.", Checked = true, Locked = true }; content.Controls.Add(gameCard); // Card 2: Fortune Neural Model if (package.HasModel) { CasinoCardCheck modelCard = new CasinoCardCheck { Bounds = new Rectangle(0, 116, 375, 66), Title = "Офлайн-предсказательница", Badge = FormatSize(InstallPaths.Number(package.Model, "bytes")), Description = "Локальная нейросеть Qwen 4B (GGUF). Работает автономно.", Checked = includeModel }; modelCard.CheckedChanged += (object s, EventArgs e) => { includeModel = modelCard.Checked; UpdateSizes(); }; content.Controls.Add(modelCard); } else { Panel noModelPanel = new Panel { Bounds = new Rectangle(0, 116, 375, 66), BackColor = Color.FromArgb(24, 26, 28) }; noModelPanel.Paint += (object s, PaintEventArgs pe) => { pe.Graphics.SmoothingMode = SmoothingMode.AntiAlias; Rectangle r = new Rectangle(0, 0, noModelPanel.Width - 1, noModelPanel.Height - 1); using Pen bp = new Pen(Color.FromArgb(80, 70, 50), 1f); pe.Graphics.DrawRectangle(bp, r); }; Label noModelTitle = new Label { Text = "Версия без встроенной нейросети", Bounds = new Rectangle(12, 10, 350, 20), ForeColor = Gold, Font = new Font("Segoe UI", 9.5f, FontStyle.Bold), BackColor = Color.Transparent }; Label noModelDesc = new Label { Text = "Чтобы включить гадалку, используйте полный установщик.", Bounds = new Rectangle(12, 32, 350, 26), ForeColor = Color.FromArgb(160, 170, 166), Font = new Font("Segoe UI", 8.8f), BackColor = Color.Transparent }; noModelPanel.Controls.Add(noModelTitle); noModelPanel.Controls.Add(noModelDesc); content.Controls.Add(noModelPanel); } // Card 3: Desktop shortcut CasinoCardCheck shortcutCard = new CasinoCardCheck { Bounds = new Rectangle(0, 190, 375, 60), Title = "Ярлык на рабочем столе", Badge = "Быстрый запуск", Description = "Удобный значок на рабочем столе для быстрого входа в игру.", Checked = desktopShortcut }; shortcutCard.CheckedChanged += (object s, EventArgs e) => { desktopShortcut = shortcutCard.Checked; }; content.Controls.Add(shortcutCard); } else if (step == 3) { // Step 3: Installation in progress CreateLabel("Открываем двери казино", 0, 34, 21f, Paper, FontStyle.Bold); roulette.Bounds = new Rectangle(95, 38, 185, 185); content.Controls.Add(roulette); status.Bounds = new Rectangle(0, 230, 305, 22); status.ForeColor = Paper; status.Font = new Font("Segoe UI", 9f); status.Text = "Подготовка к распаковке компонентов…"; status.BackColor = Color.Transparent; content.Controls.Add(status); percentLabel.Bounds = new Rectangle(310, 228, 65, 22); percentLabel.ForeColor = Gold; percentLabel.Font = new Font("Segoe UI", 10f, FontStyle.Bold); percentLabel.TextAlign = ContentAlignment.TopRight; percentLabel.Text = $"{progress.Value}%"; percentLabel.BackColor = Color.Transparent; content.Controls.Add(percentLabel); progress.Bounds = new Rectangle(0, 258, 375, 18); progress.Value = 0; percentLabel.Text = "0%"; content.Controls.Add(progress); } else { // Step 4: Finished CreateLabel("Казино открыто!", 0, 40, 24f, Gold, FontStyle.Bold); CreateLabel("Игра успешно установлена. Все компоненты готовы к запуску.", 42, 38, 10.5f, Paper); // Summary Checklist Card Panel summaryCard = new Panel { Bounds = new Rectangle(0, 88, 375, 136), BackColor = Color.FromArgb(20, 24, 27) }; summaryCard.Paint += (object s, PaintEventArgs pe) => { pe.Graphics.SmoothingMode = SmoothingMode.AntiAlias; Rectangle r = new Rectangle(0, 0, summaryCard.Width - 1, summaryCard.Height - 1); using Pen bp = new Pen(Color.FromArgb(90, 78, 55), 1.2f); pe.Graphics.DrawRectangle(bp, r); }; string mText = includeModel ? "✦ Нейросеть предсказательницы готова (локально на ПК)" : "✦ Установлено без модели гадалки"; string[] checkItems = new string[] { "✓ Файлы Assembler Casino распакованы", "✓ 3D-движок зала, мини-игры и аудио настроены", mText, desktopShortcut ? "✓ Ярлык создан на рабочем столе" : "✓ Установка в отдельную папку завершена" }; for (int j = 0; j < checkItems.Length; j++) { Label item = new Label { Text = checkItems[j], Bounds = new Rectangle(12, 12 + j * 28, 350, 22), ForeColor = (j == 2 && !includeModel) ? Color.FromArgb(170, 165, 150) : Color.FromArgb(145, 210, 160), Font = new Font("Segoe UI", 9.2f, FontStyle.Bold), BackColor = Color.Transparent }; summaryCard.Controls.Add(item); } content.Controls.Add(summaryCard); // Launch checkbox launch = new CheckBox { Text = "Запустить Assembler Casino прямо сейчас", Checked = true, Bounds = new Rectangle(6, 242, 365, 34), ForeColor = Gold, Font = new Font("Segoe UI", 10.5f, FontStyle.Bold), BackColor = Color.Transparent }; launch.CheckedChanged += (object s, EventArgs e) => { next.Text = launch.Checked ? "Играть →" : "Готово"; }; content.Controls.Add(launch); } UpdateSizes(); } private static string FormatSize(long bytes) { return ((double)bytes / 1073741824.0).ToString("0.00") + " ГБ"; } private void UpdateSizes() { string freeText = ""; try { freeText = " · Свободно: " + FormatSize(new DriveInfo(Path.GetPathRoot(Path.GetFullPath(target))).AvailableFreeSpace); } catch { } sizes.Text = "Требуется места: " + FormatSize(package.RequiredBytes(includeModel)) + freeText; } private async void Next(object sender, EventArgs e) { if (step == 4) { if (launch != null && launch.Checked) { try { ProcessStartInfo psi = new ProcessStartInfo { FileName = Path.Combine(target, "Assembler Casino.exe"), WorkingDirectory = target }; Process.Start(psi); } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Ошибка запуска", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } Close(); return; } if (step == 1) { try { target = InstallPaths.Normalize(target); InstallPaths.ValidateTarget(target, Application.ExecutablePath); } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Папка установки", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } if (step != 2) { ShowStep(step + 1); return; } // Step 2 -> 3: Start install installing = true; cancellation = new CancellationTokenSource(); ShowStep(3); try { PackageInstaller installer = new PackageInstaller(package); await Task.Run(() => { installer.Install(target, includeModel, desktopShortcut, integration: true, (InstallProgress p) => { Interlocked.Exchange(ref latest, p); }, cancellation.Token); }); installing = false; ShowStep(4); if (installer.IntegrationWarning != null) { MessageBox.Show(this, installer.IntegrationWarning, "Игра установлена", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (OperationCanceledException) { installing = false; ShowStep(2); } catch (Exception ex) { installing = false; ShowStep(2); MessageBox.Show(this, ex.Message, "Ошибка установки", MessageBoxButtons.OK, MessageBoxIcon.Hand); } finally { cancellation?.Dispose(); cancellation = null; cancel.Enabled = true; } } private void CancelInstall() { if (cancellation != null && !cancellation.IsCancellationRequested && MessageBox.Show(this, "Отменить установку Assembler Casino?", "Assembler Casino", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { cancellation.Cancel(); cancel.Enabled = false; status.Text = "Отмена, очистка временных файлов…"; } } }