Skip to content

Commit

Permalink
Add support for MSFS2024 (#1825)
Browse files Browse the repository at this point in the history
* Install WASM in 2024 folders. 
* Update UI strings
* Use simpler strings for MSFS
* Add manual script for 2024
  • Loading branch information
neilenns authored Nov 21, 2024
1 parent 29ef81e commit bbc6071
Show file tree
Hide file tree
Showing 19 changed files with 4,607 additions and 4,514 deletions.
2 changes: 1 addition & 1 deletion MSFS2020-module/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ Simply copy the whole folder

mobiflight-event-module

into your MSFS2020 Community Folder, e.g. C:\MSFS2020\Community
into your MSFS2020 Community Folder (e.g. C:\MSFS2020\Community) or your MSFS2024 Community Folder (e.g. C:\MSFS2024\Community)
29 changes: 29 additions & 0 deletions MSFS2020-module/install-mobiflight-event-module-2024.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
setLocal EnableDelayedExpansion
@echo off
IF EXIST "%LOCALAPPDATA%\Packages\Microsoft.LimitlessBeta_8wekyb3d8bbwe\LocalCache\UserCfg.opt" (
echo store version
SET TOSEARCH="%LOCALAPPDATA%\Packages\Microsoft.Limitless_8wekyb3d8bbwe\LocalCache\UserCfg.opt"
) ELSE (
echo normal version
SET TOSEARCH="%appdata%\Microsoft Flight Simulator 2024\UserCfg.opt"
)
IF EXIST %TOSEARCH% (
for /f "delims=" %%i in ('findstr "InstalledPackagesPath " %TOSEARCH%') do (
SET RESULT=%%i
)
echo found !RESULT!
SET RESULT=!RESULT:~23!
SET RESULT=!RESULT:~0,-1!
echo transform !RESULT!
IF EXIST !RESULT!\Community\ (
xcopy /F /R /Y /E /C .\mobiflight-event-module !RESULT!\Community\mobiflight-event-module\
exit 0
) ELSE (
echo ERROR Community folder not found...
)
) ELSE (
echo ERROR MSFS2020 config file not found...
)
pause
exit 0

10 changes: 10 additions & 0 deletions MobiFlight/FlightSim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ static public bool IsAvailable()
return true;
}

proc = "flightsimulator2024";
// check for msfs2024
if (Process.GetProcessesByName(proc).Length > 0)
{
FlightSimConnectionMethod = FlightSimConnectionMethod.FSUIPC;
FlightSimType = FlightSimType.MSFS2020;
return true;
}

proc = "wideclient";
// check for FSUIPC wide client
if (Process.GetProcessesByName(proc).Length > 0)
Expand All @@ -94,6 +103,7 @@ static public bool IsAvailable()
FlightSimType = FlightSimType.UNKNOWN;
return true;
}

// check for prepar3d
proc = "prepar3d";
if (Process.GetProcessesByName(proc).Length > 0)
Expand Down
2 changes: 1 addition & 1 deletion MobiFlight/InputConfig/MSFS2020CustomInputAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace MobiFlight.InputConfig
{
public class MSFS2020CustomInputAction : InputAction, ICloneable
{
public new const String Label = "Microsoft Flight Simulator 2020";
public new const String Label = "Microsoft Flight Simulator";
public new const String CacheType = "SimConnect";
public const String TYPE = "MSFS2020CustomInputAction";
public String Command;
Expand Down
2 changes: 1 addition & 1 deletion ProjectMessages/ProjectMessages.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ProjectMessages/ProjectMessages.de.resx
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,8 @@ Du kannst es jederzeit wieder in den Einstellungen aktivieren </value>
<value>Du hast das aktuelle MobiFlight WASM Modul bereits installiert.</value>
</data>
<data name="uiMessageWasmUpdateCommunityFolderNotFound" xml:space="preserve">
<value>MSFS2020 Community Verzeichnis nicht gefunden. WASM Module kann nicht automatisch kopiert werden. Bitte kopiere das Verzeichnis manuell an die richtige Stelle.</value>
<comment>MSFS2020 Community Folder was not found. Can't install WASM Module automatically. Please copy the folder manually.</comment>
<value>Microsoft Flight Simulator Community Verzeichnis nicht gefunden. WASM Module kann nicht automatisch kopiert werden. Bitte kopiere das Verzeichnis manuell an die richtige Stelle.</value>
<comment>Microsoft Flight Simulator Community Folder was not found. Can't install WASM Module automatically. Please copy the folder manually.</comment>
</data>
<data name="uiMessageWasmUpdateInstallationError" xml:space="preserve">
<value>MobiFlight WASM Module konnte nicht installiert werden. Bitte checke das Log für weitere Details.</value>
Expand Down
2 changes: 1 addition & 1 deletion ProjectMessages/ProjectMessages.resx
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ You can always enable it later again in the settings menu.</value>
<value>MobiFlight WASM Module is already installed and up-to-date.</value>
</data>
<data name="uiMessageWasmUpdateCommunityFolderNotFound" xml:space="preserve">
<value>MSFS2020 Community Folder was not found. Can't install WASM Module automatically. Please copy the folder manually.</value>
<value>Microsoft Flight Simulator Community Folder was not found. Can't install WASM Module automatically. Please copy the folder manually.</value>
</data>
<data name="uiMessageWasmUpdateInstallationError" xml:space="preserve">
<value>MobiFlight WASM Module was not installed successfully. Please check the Log for more information.</value>
Expand Down
2 changes: 1 addition & 1 deletion SimConnectMSFS/SimConnectCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public bool Connect()
// Listen to exceptions
m_oSimConnect.OnRecvException += new SimConnect.RecvExceptionEventHandler(SimConnect_OnRecvException);
// Listen to exceptions
Log.Instance.log("SimConnect (MSFS2020) instantiated", LogSeverity.Debug);
Log.Instance.log("SimConnect (MSFS) instantiated", LogSeverity.Debug);
}
}
catch (COMException ex)
Expand Down
78 changes: 55 additions & 23 deletions SimConnectMSFS/WasmModuleUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ public class WasmModuleUpdater
public event EventHandler<ProgressUpdateEvent> DownloadAndInstallProgress;

