X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=FDK17%E3%83%97%E3%83%AD%E3%82%B8%E3%82%A7%E3%82%AF%E3%83%88%2F%E3%82%B3%E3%83%BC%E3%83%89%2F00.%E5%85%B1%E9%80%9A%2FCPowerPlan.cs;fp=FDK17%E3%83%97%E3%83%AD%E3%82%B8%E3%82%A7%E3%82%AF%E3%83%88%2F%E3%82%B3%E3%83%BC%E3%83%89%2F00.%E5%85%B1%E9%80%9A%2FCPowerPlan.cs;h=0000000000000000000000000000000000000000;hb=4b70e63bc3e2c99e836477240bd5039d41d10640;hp=c4abb0d8b8a74a30736b60422565a3f192d26388;hpb=296446998eeba408353da55a275458b590e4ebf5;p=dtxmania%2Fdtxmania.git diff --git a/FDK17プロジェクト/コード/00.共通/CPowerPlan.cs b/FDK17プロジェクト/コード/00.共通/CPowerPlan.cs deleted file mode 100644 index c4abb0d8..00000000 --- a/FDK17プロジェクト/コード/00.共通/CPowerPlan.cs +++ /dev/null @@ -1,159 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Runtime.InteropServices; -using System.Diagnostics; - -namespace FDK -{ - /// - /// 電源プランの制御を行う - /// - public static class CPowerPlan - { - // 参考: 電源プラン制御: http://www.fsmpi.uni-bayreuth.de/~dun3/archives/programmatically-change-power-options-using-cshar/519.html - // 参考: ConnectedStandby判別: https://social.msdn.microsoft.com/Forums/en-US/eeb164a3-8ceb-4eb2-8768-4faaa7218c59/how-to-experimentally-confirm-that-connected-standby-mode-is-enabled-on-a-computer-system?forum=tailoringappsfordevices - // http://stackoverflow.com/questions/20407094/c-sharp-how-to-use-callntpowerinformation-with-interop-to-get-system-power-infor - - readonly private static Guid GuidHighPerformance = new Guid( "8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c" ); // Vista以降は全部これのはず - private static Guid GuidBackup = Guid.Empty; - private static bool bConnectedStandbySupported = false; - - - public static void BackupCurrentPowerPlan() - { - bConnectedStandbySupported = IsConnetedStandbySupported(); - - if ( bConnectedStandbySupported ) - { - // 何もしない - } - else - { - GuidBackup = GetActivePowerPlan(); - Trace.TraceInformation( "現在の電源プラン「{0}」をバックアップしました。", GetFriendlyName( GuidBackup ) ); - } - } - - /// - /// Connected Standbyサポート機種かどうかの判定 - /// (Connected Standby機種に対しては、電源プラン操作を行わない) - /// - private static bool IsConnetedStandbySupported() - { - if ( !COS.bIsWin8OrLater ) - { - // Win8以前であれば、ConnectedStandby非サポートが確定 - return false; - } - - CWin32.SYSTEM_POWER_CAPABILITIES cap; - uint retval = CWin32.CallNtPowerInformation( - (int) CWin32.POWER_INFORMATION_LEVEL.SystemPowerCapabilities, - IntPtr.Zero, - 0, - out cap, - Marshal.SizeOf( typeof( CWin32.SYSTEM_POWER_CAPABILITIES ) ) - ); - if ( retval == 0 ) - { - //Debug.WriteLine( "SYSTEM_POWER_CAPABILITIES.AOAC: " + cap.AoAc ); - if ( cap.AoAc ) - { - //Debug.WriteLine( "Connected Standby is enabled." ); - return true; - } - else - { - //Debug.WriteLine( "Connected Standby is NOT enabled." ); - return false; - } - } - else - { - Debug.WriteLine( "CallNtPowerInformation returned: " + retval ); - //Debug.WriteLine( "Call to CallNTPowerInformation failed. GetLastError: %d\n", GetLastError() ); - return false; - } - } - - public static void RestoreCurrentPowerPlan() - { - if ( bConnectedStandbySupported ) - { - // 何もしない - } - else - { - if ( GuidBackup != System.Guid.Empty ) - { - SetActivePowerPlan( GuidBackup ); - Trace.TraceInformation( "電源プランを、「{0}」に戻しました。", GetFriendlyName( GuidBackup ) ); - GuidBackup = System.Guid.Empty; - } - } - } - public static void ChangeHighPerformance() - { - if ( bConnectedStandbySupported ) - { - Trace.TraceInformation( "ConnectedStandby対応機種のため、電源プランの変更を行いません。" ); - } - else - { - SetActivePowerPlan( GuidHighPerformance ); - Trace.TraceInformation( "電源プランを、「{0}」に変更しました。", GetFriendlyName( GuidHighPerformance ) ); - } - } - - - - private static void SetActivePowerPlan( Guid powerSchemeId ) - { - var schemeGuid = powerSchemeId; - CWin32.PowerSetActiveScheme( IntPtr.Zero, ref schemeGuid ); - } - - private static Guid GetActivePowerPlan() - { - IntPtr pCurrentSchemeGuid = IntPtr.Zero; - CWin32.PowerGetActiveScheme( IntPtr.Zero, ref pCurrentSchemeGuid ); - var currentSchemeGuid = (Guid) Marshal.PtrToStructure( pCurrentSchemeGuid, typeof( Guid ) ); - return currentSchemeGuid; - } - - - private static IEnumerable FindAll() - { - var schemeGuid = Guid.Empty; - uint sizeSchemeGuid = (uint) Marshal.SizeOf( typeof( Guid ) ); - uint schemeIndex = 0; - while ( CWin32.PowerEnumerate( IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, (uint) CWin32.AccessFlags.ACCESS_SCHEME, - schemeIndex, ref schemeGuid, ref sizeSchemeGuid ) == 0 ) - { - yield return schemeGuid; - schemeIndex++; - } - } - - private static string GetFriendlyName( Guid schemeGuid ) - { - uint sizeName = 1024; - IntPtr pSizeName = Marshal.AllocHGlobal( (int) sizeName ); - string friendlyName; - - try - { - CWin32.PowerReadFriendlyName( IntPtr.Zero, ref schemeGuid, IntPtr.Zero, IntPtr.Zero, pSizeName, ref sizeName ); - friendlyName = Marshal.PtrToStringUni( pSizeName ); - } - finally - { - Marshal.FreeHGlobal( pSizeName ); - } - return friendlyName; - } - } -}