|
# Generic CM3D2 Plugin Network Build&Install Script |
|
# This software is released under the MIT License. |
|
# Copyright (c) 2015 asm__ |
|
# version 15.9.9 |
|
&{ |
|
function global:Init($prjName){ |
|
sal csc ((Get-ItemProperty 'HKLM:\SoftWare\Microsoft\NET Framework Setup\NDP\v3.5').InstallPath+'csc.exe') -scope global |
|
$global:cm3d2= (Get-ItemProperty 'HKCU:\Software\KISS\カスタムメイド3D2').InstallPath |
|
$global:cm3d2_kaizou = Get-Location |
|
$global:source_dir = Join-Path $cm3d2_kaizou PluginSource |
|
if(!(Test-Path $source_dir)){ |
|
New-Item -path $cm3d2_kaizou -name PluginSource -type directory |
|
} |
|
$global:prjDir = Join-Path $source_dir $prjName |
|
if(!(Test-Path $prjDir)){ |
|
New-Item -path $source_dir -name $prjName -type directory |
|
} |
|
if(Test-Path (Join-Path $cm3d2_kaizou ReiPatcher)){ |
|
$global:reipatcher = (Join-Path $cm3d2_kaizou ReiPatcher) |
|
} |
|
if(Test-Path (Join-Path $cm3d2_kaizou CM3D2x64_Data)){ |
|
$global:CM3D2_Data = Join-Path $cm3d2_kaizou CM3D2x64_Data |
|
}elseif (Test-Path (Join-Path $cm3d2_kaizou CM3D2x86_Data)){ |
|
$global:CM3D2_Data = Join-Path $cm3d2_kaizou CM3D2x86_Data |
|
} |
|
} |
|
function global:WebDownload($web,$name){ |
|
# よく分からんがローカル側相対パスだとダメっぽい |
|
$web.DownloadFile($name, (Join-Path $prjDir $name)) |
|
} |
|
function global:WebDownloadString($web , $name , $enc = [Text.Encoding]::UTF8){ |
|
return $enc.GetString($web.DownloadData($name)) |
|
} |
|
# うーん、スクリプトブロック内で定義したglobalブロックの関数からスクリプトブロック呼び出せないっぽい? |
|
function global:replace_macro([string]$str){ |
|
return $str -replace '%reipatcher%',$reipatcher` |
|
-replace '%managed%',"$CM3D2_Data\Managed"` |
|
-replace '%cm3d2%',$CM3D2_KAIZOU` |
|
-replace '%uinjector%',"$CM3D2_KAIZOU\UnityInjector" |
|
} |
|
function global:make_recipe($src,$enc='utf8',$type='library'){ |
|
$src_f = Get-Content $src -Encoding $enc |
|
$argu = new-object 'System.Collections.Generic.List[System.String]' |
|
$argu.add("/t:library") |
|
|
|
foreach ($mi in @($src_f | select-string -pattern '^\/\/\s*@AB_addarg\s+([^\s].*)$' -AllMatches)){ |
|
$mi.matches | %{ |
|
$r = $_.groups[1].value |
|
$r = replace_macro $r |
|
$argu.add($r) |
|
} |
|
} |
|
$install = new-object 'System.Collections.Generic.List[System.String]'; |
|
foreach ($mi in @($src_f | select-string -pattern '^\/\/\s*@AB_install\s+([^\s].*)$' -AllMatches)){ |
|
$mi.matches | %{ |
|
$r = $_.groups[1].value |
|
$r = replace_macro $r |
|
$install.add($r)} |
|
} |
|
|
|
return (@{ |
|
argu = $argu.toarray(); |
|
type = "/t:$type"; |
|
output = $src -replace '\.cs$' , '.dll'; |
|
install = $install.toarray(); |
|
encoding = $enc; |
|
src = $src; |
|
}) |
|
} |
|
function global:compile($recipe){ |
|
Write-Host "Compile $($recipe['src'])" |
|
csc $recipe['type'] "/out:$($recipe['output'])" $recipe['argu'] $recipe['src'] |
|
} |
|
function global:install($recipe){ |
|
foreach ($path in $recipe['install']){ |
|
copy $recipe['output'] $path |
|
} |
|
} |
|
function global:make_batch($recipe){ |
|
$batch = @" |
|
@echo off |
|
$((gal csc).Definition) $($recipe['type']) /out:$($recipe['output']) $($recipe['argu']) $($recipe['src']) |
|
$(foreach ($path in $recipe['install']){ |
|
"copy $($recipe['output']) $path`n" |
|
}) |
|
@pause |
|
"@ |
|
#Write-Host $batch |
|
try{ |
|
$batch | Out-File ($recipe['src'] -replace '\.cs$','.bat') -Encoding oem -NoClobber |
|
}catch{ |
|
} |
|
} |
|
} |