Skip to content

Commit

Permalink
Changed: Cache the location of the current process.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sewer56 committed Apr 9, 2021
1 parent b3f4e31 commit 3ccd281
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion source/Reloaded.Mod.Loader/EntryPoint.cs
Expand Up @@ -63,7 +63,7 @@ private static void SetupLoader()
private static void CreateHost() => _server = new Host(_loader);
private static unsafe void PerformPeOperations()
{
_basicPeParser = new BasicPeParser(Process.GetCurrentProcess().MainModule.FileName);
_basicPeParser = new BasicPeParser(Environment.CurrentProcessLocation.Value);

// Check for Steam DRM.
DRMNotifier.PrintWarnings(_basicPeParser, _loader.Console);
Expand Down
2 changes: 1 addition & 1 deletion source/Reloaded.Mod.Loader/Loader.cs
Expand Up @@ -213,7 +213,7 @@ private HashSet<ModConfig> GetDependenciesForMods(IEnumerable<ModConfig> mods, I
private IApplicationConfig FindThisApplication()
{
var configurations = ApplicationConfig.GetAllApplications(LoaderConfig.ApplicationConfigDirectory);
var fullPath = NormalizePath(Path.GetFullPath(Process.GetCurrentProcess().MainModule.FileName));
var fullPath = NormalizePath(Environment.CurrentProcessLocation.Value);

foreach (var configuration in configurations)
{
Expand Down
7 changes: 7 additions & 0 deletions source/Reloaded.Mod.Shared/Environment.cs
@@ -1,4 +1,6 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;

namespace Reloaded.Mod.Shared
Expand All @@ -10,6 +12,11 @@ public static class Environment
/// </summary>
public static bool IsWine { get; private set; }

/// <summary>
/// Gets the full path to the current process.
/// </summary>
public static Lazy<string> CurrentProcessLocation { get; private set; } = new Lazy<string>(() => Path.GetFullPath(Process.GetCurrentProcess().MainModule.FileName));

static Environment()
{
var ntdll = GetModuleHandle("ntdll.dll");
Expand Down

0 comments on commit 3ccd281

Please sign in to comment.