-
Notifications
You must be signed in to change notification settings - Fork 23
Allow to Install When Closing Revit #137
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,11 +30,7 @@ private async void Button_ClickAsync(object sender, RoutedEventArgs e) | |
| { | ||
| this.Hide(); | ||
|
|
||
| string tempPath = Path.GetTempPath(); | ||
| string tempFolder = System.IO.Path.Combine(tempPath, "LeiaInstaller"); | ||
| string versionFolder = System.IO.Path.Combine(tempFolder, _fileVersion); | ||
| DirectoryUtils.CreateDirectoryIfNotExists(versionFolder); | ||
| DirectoryUtils.DeleteFilesInDirectoyy(versionFolder); | ||
| string versionFolder = VersionFolder(); | ||
| await DownloadFile.FromServer(versionFolder, _installerName); | ||
|
|
||
| string fileLocation = System.IO.Path.Combine(versionFolder, _installerName);; | ||
|
|
@@ -43,6 +39,28 @@ private async void Button_ClickAsync(object sender, RoutedEventArgs e) | |
| Close(); | ||
| } | ||
|
|
||
|
|
||
| private async void Button_UpdateOnExit(object sender, RoutedEventArgs e) | ||
| { | ||
| this.Hide(); | ||
| string versionFolder = VersionFolder(); | ||
| await DownloadFile.FromServer(versionFolder, _installerName); | ||
|
|
||
| string fileLocation = System.IO.Path.Combine(versionFolder, _installerName); | ||
| ExternalApplication.InstallerRoute = fileLocation; | ||
| Close(); | ||
| } | ||
|
Comment on lines
+43
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical timing issue: Window closes before download completes. The window is hidden immediately (line 45) and then closed (line 51), but the download is awaited in between (line 47). This creates several problems:
Consider one of these approaches: Option 1 (Recommended): Keep window visible with progress feedback: private async void Button_UpdateOnExit(object sender, RoutedEventArgs e)
{
- this.Hide();
+ labelMessage.Text = "Downloading installer...";
+ CloseButton.IsEnabled = false;
string versionFolder = VersionFolder();
await DownloadFile.FromServer(versionFolder, _installerName);
string fileLocation = System.IO.Path.Combine(versionFolder, _installerName);
ExternalApplication.InstallerRoute = fileLocation;
+ labelMessage.Text = "Update will install when you close Revit.";
+ await Task.Delay(2000); // Brief confirmation
Close();
}Option 2: Start download as fire-and-forget background task (not recommended due to reliability concerns): private void Button_UpdateOnExit(object sender, RoutedEventArgs e)
{
string versionFolder = VersionFolder();
- await DownloadFile.FromServer(versionFolder, _installerName);
-
- string fileLocation = System.IO.Path.Combine(versionFolder, _installerName);
- ExternalApplication.InstallerRoute = fileLocation;
+ Task.Run(async () => {
+ await DownloadFile.FromServer(versionFolder, _installerName);
+ string fileLocation = System.IO.Path.Combine(versionFolder, _installerName);
+ ExternalApplication.InstallerRoute = fileLocation;
+ });
Close();
}
🤖 Prompt for AI Agents |
||
|
|
||
| private static string VersionFolder() | ||
| { | ||
| string tempPath = Path.GetTempPath(); | ||
| string tempFolder = System.IO.Path.Combine(tempPath, "LeiaInstaller"); | ||
| string versionFolder = System.IO.Path.Combine(tempFolder, _fileVersion); | ||
| DirectoryUtils.CreateDirectoryIfNotExists(versionFolder); | ||
| DirectoryUtils.DeleteFilesInDirectoyy(versionFolder); | ||
| return versionFolder; | ||
| } | ||
|
Comment on lines
+54
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for directory operations. The Add try-catch to provide graceful error handling: private static string VersionFolder()
{
- string tempPath = Path.GetTempPath();
- string tempFolder = System.IO.Path.Combine(tempPath, "LeiaInstaller");
- string versionFolder = System.IO.Path.Combine(tempFolder, _fileVersion);
- DirectoryUtils.CreateDirectoryIfNotExists(versionFolder);
- DirectoryUtils.DeleteFilesInDirectoyy(versionFolder);
- return versionFolder;
+ try
+ {
+ string tempPath = Path.GetTempPath();
+ string tempFolder = System.IO.Path.Combine(tempPath, "LeiaInstaller");
+ string versionFolder = System.IO.Path.Combine(tempFolder, _fileVersion);
+ DirectoryUtils.CreateDirectoryIfNotExists(versionFolder);
+ DirectoryUtils.DeleteFilesInDirectoyy(versionFolder);
+ return versionFolder;
+ }
+ catch (Exception ex)
+ {
+ TaskDialog.Show("Update Error",
+ $"Failed to prepare installer directory: {ex.Message}");
+ throw;
+ }
}Note: There's a typo in
|
||
|
|
||
| private void Close_Click(object sender, RoutedEventArgs e) | ||
| { | ||
| this.Close(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Add error handling and consider timing implications.
The installer execution on shutdown has several concerns:
RunLocalFile.Actionfails silently, users won't know why the update didn't occur.InstallerRoutefield is never cleared, which could cause issues if checked in future sessions.Consider this improved implementation:
public Result OnShutdown(UIControlledApplication application) { if (!string.IsNullOrEmpty(InstallerRoute)) { - RunLocalFile.Action(InstallerRoute); + try + { + RunLocalFile.Action(InstallerRoute); + } + catch (Exception ex) + { + TaskDialog.Show("Update Error", + $"Failed to launch installer: {ex.Message}"); + } + finally + { + InstallerRoute = null; + } } return Result.Succeeded; }Verify that the installer can successfully launch while Revit is shutting down by testing on multiple machines with different configurations.
🏁 Script executed:
Length of output: 9126
🏁 Script executed:
Length of output: 1270
🏁 Script executed:
Length of output: 2098
🏁 Script executed:
Length of output: 1837
🏁 Script executed:
Length of output: 527
🏁 Script executed:
Length of output: 323
🏁 Script executed:
Length of output: 3216
🏁 Script executed:
Length of output: 4984
🏁 Script executed:
Length of output: 2239
Add error handling and clear field after use.
The installer execution on shutdown lacks proper error handling and state cleanup:
RunLocalFile.ActioncallsHyperlink.Run()without catching exceptions. If the installer fails to launch, the error goes unreported.InstallerRoutefield is never cleared after use, which could cause unintended behavior in subsequent sessions.Wrap the call in try-catch-finally to handle failures gracefully and clear the field:
public Result OnShutdown(UIControlledApplication application) { if (!string.IsNullOrEmpty(InstallerRoute)) { - RunLocalFile.Action(InstallerRoute); + try + { + RunLocalFile.Action(InstallerRoute); + } + catch (Exception ex) + { + TaskDialog.Show("Update Error", + $"Failed to launch installer: {ex.Message}"); + } + finally + { + InstallerRoute = null; + } } return Result.Succeeded; }📝 Committable suggestion
🤖 Prompt for AI Agents