pyrevitlabs / pyRevit

Rapid Application Development (RAD) Environment for Autodesk Revit®
http://wiki.pyrevitlabs.io
GNU General Public License v3.0
1.3k stars 332 forks source link

[Bug]: Output Window Bugs #2333

Closed jmcouffin closed 1 month ago

jmcouffin commented 2 months ago

✈ Pre-Flight checks

🐞 Describe the bug

Soft crash when using the following commands of the output window:

⌨ Error/Debug Message

Blocking error

ExceptionCode=0xe0434352 ExceptionFlags=0x00000001 ExceptionAddress=00007FFF98F8B699

♻️ To Reproduce

-

⏲️ Expected behavior

-

🖥️ Hardware and Software Setup (please complete the following information)

-

Additional context

@dosymep @sanzoghenzo

jmcouffin commented 1 month ago

Haven't tried it, for the SaveDialog https://github.com/pyrevitlabs/pyRevit/blob/edeeb3e7b824e3d52f57ba9c76ce594ae5062227/dev/pyRevitLabs.PyRevit.Runtime/ScriptConsole.cs#L837

private void Save_Contents_Button_Clicked(object sender, RoutedEventArgs e)
{
    var saveDlg = new System.Windows.Forms.SaveFileDialog()
    {
        Title = "Save Output to:",
        Filter = "HTML Files|*.html",
        DefaultExt = "html",
        AddExtension = true,
        RestoreDirectory = true
    };

    if (saveDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK && !string.IsNullOrWhiteSpace(saveDlg.FileName))
    {
        try
        {
            using (var f = File.CreateText(saveDlg.FileName))
            {
                f.Write(GetFullHtml());
            }
        }
        catch (Exception ex)
        {
            // Use WPF MessageBox instead of System.Windows.Forms.MessageBox
            System.Windows.MessageBox.Show($"Error saving file: {ex.Message}", "Save Error", MessageBoxButton.OK, MessageBoxImage.Error);
        }
    }
    else
    {
        System.Windows.MessageBox.Show("File saving was canceled or an invalid file name was provided.", "Save Canceled", MessageBoxButton.OK, MessageBoxImage.Information);
    }
}
jmcouffin commented 1 month ago

And the issue with the Process.Start() when opening the content of the html of the output window to the default Process

private void OpenButton_Click(object sender, RoutedEventArgs e)
{
    try
    {
        var filePath = SaveContentsToTemp();

        // Adjust for proper URI format
        var uri = new Uri(filePath).AbsoluteUri;

        // Use ProcessStartInfo to set UseShellExecute to true
        var processInfo = new ProcessStartInfo()
        {
            FileName = uri,
            UseShellExecute = true // Required in .NET Core to launch external processes
        };

        Process.Start(processInfo);
    }
    catch (Exception ex)
    {
        // Handle any exceptions and show an error message
        System.Windows.MessageBox.Show($"Error opening file: {ex.Message}", "Open Error", MessageBoxButton.OK, MessageBoxImage.Error);
    }
}
jmcouffin commented 1 month ago

Will try it tomorrow