Fix: Install - Reset method

This commit is contained in:
alstjr7375 2022-04-22 16:05:12 +09:00
parent 352616c87d
commit 9e9036a380
2 changed files with 21 additions and 12 deletions

View file

@ -718,7 +718,7 @@ $customFileApplied = $false
function Apply-CustomFile() { function Apply-CustomFile() {
Param ( Param (
[Parameter(Mandatory=$true, Position=0)] [Parameter(Mandatory=$true, Position=0)]
[string] $gitDir, [string] $profilePath,
[Parameter(Mandatory=$true, Position=1)] [Parameter(Mandatory=$true, Position=1)]
[string] $targetFile, [string] $targetFile,
[Parameter(Mandatory=$true, Position=2)] [Parameter(Mandatory=$true, Position=2)]
@ -727,6 +727,7 @@ function Apply-CustomFile() {
[string] $otherCustom = "" [string] $otherCustom = ""
) )
$local:gitDir = "${profilePath}\chrome\.git"
if ( Test-Path -Path "${customFile}" -PathType leaf ) { if ( Test-Path -Path "${customFile}" -PathType leaf ) {
$global:customFileApplied = $true $global:customFileApplied = $true
@ -735,7 +736,12 @@ function Apply-CustomFile() {
} }
if ( "${customReset}" -eq $true ) { if ( "${customReset}" -eq $true ) {
git --git-dir "${gitDir}" reset --hard HEAD if ( "${targetFile}" -like "*user.js" ) {
Copy-Item -Path "${customFile}" -Destination "${targetFile}" -Force
}
else {
git --git-dir "${gitDir}" --quiet checkout HEAD -- "${targetFile}"
}
} }
if ( "${customAppend}" -eq $true ) { if ( "${customAppend}" -eq $true ) {
# Apply without duplication # Apply without duplication
@ -745,23 +751,22 @@ function Apply-CustomFile() {
} }
} }
elseif ( "${otherCustom}" -ne "" ) { elseif ( "${otherCustom}" -ne "" ) {
Apply-CustomFile "${gitDir}" "${targetFile}" "${otherCustom}" Apply-CustomFile "${profilePath}" "${targetFile}" "${otherCustom}"
} }
} }
function Apply-CustomFiles() { function Apply-CustomFiles() {
foreach ( $profilePath in $global:firefoxProfilePaths ) { foreach ( $profilePath in $global:firefoxProfilePaths ) {
$local:LEPTONGITPATH="${profilePath}\chrome\.git"
foreach ( $customFile in $global:customFiles ) { foreach ( $customFile in $global:customFiles ) {
$local:targetFile = $customFile.Replace("-overrides", "") $local:targetFile = $customFile.Replace("-overrides", "")
if ( "${customFile}" -eq "user-overrides.js" ) { if ( "${customFile}" -eq "user-overrides.js" ) {
$local:targetPath = "${profilePath}\${targetFile}" $local:targetPath = "${profilePath}\${targetFile}"
$local:customPath = "${profilePath}\user-overrides.js" $local:customPath = "${profilePath}\user-overrides.js"
$local:otherCustomPath = "${profilePath}\chrome\user-overrides.js" $local:otherCustomPath = "${profilePath}\chrome\user-overrides.js"
Apply-CustomFile "${LEPTONGITPATH}" "${targetPath}" "${customPath}" "${otherCustomPath}" Apply-CustomFile "${profilePath}" "${targetPath}" "${customPath}" "${otherCustomPath}"
} }
else { else {
Apply-CustomFile "${LEPTONGITPATH}" "${profilePath}\chrome\${targetFile}" "${profilePath}\chrome\${customFile}" Apply-CustomFile "${profilePath}" "${profilePath}\chrome\${targetFile}" "${profilePath}\chrome\${customFile}"
} }
} }
} }

View file

@ -695,11 +695,12 @@ set_custom_method() {
customFileApplied="" customFileApplied=""
apply_custom_file() { apply_custom_file() {
local gitDir=$1 local profilePath=$1
local targetFile=$2 local targetFile=$2
local customFile=$3 local customFile=$3
local otherCustom=$4 local otherCustom=$4
local gitDir="${profilePath}/chrome/.git"
if [ -f "${customFile}" ]; then if [ -f "${customFile}" ]; then
customFileApplied="true" customFileApplied="true"
@ -708,7 +709,11 @@ apply_custom_file() {
fi fi
if [ "${customReset}" == "true" ]; then if [ "${customReset}" == "true" ]; then
git --git-dir "${gitDir}" reset --hard HEAD if [[ "${targetFile}" == *"user.js" ]]; then
\cp -f "${profilePath}/chrome/user.js" "${targetFile}"
else
git --git-dir "${gitDir}" --quiet checkout HEAD -- "${targetFile}"
fi
fi fi
if [ "${customAppend}" == "true" ]; then if [ "${customAppend}" == "true" ]; then
# Apply without duplication # Apply without duplication
@ -717,22 +722,21 @@ apply_custom_file() {
fi fi
fi fi
elif [ -n "${otherCustom}" ]; then elif [ -n "${otherCustom}" ]; then
apply_custom_file "${gitDir}" "${targetFile}" "${otherCustom}" apply_custom_file "${profilePath}" "${targetFile}" "${otherCustom}"
fi fi
} }
apply_custom_files() { apply_custom_files() {
for profilePath in "${firefoxProfilePaths[@]}"; do for profilePath in "${firefoxProfilePaths[@]}"; do
local LEPTONGITPATH="${profilePath}/chrome/.git"
for customFile in "${customFiles[@]}"; do for customFile in "${customFiles[@]}"; do
local targetFile="${customFile//-overrides/}" local targetFile="${customFile//-overrides/}"
if [ "${customFile}" == "user-overrides.js" ]; then if [ "${customFile}" == "user-overrides.js" ]; then
local targetPath="${profilePath}/${targetFile}" local targetPath="${profilePath}/${targetFile}"
local customPath="${profilePath}/user-overrides.js" local customPath="${profilePath}/user-overrides.js"
local otherCustomPath="${profilePath}/chrome/user-overrides.js" local otherCustomPath="${profilePath}/chrome/user-overrides.js"
apply_custom_file "${LEPTONGITPATH}" "${targetPath}" "${customPath}" "${otherCustomPath}" apply_custom_file "${profilePath}" "${targetPath}" "${customPath}" "${otherCustomPath}"
else else
apply_custom_file "${LEPTONGITPATH}" "${profilePath}/chrome/${targetFile}" "${profilePath}/chrome/${customFile}" apply_custom_file "${profilePath}" "${profilePath}/chrome/${targetFile}" "${profilePath}/chrome/${customFile}"
fi fi
done done
done done