This repository has been archived by the owner on May 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.bat
204 lines (189 loc) · 6.37 KB
/
main.bat
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
::EXTENDIFY FOR WINDOWS BY REVOX 2019
::FEEL FREE TO USE PARTS OF THE CODE, IF YOU DO IT WOULD BE NICE TO GIVE CREDITS TO ME AND THIS REPO :)
::startup stuff
@echo off
title Extendify alpha 2c by revox
cd %~dp0
setlocal EnableDelayedExpansion
set drivelbl=NEW VOLUME
set driveltr=A:
cd resources
for /f "usebackq delims=" %%a in ("options.ini") do set %%a
if %legacy-colors% == 0 color F0
if %debug% == 1 echo DEBUG: set startup options
if %debug% == 1 echo DEBUG: loaded options file
goto selectscr
:selectscr
cls
echo Extendify version 2c by revox
echo What do you want to do?
if %debug% == 1 echo DEBUG: awaiting input
cmdMenuSel F08F "Extend capacity of a removable drive" "Restore original capacity of a removable drive"
if %ERRORLEVEL% == 1 goto drivescr
if %ERRORLEVEL% == 2 goto restorescr
goto selectscr
:restorescr
cls
echo Select the drive you want to restore capacity
echo Available drives:
::use wmic to get available drives and save them to a file:
for /f "tokens=2 delims==" %%d in ('wmic logicaldisk get name /format:value') do echo %%d >drives.ini
if %debug% == 1 echo DEBUG: wmic got disk list
::parse values from the file:
set/p array=< drives.ini
set a=%array:~0,5%
set b=%array:~2,2%
set c=%array:~5,2%
set d=%array:~7,2%
set e=%array:~9,2%
set f=%array:~11,2%
if %debug% == 1 echo DEBUG: array generated
del drives.ini
if %debug% == 1 echo DEBUG: temp file deleted
::create a selection screen using previously saved sets:
if %debug% == 1 echo DEBUG: awaiting input
cmdMenuSel F08F "%a%" "%b%" "%c%" "%d%" "%e%" "%f%"
if %ERRORLEVEL% == 1 set driveltr=%a%
if %ERRORLEVEL% == 2 set driveltr=%b%
if %ERRORLEVEL% == 3 set driveltr=%c%
if %ERRORLEVEL% == 4 set driveltr=%d%
if %ERRORLEVEL% == 5 set driveltr=%e%
if %ERRORLEVEL% == 6 set driveltr=%f%
goto confirmrestore
:confirmrestore
cls
echo You have selected drive %driveltr%
echo The drive will be reset to its orignal capacity
echo Be aware that this process will erase all data (format it)!
echo Continue?
if %debug% == 1 echo DEBUG: awaiting input
cmdMenuSel F08F "Yes" "No"
if %ERRORLEVEL% == 1 goto restore
if %ERRORLEVEL% == 2 goto restorescr
goto confirmrestore
:restore
cls
echo Please wait...
timeout 1 >nul
::we use mkdosfs windows port to format the drive which will then use its original capacity
mkdosfs -n "%drivelbl%" -v %driveltr%
goto restorefinishscr
:restorefinishscr
cls
echo The drive has been successfully restored to its original capacity
echo What do you want to do next?
if %debug% == 1 echo DEBUG: awaiting input
cmdMenuSel F08F "Go back to main menu" "Exit program"
if %ERRORLEVEL% == 1 goto selectscr
if %ERRORLEVEL% == 2 exit
goto restorefinishscr
:drivescr
cls
echo Select the drive you want to extend
echo Available drives:
::use wmic to get available drives and save them to a file:
for /f "tokens=2 delims==" %%d in ('wmic logicaldisk get name /format:value') do echo %%d >drives.ini
if %debug% == 1 echo DEBUG: wmic got disk list
::parse values from the file:
set/p array=< drives.ini
set a=%array:~0,5%
set b=%array:~2,2%
set c=%array:~5,2%
set d=%array:~7,2%
set e=%array:~9,2%
set f=%array:~11,2%
if %debug% == 1 echo DEBUG: array generated
del drives.ini
if %debug% == 1 echo DEBUG: temp file deleted
::create a selection screen using previously saved sets:
if %debug% == 1 echo DEBUG: awaiting input
cmdMenuSel F08F "%a%" "%b%" "%c%" "%d%" "%e%" "%f%"
if %ERRORLEVEL% == 1 set driveltr=%a%
if %ERRORLEVEL% == 2 set driveltr=%b%
if %ERRORLEVEL% == 3 set driveltr=%c%
if %ERRORLEVEL% == 4 set driveltr=%d%
if %ERRORLEVEL% == 5 set driveltr=%e%
if %ERRORLEVEL% == 6 set driveltr=%f%
goto confirmdrive
:confirmdrive
cls
echo You have selected drive %driveltr%
echo Is this correct?
if %debug% == 1 echo DEBUG: awaiting input
cmdMenuSel F08F "Yes" "No"
if %ERRORLEVEL% == 1 goto labelscr
if %ERRORLEVEL% == 2 goto drivescr
goto confirmdrive
:labelscr
::set default drive label if user doesn't want a custom one
if %debug% == 1 echo DEBUG: new drive name: %drivelbl%
set drivelbl=NEW VOLUME
cls
echo Would you like to add a custom label to drive?
if %debug% == 1 echo DEBUG: awaiting input
cmdMenuSel F08F "Yes" "No"
if %ERRORLEVEL% == 1 goto labelscr-label
if %ERRORLEVEL% == 2 goto extendscr
goto labelscr
:labelscr-label
cls
echo Type label you want and press enter
:: i used ccolor to make input combine better with rest of the UI (gray instead of black)
if %debug% == 1 echo DEBUG: awaiting input
ccolor F8 /p ='Label: '
set/p drivelbl=Label:
ccolor F0 /p ='Label: '
goto confirmlabel
:confirmlabel
cls
echo You want the drive to be labeled "%drivelbl%"
echo Is this correct?
if %debug% == 1 echo DEBUG: awaiting input
cmdMenuSel F08F "Yes" "No"
if %ERRORLEVEL% == 1 goto extendscr
if %ERRORLEVEL% == 2 goto labelscr-label
goto confirmlabel
:extendscr
cls
echo You are all ready to extend the drive.
echo Is the information correct?
echo.
echo Drive letter: %driveltr%
echo Drive label: %drivelbl%
if %debug% == 1 echo DEBUG: awaiting input
cmdMenuSel F08F "Yes" "No"
if %ERRORLEVEL% == 1 goto extend-confirm
if %ERRORLEVEL% == 2 goto drivescr
:extend-confirm
cls
echo The following proccess will wipe all data
echo from your USB drive. Make a backup first.
echo Do you want to continue?
if %debug% == 1 echo DEBUG: awaiting input
cmdMenuSel F08F "Yes" "No"
if %ERRORLEVEL% == 1 goto extend
if %ERRORLEVEL% == 2 goto drivescr
:extend
cls
echo Please wait...
if %debug% == 1 echo DEBUG: running mkdosfs
::we use mkdosfs windows port in order to increase the drive capacity, which will extend it visually to 4gb
::even though it won't be possible to use all 4gb without data corruption,
::it's gonna shift registers and allow to copy a few dozens MB more.
::we also save mkdosfs log to file in order to identify problems
timeout 1 >nul
mkdosfs -n "%drivelbl%" -v %driveltr% %mkdosfs-level%
if %debug% == 1 echo DEBUG: extended drive %driveltr% & pause
goto finishscr
:finishscr
cls
echo Thanks for using Extendify by revox.
echo The drive has been successfully extended.
echo Be aware, that it will visually show as 4gb
echo But you will only recieve ~80mb more to use.
echo Do you want to extend another drive?
if %debug% == 1 echo DEBUG: awaiting input
cmdMenuSel F08F "Yes" "No"
if %ERRORLEVEL% == 1 drivescr
if %ERRORLEVEL% == 2 exit
goto finishscr