-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.ps1
98 lines (78 loc) · 4.48 KB
/
setup.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
param(
[string] $SpaceEngineersBinPath,
[string] $OutputPath,
[string] $ProjectName
)
if ($null -eq $SpaceEngineersBinPath -or $SpaceEngineersBinPath.Length -eq 0) {
try {
. (".\settings.ps1")
} catch {
function Show-Folder-Selection-Dialog([string] $Description, [string] $SelectedPath) {
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
[System.Windows.Forms.FolderBrowserDialog] $dialog = New-Object System.Windows.Forms.FolderBrowserDialog
$dialog.Description = $Description
$dialog.ShowNewFolderButton = $true
$dialog.SelectedPath = $SelectedPath
$dialog.ShowDialog() | Out-Null
return $dialog.SelectedPath
}
if ($null -eq $SpaceEngineersBinPath -or $SpaceEngineersBinPath.Length -eq 0) {
[string] $default = "${env:ProgramFiles(x86)}\Steam\steamapps\common\SpaceEngineers\Bin64"
$SpaceEngineersBinPath = Show-Folder-Selection-Dialog -Description "Select the binary directory of SpaceEngineers`nDefault: $default" -SelectedPath $default
Remove-Variable -Name default
}
if ($null -eq $OutputPath -or $OutputPath.Length -eq 0) {
[string] $default = "${env:APPDATA}\SpaceEngineers\IngameScripts\local"
$OutputPath = Show-Folder-Selection-Dialog -Description "Select the path to the output folder`nDefault: $default" -SelectedPath $default
Remove-Variable -Name default
}
}
}
Write-Host "Selected game binary folder: '$SpaceEngineersBinPath'"
Write-Host "Selected output folder: '$OutputPath'"
Set-Content -Path .\settings.ps1 -Value "`$SpaceEngineersBinPath = `"$SpaceEngineersBinPath`"`n`$OutputPath = `"$OutputPath`""
while ($ProjectName.Length -eq 0) {
$ProjectName = Read-Host -Prompt "Input the project name"
}
Write-Host "Selected project name: '$ProjectName'"
$OutputPath = "${OutputPath}\${ProjectName}\src"
Write-Host "Final output path: $OutputPath"
# Create solution directory and change to it
New-Item -Path $OutputPath -ItemType Directory -Force
$csproj = (Get-Content -Path .\template\SpaceEngineers.csproj -Raw) -replace 'SpaceEngineersBinPath',$SpaceEngineersBinPath
Set-Content -Path $OutputPath\SpaceEngineers.csproj -Value $csproj
Remove-Variable -Name csproj
if (!(Test-Path $OutputPath\Program.cs -PathType leaf)) {
[string] $programcs = (Get-Content -Path .\template\Program.cs -Raw) -replace 'ProjectName',$ProjectName
if (Test-Path $OutputPath\..\Script.cs -PathType leaf) {
[int] $programcs_header_end = $programcs.IndexOf("#endregion") + "#endregion".Length
[int] $programcs_footer_start = $programcs.LastIndexOf("#region")
[string] $scriptcs = Get-Content -Path $OutputPath\..\Script.cs -Raw
[int] $indention = 8
$programcs = $programcs.Substring(0, $programcs_header_end) + "`n`n" + "".PadRight($indention, ' ') + $scriptcs.Replace("`n", "`n" + "".PadRight($indention, ' ')) + "`n`n" + $programcs.Substring($programcs_footer_start)
Remove-Variable -Name scriptcs
}
Set-Content -Path $OutputPath\Program.cs -Value $programcs
Remove-Variable -Name programcs
} else {
Write-Host "WARNING: $OutputPath\Program.cs already exists and will not be overwritten." -ForegroundColor Yellow
}
Copy-Item -Path .\template\.gitignore -Destination $OutputPath\
Copy-Item -Path .\template\check_size.ps1 -Destination $OutputPath\
Copy-Item -Path .\template\extract_script.ps1 -Destination $OutputPath\
Copy-Item -Path .\template\modinfo.sbmi.xml -Destination $OutputPath\
Copy-Item -Path .\template\README.md -Destination $OutputPath\
if (!(Test-Path $OutputPath\thumb.png -PathType leaf)) {
Copy-Item -Path .\template\thumb.png -Destination $OutputPath\
} else {
Write-Host "WARNING: $OutputPath\thumb.png already exists and will not be overwritten." -ForegroundColor Yellow
}
mkdir -Path $OutputPath\.vscode -Force
Copy-Item -Path .\template\.vscode\tasks.json -Destination $OutputPath\.vscode\
[string] $settingsJson = (Get-Content -Path .\template\.vscode\settings.json -Raw) -replace 'ProjectName',$ProjectName
Set-Content -Path $OutputPath\.vscode\settings.json -Value $settingsJson
Remove-Variable -Name settingsJson
Set-Location -Path $OutputPath
# Create relevant solution and project files
dotnet new sln -n ${ProjectName} --force
dotnet sln add .\SpaceEngineers.csproj