Clean: Install - *File -> *Path at apply_custom_file

This commit is contained in:
alstjr7375 2022-04-22 16:15:54 +09:00
parent 9e9036a380
commit b1bd85d869
2 changed files with 23 additions and 23 deletions

View file

@ -720,15 +720,15 @@ function Apply-CustomFile() {
[Parameter(Mandatory=$true, Position=0)]
[string] $profilePath,
[Parameter(Mandatory=$true, Position=1)]
[string] $targetFile,
[string] $targetPath,
[Parameter(Mandatory=$true, Position=2)]
[string] $customFile,
[string] $customPath,
[Parameter(Position=3)]
[string] $otherCustom = ""
[string] $otherCustomPath = ""
)
$local:gitDir = "${profilePath}\chrome\.git"
if ( Test-Path -Path "${customFile}" -PathType leaf ) {
if ( Test-Path -Path "${customPath}" -PathType leaf ) {
$global:customFileApplied = $true
if ( "${customMethod}" -eq "" ) {
@ -736,22 +736,22 @@ function Apply-CustomFile() {
}
if ( "${customReset}" -eq $true ) {
if ( "${targetFile}" -like "*user.js" ) {
Copy-Item -Path "${customFile}" -Destination "${targetFile}" -Force
if ( "${targetPath}" -like "*user.js" ) {
Copy-Item -Path "${customFile}" -Destination "${targetPath}" -Force
}
else {
git --git-dir "${gitDir}" --quiet checkout HEAD -- "${targetFile}"
git --git-dir "${gitDir}" --quiet checkout HEAD -- "${targetPath}"
}
}
if ( "${customAppend}" -eq $true ) {
# Apply without duplication
if ( -not (Write-Output "$(Write-Output $(Get-Content -Path "${targetFile}"))" | Select-String -Pattern "$(Write-Output $(Get-Content -Path "${customFile}"))" -SimpleMatch -Quiet) ) {
Get-Content -Path "${customFile}" | Out-File -FilePath "${targetFile}" -Append
if ( -not (Write-Output "$(Write-Output $(Get-Content -Path "${targetPath}"))" | Select-String -Pattern "$(Write-Output $(Get-Content -Path "${customPath}"))" -SimpleMatch -Quiet) ) {
Get-Content -Path "${customPath}" | Out-File -FilePath "${targetPath}" -Append
}
}
}
elseif ( "${otherCustom}" -ne "" ) {
Apply-CustomFile "${profilePath}" "${targetFile}" "${otherCustom}"
elseif ( "${otherCustomPath}" -ne "" ) {
Apply-CustomFile "${profilePath}" "${targetPath}" "${otherCustomPath}"
}
}

View file

@ -696,33 +696,33 @@ set_custom_method() {
customFileApplied=""
apply_custom_file() {
local profilePath=$1
local targetFile=$2
local customFile=$3
local otherCustom=$4
local targetPath=$2
local customPath=$3
local otherCustomPath=$4
local gitDir="${profilePath}/chrome/.git"
if [ -f "${customFile}" ]; then
customFileApplied="true"
if [ -f "${customPath}" ]; then
customPathApplied="true"
if [ -z "${customMethod}" ]; then
set_custom_method
fi
if [ "${customReset}" == "true" ]; then
if [[ "${targetFile}" == *"user.js" ]]; then
\cp -f "${profilePath}/chrome/user.js" "${targetFile}"
if [[ "${targetPath}" == *"user.js" ]]; then
\cp -f "${profilePath}/chrome/user.js" "${targetPath}"
else
git --git-dir "${gitDir}" --quiet checkout HEAD -- "${targetFile}"
git --git-dir "${gitDir}" --quiet checkout HEAD -- "${targetPath}"
fi
fi
if [ "${customAppend}" == "true" ]; then
# Apply without duplication
if ! grep -Fq "$(echo $(cat "${customFile}"))" <(echo "$(echo $(cat "${targetFile}"))"); then
cat "${customFile}" >> "${targetFile}"
if ! grep -Fq "$(echo $(cat "${customPath}"))" <(echo "$(echo $(cat "${targetPath}"))"); then
cat "${customPath}" >> "${targetPath}"
fi
fi
elif [ -n "${otherCustom}" ]; then
apply_custom_file "${profilePath}" "${targetFile}" "${otherCustom}"
elif [ -n "${otherCustomPath}" ]; then
apply_custom_file "${profilePath}" "${targetPath}" "${otherCustomPath}"
fi
}