Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
dadigang
Ventoy
Commits
e6453017
Commit
e6453017
authored
Nov 10, 2022
by
longpanda
Browse files
Optimization for Windows unattended install process.
parent
43b415c0
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
171 additions
and
80 deletions
+171
-80
INSTALL/ventoy/vtoyjump32.exe
INSTALL/ventoy/vtoyjump32.exe
+0
-0
INSTALL/ventoy/vtoyjump64.exe
INSTALL/ventoy/vtoyjump64.exe
+0
-0
vtoyjump/vtoyjump/vtoyjump.c
vtoyjump/vtoyjump/vtoyjump.c
+171
-80
No files found.
INSTALL/ventoy/vtoyjump32.exe
View file @
e6453017
No preview for this file type
INSTALL/ventoy/vtoyjump64.exe
View file @
e6453017
No preview for this file type
vtoyjump/vtoyjump/vtoyjump.c
View file @
e6453017
...
@@ -128,6 +128,64 @@ static void TrimString(CHAR *String, BOOL TrimLeft)
...
@@ -128,6 +128,64 @@ static void TrimString(CHAR *String, BOOL TrimLeft)
return
;
return
;
}
}
static
int
VentoyProcessRunCmd
(
const
char
*
Fmt
,
...)
{
int
Len
=
0
;
va_list
Arg
;
STARTUPINFOA
Si
;
PROCESS_INFORMATION
Pi
;
char
szBuf
[
1024
]
=
{
0
};
va_start
(
Arg
,
Fmt
);
Len
+=
vsnprintf_s
(
szBuf
+
Len
,
sizeof
(
szBuf
)
-
Len
,
sizeof
(
szBuf
)
-
Len
,
Fmt
,
Arg
);
va_end
(
Arg
);
GetStartupInfoA
(
&
Si
);
Si
.
dwFlags
|=
STARTF_USESHOWWINDOW
;
Si
.
wShowWindow
=
SW_HIDE
;
Log
(
"Process Run: <%s>"
,
szBuf
);
CreateProcessA
(
NULL
,
szBuf
,
NULL
,
NULL
,
FALSE
,
0
,
NULL
,
NULL
,
&
Si
,
&
Pi
);
WaitForSingleObject
(
Pi
.
hProcess
,
INFINITE
);
return
0
;
}
static
CHAR
VentoyGetFirstFreeDriveLetter
(
BOOL
Reverse
)
{
int
i
;
CHAR
Letter
=
'T'
;
DWORD
Drives
;
Drives
=
GetLogicalDrives
();
if
(
Reverse
)
{
for
(
i
=
25
;
i
>=
2
;
i
--
)
{
if
(
0
==
(
Drives
&
(
1
<<
i
)))
{
Letter
=
'A'
+
i
;
break
;
}
}
}
else
{
for
(
i
=
2
;
i
<
26
;
i
++
)
{
if
(
0
==
(
Drives
&
(
1
<<
i
)))
{
Letter
=
'A'
+
i
;
break
;
}
}
}
Log
(
"FirstFreeDriveLetter %u %C:"
,
Reverse
,
Letter
);
return
Letter
;
}
void
Log
(
const
char
*
Fmt
,
...)
void
Log
(
const
char
*
Fmt
,
...)
{
{
va_list
Arg
;
va_list
Arg
;
...
@@ -910,51 +968,7 @@ UINT64 GetVentoyEfiPartStartSector(HANDLE hDrive)
...
@@ -910,51 +968,7 @@ UINT64 GetVentoyEfiPartStartSector(HANDLE hDrive)
return
StartSector
;
return
StartSector
;
}
}
static
int
VentoyRunImdisk
(
const
char
*
IsoPath
,
const
char
*
imdiskexe
)
static
int
VentoyCopyImdisk
(
DWORD
PhyDrive
,
CHAR
*
ImPath
)
{
CHAR
Letter
;
CHAR
Cmdline
[
512
];
WCHAR
CmdlineW
[
512
];
PROCESS_INFORMATION
Pi
;
Log
(
"VentoyRunImdisk <%s> <%s>"
,
IsoPath
,
imdiskexe
);
Letter
=
GetIMDiskMountLogicalDrive
();
sprintf_s
(
Cmdline
,
sizeof
(
Cmdline
),
"%s -a -o ro -f
\"
%s
\"
-m %C:"
,
imdiskexe
,
IsoPath
,
Letter
);
Log
(
"mount iso to %C: use imdisk cmd <%s>"
,
Letter
,
Cmdline
);
if
(
IsUTF8Encode
(
IsoPath
))
{
STARTUPINFOW
Si
;
GetStartupInfoW
(
&
Si
);
Si
.
dwFlags
|=
STARTF_USESHOWWINDOW
;
Si
.
wShowWindow
=
SW_HIDE
;
Utf8ToUtf16
(
Cmdline
,
CmdlineW
);
CreateProcessW
(
NULL
,
CmdlineW
,
NULL
,
NULL
,
FALSE
,
0
,
NULL
,
NULL
,
&
Si
,
&
Pi
);
Log
(
"This is UTF8 encoding"
);
}
else
{
STARTUPINFOA
Si
;
GetStartupInfoA
(
&
Si
);
Si
.
dwFlags
|=
STARTF_USESHOWWINDOW
;
Si
.
wShowWindow
=
SW_HIDE
;
CreateProcessA
(
NULL
,
Cmdline
,
NULL
,
NULL
,
FALSE
,
0
,
NULL
,
NULL
,
&
Si
,
&
Pi
);
Log
(
"This is ANSI encoding"
);
}
Log
(
"Wait for imdisk process ..."
);
WaitForSingleObject
(
Pi
.
hProcess
,
INFINITE
);
Log
(
"imdisk process finished"
);
return
0
;
}
int
VentoyMountISOByImdisk
(
const
char
*
IsoPath
,
DWORD
PhyDrive
)
{
{
int
rc
=
1
;
int
rc
=
1
;
BOOL
bRet
;
BOOL
bRet
;
...
@@ -963,12 +977,17 @@ int VentoyMountISOByImdisk(const char *IsoPath, DWORD PhyDrive)
...
@@ -963,12 +977,17 @@ int VentoyMountISOByImdisk(const char *IsoPath, DWORD PhyDrive)
CHAR
PhyPath
[
MAX_PATH
];
CHAR
PhyPath
[
MAX_PATH
];
GET_LENGTH_INFORMATION
LengthInfo
;
GET_LENGTH_INFORMATION
LengthInfo
;
Log
(
"VentoyMountISOByImdisk %s"
,
IsoPath
);
if
(
IsFileExist
(
"X:
\\
Windows
\\
System32
\\
imdisk.exe"
))
if
(
IsFileExist
(
"X:
\\
Windows
\\
System32
\\
imdisk.exe"
))
{
{
Log
(
"imdisk.exe exist, use it directly..."
);
Log
(
"imdisk.exe already exist, no need to copy..."
);
VentoyRunImdisk
(
IsoPath
,
"imdisk.exe"
);
strcpy_s
(
ImPath
,
MAX_PATH
,
"imdisk.exe"
);
return
0
;
}
if
(
IsFileExist
(
"X:
\\
Windows
\\
System32
\\
ventoy
\\
imdisk.exe"
))
{
Log
(
"imdisk.exe already copied, no need to copy..."
);
strcpy_s
(
ImPath
,
MAX_PATH
,
"ventoy
\\
imdisk.exe"
);
return
0
;
return
0
;
}
}
...
@@ -1014,7 +1033,7 @@ int VentoyMountISOByImdisk(const char *IsoPath, DWORD PhyDrive)
...
@@ -1014,7 +1033,7 @@ int VentoyMountISOByImdisk(const char *IsoPath, DWORD PhyDrive)
if
(
LoadNtDriver
(
PhyPath
)
==
0
)
if
(
LoadNtDriver
(
PhyPath
)
==
0
)
{
{
VentoyRunImdisk
(
IsoPath
,
"ventoy
\\
imdisk.exe"
);
strcpy_s
(
ImPath
,
MAX_PATH
,
"ventoy
\\
imdisk.exe"
);
rc
=
0
;
rc
=
0
;
}
}
}
}
...
@@ -1027,6 +1046,66 @@ End:
...
@@ -1027,6 +1046,66 @@ End:
return
rc
;
return
rc
;
}
}
static
int
VentoyRunImdisk
(
const
char
*
IsoPath
,
const
char
*
imdiskexe
)
{
CHAR
Letter
;
CHAR
Cmdline
[
512
];
WCHAR
CmdlineW
[
512
];
PROCESS_INFORMATION
Pi
;
Log
(
"VentoyRunImdisk <%s> <%s>"
,
IsoPath
,
imdiskexe
);
Letter
=
GetIMDiskMountLogicalDrive
();
sprintf_s
(
Cmdline
,
sizeof
(
Cmdline
),
"%s -a -o ro -f
\"
%s
\"
-m %C:"
,
imdiskexe
,
IsoPath
,
Letter
);
Log
(
"mount iso to %C: use imdisk cmd <%s>"
,
Letter
,
Cmdline
);
if
(
IsUTF8Encode
(
IsoPath
))
{
STARTUPINFOW
Si
;
GetStartupInfoW
(
&
Si
);
Si
.
dwFlags
|=
STARTF_USESHOWWINDOW
;
Si
.
wShowWindow
=
SW_HIDE
;
Utf8ToUtf16
(
Cmdline
,
CmdlineW
);
CreateProcessW
(
NULL
,
CmdlineW
,
NULL
,
NULL
,
FALSE
,
0
,
NULL
,
NULL
,
&
Si
,
&
Pi
);
Log
(
"This is UTF8 encoding"
);
}
else
{
STARTUPINFOA
Si
;
GetStartupInfoA
(
&
Si
);
Si
.
dwFlags
|=
STARTF_USESHOWWINDOW
;
Si
.
wShowWindow
=
SW_HIDE
;
CreateProcessA
(
NULL
,
Cmdline
,
NULL
,
NULL
,
FALSE
,
0
,
NULL
,
NULL
,
&
Si
,
&
Pi
);
Log
(
"This is ANSI encoding"
);
}
Log
(
"Wait for imdisk process ..."
);
WaitForSingleObject
(
Pi
.
hProcess
,
INFINITE
);
Log
(
"imdisk process finished"
);
return
0
;
}
int
VentoyMountISOByImdisk
(
const
char
*
IsoPath
,
DWORD
PhyDrive
)
{
int
rc
=
1
;
CHAR
ImPath
[
MAX_PATH
];
Log
(
"VentoyMountISOByImdisk %s"
,
IsoPath
);
if
(
0
==
VentoyCopyImdisk
(
PhyDrive
,
ImPath
))
{
VentoyRunImdisk
(
IsoPath
,
ImPath
);
rc
=
0
;
}
return
rc
;
}
static
int
GetIsoId
(
CONST
CHAR
*
IsoPath
,
IsoId
*
ids
)
static
int
GetIsoId
(
CONST
CHAR
*
IsoPath
,
IsoId
*
ids
)
{
{
int
i
;
int
i
;
...
@@ -1863,14 +1942,30 @@ static int UnattendVarExpand(const char *script, const char *tmpfile)
...
@@ -1863,14 +1942,30 @@ static int UnattendVarExpand(const char *script, const char *tmpfile)
//#define VAR_DEBUG 1
//#define VAR_DEBUG 1
static
int
Process
Unattend
edInstallation
(
const
char
*
script
)
static
int
Create
Unattend
RegKey
(
const
char
*
file
)
{
{
DWORD
dw
;
DWORD
dw
;
HKEY
hKey
;
HKEY
hKey
;
LSTATUS
Ret
;
LSTATUS
Ret
;
#ifndef VAR_DEBUG
Ret
=
RegCreateKeyEx
(
HKEY_LOCAL_MACHINE
,
"System
\\
Setup"
,
0
,
NULL
,
REG_OPTION_NON_VOLATILE
,
KEY_ALL_ACCESS
,
NULL
,
&
hKey
,
&
dw
);
if
(
ERROR_SUCCESS
==
Ret
)
{
Ret
=
RegSetValueEx
(
hKey
,
"UnattendFile"
,
0
,
REG_SZ
,
file
,
(
DWORD
)(
strlen
(
file
)
+
1
));
}
#endif
return
0
;
}
static
int
ProcessUnattendedInstallation
(
const
char
*
script
,
DWORD
PhyDrive
)
{
CHAR
Letter
;
CHAR
Letter
;
CHAR
DrvLetter
;
CHAR
TmpFile
[
MAX_PATH
];
CHAR
TmpFile
[
MAX_PATH
];
CHAR
CurDir
[
MAX_PATH
];
CHAR
CurDir
[
MAX_PATH
];
CHAR
ImPath
[
MAX_PATH
];
Log
(
"Copy unattended XML ..."
);
Log
(
"Copy unattended XML ..."
);
...
@@ -1888,7 +1983,7 @@ static int ProcessUnattendedInstallation(const char *script)
...
@@ -1888,7 +1983,7 @@ static int ProcessUnattendedInstallation(const char *script)
#ifdef VAR_DEBUG
#ifdef VAR_DEBUG
sprintf_s
(
CurDir
,
sizeof
(
CurDir
),
"%C:
\\
AutounattendXXX.xml"
,
Letter
);
sprintf_s
(
CurDir
,
sizeof
(
CurDir
),
"%C:
\\
AutounattendXXX.xml"
,
Letter
);
#else
#else
sprintf_s
(
CurDir
,
sizeof
(
CurDir
),
"%C:
\\
Autou
nattend.xml"
,
Letter
);
sprintf_s
(
CurDir
,
sizeof
(
CurDir
),
"%C:
\\
U
nattend.xml"
,
Letter
);
#endif
#endif
if
(
UnattendNeedVarExpand
(
script
))
if
(
UnattendNeedVarExpand
(
script
))
...
@@ -1897,21 +1992,32 @@ static int ProcessUnattendedInstallation(const char *script)
...
@@ -1897,21 +1992,32 @@ static int ProcessUnattendedInstallation(const char *script)
UnattendVarExpand
(
script
,
TmpFile
);
UnattendVarExpand
(
script
,
TmpFile
);
Log
(
"Expand Copy file <%s> --> <%s>"
,
script
,
CurDir
);
Log
(
"Expand Copy file <%s> --> <%s>"
,
script
,
CurDir
);
CopyFile
(
TmpFile
,
CurDir
,
FALSE
);
CopyFile
A
(
TmpFile
,
CurDir
,
FALSE
);
}
}
else
else
{
{
Log
(
"No var expand copy file <%s> --> <%s>"
,
script
,
CurDir
);
Log
(
"No var expand copy file <%s> --> <%s>"
,
script
,
CurDir
);
CopyFile
(
script
,
CurDir
,
FALSE
);
CopyFile
A
(
script
,
CurDir
,
FALSE
);
}
}
#ifndef VAR_DEBUG
VentoyCopyImdisk
(
PhyDrive
,
ImPath
);
Ret
=
RegCreateKeyEx
(
HKEY_LOCAL_MACHINE
,
"System
\\
Setup"
,
0
,
NULL
,
REG_OPTION_NON_VOLATILE
,
KEY_ALL_ACCESS
,
NULL
,
&
hKey
,
&
dw
);
DrvLetter
=
VentoyGetFirstFreeDriveLetter
(
FALSE
);
if
(
ERROR_SUCCESS
==
Ret
)
VentoyProcessRunCmd
(
"%s -a -s 64M -m %C: -p
\"
/fs:FAT32 /q /y
\"
"
,
ImPath
,
DrvLetter
);
Sleep
(
300
);
sprintf_s
(
TmpFile
,
sizeof
(
TmpFile
),
"%C:
\\
Unattend.xml"
,
DrvLetter
);
if
(
CopyFileA
(
CurDir
,
TmpFile
,
FALSE
))
{
{
Ret
=
RegSetValueEx
(
hKey
,
"UnattendFile"
,
0
,
REG_SZ
,
CurDir
,
(
DWORD
)(
strlen
(
CurDir
)
+
1
));
DeleteFileA
(
CurDir
);
Log
(
"Move file <%s> ==> <%s>, use the later as unattend XML"
,
CurDir
,
TmpFile
);
CreateUnattendRegKey
(
TmpFile
);
}
else
{
Log
(
"Failed to copy file <%s> ==> <%s>, use OLD"
,
CurDir
,
TmpFile
);
CreateUnattendRegKey
(
CurDir
);
}
}
#endif
return
0
;
return
0
;
}
}
...
@@ -2261,7 +2367,7 @@ static int VentoyHook(ventoy_os_param *param)
...
@@ -2261,7 +2367,7 @@ static int VentoyHook(ventoy_os_param *param)
if
(
IsFileExist
(
"%s"
,
VTOY_AUTO_FILE
))
if
(
IsFileExist
(
"%s"
,
VTOY_AUTO_FILE
))
{
{
Log
(
"use auto install script %s..."
,
VTOY_AUTO_FILE
);
Log
(
"use auto install script %s..."
,
VTOY_AUTO_FILE
);
ProcessUnattendedInstallation
(
VTOY_AUTO_FILE
);
ProcessUnattendedInstallation
(
VTOY_AUTO_FILE
,
VtoyDiskNum
);
}
}
else
else
{
{
...
@@ -2482,22 +2588,6 @@ End:
...
@@ -2482,22 +2588,6 @@ End:
}
}
static
int
vtoy_cmd_delete_file
(
char
*
File
)
{
CHAR
szCmd
[
MAX_PATH
];
STARTUPINFOA
Si
;
PROCESS_INFORMATION
Pi
;
GetStartupInfoA
(
&
Si
);
Si
.
dwFlags
|=
STARTF_USESHOWWINDOW
;
Si
.
wShowWindow
=
SW_HIDE
;
sprintf_s
(
szCmd
,
sizeof
(
szCmd
),
"cmd.exe /c del /F /Q %s"
,
File
);
CreateProcessA
(
NULL
,
szCmd
,
NULL
,
NULL
,
FALSE
,
0
,
NULL
,
NULL
,
&
Si
,
&
Pi
);
WaitForSingleObject
(
Pi
.
hProcess
,
INFINITE
);
return
0
;
}
int
real_main
(
int
argc
,
char
**
argv
)
int
real_main
(
int
argc
,
char
**
argv
)
{
{
int
i
=
0
;
int
i
=
0
;
...
@@ -2575,6 +2665,8 @@ int real_main(int argc, char **argv)
...
@@ -2575,6 +2665,8 @@ int real_main(int argc, char **argv)
if
(
g_os_param_reserved
[
0
]
==
4
)
if
(
g_os_param_reserved
[
0
]
==
4
)
{
{
Log
(
"Open cmd for debug ..."
);
Log
(
"Open cmd for debug ..."
);
Si
.
dwFlags
|=
STARTF_USESHOWWINDOW
;
Si
.
wShowWindow
=
SW_NORMAL
;
sprintf_s
(
LunchFile
,
sizeof
(
LunchFile
),
"%s"
,
"cmd.exe"
);
sprintf_s
(
LunchFile
,
sizeof
(
LunchFile
),
"%s"
,
"cmd.exe"
);
}
}
...
@@ -2724,4 +2816,3 @@ int main(int argc, char **argv)
...
@@ -2724,4 +2816,3 @@ int main(int argc, char **argv)
return
real_main
(
argc
,
argv
);
return
real_main
(
argc
,
argv
);
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment