User:Schnusch/Notepad++/Papyrus Compiler

From the CreationKit Wiki
Jump to navigation Jump to search
@ECHO OFF
mode 100,50
VERIFY > nul
CLS
:: read Skyrim path from registry and write the line containing the result to a temporary file
if %PROCESSOR_ARCHITECTURE%==x86 (
  REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Bethesda Softworks\Skyrim" /v "Installed Path" | FINDSTR /R "\<.:">"%Temp%\SkyrimPath.txt"
) else (
  REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Bethesda Softworks\Skyrim" /v "Installed Path" | FINDSTR /R "\<.:">"%Temp%\SkyrimPath.txt"
)

::The "\<.:" means a line with any characters containing a colon. However key name and key type are included

:: read Skyrim path from the temporary file and save it to a variable
SET /P Skyrim=<"%Temp%\SkyrimPath.txt"

:: Remove Spaces
set TempSkyrim=%Skyrim: =%

:: Trim keyname and keytype and save Skyrim directory path
set Skyrim=%TempSkyrim:InstalledPathREG_SZ=%


:: delete the temporary file
DEL /F "%Temp%\SkyrimPath.txt"

cd \

:: detect 64 bit H/W see http://ss64.com/nt/syntax-64bit.html

IF NOT %PROCESSOR_ARCHITECTURE% == x86 (
Pushd %Skyrim:~64%
GOTO SIXTYFOUR
)
IF DEFINED PROCESSOR_ARCHITEW6432 (
Pushd %Skyrim:~64%
) else (
Pushd %Skyrim:~32%
)
:SIXTYFOUR


:: retrieved path is invalid
IF NOT %ErrorLevel%==0 (
    echo(
	ECHO I hope you saved this script in the Skyrim directory or at least a subdirectory.
	echo(
	:: script in Skyrim directory?
	IF EXIST "%~dp0\TESV.exe" (
		CD /D "%~dp0"
	) ELSE (
		:: script in Skyrim subdirectory?
		IF EXIST "%~dp0\..\TESV.exe" (
			CD /D "%~dp0\.."
		) ELSE (
			:: failed to retrieve the path of the Skyrim directory
			echo(
			ECHO Failed to retrieve the Skyrim directory.
			echo(
			GOTO Finish
		)
	)
)


:: retrieve script directory (output)


SET "Output=%Skyrim%Data\Scripts"

CD %Output%


:: retrieve script source directory (import)
SET "Import=%Output%\Source"
CD %Import%

IF [%2]==[] GOTO NOADDITIONALIMPORTS

    IF [%2]==[ADDITIONAL IMPORTS] (
	echo(
    @echo Valid import directory not specified in Notepad++ "Papyrus Compiler.bat" Command line.
	GOTO NOADDITIONALIMPORTS
    )

	SET "AdditionalImports"="%2"

SET Import=%Import%\;%AdditionalImports:~1,-1%

:NOADDITIONALIMPORTS
:: log paths
echo(
ECHO %%Skyrim%%=%Skyrim%
ECHO %%Import%%=%Import%
ECHO %%Output%%=%Output%

Popd
echo(
echo(
echo(
:: run the compiler

start "PapyrusCompiler" /B "%Skyrim%Papyrus Compiler\PapyrusCompiler.exe" %1 -f="TESV_Papyrus_Flags.flg" -import="%Import%" -output="%Output%"

:LOOP
timeout /t 1 /nobreak > nul
tasklist /fi "IMAGENAME eq PapyrusCompiler.exe" | find /i "PapyrusCompiler.exe" > nul
if errorlevel 1 goto Finish
if errorlevel 0 goto LOOP
ECHO ________________________________________________________________________________
:Finish
ECHO Press any key to exit.
PAUSE>NUL
goto :EOF

Save the script anywhere (If an error occurs move this script to the Skyrim directory or a subdirectory e. g. "\Papyrus Compiler".) and configure Notepad++ to run this:

cmd /c ""<SCRIPT DIR>\Papyrus Compiler.bat" "$(FULL_CURRENT_PATH)" "<ADDITIONAL IMPORTS>""

(Replace <SCRIPT DIR> with the path name that contains "Papyrus Compiler.bat". You can remove the second parameter which defines additional import directories but if you use it you must put this parameter in quotes for this script to work.)