-
Notifications
You must be signed in to change notification settings - Fork 0
/
FormMain.cs
99 lines (89 loc) · 2.86 KB
/
FormMain.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using Microsoft.Win32;
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
namespace jgdpsinstaller
{
public partial class FormMain : Form
{
private bool installState = false;
private bool uninstallState = false;
private bool finishState = false;
private bool mouseDown = false;
private readonly bool installed = Registry.LocalMachine.OpenSubKey("SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\JustinGDPS") != null;
private int mouseX = 0;
private int mouseY = 0;
private int tick = 0;
public FormMain()
{
InitializeComponent();
if (installed)
{
BtnBrowse.Enabled = false;
FolderInput.Enabled = false;
DesktopCheck.Enabled = false;
StartMenuCheck.Enabled = false;
LabelDisclaimer.Enabled = false;
BtnBrowse.Visible = false;
FolderInput.Visible = false;
DesktopCheck.Visible = false;
StartMenuCheck.Visible = false;
LabelDisclaimer.Visible = false;
BtnInstall.Text = "Uninstall";
BtnInstall.BackColor = Color.LightCoral;
}
else
{
FolderInput.Text = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "JustinGDPS");
FolderSelect.SelectedPath = FolderInput.Text;
LabelDisclaimer.Text += GetDiskSpace();
}
}
private string GetDiskSpace()
{
try
{
string diskName = FolderSelect.SelectedPath.Split(char.Parse("\\"))[0];
DriveInfo disk = Array.Find(DriveInfo.GetDrives(), (DriveInfo x) => x.Name.StartsWith(diskName));
decimal bytes = disk.AvailableFreeSpace;
decimal kilobytes = Math.Floor(bytes / 1024);
decimal megabytes = Math.Floor(kilobytes / 1024);
decimal gigabytes = Math.Floor(megabytes / 1024);
decimal terabytes = Math.Floor(gigabytes / 1024);
string byteValues_bytes = bytes + " B";
string byteValues_kilobytes = "";
string byteValues_megabytes = "";
string byteValues_gigabytes = "";
string byteValues_terabytes = "";
if (kilobytes >= 1) byteValues_kilobytes = kilobytes + " KB";
if (megabytes >= 1) byteValues_megabytes = megabytes + " MB";
if (gigabytes >= 1) byteValues_gigabytes = gigabytes + " GB";
if (terabytes >= 1) byteValues_terabytes = terabytes + " TB";
if (byteValues_terabytes != "") return byteValues_terabytes;
else
{
if (byteValues_gigabytes != "") return byteValues_gigabytes;
else
{
if (byteValues_megabytes != "") return byteValues_megabytes;
else
{
if (byteValues_kilobytes != "") return byteValues_kilobytes;
else return byteValues_bytes;
}
}
}
}
catch
{
return "Unknown";
}
}
private void ErrorReport(Exception err)
{
MessageBox.Show(err.ToString() + "\n\nPlease use Ctrl+C and report error to https://github.com/justingdps/installer", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Environment.Exit(1);
}
}
}