diff --git a/.github/scripts/inject-token.ps1 b/.github/scripts/inject-token.ps1 index f23310325..ac3df9f9b 100644 --- a/.github/scripts/inject-token.ps1 +++ b/.github/scripts/inject-token.ps1 @@ -26,9 +26,16 @@ $dataStr = ($obfuscated | ForEach-Object { "0x{0:x2}" -f $_ }) -join ", " $keyStr = ($key | ForEach-Object { "0x{0:x2}" -f $_ }) -join ", " $content = Get-Content $constantsPath -Raw -# Replace the placeholders we put in the static property -$content = $content -replace 'byte\[\] data = \[\]; // \[PLACEHOLDER_DATA\]', "byte[] data = [$dataStr];" -$content = $content -replace 'byte\[\] key = \[\]; // \[PLACEHOLDER_KEY\]', "byte[] key = [$keyStr];" + +# Use regex replace to be robust against whitespace +# Pattern: byte[] data = []; // [PLACEHOLDER_DATA] +$content = [System.Text.RegularExpressions.Regex]::Replace($content, 'byte\[\]\s+data\s*=\s*\[\];\s*//\s*\[PLACEHOLDER_DATA\]', "byte[] data = [$dataStr];") +$content = [System.Text.RegularExpressions.Regex]::Replace($content, 'byte\[\]\s+key\s*=\s*\[\];\s*//\s*\[PLACEHOLDER_KEY\]', "byte[] key = [$keyStr];") + +if ($content -notmatch "0x") { + Write-Error "Token injection failed! Placeholders were not found or replaced." + exit 1 +} Set-Content $constantsPath $content Write-Host "Successfully injected and obfuscated UPLOADTHING_TOKEN into ApiConstants.cs" diff --git a/GenHub/GenHub.Windows/Program.cs b/GenHub/GenHub.Windows/Program.cs index 55e86e1f0..636c13be3 100644 --- a/GenHub/GenHub.Windows/Program.cs +++ b/GenHub/GenHub.Windows/Program.cs @@ -36,10 +36,35 @@ public static void Main(string[] args) // Load environment variables (locally) try { - Env.TraversePath().Load(); + // TraversePath() uses CWD by default. Use BaseDirectory to be sure we start from where the exe is. + var binDir = AppContext.BaseDirectory; + var path = binDir; + var found = false; + + // Search up to 6 levels up + for (int i = 0; i < 6; i++) + { + if (System.IO.File.Exists(System.IO.Path.Combine(path, ".env"))) + { + Env.Load(System.IO.Path.Combine(path, ".env")); + found = true; + break; + } + + var parent = System.IO.Directory.GetParent(path); + if (parent == null) break; + path = parent.FullName; + } + + if (!found) + { + // Fallback to DotNetEnv default traversal just in case + Env.TraversePath().Load(); + } } catch (Exception ex) { + Console.WriteLine($"Failed to load environment variables: {ex}"); System.Diagnostics.Debug.WriteLine($"Failed to load environment variables: {ex}"); }