1- using System . Globalization ;
21using System . IO ;
3- using System . Text ;
42using System . Windows ;
53using System . Windows . Threading ;
64using BatchConvertToCHD . Services ;
75using SevenZip ;
8- using Microsoft . Win32 ;
96
107namespace BatchConvertToCHD ;
118
@@ -25,21 +22,18 @@ public partial class App : IDisposable
2522
2623 public App ( )
2724 {
25+ // Initialize SevenZipSharp library path first to determine its availability
26+ InitializeSevenZipSharp ( ) ;
27+
2828 // Initialize the bug report service as a shared instance
29- SharedBugReportService = new BugReportService ( AppConfig . BugReportApiUrl , AppConfig . BugReportApiKey , AppConfig . ApplicationName ) ;
29+ SharedBugReportService = new BugReportService ( AppConfig . BugReportApiUrl , AppConfig . BugReportApiKey , AppConfig . ApplicationName , IsSevenZipAvailable ) ;
3030 _bugReportService = SharedBugReportService ;
3131
3232 // Set up global exception handling
3333 AppDomain . CurrentDomain . UnhandledException += CurrentDomain_UnhandledException ;
3434 DispatcherUnhandledException += App_DispatcherUnhandledException ;
3535 TaskScheduler . UnobservedTaskException += TaskScheduler_UnobservedTaskException ;
3636
37- // Initialize SevenZipSharp library path
38- InitializeSevenZipSharp ( ) ;
39-
40- // Log environment details for debugging
41- LogEnvironmentDetails ( ) ;
42-
4337 // Register the Exit event handler
4438 Exit += App_Exit ;
4539 }
@@ -80,12 +74,10 @@ private async void ReportException(Exception exception, string source)
8074 {
8175 try
8276 {
83- var message = BuildExceptionReport ( exception , source ) ;
84-
8577 // Notify the developer using the shared service instance
8678 if ( _bugReportService != null )
8779 {
88- await _bugReportService . SendBugReportAsync ( message ) ;
80+ await _bugReportService . SendBugReportAsync ( $ "Unhandled Exception from { source } " , exception ) ;
8981 }
9082 }
9183 catch
@@ -94,47 +86,6 @@ private async void ReportException(Exception exception, string source)
9486 }
9587 }
9688
97- internal static string BuildExceptionReport ( Exception exception , string source )
98- {
99- var sb = new StringBuilder ( ) ;
100- sb . AppendLine ( CultureInfo . InvariantCulture , $ "Error Source: { source } ") ;
101- sb . AppendLine ( CultureInfo . InvariantCulture , $ "Date and Time: { DateTime . Now } ") ;
102- sb . AppendLine ( CultureInfo . InvariantCulture , $ "OS Version: { Environment . OSVersion } ") ;
103- sb . AppendLine ( CultureInfo . InvariantCulture , $ ".NET Version: { Environment . Version } ") ;
104- sb . AppendLine ( ) ;
105-
106- // Add exception details
107- sb . AppendLine ( "Exception Details:" ) ;
108- AppendExceptionDetails ( sb , exception ) ;
109-
110- return sb . ToString ( ) ;
111- }
112-
113- internal static void AppendExceptionDetails ( StringBuilder sb , Exception exception , int level = 0 )
114- {
115- while ( true )
116- {
117- var indent = new string ( ' ' , level * 2 ) ;
118-
119- sb . AppendLine ( CultureInfo . InvariantCulture , $ "{ indent } Type: { exception . GetType ( ) . FullName } ") ;
120- sb . AppendLine ( CultureInfo . InvariantCulture , $ "{ indent } Message: { exception . Message } ") ;
121- sb . AppendLine ( CultureInfo . InvariantCulture , $ "{ indent } Source: { exception . Source } ") ;
122- sb . AppendLine ( CultureInfo . InvariantCulture , $ "{ indent } StackTrace:") ;
123- sb . AppendLine ( CultureInfo . InvariantCulture , $ "{ indent } { exception . StackTrace } ") ;
124-
125- // If there's an inner exception, include it too
126- if ( exception . InnerException != null )
127- {
128- sb . AppendLine ( CultureInfo . InvariantCulture , $ "{ indent } Inner Exception:") ;
129- exception = exception . InnerException ;
130- level += 1 ;
131- continue ;
132- }
133-
134- break ;
135- }
136- }
137-
13889 private void InitializeSevenZipSharp ( )
13990 {
14091 try
@@ -153,7 +104,7 @@ private void InitializeSevenZipSharp()
153104 var errorMessage = $ "Could not find the required 7-Zip library: { dllName } in { AppDomain . CurrentDomain . BaseDirectory } ";
154105 if ( _bugReportService != null )
155106 {
156- _ = _bugReportService . SendBugReportAsync ( errorMessage ) ;
107+ _ = _bugReportService . SendBugReportAsync ( errorMessage , null ) ;
157108 }
158109
159110 IsSevenZipAvailable = false ;
@@ -164,72 +115,13 @@ private void InitializeSevenZipSharp()
164115 // Notify developer
165116 if ( _bugReportService != null )
166117 {
167- _ = _bugReportService . SendBugReportAsync ( ex . Message ) ;
118+ _ = _bugReportService . SendBugReportAsync ( "Error initializing 7-Zip library" , ex ) ;
168119 }
169120
170121 IsSevenZipAvailable = false ;
171122 }
172123 }
173124
174- /// <summary>
175- /// Logs detailed environment information for debugging
176- /// </summary>
177- private void LogEnvironmentDetails ( )
178- {
179- try
180- {
181- var sb = new StringBuilder ( ) ;
182- sb . AppendLine ( "=== Application Environment ===" ) ;
183- sb . AppendLine ( CultureInfo . InvariantCulture , $ "OS Version: { Environment . OSVersion } ") ;
184- sb . AppendLine ( CultureInfo . InvariantCulture , $ ".NET Version: { Environment . Version } ") ;
185- sb . AppendLine ( CultureInfo . InvariantCulture , $ "Process Architecture: { Environment . GetEnvironmentVariable ( "PROCESSOR_ARCHITECTURE" ) } ") ;
186- sb . AppendLine ( CultureInfo . InvariantCulture , $ "Is 64-bit Process: { Environment . Is64BitProcess } ") ;
187- sb . AppendLine ( CultureInfo . InvariantCulture , $ "Base Directory: { AppDomain . CurrentDomain . BaseDirectory } ") ;
188- sb . AppendLine ( CultureInfo . InvariantCulture , $ "Temp Path: { Path . GetTempPath ( ) } ") ;
189- sb . AppendLine ( CultureInfo . InvariantCulture , $ "User: { Environment . UserName } ") ;
190-
191- // Check for common security software
192- var securitySoftware = new List < string > ( ) ;
193- try
194- {
195- using var key = Registry . LocalMachine . OpenSubKey ( @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" ) ;
196- if ( key != null )
197- {
198- foreach ( var subKeyName in key . GetSubKeyNames ( ) )
199- {
200- using var subKey = key . OpenSubKey ( subKeyName ) ;
201- var displayName = subKey ? . GetValue ( "DisplayName" ) ? . ToString ( ) ?? "" ;
202- if ( displayName . Contains ( "Defender" ) || displayName . Contains ( "Antivirus" ) ||
203- displayName . Contains ( "Security" ) || displayName . Contains ( "ESET" ) ||
204- displayName . Contains ( "Norton" ) || displayName . Contains ( "McAfee" ) )
205- {
206- securitySoftware . Add ( displayName ) ;
207- }
208- }
209- }
210- }
211- catch
212- {
213- /* ignore */
214- }
215-
216- if ( securitySoftware . Count != 0 )
217- {
218- sb . AppendLine ( CultureInfo . InvariantCulture , $ "Detected Security Software: { string . Join ( "; " , securitySoftware ) } ") ;
219- }
220-
221- // Log to the bug report service if available
222- if ( _bugReportService != null )
223- {
224- _ = _bugReportService . SendBugReportAsync ( sb . ToString ( ) ) ;
225- }
226- }
227- catch ( Exception )
228- {
229- // Silently ignore logging errors
230- }
231- }
232-
233125 /// <inheritdoc />
234126 /// <summary>
235127 /// Releases all resources used by the App.
0 commit comments