TVTestをビルドするバッチファイル(完全版)

スポンサーリンク
スポンサーリンク
TS抜き

ソースをダウンロードしてビルド、アーカイブを作成するバッチファイルです。
TVTestに加えて以下をビルドします。

  • CasProcessor
  • B25.tvcas
  • TVTestVideoDecoder
  • TvtPlay
  • NicoJK
  • jkcnsl
  • TVCaptionMod2
  • TVTDataBroadcastingWV2
スポンサーリンク
スポンサーリンク

必要

Visual Studio

2019以降でビルドできます。

こちらの記事を参考にインストールしてください。

2022で動作確認しています。

Node.js

公式サイトからLTS版をダウンロードします。

インストールで特に変更するところはありません。

Yarn

コマンドプロンプトで以下のコマンドを実行してインストールします。

npm install -g yarn

Git for Windows

公式サイトの「Download」をクリックします。

インストールで特に変更するところはありません。

7-Zip

公式サイトからダウンロードしてインストールします。

バッチファイル

拡張子を.batにして保存します。

@echo off
setlocal
cd /d %~dp0

rem デフォルト設定
set ARCH=x86
set RUNTIME=dynamic
set TARGET=Build
set CONFIG=Release
set REPO_DEL=False
set CLONE_DIR=
set OUT_DIR=TVTest\package

rem 引数の取得
for %%i in (%*) do (
    if /i "%%i" == "help"    goto Help
    if /i "%%i" == "x86"     set ARCH=x86
    if /i "%%i" == "x64"     set ARCH=x64
    if /i "%%i" == "Both"    set ARCH=Both
    if /i "%%i" == "dynamic" set RUNTIME=dynamic
    if /i "%%i" == "MD"      set RUNTIME=dynamic
    if /i "%%i" == "static"  set RUNTIME=static
    if /i "%%i" == "MT"      set RUNTIME=static
    if /i "%%i" == "Build"   set TARGET=Build
    if /i "%%i" == "Rebuild" set TARGET=Rebuild
    if /i "%%i" == "Clean"   set TARGET=Clean
    if /i "%%i" == "Debug"   set CONFIG=Debug
    if /i "%%i" == "Release" set CONFIG=Release
    if /i "%%i" == "del"     set REPO_DEL=True
)

if defined CLONE_DIR (
    if not exist "%CLONE_DIR%" md "%CLONE_DIR%"
    cd /d "%CLONE_DIR%"
)
if /i "%REPO_DEL%" == "True" (
    if exist TVTest                 rd /s /q TVTest
    if exist CasProcessor           rd /s /q CasProcessor
    if exist TvCas                  rd /s /q TvCas
    if exist TVTestVideoDecoder     rd /s /q TVTestVideoDecoder
    if exist TvtPlay                rd /s /q TvtPlay
    if exist NicoJK                 rd /s /q NicoJK
    if exist jkcnsl                 rd /s /q jkcnsl
    if exist TVCaptionMod2          rd /s /q TVCaptionMod2
    if exist TVTDataBroadcastingWV2 rd /s /q TVTDataBroadcastingWV2
)
rem ソースのダウンロード
if not exist TVTest                 git clone -b develop --recursive https://github.com/DBCTRADO/TVTest.git
if not exist CasProcessor           git clone https://github.com/logue/CasProcessor.git
if not exist TvCas                  git clone https://github.com/logue/TvCas.git
if not exist TVTestVideoDecoder     git clone https://github.com/DBCTRADO/TVTestVideoDecoder.git
if not exist TvtPlay                git clone -b work-plus https://github.com/xtne6f/TvtPlay.git
if not exist NicoJK                 git clone https://github.com/xtne6f/NicoJK.git
if not exist jkcnsl                 git clone https://github.com/xtne6f/jkcnsl.git
if not exist TVCaptionMod2          git clone https://github.com/xtne6f/TVCaptionMod2.git
if not exist TVTDataBroadcastingWV2 git clone --recursive https://github.com/otya128/TVTDataBroadcastingWV2.git

copy /v /y TVTest\src\TVTestPlugin.h    CasProcessor >nul
copy /v /y TVTest\src\TVTestInterface.h CasProcessor >nul

rem Visual Studioのインストールフォルダの検索
for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do (
    set VS_INSTALL_DIR=%%i
)
rem 開発者コマンドプロンプトの起動
call "%VS_INSTALL_DIR%\Common7\Tools\VsDevCmd.bat" -no_logo

set TOOLSET=v142
if "%VisualStudioVersion%" == "17.0" set TOOLSET=v143

if /i "%ARCH%" == "Both" (
    call :Build x86
    if errorlevel 1 exit /b 1
    call :Build x64
    if errorlevel 1 exit /b 1
) else (
    call :Build %ARCH%
    if errorlevel 1 exit /b 1
)
exit /b 0

:Build
set ARCH=%1
if /i "%ARCH%" == "x86" (
    set PLATFORM=Win32
) else (
    set PLATFORM=%ARCH%
)

if /i "%CONFIG%" == "Debug" set RUNTIME=

set TVTEST_CONFIG=%CONFIG%
if /i "%RUNTIME%" == "dynamic" set TVTEST_CONFIG=%TVTEST_CONFIG%_MD

rem LibISDBのビルド
pushd TVTest\src\LibISDB\Projects
MSBuild LibISDB.sln /nologo /m /t:%TARGET% /p:Configuration=%TVTEST_CONFIG%;Platform=%ARCH%
popd
if errorlevel 1 exit /b 1

rem TVTestのビルド
pushd TVTest\src
MSBuild TVTest.sln /nologo /m /t:%TARGET% /p:Configuration=%TVTEST_CONFIG%;Platform=%PLATFORM%
popd
if errorlevel 1 exit /b 1

set PLUGIN_CONFIG=%CONFIG%
if /i "%RUNTIME%" == "static" set PLUGIN_CONFIG=%PLUGIN_CONFIG%_static

rem サンプルプラグインのビルド
pushd TVTest\sdk\Samples
MSBuild Samples.sln /nologo /m /t:%TARGET% /p:Configuration=%PLUGIN_CONFIG%;Platform=%PLATFORM%
popd
if errorlevel 1 exit /b 1

rem CasProcessorのビルド
pushd CasProcessor
MSBuild CasProcessor.sln /nologo /m /t:%TARGET% /p:Configuration=%CONFIG%;Platform=%PLATFORM%;PlatformToolset=%TOOLSET%;WindowsTargetPlatformVersion=10.0
popd
if errorlevel 1 exit /b 1

rem B25.tvcasのビルド
pushd TvCas
MSBuild TvCas.sln /nologo /m /t:%TARGET% /p:Configuration=%CONFIG%;Platform=%ARCH%;PlatformToolset=%TOOLSET%;WindowsTargetPlatformVersion=10.0
popd
if errorlevel 1 exit /b 1

rem TVTestVideoDecoderのビルド
pushd TVTestVideoDecoder\src
MSBuild TVTestVideoDecoder.sln /nologo /m /t:%TARGET% /p:Configuration=%CONFIG%;Platform=%PLATFORM%
popd
if errorlevel 1 exit /b 1

rem TvtPlayのビルド
pushd TvtPlay\src
MSBuild TvtPlay.sln /nologo /m /t:%TARGET% /p:Configuration=%CONFIG%;Platform=%PLATFORM%;PlatformToolset=%TOOLSET%;WindowsTargetPlatformVersion=10.0
popd
if errorlevel 1 exit /b 1

rem BonDriver_Pipeのビルド
pushd TvtPlay\BonDriver_Pipe_src
MSBuild BonDriver_Pipe.sln /nologo /m /t:%TARGET% /p:Configuration=%CONFIG%;Platform=%PLATFORM%;PlatformToolset=%TOOLSET%;WindowsTargetPlatformVersion=10.0
popd
if errorlevel 1 exit /b 1

rem BaseClassesのビルド
pushd TvtPlay\TvtAudioStretchFilter_src\baseclasses
MSBuild BaseClasses_VC14.sln /nologo /m /t:%TARGET% /p:Configuration=%CONFIG%;Platform=%PLATFORM%;PlatformToolset=%TOOLSET%;WindowsTargetPlatformVersion=10.0
popd
if errorlevel 1 exit /b 1

rem SoundTouchのビルド
pushd TvtPlay\TvtAudioStretchFilter_src\soundtouch\source\SoundTouch
MSBuild SoundTouch.sln /nologo /m /t:%TARGET% /p:Configuration=%CONFIG%;Platform=%PLATFORM%;PlatformToolset=%TOOLSET%;WindowsTargetPlatformVersion=10.0
popd
if errorlevel 1 exit /b 1

rem TvtAudioStretchFilterのビルド
pushd TvtPlay\TvtAudioStretchFilter_src
MSBuild TvtAudioStretchFilter.sln /nologo /m /t:%TARGET% /p:Configuration=%CONFIG%;Platform=%PLATFORM%;PlatformToolset=%TOOLSET%;WindowsTargetPlatformVersion=10.0
popd
if errorlevel 1 exit /b 1

rem NicoJKのビルド
pushd NicoJK
MSBuild NicoJK.sln /nologo /m /t:%TARGET% /p:Configuration=%CONFIG%;Platform=%PLATFORM%;PlatformToolset=%TOOLSET%;WindowsTargetPlatformVersion=10.0
popd
if errorlevel 1 exit /b 1

rem jkcnslのビルド
pushd jkcnsl
if /i not "%TARGET%" == "Build" (
    if exist bin rd /s /q bin
    if exist obj rd /s /q obj
)
if /i not "%TARGET%" == "Clean" (
    dotnet publish --nologo -c %CONFIG% -r win10-%ARCH% /p:Platform="Any CPU";PublishSingleFile=true;PublishTrimmed=true
)
popd
if errorlevel 1 exit /b 1

rem TVCaptionMod2のビルド
pushd TVCaptionMod2\Caption_src
MSBuild Caption.sln /nologo /m /t:%TARGET% /p:Configuration=%CONFIG%;Platform=%PLATFORM%;PlatformToolset=%TOOLSET%;WindowsTargetPlatformVersion=10.0
popd
if errorlevel 1 exit /b 1

pushd TVCaptionMod2\src
MSBuild TVCaption2.sln /nologo /m /t:%TARGET% /p:Configuration=%CONFIG%;Platform=%PLATFORM%;PlatformToolset=%TOOLSET%;WindowsTargetPlatformVersion=10.0
popd
if errorlevel 1 exit /b 1

rem TVTDataBroadcastingWV2のビルド
pushd TVTDataBroadcastingWV2
MSBuild TVTDataBroadcastingWV2.sln /nologo /m /t:%TARGET% /restore /p:Configuration=%CONFIG%;Platform=%ARCH%;PlatformToolset=%TOOLSET%;RestorePackagesConfig=true
popd
if errorlevel 1 exit /b 1

if /i "%TARGET%" == "Clean" exit /b 0

rem web-bmlのビルド
pushd TVTDataBroadcastingWV2\browser
if not exist dist\TVTDataBroadcastingWV2.js (
    call yarn install
    call yarn workspace @chinachu/aribts build
    call yarn run build
)
popd
if errorlevel 1 exit /b 1

rem フォントのダウンロード
pushd TVTDataBroadcastingWV2
if not exist fonts (
    md fonts
    curl -L https://github.com/googlefonts/kosugi/raw/main/fonts/ttf/Kosugi-Regular.ttf          -o fonts\Kosugi-Regular.ttf
    curl -L https://github.com/googlefonts/kosugi-maru/raw/main/fonts/ttf/KosugiMaru-Regular.ttf -o fonts\KosugiMaru-Regular.ttf
)
popd

rem TVTestのファイルの配置
pushd TVTest
package.sh -a %ARCH% -c "%RUNTIME%" -t %CONFIG% -l all -o package -r ""
popd

set SRC_DIR=%PLATFORM%\%CONFIG%
if /i "%ARCH%" == "x86" (
    set SRC_DIR2=%CONFIG%
) else (
    set SRC_DIR2=%SRC_DIR%
)
set DST_DIR=TVTest\package\%ARCH%\%CONFIG%

rem フォルダの準備
md "%DST_DIR%\Plugins\NicoJK"
md "%DST_DIR%\Plugins\TVCaptionMod2"
md "%DST_DIR%\Plugins\TVTDataBroadcastingWV2\resources\dist"

rem ファイルの配置
copy /v TVTest\sdk\Samples\DiskRelay\DiskRelay.txt                            "%DST_DIR%\Plugins" >nul
copy /v TVTest\sdk\Samples\MemoryCapture\MemoryCapture.txt                    "%DST_DIR%\Plugins" >nul
copy /v CasProcessor\%SRC_DIR%\CasProcessor.tvtp                              "%DST_DIR%\Plugins" >nul
copy /v TvCas\%SRC_DIR%\B25.tvcas                                             "%DST_DIR%" >nul
copy /v TVTestVideoDecoder\src\%SRC_DIR%\TVTestVideoDecoder.ax                "%DST_DIR%" >nul
copy /v TVTestVideoDecoder\doc\TVTestVideoDecoder.txt                         "%DST_DIR%" >nul
copy /v TvtPlay\src\%SRC_DIR2%\TvtPlay.tvtp                                   "%DST_DIR%\Plugins" >nul
copy /v TvtPlay\BonDriver_Pipe_src\%SRC_DIR2%\BonDriver_Pipe.dll              "%DST_DIR%" >nul
copy /v TvtPlay\TvtAudioStretchFilter_src\%SRC_DIR2%\TvtAudioStretchFilter.ax "%DST_DIR%" >nul
copy /v TvtPlay\src\Buttons24.bmp                                             "%DST_DIR%\Plugins" >nul
copy /v TvtPlay\src\Buttons32.bmp                                             "%DST_DIR%\Plugins" >nul
copy /v TvtPlay\TvtPlay_*.txt                                                 "%DST_DIR%\Plugins" >nul
copy /v NicoJK\%SRC_DIR2%\NicoJK.tvtp                                         "%DST_DIR%\Plugins" >nul
copy /v NicoJK\%SRC_DIR2%\*.exe                                               "%DST_DIR%\Plugins\NicoJK" >nul
copy /v NicoJK\NicoJK.ini                                                     "%DST_DIR%\Plugins\NicoJK_default.ini" >nul
copy /v NicoJK\jkch.sh.txt                                                    "%DST_DIR%\Plugins" >nul
copy /v NicoJK\Readme.txt                                                     "%DST_DIR%\Plugins\NicoJK_Readme.txt" >nul
copy /v jkcnsl\bin\%CONFIG%\netcoreapp3.1\win10-%ARCH%\publish\jkcnsl.exe     "%DST_DIR%" >nul
copy /v TVCaptionMod2\src\%SRC_DIR2%\TVCaptionMod2.tvtp                       "%DST_DIR%\Plugins" >nul
copy /v TVCaptionMod2\gaiji\TVCaptionMod2_Gaiji_*.txt                         "%DST_DIR%\Plugins" >nul
copy /v TVCaptionMod2\src\rom                                                 "%DST_DIR%\Plugins\TVCaptionMod2" >nul
copy /v TVCaptionMod2\TVCaptionMod2_Readme.txt                                "%DST_DIR%\Plugins" >nul
copy /v TVTDataBroadcastingWV2\%SRC_DIR2%\TVTDataBroadcastingWV2.tvtp         "%DST_DIR%\Plugins" >nul
copy /v TVTDataBroadcastingWV2\browser\dist\TVTDataBroadcastingWV2.js         "%DST_DIR%\Plugins\TVTDataBroadcastingWV2\resources\dist" >nul
copy /v TVTDataBroadcastingWV2\browser\TVTDataBroadcastingWV2.html            "%DST_DIR%\Plugins\TVTDataBroadcastingWV2\resources" >nul
copy /v TVTDataBroadcastingWV2\fonts                                          "%DST_DIR%\Plugins\TVTDataBroadcastingWV2\resources\dist" >nul
copy /v TVTDataBroadcastingWV2\README.md                                      "%DST_DIR%\Plugins\TVTDataBroadcastingWV2_README.md" >nul

