KAZIK/build/UninstallAssemblerCasino.cs

235 lines
8.7 KiB
C#

using Microsoft.Win32;
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Windows.Forms;
namespace AssemblerCasinoUninstaller
{
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new UninstallForm());
}
}
sealed class UninstallForm : Form
{
readonly Color bg = Color.FromArgb(15, 12, 10);
readonly Color panel = Color.FromArgb(28, 22, 18);
readonly Color gold = Color.FromArgb(236, 186, 75);
readonly Color red = Color.FromArgb(164, 26, 32);
readonly Color text = Color.FromArgb(245, 236, 205);
readonly string installDir = AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\');
CheckBox removeSaves;
Button uninstallButton;
public UninstallForm()
{
Text = "Uninstall Assembler Casino";
try { Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath); } catch { }
StartPosition = FormStartPosition.CenterScreen;
FormBorderStyle = FormBorderStyle.FixedDialog;
MaximizeBox = false;
MinimizeBox = false;
ClientSize = new Size(680, 390);
BackColor = bg;
Font = new Font("Segoe UI", 10f);
var art = new UninstallArt { Dock = DockStyle.Left, Width = 220 };
Controls.Add(art);
var content = new Panel { Left = 242, Top = 28, Width = 400, Height = 250, BackColor = panel };
content.Paint += (s, e) =>
{
using (var pen = new Pen(Color.FromArgb(88, gold), 2))
e.Graphics.DrawRectangle(pen, 0, 0, content.Width - 1, content.Height - 1);
};
Controls.Add(content);
AddLabel(content, "Удаление казино", 28, 26, 340, 38, 21f, FontStyle.Bold);
AddLabel(content, "Игра будет удалена из этой папки:", 30, 82, 340, 26, 10.5f, FontStyle.Regular);
AddLabel(content, installDir, 30, 112, 340, 46, 9.5f, FontStyle.Regular);
AddLabel(content, "Ярлык на рабочем столе и запись в списке программ тоже будут убраны.", 30, 160, 340, 42, 10f, FontStyle.Regular);
removeSaves = new CheckBox
{
Text = "Также удалить сохранения аккаунтов из AppData",
Left = 30,
Top = 208,
Width = 345,
Height = 26,
BackColor = Color.Transparent,
ForeColor = text
};
content.Controls.Add(removeSaves);
uninstallButton = MakeButton("Удалить");
uninstallButton.Left = 386; uninstallButton.Top = 312;
uninstallButton.Click += (s, e) => Uninstall();
Controls.Add(uninstallButton);
var cancel = MakeButton("Отмена");
cancel.Left = 514; cancel.Top = 312;
cancel.Click += (s, e) => Close();
Controls.Add(cancel);
}
void AddLabel(Control parent, string caption, int x, int y, int w, int h, float size, FontStyle style)
{
parent.Controls.Add(new Label
{
Text = caption,
Left = x,
Top = y,
Width = w,
Height = h,
ForeColor = text,
BackColor = Color.Transparent,
Font = new Font("Segoe UI", size, style)
});
}
Button MakeButton(string caption)
{
var b = new Button
{
Text = caption,
Width = 108,
Height = 38,
FlatStyle = FlatStyle.Flat,
BackColor = Color.FromArgb(62, 43, 20),
ForeColor = text,
Font = new Font("Segoe UI", 10f, FontStyle.Bold),
Cursor = Cursors.Hand
};
b.FlatAppearance.BorderColor = gold;
b.FlatAppearance.MouseOverBackColor = Color.FromArgb(94, 61, 24);
b.FlatAppearance.MouseDownBackColor = Color.FromArgb(120, 71, 22);
return b;
}
void Uninstall()
{
if (MessageBox.Show(this, "Удалить Assembler Casino?", "Assembler Casino", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes)
return;
uninstallButton.Enabled = false;
try
{
TryDeleteShortcut();
TryDeleteRegistry();
if (removeSaves.Checked)
TryDeleteSaves();
var parent = Directory.GetParent(installDir);
var cmd = "/c timeout /t 1 /nobreak >nul & rmdir /s /q \"" + installDir + "\"";
Process.Start(new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = cmd,
WorkingDirectory = parent == null ? Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) : parent.FullName,
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden
});
Close();
}
catch (Exception ex)
{
uninstallButton.Enabled = true;
MessageBox.Show(this, ex.Message, "Ошибка удаления", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
void TryDeleteShortcut()
{
try
{
var desktop = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
var link = Path.Combine(desktop, "Assembler Casino.lnk");
if (File.Exists(link)) File.Delete(link);
}
catch { }
}
void TryDeleteRegistry()
{
try
{
Registry.CurrentUser.DeleteSubKeyTree(@"Software\Microsoft\Windows\CurrentVersion\Uninstall\AssemblerCasino", false);
}
catch { }
}
void TryDeleteSaves()
{
try
{
var saves = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "AssemblerCasino");
if (Directory.Exists(saves)) Directory.Delete(saves, true);
}
catch { }
}
}
sealed class UninstallArt : Control
{
readonly Color gold = Color.FromArgb(236, 186, 75);
readonly Color red = Color.FromArgb(164, 26, 32);
public UninstallArt()
{
DoubleBuffered = true;
}
protected override void OnPaint(PaintEventArgs e)
{
var g = e.Graphics;
g.SmoothingMode = SmoothingMode.AntiAlias;
using (var br = new LinearGradientBrush(ClientRectangle, Color.FromArgb(48, 9, 12), Color.FromArgb(12, 12, 12), 90f))
g.FillRectangle(br, ClientRectangle);
using (var f = new Font("Georgia", 19f, FontStyle.Bold))
using (var b = new SolidBrush(gold))
g.DrawString("CASINO", f, b, 48, 36);
DrawChip(g, 78, 112, red, "X");
DrawCardBack(g, 62, 190);
using (var p = new Pen(Color.FromArgb(120, gold), 2))
g.DrawLine(p, Width - 1, 0, Width - 1, Height);
}
void DrawChip(Graphics g, int x, int y, Color c, string label)
{
using (var br = new SolidBrush(c)) g.FillEllipse(br, x, y, 62, 62);
using (var p = new Pen(Color.White, 4)) g.DrawEllipse(p, x + 6, y + 6, 50, 50);
using (var p = new Pen(gold, 2)) g.DrawEllipse(p, x + 1, y + 1, 60, 60);
using (var f = new Font("Segoe UI", 17f, FontStyle.Bold))
using (var b = new SolidBrush(Color.White))
{
var sz = g.MeasureString(label, f);
g.DrawString(label, f, b, x + 31 - sz.Width / 2, y + 31 - sz.Height / 2);
}
}
void DrawCardBack(Graphics g, int x, int y)
{
var r = new Rectangle(x, y, 88, 122);
using (var br = new SolidBrush(Color.FromArgb(18, 18, 18))) g.FillRectangle(br, r);
using (var p = new Pen(gold, 3)) g.DrawRectangle(p, r);
using (var p = new Pen(red, 2))
{
g.DrawRectangle(p, x + 10, y + 10, 68, 102);
g.DrawLine(p, x + 18, y + 20, x + 70, y + 102);
g.DrawLine(p, x + 70, y + 20, x + 18, y + 102);
}
}
}
}