|
| 1 | +using System.Runtime.InteropServices; |
| 2 | + |
| 3 | +namespace EliteAPI.Journals; |
| 4 | + |
| 5 | +public static class JournalUtils |
| 6 | +{ |
| 7 | + public static DirectoryInfo GetJournalsDirectory() |
| 8 | + { |
| 9 | + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) |
| 10 | + { |
| 11 | + // on windows, use registry |
| 12 | + var result = SHGetKnownFolderPath( |
| 13 | + new Guid("4C5C32FF-BB9D-43B0-B5B4-2D72E54EAAA4"), |
| 14 | + 0, |
| 15 | + new IntPtr(0), |
| 16 | + out var path); |
| 17 | + |
| 18 | + if (result == 0 && path != IntPtr.Zero) |
| 19 | + { |
| 20 | + var folderPath = Marshal.PtrToStringUni(path); |
| 21 | + if (!string.IsNullOrWhiteSpace(folderPath)) |
| 22 | + return new DirectoryInfo(Path.Combine(folderPath, "Frontier Developments", "Elite Dangerous")); |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + // get through userprofile |
| 27 | + var userProfile = Environment.GetEnvironmentVariable("USERPROFILE"); |
| 28 | + if (!string.IsNullOrWhiteSpace(userProfile)) |
| 29 | + return new DirectoryInfo(Path.Combine(userProfile, "Saved Games", "Frontier Developments", "Elite Dangerous")); |
| 30 | + |
| 31 | + // last resort, hardcoded with C:\ drive, hopefully we'll neve reach this.. |
| 32 | + return new DirectoryInfo(Path.Combine($@"C:\Users\{Environment.UserName}\Saved Games\Frontier Developments\Elite Dangerous")); |
| 33 | + } |
| 34 | + |
| 35 | + [DllImport("Shell32.dll")] |
| 36 | + private static extern int SHGetKnownFolderPath([MarshalAs(UnmanagedType.LPStruct)] Guid rfid, uint dwFlags, |
| 37 | + IntPtr hToken, out IntPtr path); |
| 38 | +} |
0 commit comments