No App Exit
Hi, im trying to use this to update some depend files on a ZIP, Exiting the App is NOT desired.
AutoUpdater.ReportErrors = true;
AutoUpdater.CheckForUpdateEvent += AutoUpdater_MODUpdateEvent;
AutoUpdater.ApplicationExitEvent += AutoUpdater_ApplicationExitEvent;
AutoUpdater.InstalledVersion = new Version(InstalledVersion);
AutoUpdater.DownloadPath = Path.Combine(System.IO.Path.GetTempPath(), "EDHM_UI");
AutoUpdater.InstallationPath = Path.Combine(this.AppExePath, "Updates");
AutoUpdater.RunUpdateAsAdmin = false;
AutoUpdater.Synchronous = true;
Im handling the Update Event as instructed:
if (AutoUpdater.DownloadUpdate(args))
{
#SomeCode:
}
The problem is that it never gets to #SomeCode tag, the Application Exits itself, idk why. Im even handling the
private void AutoUpdater_ApplicationExitEvent()
{
string version_info = Path.Combine(this.AppExePath, @"Updates\version.info");
if (File.Exists(version_info))
{
//This part NEVER gets executed:
string ver = Util.ReadTextFile(version_info, Util.TextEncoding.UTF8);
string _Instance = this.ActiveInstance.key == "ED_Horizons" ? "HORIZ" : "ODYSS";
string _FileName = string.Format("{0}_EDHM_Version", _Instance);
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings[_FileName].Value = ver;
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
}
InstallGameInstance(this.ActiveInstance);
//Application.Exit();
}
But it never gets into that.
How do i disable the EXIT ? or what am i doing wrong?
Thanks.
Does it successfully download the application? Do you see the downloaded file at download location? ApplicationExitEvent won't work because you are handling the update using the event. You have to move code inside it after "#SomeCode:".
Yes, it downloads the ZIP file and Closes the App inmediatelly. i indeed put code in the "#SomeCode:" but as i told u, the App closes itself right after the download is finish and whatever in the "#SomeCode:" does not get the chance to be executed
OK, i tried something, in the XML i had set 'Mandatory' to true, i now set it as 'false', the code inside "#SomeCode" now gets executed, the content of the ZIP file even gets extracted as it should, but i get this:
Then the App Closes itself even when i have not set any explicit .Close() method, is it possible to NOT close the App?
ZipExtractor is designed to not work without closing the app, so you must have to remove these lines and compile the library. The whole library is designed to download the update, close the app, extract the zip file into an executable directory or into the installation path and then reopen the executable.
Also, if you're trying this in a dummy console app, then you must use something like Console.ReadKey() to prevent it from exiting after execution of the app logic.
Thanks, ill do that, and if may i suggest to add a boolean property like this:
public bool CloseApplication { get; set; }
Then..
if (this.CloseApplication)
{
foreach (var process in Process.GetProcessesByName(Path.GetFileNameWithoutExtension(executablePath)))
{
try
{
if (process.MainModule is { FileName: { } } && process.MainModule.FileName.Equals(executablePath))
{
_logBuilder.AppendLine("Waiting for application process to exit...");
_backgroundWorker.ReportProgress(0, "Waiting for application to exit...");
process.WaitForExit();
}
}
catch (Exception exception)
{
Debug.WriteLine(exception.Message);
}
}
}
Default will be true but, not necessary to close the App when patching additional files.
If I add it, then I have to stop it from existing from other places too. If this feature has enough attention, then I may implement it.
