videre-project / MTGOSDK

A software development kit (SDK) for inspecting and interacting with the Magic: The Gathering Online (MTGO) client.
Apache License 2.0
9 stars 1 forks source link

Custom ClickOnce Launcher #25

Closed Qonfused closed 1 month ago

Qonfused commented 1 month ago

Rather than invoking the ClickOnce installer for MTGO, it's possible instead to perform the same verification and installation using ClickOnce's InPlaceHostingManager class. This way, we can assert that the MTGO manifest is pre-trusted

https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2015/deployment/walkthrough-creating-a-custom-installer-for-a-clickonce-application?view=vs-2015&redirectedfrom=MSDN

using System.Deployment.Application;  
using System.Windows.Forms;

Uri deploymentUri = new Uri(deployManifestUriStr);
InPlaceHostingManager iphm = new (deploymentUri, false);

iphm.GetManifestCompleted += iphm_GetManifestCompleted;
iphm.GetManifestAsync();

void iphm_GetManifestCompleted(object sender, GetManifestCompletedEventArgs e)
{
  if (e.Error != null)
    throw new Exception("Could not download manifest. Error: " + e.Error.Message);

  // Verify and grant permissions specified in the application manifest.
  iphm.AssertApplicationRequirements(true);

  // Download the deployment manifest. 
  iphm.DownloadProgressChanged += iphm_DownloadProgressChanged;
  iphm.DownloadApplicationCompleted += iphm_DownloadApplicationCompleted;
  iphm.DownloadApplicationAsync();
}
Qonfused commented 1 month ago

Added in 670e248e7a6a145066160f67758f28d4eb730ee6.