NativeApp.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System.Runtime.InteropServices;
  2. namespace MediaBrowser.ServerApplication.Native
  3. {
  4. /// <summary>
  5. /// Class NativeApp
  6. /// </summary>
  7. public static class NativeApp
  8. {
  9. /// <summary>
  10. /// Shutdowns this instance.
  11. /// </summary>
  12. public static void Shutdown()
  13. {
  14. MainStartup.Shutdown();
  15. }
  16. /// <summary>
  17. /// Restarts this instance.
  18. /// </summary>
  19. public static void Restart()
  20. {
  21. MainStartup.Restart();
  22. }
  23. /// <summary>
  24. /// Determines whether this instance [can self restart].
  25. /// </summary>
  26. /// <returns><c>true</c> if this instance [can self restart]; otherwise, <c>false</c>.</returns>
  27. public static bool CanSelfRestart
  28. {
  29. get
  30. {
  31. return MainStartup.CanSelfRestart;
  32. }
  33. }
  34. /// <summary>
  35. /// Gets a value indicating whether [supports automatic run at startup].
  36. /// </summary>
  37. /// <value><c>true</c> if [supports automatic run at startup]; otherwise, <c>false</c>.</value>
  38. public static bool SupportsAutoRunAtStartup
  39. {
  40. get
  41. {
  42. return true;
  43. }
  44. }
  45. /// <summary>
  46. /// Gets a value indicating whether this instance can self update.
  47. /// </summary>
  48. /// <value><c>true</c> if this instance can self update; otherwise, <c>false</c>.</value>
  49. public static bool CanSelfUpdate
  50. {
  51. get
  52. {
  53. return MainStartup.CanSelfUpdate;
  54. }
  55. }
  56. public static void PreventSystemStandby()
  57. {
  58. SystemHelper.ResetStandbyTimer();
  59. }
  60. internal enum EXECUTION_STATE : uint
  61. {
  62. ES_NONE = 0,
  63. ES_SYSTEM_REQUIRED = 0x00000001,
  64. ES_DISPLAY_REQUIRED = 0x00000002,
  65. ES_USER_PRESENT = 0x00000004,
  66. ES_AWAYMODE_REQUIRED = 0x00000040,
  67. ES_CONTINUOUS = 0x80000000
  68. }
  69. public class SystemHelper
  70. {
  71. [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  72. static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags);
  73. public static void ResetStandbyTimer()
  74. {
  75. EXECUTION_STATE es = SetThreadExecutionState(EXECUTION_STATE.ES_SYSTEM_REQUIRED);
  76. }
  77. }
  78. }
  79. }