-
Notifications
You must be signed in to change notification settings - Fork 0
/
usb-formatter.cpp
123 lines (92 loc) · 2.87 KB
/
usb-formatter.cpp
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
113
114
115
116
117
118
119
120
121
122
123
#include <iostream>
#include <cstdlib>
#include <unistd.h>
using namespace std;
int main() {
string disk,confirm,choice,newdiskname,type;
cout << "USB Formatter (Beta)" << endl;
cout << "Created by akkiisfrommars" << endl;
cout << "---------------------------" << endl;
cout << "Loading available volumes..." << endl;
sleep(3);
string avlvol = "diskutil list";
system(avlvol.c_str());
cout << "Enter disk location: ";
cin >> disk;
cout << endl;
cout << "Unmounting the disk..." << endl;
sleep(1);
string umount = "diskutil unmountDisk " + disk;
int umountResult = system(umount.c_str());
if (umountResult !=0) {
cerr << "Failed to unmount disk :(" << endl;
cout << "Reloading..." << endl;
main();
}
else{
cout << "Unmounting successful, proceeding..." << endl;
}
cout << "Enter name of formatted disk: ";
cin >> newdiskname;
cout << endl << "Format options" << endl;
cout << "1) APFS" << endl;
cout << "2) ExFAT" << endl;
cout << "3) JHFS+" << endl;
cout << "4) FAT32 " << endl;
cout << "5) NTFS" << endl;
cout << "6) UFS" << endl;
cout << "7) FAT" << endl;
cout << "More coming soon..." << endl;
cout << "Format option: ";
cin >> choice;
if(choice == "1"){
type = "APFS";
}
else if (choice == "2"){
type = "ExFAT";
}
else if (choice == "3"){
type = "JHFS+";
}
else if (choice == "4"){
type = "FAT32";
}
else if (choice == "5"){
type = "NTFS";
}
else if (choice == "6"){
type = "UFS";
}
else if (choice == "7"){
type = "MS-DOS";
}
else{
cout << "Please enter a valid option..." << endl;
main();
}
cout << "Formatting the disk " << disk << " as " << type << "..." << endl;
cout << "All data on this disk will be erased ";
cout << "Are you sure you want to continue? (y/N) ";
cin >> confirm;
if (confirm == "y" || confirm == "Y") {
string format = "diskutil eraseDisk " + type + " " + newdiskname + " " + disk;
cout << format << endl;
// diskutil eraseDisk JHFS+ NewDiskName /dev/diskX
int formatResult = system(format.c_str());
if(formatResult != 0){
cerr << "Error formatting disk :(" << endl;
cout << "Reloading..." << endl;
main();
}
else{
cout << "Format complete, verifying..." << endl;
string verify = "diskutil verifyDisk " + disk;
system(verify.c_str());
cout << endl << "Format successful" << endl << endl;
}
}
else{
cout << "Abort" << endl << endl;
}
return 0;
}