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;
- }
- }
-}