Skip to content

Commit

Permalink
Fix that SimConnect.cfg was being copied into the wrong folder when p…
Browse files Browse the repository at this point in the history
…lugin runs from TP.
  • Loading branch information
mpaperno committed Apr 18, 2022
1 parent 04a73a0 commit 1cf22dc
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions MSFSTouchPortalPlugin/Configuration/PluginConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal class PluginConfig
public static string SimVarsImportsFile { get; set; } = "SimVariables.ini";
public static string SimEventsImportsFile { get; set; } = "SimEvents.ini";

public static string AppRootFolder { get; set; } = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
public static string AppRootFolder { get; set; } = Path.GetDirectoryName(AppContext.BaseDirectory);
public static string AppConfigFolder { get; set; } = Path.Combine(AppRootFolder, "Configuration");

public static string UserConfigFolder {
Expand Down Expand Up @@ -206,18 +206,21 @@ public bool TryGetImportedSimEventIdFromSelector(string selector, out string eve
public bool CopySimConnectConfig() {
string filename = "SimConnect.cfg";
string srcFile = Path.Combine(UserConfigFolder, filename);
bool ret = File.Exists(srcFile);
if (!ret && Directory.GetCurrentDirectory() != AppRootFolder)
srcFile = Path.Combine(AppRootFolder, filename);

if (File.Exists(srcFile)) {
try {
File.Copy(srcFile, Path.Combine(AppRootFolder, filename), true);
_logger.LogInformation($"Using custom SimConnect.cfg file from '{UserConfigFolder}'.");
return true;
File.Copy(srcFile, Path.Combine(Directory.GetCurrentDirectory(), filename), true);
_logger.LogInformation($"Copied SimConnect.cfg file from '{srcFile}'.");
}
catch (Exception e) {
_logger.LogError($"Error trying to copy SimConnect.cfg file from '{srcFile}': {e.Message}");
return false;
ret = false;
}
}
return false;
return ret;
}

// Loads an individual sim var states config file, either from user's config folder, the default app config location, or a full file path
Expand Down

0 comments on commit 1cf22dc

Please sign in to comment.