system.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #include "rar.hpp"
  2. #ifndef _WIN_CE
  3. static int SleepTime=0;
  4. void InitSystemOptions(int SleepTime)
  5. {
  6. ::SleepTime=SleepTime;
  7. }
  8. #endif
  9. #if !defined(SFX_MODULE) && !defined(_WIN_CE) && !defined(SETUP)
  10. void SetPriority(int Priority)
  11. {
  12. #ifdef _WIN_ALL
  13. uint PriorityClass;
  14. int PriorityLevel;
  15. if (Priority<1 || Priority>15)
  16. return;
  17. if (Priority==1)
  18. {
  19. PriorityClass=IDLE_PRIORITY_CLASS;
  20. PriorityLevel=THREAD_PRIORITY_IDLE;
  21. }
  22. else
  23. if (Priority<7)
  24. {
  25. PriorityClass=IDLE_PRIORITY_CLASS;
  26. PriorityLevel=Priority-4;
  27. }
  28. else
  29. if (Priority==7)
  30. {
  31. PriorityClass=BELOW_NORMAL_PRIORITY_CLASS;
  32. PriorityLevel=THREAD_PRIORITY_ABOVE_NORMAL;
  33. }
  34. else
  35. if (Priority<10)
  36. {
  37. PriorityClass=NORMAL_PRIORITY_CLASS;
  38. PriorityLevel=Priority-7;
  39. }
  40. else
  41. if (Priority==10)
  42. {
  43. PriorityClass=ABOVE_NORMAL_PRIORITY_CLASS;
  44. PriorityLevel=THREAD_PRIORITY_NORMAL;
  45. }
  46. else
  47. {
  48. PriorityClass=HIGH_PRIORITY_CLASS;
  49. PriorityLevel=Priority-13;
  50. }
  51. SetPriorityClass(GetCurrentProcess(),PriorityClass);
  52. SetThreadPriority(GetCurrentThread(),PriorityLevel);
  53. // Background mode for Vista, too slow for real life use.
  54. // if (WinNT()>=WNT_VISTA && Priority==1)
  55. // SetPriorityClass(GetCurrentProcess(),PROCESS_MODE_BACKGROUND_BEGIN);
  56. #endif
  57. }
  58. #endif
  59. #ifndef SETUP
  60. void Wait()
  61. {
  62. #if defined(_WIN_ALL) && !defined(_WIN_CE) && !defined(SFX_MODULE)
  63. if (SleepTime!=0)
  64. Sleep(SleepTime);
  65. #endif
  66. }
  67. #endif
  68. #if defined(_WIN_ALL) && !defined(_WIN_CE) && !defined(SFX_MODULE) && !defined(SHELL_EXT) && !defined(SETUP)
  69. void Shutdown()
  70. {
  71. HANDLE hToken;
  72. TOKEN_PRIVILEGES tkp;
  73. if (OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,&hToken))
  74. {
  75. LookupPrivilegeValue(NULL,SE_SHUTDOWN_NAME,&tkp.Privileges[0].Luid);
  76. tkp.PrivilegeCount = 1;
  77. tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
  78. AdjustTokenPrivileges(hToken,FALSE,&tkp,0,(PTOKEN_PRIVILEGES)NULL,0);
  79. }
  80. ExitWindowsEx(EWX_SHUTDOWN|EWX_FORCE|EWX_POWEROFF,SHTDN_REASON_FLAG_PLANNED);
  81. }
  82. #endif