Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions .github/scripts/inject-token.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
27 changes: 26 additions & 1 deletion GenHub/GenHub.Windows/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}

Expand Down