|
| 1 | +# Copyright (c) Files Community |
| 2 | +# Licensed under the MIT License. |
| 3 | + |
| 4 | +param( |
| 5 | + [string]$Branch = "", # This has to correspond with one of the AppEnvironment enum values |
| 6 | + [string]$PackageManifestPath = "", |
| 7 | + [string]$Publisher = "", |
| 8 | + [string]$WorkingDir = "", |
| 9 | + [string]$SecretBingMapsKey = "", |
| 10 | + [string]$SecretSentry = "", |
| 11 | + [string]$SecretGitHubOAuthClientId = "" |
| 12 | +) |
| 13 | + |
| 14 | +# Load Package.appxmanifest |
| 15 | +[xml]$xmlDoc = Get-Content $PackageManifestPath |
| 16 | + |
| 17 | +# Add namespaces |
| 18 | +$nsmgr = New-Object System.Xml.XmlNamespaceManager($xmlDoc.NameTable) |
| 19 | +$nsmgr.AddNamespace("pkg", "http://schemas.microsoft.com/appx/manifest/foundation/windows10") |
| 20 | +$nsmgr.AddNamespace("rescap", "http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities") |
| 21 | +$nsmgr.AddNamespace("uap", "http://schemas.microsoft.com/appx/manifest/uap/windows10") |
| 22 | +$nsmgr.AddNamespace("uap5", "http://schemas.microsoft.com/appx/manifest/uap/windows10/5") |
| 23 | +$ap = $xmlDoc.SelectSingleNode("/pkg:Package/pkg:Applications/pkg:Application/pkg:Extensions/uap:Extension[@Category='windows.protocol']/uap:Protocol", $nsmgr) |
| 24 | +$aea = $xmlDoc.SelectSingleNode("/pkg:Package/pkg:Applications/pkg:Application/pkg:Extensions/uap5:Extension[@Category='windows.appExecutionAlias']/uap5:AppExecutionAlias", $nsmgr) |
| 25 | +$ea = $xmlDoc.SelectSingleNode("/pkg:Package/pkg:Applications/pkg:Application/pkg:Extensions/uap5:Extension[@Category='windows.appExecutionAlias']/uap5:AppExecutionAlias/uap5:ExecutionAlias", $nsmgr) |
| 26 | + |
| 27 | +# Update the publisher |
| 28 | +$xmlDoc.Package.Identity.Publisher = $Publisher |
| 29 | + |
| 30 | +if ($Branch -eq "SideloadPreview") |
| 31 | +{ |
| 32 | + # Set identities |
| 33 | + $xmlDoc.Package.Identity.Name="FilesPreview" |
| 34 | + $xmlDoc.Package.Properties.DisplayName="Files - Preview" |
| 35 | + $xmlDoc.Package.Applications.Application.VisualElements.DisplayName="Files - Preview" |
| 36 | + $xmlDoc.Package.Applications.Application.VisualElements.DefaultTile.ShortName="Files - Preview" |
| 37 | + |
| 38 | + # Update app protocol and execution alias |
| 39 | + $ap.SetAttribute("Name", "files-preview"); |
| 40 | + $ea.SetAttribute("Alias", "files-preview.exe"); |
| 41 | + |
| 42 | + # Save modified Package.appxmanifest |
| 43 | + $xmlDoc.Save($PackageManifestPath) |
| 44 | + |
| 45 | + Get-ChildItem $WorkingDir -Include *.csproj, *.appxmanifest, *.wapproj, *.xaml -recurse | ForEach-Object -Process ` |
| 46 | + { ` |
| 47 | + (Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "Assets\\AppTiles\\Dev", "Assets\AppTiles\Preview" }) | ` |
| 48 | + Set-Content $_ -NoNewline ` |
| 49 | + } |
| 50 | + |
| 51 | + Get-ChildItem $WorkingDir -Include *.cs, *.cpp -recurse | ForEach-Object -Process ` |
| 52 | + { ` |
| 53 | + (Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "files-dev", "files-preview" }) | ` |
| 54 | + Set-Content $_ -NoNewline ` |
| 55 | + } |
| 56 | +} |
| 57 | +elseif ($Branch -eq "StorePreview") |
| 58 | +{ |
| 59 | + # Set identities |
| 60 | + $xmlDoc.Package.Identity.Name="49306atecsolution.FilesPreview" |
| 61 | + $xmlDoc.Package.Properties.DisplayName="Files - Preview" |
| 62 | + $xmlDoc.Package.Applications.Application.VisualElements.DisplayName="Files - Preview" |
| 63 | + $xmlDoc.Package.Applications.Application.VisualElements.DefaultTile.ShortName="49306atecsolution.FilesPreview" |
| 64 | + |
| 65 | + # Remove capability that is only used for the sideload package |
| 66 | + $nsmgr = New-Object System.Xml.XmlNamespaceManager($xmlDoc.NameTable) |
| 67 | + $nsmgr.AddNamespace("pkg", "http://schemas.microsoft.com/appx/manifest/foundation/windows10") |
| 68 | + $nsmgr.AddNamespace("rescap", "http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities") |
| 69 | + $pm = $xmlDoc.SelectSingleNode("/pkg:Package/pkg:Capabilities/rescap:Capability[@Name='packageManagement']", $nsmgr) |
| 70 | + $xmlDoc.Package.Capabilities.RemoveChild($pm) |
| 71 | + |
| 72 | + # Update app protocol and execution alias |
| 73 | + $ap.SetAttribute("Name", "files-preview"); |
| 74 | + $ea.SetAttribute("Alias", "files-preview.exe"); |
| 75 | + |
| 76 | + $xmlDoc.Save($PackageManifestPath) |
| 77 | + |
| 78 | + Get-ChildItem $WorkingDir -Include *.csproj, *.appxmanifest, *.wapproj, *.xaml -recurse | ForEach-Object -Process ` |
| 79 | + { ` |
| 80 | + (Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "Assets\\AppTiles\\Dev", "Assets\AppTiles\Preview" }) | ` |
| 81 | + Set-Content $_ -NoNewline ` |
| 82 | + } |
| 83 | + |
| 84 | + Get-ChildItem $WorkingDir -Include *.cs, *.cpp -recurse | ForEach-Object -Process ` |
| 85 | + { ` |
| 86 | + (Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "files-dev", "files-preview" }) | ` |
| 87 | + Set-Content $_ -NoNewline ` |
| 88 | + } |
| 89 | +} |
| 90 | +elseif ($Branch -eq "SideloadStable") |
| 91 | +{ |
| 92 | + # Set identities |
| 93 | + $xmlDoc.Package.Identity.Name="Files" |
| 94 | + $xmlDoc.Package.Properties.DisplayName="Files" |
| 95 | + $xmlDoc.Package.Applications.Application.VisualElements.DisplayName="Files" |
| 96 | + $xmlDoc.Package.Applications.Application.VisualElements.DefaultTile.ShortName="Files" |
| 97 | + |
| 98 | + # Update app protocol and execution alias |
| 99 | + $ap.SetAttribute("Name", "files-stable"); |
| 100 | + $ea.SetAttribute("Alias", "files-stable.exe"); |
| 101 | + |
| 102 | + # Save modified Package.appxmanifest |
| 103 | + $xmlDoc.Save($PackageManifestPath) |
| 104 | + |
| 105 | + Get-ChildItem $WorkingDir -Include *.csproj, *.appxmanifest, *.wapproj, *.xaml -recurse | ForEach-Object -Process ` |
| 106 | + { ` |
| 107 | + (Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "Assets\\AppTiles\\Dev", "Assets\AppTiles\Release" }) | ` |
| 108 | + Set-Content $_ -NoNewline ` |
| 109 | + } |
| 110 | + |
| 111 | + Get-ChildItem $WorkingDir -Include *.cs, *.cpp -recurse | ForEach-Object -Process ` |
| 112 | + { ` |
| 113 | + (Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "files-dev", "files-stable" }) | ` |
| 114 | + Set-Content $_ -NoNewline ` |
| 115 | + } |
| 116 | +} |
| 117 | +elseif ($Branch -eq "StoreStable") |
| 118 | +{ |
| 119 | + # Set identities |
| 120 | + $xmlDoc.Package.Identity.Name="49306atecsolution.FilesUWP" |
| 121 | + $xmlDoc.Package.Properties.DisplayName="Files App" |
| 122 | + $xmlDoc.Package.Applications.Application.VisualElements.DisplayName="Files" |
| 123 | + $xmlDoc.Package.Applications.Application.VisualElements.DefaultTile.ShortName="Files" |
| 124 | + |
| 125 | + # Remove capability that is only used for the sideload package |
| 126 | + $pm = $xmlDoc.SelectSingleNode("/pkg:Package/pkg:Capabilities/rescap:Capability[@Name='packageManagement']", $nsmgr) |
| 127 | + $xmlDoc.Package.Capabilities.RemoveChild($pm) |
| 128 | + |
| 129 | + # Update app protocol and execution alias |
| 130 | + $ap.SetAttribute("Name", "files-stable"); |
| 131 | + $ea.SetAttribute("Alias", "files-stable.exe"); |
| 132 | + |
| 133 | + # Save modified Package.appxmanifest |
| 134 | + $xmlDoc.Save($PackageManifestPath) |
| 135 | + |
| 136 | + Get-ChildItem $WorkingDir -Include *.csproj, *.appxmanifest, *.wapproj, *.xaml -recurse | ForEach-Object -Process ` |
| 137 | + { ` |
| 138 | + (Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "Assets\\AppTiles\\Dev", "Assets\AppTiles\Release" }) | ` |
| 139 | + Set-Content $_ -NoNewline ` |
| 140 | + } |
| 141 | + |
| 142 | + Get-ChildItem $WorkingDir -Include *.cs, *.cpp -recurse | ForEach-Object -Process ` |
| 143 | + { ` |
| 144 | + (Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "files-dev", "files-stable" }) | ` |
| 145 | + Set-Content $_ -NoNewline ` |
| 146 | + } |
| 147 | +} |
| 148 | + |
| 149 | +Get-ChildItem $WorkingDir -Include *.cs -recurse | ForEach-Object -Process ` |
| 150 | +{ ` |
| 151 | + (Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "cd_app_env_placeholder", $Branch }) | ` |
| 152 | + Set-Content $_ -NoNewline ` |
| 153 | +} |
| 154 | + |
| 155 | +Get-ChildItem $WorkingDir -Include *.cs -recurse | ForEach-Object -Process ` |
| 156 | +{ ` |
| 157 | + (Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "bingmapskey.secret", "$SecretBingMapsKey" }) | ` |
| 158 | + Set-Content $_ -NoNewline ` |
| 159 | +} |
| 160 | + |
| 161 | +Get-ChildItem $WorkingDir -Include *.cs -recurse | ForEach-Object -Process ` |
| 162 | +{ |
| 163 | + (Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "sentry.secret", "$SecretSentry" }) | ` |
| 164 | + Set-Content $_ -NoNewline ` |
| 165 | +} |
| 166 | + |
| 167 | +Get-ChildItem $WorkingDir -Include *.cs -recurse | ForEach-Object -Process ` |
| 168 | +{ ` |
| 169 | + (Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "githubclientid.secret", "$SecretGitHubOAuthClientId" }) | ` |
| 170 | + Set-Content $_ -NoNewline ` |
| 171 | +} |
0 commit comments