-
-
Save EQAditu/e58bd92181a3ad42c333e5296bc8d44a to your computer and use it in GitHub Desktop.
A standalone plugin(snippet) that checks version information and extracts a ZIP download
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void InitPlugin(TabPage pluginScreenSpace, Label pluginStatusText) | |
{ | |
ActGlobals.oFormActMain.UpdateCheckClicked += oFormActMain_UpdateCheckClicked; | |
if (ActGlobals.oFormActMain.GetAutomaticUpdatesAllowed()) // If ACT is set to automatically check for updates, check for updates to the plugin | |
new Thread(new ThreadStart(oFormActMain_UpdateCheckClicked)) { IsBackground = true }.Start(); // If we don't put this on a separate thread, web latency will delay the plugin init phase | |
} | |
public void DeInitPlugin() | |
{ | |
ActGlobals.oFormActMain.UpdateCheckClicked -= oFormActMain_UpdateCheckClicked; | |
} | |
void oFormActMain_UpdateCheckClicked() | |
{ | |
int pluginId = 999; // This ID must be the same ID used on ACT's website. | |
try | |
{ | |
Version localVersion = this.GetType().Assembly.GetName().Version; | |
Version remoteVersion = new Version(ActGlobals.oFormActMain.PluginGetRemoteVersion(pluginId).TrimStart(new char[] { 'v' })); // Strip any leading 'v' from the string before passing to the Version constructor | |
if (remoteVersion > localVersion) | |
{ | |
Action updateAction = new Action(() => // Action we perform when told to update | |
{ | |
// You could use a MessageBox for this as well | |
TraySlider slider = new TraySlider(); | |
slider.ShowDurationMs = 60000; | |
slider.ButtonLayout = TraySlider.ButtonLayoutEnum.TwoButton; | |
slider.ButtonSE.Text = "Ignore"; | |
slider.ButtonSW.Text = "Update"; | |
slider.ButtonSW.Click += (s, e) => | |
{ | |
FileInfo updatedFile = ActGlobals.oFormActMain.PluginDownload(pluginId); | |
ActPluginData pluginData = ActGlobals.oFormActMain.PluginGetSelfData(this); | |
pluginData.pluginFile.Delete(); | |
ActGlobals.oFormActMain.UnZip(updatedFile.FullName, pluginData.pluginFile.DirectoryName); | |
// You can choose to simply restart the plugin, if the plugin can properly clean-up in DeInit and has no external assemblies that update | |
ThreadInvokes.CheckboxSetChecked(ActGlobals.oFormActMain, pluginData.cbEnabled, false); // Deinit the old plugin | |
Application.DoEvents(); | |
ThreadInvokes.CheckboxSetChecked(ActGlobals.oFormActMain, pluginData.cbEnabled, true); // Init the new version | |
// OR, you can request that ACT be restarted when the user accepts | |
ActGlobals.oFormActMain.RestartACT(true, "The PLUGINNAME plugin requires ACT to be restarted to work properly."); | |
}; | |
slider.ShowTraySlider("There is an updated version of the PLUGINNAME Plugin. Update it now?\n\n(If there is an update to ACT, you should click No and update ACT first.)", "New Version"); | |
}); | |
if (ActGlobals.oFormActMain.InvokeRequired) // TraySliders must be created on the UI thread | |
ActGlobals.oFormActMain.Invoke(updateAction); | |
else | |
updateAction.Invoke(); | |
} | |
} | |
catch (Exception ex) | |
{ | |
ActGlobals.oFormActMain.WriteExceptionLog(ex, "Plugin Update Check"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment