mirror of
				https://github.com/Nioux/AideDeJeu.git
				synced 2025-10-30 23:16:09 +00:00 
			
		
		
		
	Merge branch 'master' of https://github.com/Nioux/AideDeJeu
This commit is contained in:
		
						commit
						e357ab0698
					
				
					 1 changed files with 73 additions and 0 deletions
				
			
		|  | @ -6,6 +6,8 @@ using Android.Runtime; | ||||||
| using Android.Views; | using Android.Views; | ||||||
| using Android.Widget; | using Android.Widget; | ||||||
| using Android.OS; | using Android.OS; | ||||||
|  | using System.Threading.Tasks; | ||||||
|  | using System.Diagnostics; | ||||||
| 
 | 
 | ||||||
| namespace AideDeJeu.Droid | namespace AideDeJeu.Droid | ||||||
| { | { | ||||||
|  | @ -19,6 +21,10 @@ namespace AideDeJeu.Droid | ||||||
|             ToolbarResource = Resource.Layout.Toolbar; |             ToolbarResource = Resource.Layout.Toolbar; | ||||||
| 
 | 
 | ||||||
|             base.OnCreate(bundle); |             base.OnCreate(bundle); | ||||||
|  | 
 | ||||||
|  |             AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException; | ||||||
|  |             TaskScheduler.UnobservedTaskException += TaskSchedulerOnUnobservedTaskException; | ||||||
|  | 
 | ||||||
|             Xamarin.Essentials.Platform.Init(this, bundle); |             Xamarin.Essentials.Platform.Init(this, bundle); | ||||||
|             Xamarin.Essentials.ExperimentalFeatures.Enable(Xamarin.Essentials.ExperimentalFeatures.ShareFileRequest); |             Xamarin.Essentials.ExperimentalFeatures.Enable(Xamarin.Essentials.ExperimentalFeatures.ShareFileRequest); | ||||||
| 
 | 
 | ||||||
|  | @ -30,6 +36,8 @@ namespace AideDeJeu.Droid | ||||||
|             //global::Xamarin.Forms.FormsMaterial.Init(this, bundle); |             //global::Xamarin.Forms.FormsMaterial.Init(this, bundle); | ||||||
|             SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_e_sqlite3()); |             SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_e_sqlite3()); | ||||||
| 
 | 
 | ||||||
|  |             DisplayCrashReport(); | ||||||
|  | 
 | ||||||
|             LoadApplication(new App()); |             LoadApplication(new App()); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | @ -52,6 +60,71 @@ namespace AideDeJeu.Droid | ||||||
| 
 | 
 | ||||||
|             base.OnRequestPermissionsResult(requestCode, permissions, grantResults); |             base.OnRequestPermissionsResult(requestCode, permissions, grantResults); | ||||||
|         } |         } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |         private static void TaskSchedulerOnUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs unobservedTaskExceptionEventArgs) | ||||||
|  |         { | ||||||
|  |             var newExc = new Exception("TaskSchedulerOnUnobservedTaskException", unobservedTaskExceptionEventArgs.Exception); | ||||||
|  |             LogUnhandledException(newExc); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         private static void CurrentDomainOnUnhandledException(object sender, UnhandledExceptionEventArgs unhandledExceptionEventArgs) | ||||||
|  |         { | ||||||
|  |             var newExc = new Exception("CurrentDomainOnUnhandledException", unhandledExceptionEventArgs.ExceptionObject as Exception); | ||||||
|  |             LogUnhandledException(newExc); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         internal static void LogUnhandledException(Exception exception) | ||||||
|  |         { | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 const string errorFileName = "Fatal.log"; | ||||||
|  |                 var libraryPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); // iOS: Environment.SpecialFolder.Resources | ||||||
|  |                 var errorFilePath = System.IO.Path.Combine(libraryPath, errorFileName); | ||||||
|  |                 var errorMessage = String.Format("Time: {0}\r\nError: Unhandled Exception\r\n{1}", | ||||||
|  |                 DateTime.Now, exception.ToString()); | ||||||
|  |                 System.IO.File.WriteAllText(errorFilePath, errorMessage); | ||||||
|  | 
 | ||||||
|  |                 // Log to Android Device Logging. | ||||||
|  |                 Android.Util.Log.Error("Crash Report", errorMessage); | ||||||
|  |             } | ||||||
|  |             catch | ||||||
|  |             { | ||||||
|  |                 // just suppress any error logging exceptions | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         /// <summary> | ||||||
|  |         // If there is an unhandled exception, the exception information is diplayed  | ||||||
|  |         // on screen the next time the app is started (only in debug configuration) | ||||||
|  |         /// </summary> | ||||||
|  |         [Conditional("DEBUG")] | ||||||
|  |         private void DisplayCrashReport() | ||||||
|  |         { | ||||||
|  |             const string errorFilename = "Fatal.log"; | ||||||
|  |             var libraryPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); | ||||||
|  |             var errorFilePath = System.IO.Path.Combine(libraryPath, errorFilename); | ||||||
|  | 
 | ||||||
|  |             if (!System.IO.File.Exists(errorFilePath)) | ||||||
|  |             { | ||||||
|  |                 return; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             var errorText = System.IO.File.ReadAllText(errorFilePath); | ||||||
|  |             new AlertDialog.Builder(this) | ||||||
|  |                 .SetPositiveButton("Clear", (sender, args) => | ||||||
|  |                 { | ||||||
|  |                     System.IO.File.Delete(errorFilePath); | ||||||
|  |                 }) | ||||||
|  |                 .SetNegativeButton("Close", (sender, args) => | ||||||
|  |                 { | ||||||
|  |                     // User pressed Close. | ||||||
|  |                 }) | ||||||
|  |                 .SetMessage(errorText) | ||||||
|  |                 .SetTitle("Crash Report") | ||||||
|  |                 .Show(); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Yan Maniez
						Yan Maniez