-
Notifications
You must be signed in to change notification settings - Fork 0
/
RenameSolution.ps1
192 lines (159 loc) · 6.81 KB
/
RenameSolution.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
param([string]$cmdarg = "")
#Contibuted by Kpro#3271
#uncomment to enable logging
#Start-Transcript -OutputDirectory "C:\transcripts\"
Write-Host ""
Write-Host ""
Write-Host "WELCOME TO JOTUNNMODSTUB RENAMING UTILITY"
Write-Host "-----------------------------------------"
Write-Host ""
Write-Host "This script will do the following:"
Write-Host ""
Write-Host ""
Write-Host "1. Change the file names, folder names, and project references from the JotunnModStub to your custom solution name."
Write-Host ""
Write-Host "2. Change the DoPrebuild.props file."
Write-Host ""
Write-Host "3. Create the Environment.props file."
$modstubpath = Get-Location
$modstubfoldername = Split-Path -Path $modstubpath -leaf
Write-Host ""
if ($cmdarg -eq "-nocopy") {
$Name = $modstubfoldername
} else {
#Check for rename and copy use-case
Write-Host "Step 1. Choose one of the following options:"
Write-Host ""
Write-Host "1. Create a solution in this folder named '$modstubfoldername'"
Write-Host ""
Write-Host "2. Copy this folder to a new folder with a solution name I will choose"
Write-Host ""
$yn = Read-Host "Select (1/2)?"
if ($yn -eq "1")
{
$Name = $modstubfoldername
}
else
{
Write-Host ""
Write-Host "Got it. A copy of this folder will be created with a new folder and solution name that you choose"
$Name = Read-Host "Enter a new name for the solution."
Write-Host ""
#Copy modstub folder
Copy-Item ..\$modstubfoldername -Destination "..\$Name" -Recurse
Set-Location ..\$Name
Write-Host "Current location set to: (Get-Location)"
}
}
#Rename folders and files
if ($Name -ne "")
{
Write-Host " . . . Renaming files and folders to '$Name' . . ."
Move-Item -Path ..\$Name\JotunnModStub -Destination ..\$Name\$Name
$unity = $Name + "Unity"
Move-Item -Path ..\$Name\JotunnModUnity -Destination ..\$Name\$unity
Get-ChildItem -Path ..\$Name\ -File -Recurse | % -Process{if($_.Name -ne "JotunnModStub.zip") {Rename-Item -Path $_.PSPath -NewName $_.Name.replace("JotunnModStub", $Name)}}
}
else{
Write-Host "Error: empty solution name"
Read-Host "Enter to exit"
Exit 0
}
#Rename internal references
$msg = " . . . Replacing internal references to 'JotunnModStub' with " + '($Name)' + " . . ."
Write-Host $msg
((Get-Content -path ..\$Name\$Name.sln -Raw) -replace 'JotunnModStub',$Name) | Set-Content -Path ..\$Name\$Name.sln
((Get-Content -path ..\$Name\$Name\$Name.cs -Raw) -replace 'JotunnModStub',$Name) | Set-Content -Path ..\$Name\$Name\$Name.cs
$landed = $Name + " has landed"
((Get-Content -path ..\$Name\$Name\$Name.cs -Raw) -replace 'ModStub has landed',$landed) | Set-Content -Path ..\$Name\$Name\$Name.cs
((Get-Content -path ..\$Name\$Name\$Name.csproj -Raw) -replace 'JotunnModStub',$Name) | Set-Content -Path ..\$Name\$Name\$Name.csproj
((Get-Content -path ..\$Name\$Name\Properties\AssemblyInfo.cs -Raw) -replace 'JotunnModStub',$Name) | Set-Content -Path ..\$Name\$Name\Properties\AssemblyInfo.cs
#setting DoPrebuild.props to true
Write-Host ""
Write-Host "Step 2. . . . setting DoPrebuid.props <ExecutePrebuild> to true..."
((Get-Content -path ..\$Name\DoPreBuild.props -Raw) -replace 'False','True') | Set-Content -Path ..\$Name\DoPreBuild.props
Write-Host ""
#Test whether Environment.props exists in parent directory
if (Test-Path -Path ..\Environment.props) {
Write-Host ""
$yn = Read-Host "Step 3. . . . An Environment.Props file is dectected in the parent directory. Copy this file to solution directory (y/n)?"
if ($yn -eq "y") {
Copy-Item "..\Environment.props" -Destination ".\"
} else {
Write-Host ""
Write-Host "WARNING"
Write-Host "-------"
Write-Host ""
Write-Host "You must create an environment.props file inside the solution directory PRIOR to building the solution."
Write-Host "Instructions for creating this file can be found at"
Write-Host "https://github.com/Valheim-Modding/JotunnModStub"
Write-Host ""
Write-Host ""
Read-Host "Hit Enter to Exit"
Exit 1
}
} else {
Write-Host ""
Write-Host "Step 3 . . . . You must create an environment.props file inside the solution directory PRIOR to building the solution."
Write-Host ""
$yn3 = Read-Host " -- Would you like to create an environment.props file now (y/n)"
if ($yn3 -eq "y")
{
#Initially assume typical install location
$TypicalInstallFolder = "c:\Program Files (x86)\Steam\steamapps\common\Valheim"
#Test for existence of typical install
if (Test-Path -Path $TypicalInstallFolder) {
$ValheimFolder = $TypicalInstallFolder
} else {
$ValheimFolder = "$env:SystemDrive"
}
#Ask user to verify install folder
function Get-InstallFolder($initialDirectory="") {
[void] [System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
$OpenFolderDialog = New-Object System.Windows.Forms.FolderBrowserDialog
$OpenFolderDialog.SelectedPath = $initialDirectory
$OpenFolderDialog.Description = "Select Valheim Install Folder"
$OpenFolderDialog.rootfolder = "MyComputer"
[void] $OpenFolderDialog.ShowDialog()
return $OpenFolderDialog.SelectedPath
}
Write-Host ""
Write-Host " -- Hit ENTER to select your Valheim install folder"
$verifiedinstallfolder = Get-InstallFolder($ValheimFolder)
#Build environment.props
New-Item .\environment.props
Add-Content -Path .\environment.props -Value '<?xml version="1.0" encoding="utf-8"?>'
Add-Content -Path .\environment.props -Value '<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">'
Add-Content -Path .\environment.props -Value ' <PropertyGroup>'
Add-Content -Path .\environment.props -Value ' <!-- Needs to be your path to the base Valheim folder -->'
#Build Install Path
$installpath = " <VALHEIM_INSTALL>$verifiedinstallfolder</VALHEIM_INSTALL>"
Add-Content -Path .\environment.props -Value $installpath
Add-Content -Path .\environment.props -Value ' <!-- This is the folder where your build gets copied to when using the post-build automations -->'
Add-Content -Path .\environment.props -Value ' <MOD_DEPLOYPATH>$(VALHEIM_INSTALL)\BepInEx\plugins</MOD_DEPLOYPATH>'
Add-Content -Path .\environment.props -Value ' </PropertyGroup>'
Add-Content -Path .\environment.props -Value '</Project>'
#Copy environment.props to parent folder for reuse
Copy-Item ".\environment.props" -Destination "..\"
#check for existence of BepInEx folder
if (Test-Path -Path $verifiedinstallfolder\BepInEx) {
} else {
Write-Host "WARNING: BepInEx is not installed."
}
}
}
#Exit
Write-Host ""
Write-Host ""
Write-Host "Success"
Write-Host "-------"
Write-Host ""
Write-Host "The process is complete."
Write-Host "Note that, as stated in the wiki, the compiler will generate reference errors the first time you build the solution."
Write-Host "This is normal. Close VS2019/2022. Reopen the solution. Build. The errors should be resolved."
Write-Host ""
Write-Host ""
Read-Host "Hit Enter to Exit"
Write-Host ""
Write-Host ""
Exit 0