Setup 多线程数加速下载

在下载 UE4 的源码之后,需要先执行 Setup.bat 下载依赖才可以开始生成 VS 项目文件以及编译。
但是国内的网络环境又极差,默认的 Setup.bat 是没有指定线程数量的(Setup.bat只给 GitDenpencies 传递了 --prompt 参数)。

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
@echo off
setlocal
pushd %~dp0

rem Figure out if we should append the -prompt argument
set PROMPT_ARGUMENT=
for %%P in (%*) do if /I "%%P" == "--prompt" goto no_prompt_argument
for %%P in (%*) do if /I "%%P" == "--force" goto no_prompt_argument
set PROMPT_ARGUMENT=--prompt
:no_prompt_argument

rem Sync the dependencies...
.\Engine\Binaries\DotNET\GitDependencies.exe %PROMPT_ARGUMENT% %*
if ERRORLEVEL 1 goto error

rem Setup the git hooks...
if not exist .git\hooks goto no_git_hooks_directory
echo Registering git hooks...
echo #!/bin/sh >.git\hooks\post-checkout
echo Engine/Binaries/DotNET/GitDependencies.exe %* >>.git\hooks\post-checkout
echo #!/bin/sh >.git\hooks\post-merge
echo Engine/Binaries/DotNET/GitDependencies.exe %* >>.git\hooks\post-merge
:no_git_hooks_directory

rem Install prerequisites...
echo Installing prerequisites...
start /wait Engine\Extras\Redist\en-us\UE4PrereqSetup_x64.exe /quiet

rem Register the engine installation...
if not exist .\Engine\Binaries\Win64\UnrealVersionSelector-Win64-Shipping.exe goto :no_unreal_version_selector
.\Engine\Binaries\Win64\UnrealVersionSelector-Win64-Shipping.exe /register
:no_unreal_version_selector

rem Done!
goto :EOF

rem Error happened. Wait for a keypress before quitting.
:error
pause

GitDependencies.exe支持的参数为:

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
Usage:
GitDependencies [options]

Options:
--all Sync all folders
--include=<X> Include binaries in folders called <X>
--exclude=<X> Exclude binaries in folders called <X>
--prompt Prompt before overwriting modified files
--force Always overwrite modified files
--root=<PATH> Set the repository directory to be sync
--threads=<N> Use N threads when downloading new files
--dry-run Print a list of outdated files and exit
--max-retries Override maximum number of retries per file
--proxy=<user:password@url> Sets the HTTP proxy address and credentials
--cache=<PATH> Specifies a custom path for the download cache
--cache-size-multiplier=<N> Cache size as multiplier of current download
--cache-days=<N> Number of days to keep entries in the cache
--no-cache Disable caching of downloaded files

Detected settings:
Excluded folders: Mac, Android, Linux
Proxy server: none
Download cache: E:\UnrealEngine\EngineSource\UE_4.21_Source\.git\ue4-gitdeps

Default arguments can be set through the UE4_GITDEPS_ARGS environment variable.

所以我们可以将 Setup.bat 中的变量 PROMPT_ARGUMENT 增加上指定的线程数即可(N 替换为数字):

1
set PROMPT_ARGUMENT=--prompt --threads=N

我一般开 8 个线程,基本可以跑 2-3M/s…