sharee.bike-App/Set-GMapsApiKey.ps1

76 lines
2.1 KiB
PowerShell
Raw Normal View History

2022-06-17 14:17:58 +02:00
[cmdletbinding()]
Param(
[string]$appName,
[string]$droidApiKey,
[string]$iOsApiKey)
# Sets a text to a given value.
function Update-Text()
{
param (
[string]$TargetFileName,
[String] $FindText,
[String] $ReplaceText
)
if (-not(Test-Path -Path $TargetFileName)) {
Write-Host "File to update `"" + $TargetFileName + "`" not found!"
return 1
}
((Get-Content -path $TargetFileName -Raw) -replace $FindText, $ReplaceText) | Set-Content -Path $TargetFileName -Encoding utf8 -NoNewline
return 0
}
# Sets google maps api keys in all files for a single app to a given value.
function Set-GMapsApiKey()
{
param(
[String] $ProjectName,
[String] $DroidApiKey,
[String] $iOsApiKey
)
if ($DroidApiKey.Length -le 2)
{
Write-Host "Droid api key must not be of lenght <= 2"
return -1
}
if ($iOsApiKey.Length -le 2)
{
Write-Host "iOs api key must not be of lenght <= 2"
return -1
}
2024-04-09 12:53:23 +02:00
$fileName = Convert-Path ('.\' + $ProjectName + '\ShareeBike.Android\Properties\AndroidManifest.xml')
2022-06-17 14:17:58 +02:00
$retVal = Update-Text $fileName "API_KEY`" android:value=`".*`"" "API_KEY`" android:value=`"$DroidApiKey`""
if ($retVal -ne 0)
{
return $retVal
}
Write-Host "File `"$fileName`" updated sucessfully (.."$DroidApiKey.Substring($DroidApiKey.Length - 2, 2)")."
2024-04-09 12:53:23 +02:00
$fileName = Convert-Path ('.\' + $ProjectName + '\ShareeBike.Android\Properties\AssemblyInfo.cs')
2022-06-17 14:17:58 +02:00
$retVal = Update-Text $fileName "API_KEY`", Value = `".*`"" "API_KEY`", Value = `"$DroidApiKey`""
if ($retVal -ne 0)
{
return $retVal
}
Write-Host "File `"$fileName`" updated sucessfully (.."$DroidApiKey.Substring($DroidApiKey.Length - 2, 2)")."
2024-04-09 12:53:23 +02:00
$fileName = Convert-Path ('.\' + $ProjectName + '\ShareeBike.iOS\AppDelegate.cs')
2022-06-17 14:17:58 +02:00
$retVal = Update-Text $fileName "FormsGoogleMaps\.Init\(.*\)" "FormsGoogleMaps.Init(`"$iOsApiKey`")"
if ($retVal -ne 0)
{
return $retVal
}
Write-Host "File `"$fileName`" updated sucessfully (.."$iOsApiKey.Substring($iOsApiKey.Length - 2, 2)")."
return 0
}
return Set-GMapsApiKey $appName $droidApiKey $iOsApiKey