Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't try and install the WASM module for MSFS versions that aren't installed #1868

Merged
merged 7 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The caller now logs this based on the return value so different log messages can be sent based on the simulator version.

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