pushd TVTest
rem バージョン情報の取得
for /f "usebackq tokens=2*" %%i in (`findstr /r /c:"^#define VERSION_TEXT_A" src\TVTestVersion.h`) do set VERSION=%%~j
rem コミットハッシュの取得
for /f "usebackq tokens=*" %%i in (`git rev-parse --short HEAD`) do set GIT_HASH=%%i
popd
set ARCHIVE_NAME=%OUT_DIR%\TVTest_%VERSION%_%GIT_HASH%_%ARCH%

if exist "%ARCHIVE_NAME%.7z" del "%ARCHIVE_NAME%.7z"
rem 7-Zipのインストールフォルダの検索
for /f "usebackq tokens=1,2*" %%i in (`reg query HKLM\Software\7-Zip /v Path`) do if "%%i" == "Path" set PATH=%%k;%PATH%
rem アーカイブの作成
7z a "%ARCHIVE_NAME%.7z" ".\%DST_DIR%\*" -mx=9 -ms=on -myx=9

exit /b

:Help
echo %~nx0 [x86^|x64^|Both] [dynamic^|static] [Build^|Rebuild^|Clean] [Debug^|Release] [del]

exit /b

使い方

コマンドプロンプトでバッチファイルを実行するときに引数を指定します。

TVTest.bat [x86|x64|Both] [dynamic|static] [Build|Rebuild|Clean] [Debug|Release] [del]

上記はhelpを指定すると表示されます。

x86は32bit版、x64は64bit版、Bothは32bit版と64bit版の両方です。

dynamicは動的リンク、staticは静的リンクです。TVTestとサンプルプラグインにのみ有効です。
dynamicの代わりにMD、staticの代わりにMTを指定することもできます。

delはソースを削除します。ダウンロードし直す場合に指定します。

引数のデフォルト値は以下です。

TVTest.bat x86 dynamic Build Release

バッチファイルと同じフォルダにある TVTest\package に出力されます。

ソースのダウンロード先を変更する場合は「set CLONE_DIR=」にフォルダパスを書きます。

アーカイブの出力先を変更する場合は「set OUT_DIR=」にフォルダパスを書きます。

NicoJK.iniは上書き防止のためNicoJK_default.iniにリネームしています。

コメント

  1. John Doe より:

    どうせならアップデートをチェックするバッチファイルなんてどうでしょう
    例として「TVTest」なら以下のバッチでチェックできるはず
    =========================================================================
    cd TVTest
    set RESULT=
    for /f “usebackq tokens=*” %%i in (`git remote show origin`) do set RESULT=%RESULT%%%i
    if /i “%RESULT:~-19%” == “(local out of date)” (
    echo [33;1mTVTestが更新されています[0m
    )
    if /i “%RESULT:~-12%” == “(up to date)” (
    echo [36;1mTVTestは更新されていません[0m
    )
    =========================================================================
    判断しやすく表示を色分けしてみました

    • John Doe より:

      結果を色分けできるようにしたつもりですが、書き込んだら[の前のESCが消えちゃいました

      ついでだから補足
      「TVTest」の所を変数にしてサブルーチンにすれば複数のチェックが可能です

タイトルとURLをコピーしました