-
-
Save EQAditu/4d6e3a1945fed2199f235fedc1e3ec56 to your computer and use it in GitHub Desktop.
A standalone ACT plugin self-updating by date
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 | |
{ | |
DateTime localDate = ActGlobals.oFormActMain.PluginGetSelfDateUtc(this); | |
DateTime remoteDate = ActGlobals.oFormActMain.PluginGetRemoteDateUtc(pluginId); | |
if (localDate.AddHours(2) < remoteDate) | |
{ | |
DialogResult result = MessageBox.Show("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", MessageBoxButtons.YesNo, MessageBoxIcon.Question); | |
if (result == DialogResult.Yes) | |
{ | |
FileInfo updatedFile = ActGlobals.oFormActMain.PluginDownload(pluginId); | |
ActPluginData pluginData = ActGlobals.oFormActMain.PluginGetSelfData(this); | |
pluginData.pluginFile.Delete(); | |
updatedFile.MoveTo(pluginData.pluginFile.FullName); | |
// 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 requires ACT to be restarted to work properly."); | |
} | |
} | |
} | |
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