-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgramPrompt.cs
More file actions
112 lines (97 loc) · 3.32 KB
/
ProgramPrompt.cs
File metadata and controls
112 lines (97 loc) · 3.32 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
using CometUI;
using System;
using System.IO;
using System.IO.Compression;
using System.Reflection;
using System.Windows.Forms;
namespace CDL_Crosshair_Installer
{
public partial class ProgramPrompt : CometForm
{
public ProgramPrompt()
{
InitializeComponent();
}
private bool confirmed = false;
private void ExtractResource(string Resource, string File)
{
using (Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream(Resource))
using (FileStream fs = new FileStream(File, FileMode.OpenOrCreate))
using (BinaryReader br = new BinaryReader(s))
using (BinaryWriter bw = new BinaryWriter(fs))
bw.Write(br.ReadBytes((int)s.Length));
}
protected override void OnFormClosing(FormClosingEventArgs e)
{
base.OnFormClosing(e);
if (!confirmed)
{
DialogResult result = MessageBox.Show("Cancel path selection?\n\nIf you cancel this prompt, the program will not continue.", "Cancel Path Selection?",
MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (result == DialogResult.No)
e.Cancel = true;
else Application.Exit();
}
}
private void CancelPrompt(object sender, EventArgs e)
{
Close();
}
private void ConfirmPrompt(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(txtProgramPath.Folder))
{
MessageBox.Show("No CDL path was provided so the program will not continue.", "No Path Selected",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
bool exe1 = File.Exists($"{txtProgramPath.Folder}\\CustomDesktopLogo.exe");
bool exe2 = File.Exists($"{txtProgramPath.Folder}\\Custom Crosshair.exe");
bool systemFld = Directory.Exists($"{txtProgramPath.Folder}\\System");
bool imagesFld = Directory.Exists($"{txtProgramPath.Folder}\\System\\Images");
bool languageFld = Directory.Exists($"{txtProgramPath.Folder}\\System\\Languages");
bool settingsFld = Directory.Exists($"{txtProgramPath.Folder}\\System\\Settings");
if (!exe1 && !exe2)
{
MessageBox.Show("Path chosen does not contain the CustomDesktopLogo program.", "Program Not Found",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
else if (exe1 || exe2)
{
if (!systemFld)
{
MessageBox.Show("Path chosen does not contain the 'System' folder.", "'System' Folder Not Found",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
else if (systemFld)
{
if (!imagesFld)
{
ExtractResource("CDL_Crosshair_Installer.CDL_Files.Images.zip", $"{txtProgramPath.Folder}\\System\\Images.zip");
ZipFile.ExtractToDirectory($"{txtProgramPath.Folder}\\System\\Images.zip", $"{txtProgramPath.Folder}\\System");
File.Delete($"{txtProgramPath.Folder}\\System\\Images.zip");
}
if (!languageFld)
{
Directory.CreateDirectory($"{txtProgramPath.Folder}\\System\\Language");
ExtractResource("CDL_Crosshair_Installer.CDL_Files.English.ini", $"{txtProgramPath.Folder}\\System\\Language\\English.ini");
}
if (!settingsFld)
{
Directory.CreateDirectory($"{txtProgramPath.Folder}\\System\\Settings");
ExtractResource("CDL_Crosshair_Installer.CDL_Files.Config.ini", $"{txtProgramPath.Folder}\\System\\Settings\\Config.ini");
}
}
}
confirmed = true;
Close();
}
public string GetProgramPath()
{
ShowDialog();
return txtProgramPath.Folder;
}
}
}