forked from ReClassNET/ReClass.NET-SamplePlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetup.ps1
More file actions
55 lines (46 loc) · 1.79 KB
/
Setup.ps1
File metadata and controls
55 lines (46 loc) · 1.79 KB
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
param(
[string]$NewName
)
if (-not $NewName) {
$NewName = Read-Host "Enter the new plugin name"
}
# --- Validation ---
if ($NewName -notmatch '^[A-Za-z][A-Za-z0-9_-]*$') {
Write-Host "`n❌ Invalid plugin name!"
Write-Host "Allowed: letters, numbers, underscores, hyphens. Must start with a letter."
Write-Host "Example: MyPlugin, Cool_Mod, Plugin123"
exit 1
}
Write-Host "`nRenaming to $NewName...`n"
$OldName = "SamplePlugin"
# 1️⃣ Replace text inside files
$extensions = "*.cs","*.csproj","*.sln","*.txt","*.md"
Get-ChildItem -Recurse -Include $extensions | ForEach-Object {
(Get-Content $_.FullName -Raw) `
-replace "ReClassNET\.$OldName", "ReClassNET.$NewName" `
-replace $OldName, $NewName |
Set-Content $_.FullName
}
# 2️⃣ Rename folders (bottom-up)
Get-ChildItem -Recurse -Directory | Sort-Object FullName -Descending | ForEach-Object {
if ($_.Name -match $OldName) {
$newPath = Join-Path $_.Parent.FullName ($_.Name -replace $OldName, $NewName)
Rename-Item -LiteralPath $_.FullName -NewName $newPath
}
}
# 3️⃣ Rename files (bottom-up)
Get-ChildItem -Recurse -File | Sort-Object FullName -Descending | ForEach-Object {
if ($_.Name -match $OldName) {
$newPath = Join-Path $_.Directory.FullName ($_.Name -replace $OldName, $NewName)
Rename-Item -LiteralPath $_.FullName -NewName $newPath
}
}
# 4️⃣ Rename top-level folder if needed
$root = Get-Item .
if ($root.Name -match $OldName) {
$newRoot = Join-Path $root.Parent.FullName ($root.Name -replace $OldName, $NewName)
Write-Host "`nRenaming root folder to $($newRoot)..."
Rename-Item -LiteralPath $root.FullName -NewName $newRoot
Write-Host "Root folder renamed successfully."
}
Write-Host "`n✅ Done! Plugin renamed to $NewName`n"