Skip to content

Commit

Permalink
Don't try and install the WASM module for MSFS versions that aren't i…
Browse files Browse the repository at this point in the history
…nstalled (#1868)

* Skip WASM install for non-installed MSFS versions
Fixes #1867

* Add an info message for skipped installs

* Log a message if the install is up-to-date.

* Add successfull instal log message

* Early return best return
  • Loading branch information
neilenns authored Dec 2, 2024
1 parent 976e8c1 commit 0a3df96
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 15 deletions.
3 changes: 1 addition & 2 deletions SimConnectMSFS/WasmModuleUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ public bool InstallWasmModule(string communityFolder)
// Remove the old Wasm File
DeleteOldWasmFile(communityFolder);

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

Expand Down Expand Up @@ -188,7 +187,7 @@ public bool WasmModulesAreDifferent(string communityFolder)
string installedWASM;
string mobiflightWASM;

if (communityFolder == null) return true;
if (String.IsNullOrEmpty(communityFolder)) return true;

string wasmModulePath = Path.Combine(communityFolder, @"mobiflight-event-module\modules\", WasmModuleName);
if (!File.Exists(wasmModulePath))
Expand Down
52 changes: 39 additions & 13 deletions UI/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2118,7 +2118,8 @@ private static void InstallWasmModule()
bool Update2020Successful = false;
bool Update2024Successful = false;

try {
try
{

if (!updater.AutoDetectCommunityFolder())
{
Expand All @@ -2142,17 +2143,9 @@ private static void InstallWasmModule()
return;
}

// Try updating the 2020 install
if (Is2020Different)
{
Update2020Successful = updater.InstallWasmModule(updater.CommunityFolder);
}

// Try updating the 2024 install
if (Is2024Different)
{
Update2024Successful = updater.InstallWasmModule(updater.CommunityFolder2024);
}
// Install for both versions
Update2020Successful = HandleWasmInstall(updater, Is2020Different, updater.CommunityFolder, "2020");
Update2024Successful = HandleWasmInstall(updater, Is2024Different, updater.CommunityFolder2024, "2024");

// If either update is successful then show the success dialog.
if (Update2020Successful || Update2024Successful)
Expand All @@ -2164,7 +2157,8 @@ private static void InstallWasmModule()

return;
}
} catch (Exception ex) {
}
catch (Exception ex) {
Log.Instance.log(ex.Message, LogSeverity.Error);
}

Expand All @@ -2175,6 +2169,38 @@ private static void InstallWasmModule()
MessageBoxButtons.OK, MessageBoxIcon.Error);
}

/// <summary>
/// Handles all the necessary and log messages for installing the WASM with different versions of MSFS.
/// </summary>
/// <param name="updater">The WASM updater to use</param>
/// <param name="isDifferent">True if the versions of WASM were different</param>
/// <param name="communityFolder">The path to the community folder</param>
/// <param name="msfsVersion">The version of MSFS, either "2020" or "2024"</param>
/// <returns></returns>
private static bool HandleWasmInstall(WasmModuleUpdater updater, bool isDifferent, string communityFolder, string msfsVersion)
{
if (String.IsNullOrEmpty(communityFolder))
{
Log.Instance.log($"Skipping WASM install for MSFS{msfsVersion} since no community folder was found. This likely means MSFS{msfsVersion} is not installed.", LogSeverity.Info);
return false;
}

if (!isDifferent)
{
Log.Instance.log($"WASM module for MSFS{msfsVersion} is already up-to-date.", LogSeverity.Info);
return false;
}

bool result = updater.InstallWasmModule(communityFolder);

if (result)
{
Log.Instance.log($"Successfully installed WASM module for MSFS{msfsVersion}.", LogSeverity.Info);
}

return result;
}

private void downloadLatestEventsToolStripMenuItem_Click(object sender, EventArgs e)
{
WasmModuleUpdater updater = new WasmModuleUpdater();
Expand Down

0 comments on commit 0a3df96

Please sign in to comment.