Skip to content

Commit b0b947e

Browse files
committed
Add alternative for retrieving IPKey
- Added an alternative for retrieving the IPKey for the final build (win-x64, win-x86, linux-x64, osx-x64).
1 parent 5f3e111 commit b0b947e

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/Program.cs

+27-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.IO;
3+
using System.Threading.Tasks;
24
using Avalonia;
35
using Avalonia.ReactiveUI;
46
using FileTransfer.UtilityCollection;
@@ -11,9 +13,32 @@ internal static class Program
1113
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
1214
// yet and stuff might break.
1315
[STAThread]
14-
public static void Main(string[] args)
16+
public static async Task Main(string[] args)
1517
{
16-
Utilities.IPKey = args[0];
18+
if(args.Length > 0)
19+
Utilities.IPKey = args[0];
20+
else
21+
{
22+
string ipKeyPath = Path.Combine(Utilities.ExecutingAssemblyPath, "IPKey.txt");
23+
if (File.Exists(ipKeyPath))
24+
{
25+
string encryptedIpKey = await File.ReadAllTextAsync(ipKeyPath);
26+
string finalIpKey = string.Empty;
27+
foreach (char c in encryptedIpKey)
28+
{
29+
if (char.IsNumber(c))
30+
finalIpKey += Utilities.Cipher(c);
31+
else
32+
finalIpKey += c;
33+
}
34+
35+
Utilities.IPKey = finalIpKey;
36+
}
37+
else
38+
{
39+
throw new IOException($"File '{ipKeyPath}' doesn't exist!");
40+
}
41+
}
1742
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
1843
}
1944

src/UtilityCollection/UniversalUtilities.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ namespace FileTransfer.UtilityCollection;
1818
internal static partial class Utilities
1919
{
2020
internal const string AssetsPath = "avares://FileTransfer/Assets/";
21-
21+
22+
internal static string ExecutingAssemblyPath { get; } = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) ?? throw new DirectoryNotFoundException("Directory name of the currently executing assembly is null.");
23+
2224
/// <summary>
2325
/// The parent path of all settings- and data-files
2426
/// </summary>

0 commit comments

Comments
 (0)