Exemplo n.º 1
0
static BOOLEAN
CreateEnergyList(HWND hwnd)
{
	BOOLEAN retval;
	POWER_POLICY pp;
	SYSTEM_POWER_CAPABILITIES spc;

	hList = hwnd;

	if (!GetActivePwrScheme(&aps))
		return FALSE;

	if (!ReadGlobalPwrPolicy(&gGPP))
		return FALSE;

	if (!ReadPwrScheme(aps,&pp))
		return FALSE;

	if (!ValidatePowerPolicies(&gGPP,0))
		return FALSE;

/*
	if (!SetActivePwrScheme(aps,&gGPP,&pp))
		return FALSE;
*/

	if (!GetPwrCapabilities(&spc))
		return FALSE;

	if (CanUserWritePwrScheme())
	{
		// TODO:
		// Enable write / delete powerscheme button
	}

	Pos_InitPage(GetParent(hwnd));

	if (!GetActivePwrScheme(&aps))
		return FALSE;

	retval = EnumPwrSchemes(callback_EnumPwrScheme, aps);

    if(SendMessage(hwnd, CB_GETCOUNT, 0, 0) > 0)
    {
        EnableWindow(GetDlgItem(hwndDialog, IDC_DELETE_BTN),TRUE);
		EnableWindow(GetDlgItem(hwndDialog, IDC_SAVEAS_BTN),TRUE);
    }

	return retval;
}
Exemplo n.º 2
0
//------------------------------------------------------------------
// create new profile from current one
//
// return codes:
//   -1: active profile detection failed
//   -2: reading active profile policy failed
//   -3: writing our own profile failed
//   -4: reading active cpu policy failed
//   -5: writing our own cpu policy failed
//   -6: new profile activation failed
//   0: profile creation successful
//------------------------------------------------------------------
int createProfile()
{
  // get the # of the currently active profile
  UINT activeProfile;
  if( !GetActivePwrScheme(&activeProfile) )
    return -1;  

  // read the profile policy settings
  if( !ReadPwrScheme(activeProfile,&toBeCopied) )
    return -2;

  // copy this to the one we use later
  internalPolicy = toBeCopied;

  // create the # of our own profile
  lastChecked++;

  // disable throttling in this new profile
  internalPolicy.user.ForcedThrottleAc = 100;
  internalPolicy.user.ForcedThrottleDc = 100;

  // write our own profile policy settings to the registry
  if( !WritePwrScheme(&lastChecked,L"Speedswitch Control",L"\0\0",&internalPolicy) )
    return -3;

  // this is our profile #
  internalProfile = lastChecked;

  // read the CPU policy from the active profile
  if( !ReadProcessorPwrScheme(activeProfile,&mach) )
    return -4;

  // use this CPU policy for our own profile
  if( !WriteProcessorPwrScheme(internalProfile,&mach) )
    return -5;

  if( !SetActivePwrScheme(internalProfile,NULL,NULL) )
    return -6;

  updateStates();

  return 0;
}
Exemplo n.º 3
0
//------------------------------------------------------------------
// write changed power policies
//
// return codes:
//   -1: power policy writing failure
//   -2: cpu policy writing failure
//   0: success
//------------------------------------------------------------------
int writePolicies( BOOL power, BOOL cpu )
{
  if( power && !WritePwrScheme(&internalProfile,L"Speedswitch Control",L"\0\0",&internalPolicy) )
  {
    ReadPwrScheme( internalProfile, &internalPolicy );
    return -1;
  }

  if( cpu && !WriteProcessorPwrScheme(internalProfile,&mach) )
  {
    ReadProcessorPwrScheme( internalProfile, &mach );

    if( power )
      SetActivePwrScheme( internalProfile, NULL, NULL );

    return -2;
  }

  SetActivePwrScheme( internalProfile, NULL, NULL );
  return 0;
}
Exemplo n.º 4
0
HRESULT WindowsPowerLW::GetCurrentPowerScheme()
{
    DEBUG_XCOVER_MARK_LINE;
    memset(&pwrPolicy,0,sizeof(POWER_POLICY));
    //得到当前正在使用的Power Scheme的索引 
    if (!GetActivePwrScheme(&nIndex))
    {
        return HRESULT_FROM_WIN32(::GetLastError());
    }
    DEBUG_XCOVER_MARK_LINE;
    if (!ReadPwrScheme(nIndex,&pwrPolicy))
    {
        return HRESULT_FROM_WIN32(::GetLastError());
    }
    //得到电源情况
    DEBUG_XCOVER_MARK_LINE;
    if (!GetSystemPowerStatus(&SystemPowerStatus))
    {
        return HRESULT_FROM_WIN32(GetLastError());
    }
    DEBUG_XCOVER_MARK_LINE;
    return S_OK;
}
Exemplo n.º 5
0
//------------------------------------------------------------------
// check power scheme integrity
//
// check: 0=no consistency check
//        1=check power scheme only
//        2=check processor scheme only
//        3=check both power and processor scheme
//------------------------------------------------------------------
BOOL checkProfile( int check )
{
  log( _T("Checking power scheme integrity ...") );
  
  CString err;
  err.LoadStringW( IDS_MAINERR2 );

  POWER_POLICY policyTemp;
  MACHINE_PROCESSOR_POWER_POLICY machTemp;
  static TCHAR msg[1024];   // für diverse Fehlertexte
  BOOL forceActivate = FALSE;

  if( !ReadPwrScheme(internalProfile,&policyTemp) )
  {
    log( _T("Recreating power scheme ...") );
    UINT x = internalProfile;

    if( !WritePwrScheme(&x,L"Speedswitch Control",L"\0\0",&internalPolicy) )
    {
      CString s1;
      s1.LoadStringW( IDS_SW1 );
      wsprintf( msg, s1, GetLastError() );
      MessageBox( NULL, msg, err, MB_ICONEXCLAMATION|MB_OK );
      return FALSE;
    }

    forceActivate = TRUE;
  }
  else if( check&1 )
  {
    if( !comparePowerProfile(policyTemp,internalPolicy) )
    {
      log( _T("Restoring power scheme data ...") );
      UINT x = internalProfile;

      if( !WritePwrScheme(&x,L"Speedswitch Control",L"\0\0",&internalPolicy) )
      {
        CString s1;
        s1.LoadStringW( IDS_SW2 );
        wsprintf( msg, s1, GetLastError() );
        MessageBox( NULL, msg, err, MB_ICONEXCLAMATION|MB_OK );
        return FALSE;
      }

      forceActivate = TRUE;
    }
  }

  if( !ReadProcessorPwrScheme(internalProfile,&machTemp) )
  {
    log( _T("Recreating processor scheme ...") );
    if( !WriteProcessorPwrScheme(internalProfile,&mach) )
    {
      CString s1;
      s1.LoadStringW( IDS_SW3 );
      wsprintf( msg, s1, GetLastError() );
      MessageBox( NULL, msg, err, MB_ICONEXCLAMATION|MB_OK );
      return FALSE;
    }   

    forceActivate = TRUE;
  }
  else if( check&2 )
  {
    if( !compareCPUScheme(machTemp,mach) )
    {
      log( _T("Restoring processor scheme data ...") );
      if( !WriteProcessorPwrScheme(internalProfile,&mach) )
      {
        CString s1;
        s1.LoadStringW( IDS_SW4 );
        wsprintf( msg, s1, GetLastError() );
        MessageBox( NULL, msg, err, MB_ICONEXCLAMATION|MB_OK );
        return FALSE;
      }  

      forceActivate = TRUE;
    }
  }

  UINT profile;

  if( !GetActivePwrScheme(&profile) )
  {
    CString s1;
    s1.LoadStringW( IDS_SW5 );
    wsprintf( msg, s1, GetLastError() );
    MessageBox( NULL, msg, err, MB_OK|MB_ICONEXCLAMATION );
    return FALSE;
  }

  if( forceActivate || profile!=internalProfile )
  {
    log( _T("Reactivating power scheme (%d, %d) ..."), profile, internalProfile );
    if( !SetActivePwrScheme(internalProfile,NULL,NULL) )
    {
      CString s1;
      s1.LoadStringW( IDS_SW6 );
      wsprintf( msg, s1, GetLastError() );
      MessageBox( NULL, msg, err, MB_ICONEXCLAMATION|MB_OK );
      return FALSE;
    }
  }

  return TRUE;
}