public String CommunityFolder { get; set; }
public string CommunityFolder2024 { get; set; }

private String ExtractCommunityFolderFromUserCfg(String UserCfg)
{
Log.Instance.log($"Attempting to extract community folder path from {UserCfg}", LogSeverity.Debug);

string CommunityFolder = null;
string line;
string InstalledPackagesPath = "";
Expand All @@ -63,58 +66,87 @@ private String ExtractCommunityFolderFromUserCfg(String UserCfg)
char[] charsToTrim = { '"' };

InstalledPackagesPath = InstalledPackagesPath.TrimEnd(charsToTrim);

if (Directory.Exists(InstalledPackagesPath + @"\Community"))

string targetPath = Path.Combine(Path.Combine(InstalledPackagesPath, @"Community"));

Log.Instance.log($"Detected community folder path from UserCfg.opt: {targetPath}", LogSeverity.Debug);

if (Directory.Exists(targetPath))
{
CommunityFolder = InstalledPackagesPath + @"\Community";
CommunityFolder = targetPath;
}

return CommunityFolder;
}

public bool AutoDetectCommunityFolder()
{
string searchpath = Environment.GetEnvironmentVariable("AppData") + @"\Microsoft Flight Simulator\UserCfg.opt";
Log.Instance.log("Attempting to auto-detect community folder location for MSFS 2020", LogSeverity.Debug);
// Find the 2020 community folder
CommunityFolder = ExtractCommunityFolderPath(new string[] {
Path.Combine(Environment.GetEnvironmentVariable("AppData"), "Microsoft Flight Simulator"),
Path.Combine(Environment.GetEnvironmentVariable("LocalAppData"), @"Packages\Microsoft.FlightSimulator_8wekyb3d8bbwe\LocalCache\") }
);

Log.Instance.log("Attempting to auto-detect community folder location for MSFS 2024", LogSeverity.Debug);
// Find the 2024 community folder
CommunityFolder2024 = ExtractCommunityFolderPath(new string[] {
Path.Combine(Environment.GetEnvironmentVariable("AppData"), "Microsoft Flight Simulator 2024"),
Path.Combine(Environment.GetEnvironmentVariable("LocalAppData"), @"Packages\Microsoft.Limitless_8wekyb3d8bbwe\LocalCache\") }
);

return CommunityFolder != null || CommunityFolder2024 != null;
}

if (!File.Exists(searchpath))
/// <summary>
/// Finds the community folder path inside the UserCfg.opt file
/// </summary>
/// <param name="basePaths">An array of paths to search for the UserCfg.opts file in</param>
/// <returns>The path to the community folder or null if not found</returns>
private string ExtractCommunityFolderPath(string[] basePaths)
{
foreach (string basePath in basePaths)
{
searchpath = Environment.GetEnvironmentVariable("LocalAppData") + @"\Packages\Microsoft.FlightSimulator_8wekyb3d8bbwe\LocalCache\UserCfg.opt";
if (!File.Exists(searchpath))
string userCfgPath = Path.Combine(basePath, "UserCfg.opt");
if (!File.Exists(userCfgPath))
{
return false;
Log.Instance.log($"No UserCfg found at {userCfgPath}", LogSeverity.Debug);
continue;
}

return ExtractCommunityFolderFromUserCfg(userCfgPath);
}

CommunityFolder = ExtractCommunityFolderFromUserCfg(searchpath);
return true;
return null;
}

public bool InstallWasmModule()
public bool InstallWasmModule(string communityFolder)
{
if (!Directory.Exists(WasmModuleFolder))
{
Log.Instance.log($"WASM module cannot be installed. WASM module folder {WasmModuleFolder} not found.", LogSeverity.Error);
Log.Instance.log($"WASM module cannot be installed. WASM module folder '{WasmModuleFolder}' not found.", LogSeverity.Error);
return false;
}

if (!Directory.Exists(CommunityFolder))
if (!Directory.Exists(communityFolder))
{
Log.Instance.log($"WASM module cannot be installed. Community folder {CommunityFolder} not found.", LogSeverity.Error);
Log.Instance.log($"WASM module cannot be installed. Community folder '{communityFolder}' not found.", LogSeverity.Error);
return false;
}

String destFolder = CommunityFolder + @"\mobiflight-event-module";
String destFolder = Path.Combine(communityFolder, @"mobiflight-event-module");
CopyFolder(new DirectoryInfo(WasmModuleFolder), new DirectoryInfo(destFolder));

// Remove the old Wasm File
DeleteOldWasmFile();
DeleteOldWasmFile(communityFolder);

Log.Instance.log("WASM module has been installed successfully.", LogSeverity.Info);
return true;
}

private void DeleteOldWasmFile()
private void DeleteOldWasmFile(string communityFolder)
{
String installedWASM = CommunityFolder + $@"\mobiflight-event-module\modules\{WasmModuleNameOld}";
String installedWASM = Path.Combine(communityFolder, @"mobiflight-event-module\modules", WasmModuleNameOld);
if(System.IO.File.Exists(installedWASM))
System.IO.File.Delete(installedWASM);
}
Expand Down Expand Up @@ -149,23 +181,23 @@ static string CalculateMD5(string filename)
}
}

public bool WasmModulesAreDifferent()
public bool WasmModulesAreDifferent(string communityFolder)
{
Console.WriteLine("Check if WASM module needs to be updated");

string installedWASM;
string mobiflightWASM;

if (CommunityFolder == null) return true;
if (communityFolder == null) return true;

string wasmModulePath = Path.Combine(CommunityFolder, @"mobiflight-event-module\modules\", WasmModuleName);
string wasmModulePath = Path.Combine(communityFolder, @"mobiflight-event-module\modules\", WasmModuleName);
if (!File.Exists(wasmModulePath))
{
return true;
}

installedWASM = CalculateMD5(CommunityFolder + $@"\mobiflight-event-module\modules\{WasmModuleName}");
mobiflightWASM = CalculateMD5($@".\MSFS2020-module\mobiflight-event-module\modules\{WasmModuleName}");
installedWASM = CalculateMD5(Path.Combine(communityFolder, @"mobiflight-event-module\modules\", WasmModuleName));
mobiflightWASM = CalculateMD5(Path.Combine(@".\MSFS2020-module\mobiflight-event-module\modules\", WasmModuleName));

return installedWASM != mobiflightWASM;
}
Expand Down
2 changes: 1 addition & 1 deletion UI/Dialogs/CommunityFeedbackStartupForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -7147,7 +7147,7 @@
</value>
</data>
<data name="$this.Text" xml:space="preserve">
<value>MobiFlight Support for MSFS2020 </value>
<value>MobiFlight Support for Microsoft Flight Simulator </value>
</data>
<data name="&gt;&gt;$this.Name" xml:space="preserve">
<value>CommunityFeedbackStartupForm</value>
Expand Down
10 changes: 5 additions & 5 deletions UI/Dialogs/ConfigWizard.resx
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@
<value>NoControl</value>
</data>
<data name="OffsetTypeVariableRadioButton.Location" type="System.Drawing.Point, System.Drawing">
<value>270, 5</value>
<value>242, 5</value>
</data>
<data name="OffsetTypeVariableRadioButton.Size" type="System.Drawing.Size, System.Drawing">
<value>114, 17</value>
Expand Down Expand Up @@ -373,13 +373,13 @@
<value>119, 5</value>
</data>
<data name="OffsetTypeSimConnectRadioButton.Size" type="System.Drawing.Size, System.Drawing">
<value>144, 17</value>
<value>120, 17</value>
</data>
<data name="OffsetTypeSimConnectRadioButton.TabIndex" type="System.Int32, mscorlib">
<value>1</value>
</data>
<data name="OffsetTypeSimConnectRadioButton.Text" xml:space="preserve">
<value>SimConnect (MSFS2020)</value>
<value>SimConnect (MSFS)</value>
</data>
<data name="&gt;&gt;OffsetTypeSimConnectRadioButton.Name" xml:space="preserve">
<value>OffsetTypeSimConnectRadioButton</value>
Expand All @@ -400,7 +400,7 @@
<value>NoControl</value>
</data>
<data name="OffsetTypeFsuipRadioButton.Location" type="System.Drawing.Point, System.Drawing">
<value>390, 5</value>
<value>362, 5</value>
</data>
<data name="OffsetTypeFsuipRadioButton.Size" type="System.Drawing.Size, System.Drawing">
<value>94, 17</value>
Expand Down Expand Up @@ -430,7 +430,7 @@
<value>NoControl</value>
</data>
<data name="OffsetTypeXplaneRadioButton.Location" type="System.Drawing.Point, System.Drawing">
<value>496, 5</value>
<value>468, 5</value>
</data>
<data name="OffsetTypeXplaneRadioButton.Size" type="System.Drawing.Size, System.Drawing">
<value>105, 17</value>
Expand Down
7 changes: 4 additions & 3 deletions UI/Dialogs/Msfs2020StartupForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit bbc6071

Please sign in to comment.