You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reorganized main menu logic and split disk setup and image writing into dedicated functions. Added support for automated disk partitioning using diskpart scripts for both MBR and GPT, with improved user prompts and error handling. Updated project settings to require administrator privileges and use multi-threaded runtime.
cout << "Welcome to the Automated Windows Installer!\n";
23
-
cout << "Created by SSP6904 (https://shaunhoffer.cc)\n";
24
-
cout << "Select one of the options below to get started!\n";
25
-
cout << "1 - Setup the disk\n";
26
-
cout << "2 - Write the image file\n";
27
-
cout << "3 - Quit the application\n";
22
+
cout << "Menu selection: \n";
23
+
cout << "[1] - Setup the disk\n";
24
+
cout << "[2] - Write the image file\n";
25
+
cout << "[3] - Quit the application\n";
28
26
cout << "Enter the number: ";
29
27
while (true) {
30
-
option = _getch();
31
-
if (option == '1') {
32
-
system("cls");
33
-
cout << "Check the README for how you can setup your disk!\n";
34
-
system("diskpart");
35
-
cout << "\n";
36
-
cout << "Please be sure that you know what your drive letters that you set for your disk setup! \n";
37
-
cout << "If you know what they are, you may exit this step!";
38
-
cin.ignore();
39
-
system("cls");
40
-
main();
41
-
}
42
-
elseif (option == '2') {
43
-
system("cls");
44
-
WriteImg();
45
-
}
46
-
elseif (option == '3') {
47
-
exit(-1);
48
-
}
49
-
else {
50
-
cout << "Invalid option! Please try again!";
51
-
cin.ignore();
52
-
system("cls");
53
-
main();
28
+
int option = _getch();
29
+
switch (option) {
30
+
case'1':
31
+
system("cls");
32
+
DiskPartionSetup();
33
+
break;
34
+
case'2':
35
+
system("cls");
36
+
WriteImageFile();
37
+
break;
38
+
case'3':
39
+
exit(-1);
40
+
break;
41
+
default:
42
+
cout << "Invalid option! Please try again!";
43
+
cin.ignore();
44
+
system("cls");
45
+
main();
46
+
break;
54
47
}
55
48
}
56
49
}
57
50
58
-
voidcommandRun(string cmd) {
59
-
int runCmd = system(cmd.c_str());
60
-
if (runCmd != 0) {
61
-
cout << "Something went wrong while trying to run this command! Sorry about that! If this is an issue with the program, please submit it to this program's GitHub repository!";
62
-
cout << "Press any key to exit the program";
63
-
cin.ignore();
64
-
exit(-1);
51
+
voidDiskPartionSetup() {
52
+
// Variables
53
+
string disk_number;
54
+
55
+
// Warning
56
+
cout << "Make sure that you have backed up any important data from your hard disk before you continue forward!\n";
57
+
cout << "If you are ready to begin, press the enter key!\n";
58
+
if (cin.ignore()) {
59
+
// Step 1
60
+
commandRun("diskpart /s ./" + writeDiskScript(
61
+
"list disk\n"
62
+
"exit"
63
+
));
64
+
cout << "Enter the disk number from above: ";
65
+
cin >> disk_number;
66
+
67
+
// Step 2
68
+
cout << "Will you be using GPT or MBR for your partition table? [m/g]";
69
+
while (true) {
70
+
int disk_type = _getch();
71
+
switch (disk_type) {
72
+
case'm':
73
+
case'M':
74
+
commandRun("diskpart /s " + writeDiskScript(
75
+
"select disk " + disk_number + "\n"
76
+
"clean\n"
77
+
"convert mbr\n"
78
+
"exit"
79
+
));
80
+
cout << "\n";
81
+
cout << "Creating the required partitons! Please wait a moment!";
82
+
commandRun("diskpart /s " + writeDiskScript(
83
+
"select disk " + disk_number + "\n"
84
+
"create part primary size=100\n"
85
+
"format fs=ntfs label=SYSTEM quick\n"
86
+
"assign letter w\n"
87
+
"active\n"
88
+
"create par primary\n"
89
+
"format fs=ntfs label=Windows quick\n"
90
+
"assign letter r\n"
91
+
"exit"
92
+
));
93
+
system("cls");
94
+
cout << "All done with this step! You can now write the image file! Make sure that you remember these drive letters for later!\n";
95
+
cout << "Boot partition: W:\n";
96
+
cout << "Windows partition: R:\n";
97
+
remove("./diskpart_script.txt");
98
+
system("pause>nul");
99
+
system("cls");
100
+
main();
101
+
break;
102
+
case'g':
103
+
case'G':
104
+
commandRun("diskpart /s " + writeDiskScript(
105
+
"select disk " + disk_number + "\n"
106
+
"clean\n"
107
+
"convert gpt\n"
108
+
"exit"
109
+
));
110
+
cout << "\n";
111
+
cout << "Creating the required partitons! Please wait a moment!";
112
+
commandRun("diskpart /s " + writeDiskScript(
113
+
"select disk " + disk_number + "\n"
114
+
"create part EFI size=500\n"
115
+
"format fs=fat32 label=EFI quick\n"
116
+
"assign letter w\n"
117
+
"create par primary\n"
118
+
"format fs=ntfs label=Windows quick\n"
119
+
"assign letter r\n"
120
+
"exit"
121
+
));
122
+
system("cls");
123
+
cout << "All done with this step! You can now write the image file! Make sure that you remember these drive letters for later!\n";
124
+
cout << "Boot partition: W:\n";
125
+
cout << "Windows partition: R:\n";
126
+
remove("./diskpart_script.txt");
127
+
system("pause>nul");
128
+
system("cls");
129
+
main();
130
+
break;
131
+
default:
132
+
system("cls");
133
+
main();
134
+
break;
135
+
}
136
+
}
65
137
}
66
138
}
67
139
68
-
voidWriteImg() {
140
+
voidWriteImageFile() {
69
141
int indexImg;
70
-
char gptan;
71
142
string imgFile;
72
143
73
144
cout << "Enter the WIM file path: ";
@@ -91,64 +162,95 @@ void WriteImg() {
91
162
cout << "Are you using either MBR or GPT for the disk partition scheme? [m/g] ";
92
163
93
164
while (true) {
94
-
gptan = _getch();
95
-
// Choose this if the partion scheme is GPT
96
-
if (gptan == 'g') {
97
-
string efiPar;
98
-
string winPar;
99
-
cout << "\n";
100
-
cout << "Input the EFI partiton letter: ";
101
-
cin >> efiPar;
102
-
cout << "Input the Windows partition letter: ";
103
-
cin >> winPar;
104
-
cout << "Starting the image writing! Please do not close this window while the writing is in progress!\n";
0 commit comments