PageRenderTime 36ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/TEditXna/App.xaml.cs

https://github.com/Surfpup/Terraria-Map-Editor
C# | 86 lines | 69 code | 11 blank | 6 comment | 9 complexity | 4cb2ce74016e8b0e40214c5a5e0d6ece MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Threading;
  7. using System.Windows;
  8. namespace TEditXna
  9. {
  10. /// <summary>
  11. /// Interaction logic for App.xaml
  12. /// </summary>
  13. public partial class App : Application
  14. {
  15. static App()
  16. {
  17. BCCL.MvvmLight.Threading.DispatcherHelper.Initialize();
  18. }
  19. protected override void OnStartup(StartupEventArgs e)
  20. {
  21. if (!DependencyChecker.VerifyDotNet())
  22. {
  23. MessageBox.Show("Please install .Net 4.0", "Missing .Net", MessageBoxButton.OK, MessageBoxImage.Stop);
  24. ErrorLogging.LogException(new ApplicationException("MISSING .NET"));
  25. Shutdown();
  26. }
  27. if (!DependencyChecker.VerifyXna())
  28. {
  29. MessageBox.Show("Please install XNA Framework 4.0", "Missing XNA", MessageBoxButton.OK, MessageBoxImage.Stop);
  30. ErrorLogging.LogException(new ApplicationException("MISSING XNA"));
  31. Shutdown();
  32. }
  33. if (!DependencyChecker.VerifyTerraria())
  34. {
  35. ErrorLogging.Log("Unable to locate Terraria. No texture data will be available.");
  36. }
  37. if (e.Args != null && e.Args.Count() > 0)
  38. {
  39. this.Properties["OpenFile"] = e.Args[0];
  40. }
  41. if (AppDomain.CurrentDomain.SetupInformation.ActivationArguments != null &&
  42. AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData != null &&
  43. AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData.Length > 0)
  44. {
  45. string fname = "No filename given";
  46. try
  47. {
  48. fname = AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData[0];
  49. // It comes in as a URI; this helps to convert it to a path.
  50. var uri = new Uri(fname);
  51. fname = uri.LocalPath;
  52. this.Properties["OpenFile"] = fname;
  53. }
  54. catch (Exception ex)
  55. {
  56. // For some reason, this couldn't be read as a URI.
  57. // Do what you must...
  58. }
  59. }
  60. BCCL.MvvmLight.Threading.TaskFactoryHelper.Initialize();
  61. AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
  62. base.OnStartup(e);
  63. }
  64. private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
  65. {
  66. #if DEBUG
  67. throw (Exception)e.ExceptionObject;
  68. #else
  69. ErrorLogging.LogException(e.ExceptionObject);
  70. MessageBox.Show("An unhandled exception has occured. Please copy the log from \"log.txt\" to the GitHub Issues list.\r\nThe program will now exit.", "Unhandled Exception");
  71. Current.Shutdown();
  72. #endif
  73. }
  74. }
  75. }