Skip to content

Commit 610808a

Browse files
authored
Update codeql.yml
1 parent e7b56a6 commit 610808a

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed

.github/workflows/codeql.yml

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,54 @@ jobs:
6767
run: git clone https://github.com/Jesus-QC/SecretLabDependenciesBuilder.git
6868

6969
- name: Patch ServerDownloader.cs to skip prompts
70+
shell: pwsh
7071
run: |
71-
sed -i '/public static async Task RunAsync()/,/^\}/c\public static async Task RunAsync()\n{\n ConsoleWriter.WriteTitle();\n _beta = Environment.GetEnvironmentVariable("SL_BETA") ?? ""; \n _betaPassword = Environment.GetEnvironmentVariable("SL_BETA_PASSWORD") ?? ""; \n DirectoryInfo installationDirectory = new(Path.Combine(Environment.CurrentDirectory, "temp"));\n installationDirectory.Create();\n string filesPath = Path.Combine(installationDirectory.FullName, "files.txt");\n await File.WriteAllTextAsync(filesPath, "regex:SCPSL_Data/Managed/*");\n List<string> args = [ "-app", "996560", "-filelist", filesPath, "-dir", installationDirectory.FullName ];\n if (!string.IsNullOrEmpty(_beta)) {\n args.Add("-beta"); args.Add(_beta);\n if (!string.IsNullOrEmpty(_betaPassword)) {\n args.Add("-betapassword"); args.Add(_betaPassword);\n }\n }\n bool success = await DepotProgram.Main(args.ToArray()) == 0;\n if (!success) {\n ConsoleWriter.Write("An error occurred while downloading the files.", ConsoleColor.Red);\n return;\n }\n DirectoryInfo managedDirectory = new(Path.Combine(installationDirectory.FullName, "SCPSL_Data/Managed"));\n AssembliesPublicizer.RunPublicizer(managedDirectory);\n installationDirectory.Delete(true);\n}\n}' SecretLabDependenciesBuilder/SecretLabDependenciesBuilder/ServerDownloader.cs
72-
72+
$path = "SecretLabDependenciesBuilder/SecretLabDependenciesBuilder/ServerDownloader.cs"
73+
$content = Get-Content $path
74+
$patternStart = 'public static async Task RunAsync\(\)'
75+
$startIndex = $content.FindIndex({ $_ -match $patternStart })
76+
if ($startIndex -lt 0) { throw "Start pattern not found." }
77+
78+
$braceCount = 0
79+
for ($i = $startIndex; $i -lt $content.Count; $i++) {
80+
$line = $content[$i]
81+
$braceCount += ($line -split '{').Count - 1
82+
$braceCount -= ($line -split '}').Count - 1
83+
if ($braceCount -eq 0 -and $i -ne $startIndex) {
84+
$endIndex = $i
85+
break
86+
}
87+
}
88+
$replacement = @'
89+
public static async Task RunAsync()
90+
{
91+
ConsoleWriter.WriteTitle();
92+
_beta = Environment.GetEnvironmentVariable("SL_BETA") ?? "";
93+
_betaPassword = Environment.GetEnvironmentVariable("SL_BETA_PASSWORD") ?? "";
94+
DirectoryInfo installationDirectory = new(Path.Combine(Environment.CurrentDirectory, "temp"));
95+
installationDirectory.Create();
96+
string filesPath = Path.Combine(installationDirectory.FullName, "files.txt");
97+
await File.WriteAllTextAsync(filesPath, "regex:SCPSL_Data/Managed/*");
98+
List<string> args = [ "-app", "996560", "-filelist", filesPath, "-dir", installationDirectory.FullName ];
99+
if (!string.IsNullOrEmpty(_beta)) {
100+
args.Add("-beta"); args.Add(_beta);
101+
if (!string.IsNullOrEmpty(_betaPassword)) {
102+
args.Add("-betapassword"); args.Add(_betaPassword);
103+
}
104+
}
105+
bool success = await DepotProgram.Main(args.ToArray()) == 0;
106+
if (!success) {
107+
ConsoleWriter.Write("An error occurred while downloading the files.", ConsoleColor.Red);
108+
return;
109+
}
110+
DirectoryInfo managedDirectory = new(Path.Combine(installationDirectory.FullName, "SCPSL_Data/Managed"));
111+
AssembliesPublicizer.RunPublicizer(managedDirectory);
112+
installationDirectory.Delete(true);
113+
}
114+
'@ -split "`n"
115+
$newContent = $content[0..($startIndex - 1)] + $replacement + $content[($endIndex + 1)..($content.Count - 1)]
116+
Set-Content -Path $path -Value $newContent
117+
73118
- name: Build SecretLabDependenciesBuilder
74119
run: |
75120
dotnet publish SecretLabDependenciesBuilder/SecretLabDependenciesBuilder/SecretLabDependenciesBuilder.csproj -c Release -r win-x64 --self-contained true -p:PublishSingleFile=true -o builder-out

0 commit comments

Comments
 (0)