Rev 10 | Blame | Compare with Previous | Last modification | View Log | RSS feed
$failed = @()
$treated = @()
$schematicbased = @()
$thispath = pwd
$asylist = Get-ChildItem . -Recurse -Include *.asy
$encodings = @("UTF8", "UNICODE", "ASCII")
$encode_mode = 0
foreach($asy in $asylist)
{
$asyname = Split-Path $asy -Leaf
$all_encodes_done = 0
$encode_mode = 0
$successmatch = 0
$modelfile = ""
while(1)
{
if($args[0] -eq "-v"){
Write-Host "Trying encoding <" $encodings[$encode_mode] "> on " $asyname " : " -nonewline
pause
}
$content = Get-Content $asy -Encoding $encodings[$encode_mode]
# extracting model file in case it does not match the .asy name
foreach ($line in $content)
{
if($line -match "\b[^\\\s]+\.(lib|mdl|mod)\b")
{
$modelfile = $matches[0]
$successmatch = 1
if($args[0] -eq "-v"){
Write-Host "Success, found " $matches[0]
}
break #break from the foreach
}
}
#if regex succeeded, break from the encoding reader loop
if($successmatch){
break
}
#else, try to change the encoder or if no encoder remaining, set as failed
else
{
if($args[0] -eq "-v"){
Write-Host "Failed, selecting another encoder..."}
$encode_mode = $encode_mode + 1
if($encode_mode -ge $encodings.Count)
{
break
}
}
}
#if the model file is not found, previous steps failed.
if($modelfile -eq "")
{
if($args[0] -eq "-v"){
echo "model file is empty"}
$ascpath = $asyname.Split('.')[0] + ".asc"
if(Test-Path -Path $ascpath)
{
if($args[0] -eq "-v"){
echo "$asyname has a corresponsing .asc : $ascpath"
echo "-----------------------------------"
echo "Processing .asy : $asyname"
echo "Schematic file : $ascpath"
echo "-----------------------------------"}
$schematicbased += $asyname
}
else
{
if($args[0] -eq "-v"){
echo "no link to model file for $asyname, extracted : $modelfile."}
$failed += $asyname
}
}
else
{
if($args[0] -eq "-v"){
echo "-----------------------------------"
echo "Processing .asy : $asyname"
echo "Model file : $modelfile"
echo "-----------------------------------"}
$symattr = 'SYMATTR ModelFile ' + $modelfile
$edited = $content -replace ( 'SYMATTR ModelFile (.+)', $symattr)
$edited | Set-Content $asy
$treated += $asyname
}
}
$okcount = $treated.Count
$nokcount = $failed.Count
$schematiccount = $schematicbased.Count
echo "Files using a referenced .lib, .mdl, .mod:"
echo "-----------------------------------"
foreach($ffile in $treated)
{
echo $ffile
}
echo "-----------------------------------"
echo ""
echo "Files using a matched-name .asc :"
echo "-----------------------------------"
foreach($ffile in $schematicbased)
{
echo $ffile
}
echo "-----------------------------------"
echo ""
echo "Failed files, no .lib reference or no matched .asc :"
echo "-----------------------------------"
foreach($ffile in $failed)
{
echo $ffile
}
echo "-----------------------------------"
echo ""
echo "Edited $okcount files, $schematiccount based on a matched LTspice schematic, $nokcount failed."
echo ""