2013-03-16 20:25:38 +00:00
|
|
|
/*
|
2006-06-15 14:16:29 +00:00
|
|
|
* PROJECT: ReactOS Power Configuration Applet
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
|
|
* FILE: dll/cpl/powercfg/hibernate.c
|
|
|
|
* PURPOSE: hibernate tab of applet
|
|
|
|
* PROGRAMMERS: Alexander Wurzinger (Lohnegrim at gmx dot net)
|
2013-09-15 13:06:05 +00:00
|
|
|
* Johannes Anderwald (johannes.anderwald@reactos.org)
|
2006-06-15 14:16:29 +00:00
|
|
|
* Martin Rottensteiner
|
2007-11-30 18:52:33 +00:00
|
|
|
* Dmitry Chapyshev (lentind@yandex.ru)
|
2006-06-15 14:16:29 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "powercfg.h"
|
2006-07-10 13:47:11 +00:00
|
|
|
|
2006-06-15 14:16:29 +00:00
|
|
|
BOOLEAN Pos_InitData();
|
|
|
|
void Adv_InitDialog();
|
|
|
|
|
|
|
|
|
2007-12-02 14:25:17 +00:00
|
|
|
static VOID
|
|
|
|
Hib_InitDialog(HWND hwndDlg)
|
2006-06-15 14:16:29 +00:00
|
|
|
{
|
2015-09-07 21:56:38 +00:00
|
|
|
SYSTEM_POWER_CAPABILITIES PowerCaps;
|
|
|
|
MEMORYSTATUSEX msex;
|
|
|
|
TCHAR szTemp[MAX_PATH];
|
2016-09-29 20:54:58 +00:00
|
|
|
LPTSTR lpRoot;
|
2015-09-07 21:56:38 +00:00
|
|
|
ULARGE_INTEGER FreeBytesAvailable, TotalNumberOfBytes, TotalNumberOfFreeBytes;
|
2006-06-15 14:16:29 +00:00
|
|
|
|
2015-09-07 21:56:38 +00:00
|
|
|
if (GetPwrCapabilities(&PowerCaps))
|
|
|
|
{
|
|
|
|
CheckDlgButton(hwndDlg,
|
|
|
|
IDC_HIBERNATEFILE,
|
|
|
|
PowerCaps.HiberFilePresent ? BST_CHECKED : BST_UNCHECKED);
|
2006-06-15 14:16:29 +00:00
|
|
|
|
2015-09-07 21:56:38 +00:00
|
|
|
msex.dwLength = sizeof(msex);
|
|
|
|
if (!GlobalMemoryStatusEx(&msex))
|
|
|
|
{
|
|
|
|
return; // FIXME
|
|
|
|
}
|
2006-06-15 14:16:29 +00:00
|
|
|
|
2015-09-07 21:56:38 +00:00
|
|
|
if (GetWindowsDirectory(szTemp,MAX_PATH))
|
2016-09-29 20:54:58 +00:00
|
|
|
lpRoot = szTemp;
|
2015-09-07 21:56:38 +00:00
|
|
|
else
|
2016-09-29 20:54:58 +00:00
|
|
|
lpRoot = NULL;
|
2007-10-21 13:02:26 +00:00
|
|
|
|
2016-09-29 20:54:58 +00:00
|
|
|
// Get available space and size of selected volume.
|
|
|
|
if (!GetDiskFreeSpaceEx(lpRoot, &FreeBytesAvailable, &TotalNumberOfBytes, &TotalNumberOfFreeBytes))
|
|
|
|
TotalNumberOfFreeBytes.QuadPart = 0;
|
2006-06-15 14:16:29 +00:00
|
|
|
|
2016-09-29 20:54:58 +00:00
|
|
|
// Print the free available space into selected volume.
|
|
|
|
StrFormatByteSize(TotalNumberOfFreeBytes.QuadPart, szTemp, _countof(szTemp));
|
|
|
|
SetDlgItemText(hwndDlg, IDC_FREESPACE, szTemp);
|
|
|
|
|
|
|
|
// Print the amount of space required for hibernation.
|
|
|
|
StrFormatByteSize(msex.ullTotalPhys, szTemp, _countof(szTemp));
|
|
|
|
SetDlgItemText(hwndDlg, IDC_SPACEFORHIBERNATEFILE, szTemp);
|
2007-10-21 13:02:26 +00:00
|
|
|
|
2015-09-07 21:56:38 +00:00
|
|
|
if (TotalNumberOfFreeBytes.QuadPart < msex.ullTotalPhys && !PowerCaps.HiberFilePresent)
|
|
|
|
{
|
|
|
|
EnableWindow(GetDlgItem(hwndDlg, IDC_HIBERNATEFILE), FALSE);
|
|
|
|
ShowWindow(GetDlgItem(hwndDlg, IDC_TOLESSFREESPACE), TRUE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ShowWindow(GetDlgItem(hwndDlg, IDC_TOLESSFREESPACE), FALSE);
|
|
|
|
EnableWindow(GetDlgItem(hwndDlg, IDC_HIBERNATEFILE), TRUE);
|
|
|
|
}
|
|
|
|
}
|
2006-06-15 14:16:29 +00:00
|
|
|
}
|
|
|
|
|
2007-12-02 14:25:17 +00:00
|
|
|
INT_PTR
|
|
|
|
Hib_SaveData(HWND hwndDlg)
|
2006-06-15 14:16:29 +00:00
|
|
|
{
|
2015-09-07 21:56:38 +00:00
|
|
|
BOOLEAN bHibernate;
|
2007-10-19 23:21:45 +00:00
|
|
|
|
2015-09-07 21:56:38 +00:00
|
|
|
bHibernate = (BOOLEAN)(IsDlgButtonChecked(hwndDlg, IDC_HIBERNATEFILE) == BST_CHECKED);
|
2007-10-21 13:02:26 +00:00
|
|
|
|
2015-09-07 21:56:38 +00:00
|
|
|
if (CallNtPowerInformation(SystemReserveHiberFile,&bHibernate, sizeof(bHibernate), NULL, 0) == STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
Pos_InitData();
|
|
|
|
Adv_InitDialog();
|
|
|
|
Hib_InitDialog(hwndDlg);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2007-10-21 13:02:26 +00:00
|
|
|
|
2015-09-07 21:56:38 +00:00
|
|
|
return FALSE;
|
2006-06-15 14:16:29 +00:00
|
|
|
}
|
2007-12-02 14:25:17 +00:00
|
|
|
|
|
|
|
/* Property page dialog callback */
|
|
|
|
INT_PTR CALLBACK
|
|
|
|
HibernateDlgProc(HWND hwndDlg,
|
|
|
|
UINT uMsg,
|
|
|
|
WPARAM wParam,
|
|
|
|
LPARAM lParam)
|
|
|
|
{
|
|
|
|
switch(uMsg)
|
|
|
|
{
|
|
|
|
case WM_INITDIALOG:
|
2015-09-07 21:56:38 +00:00
|
|
|
Hib_InitDialog(hwndDlg);
|
|
|
|
return TRUE;
|
|
|
|
case WM_COMMAND:
|
|
|
|
switch(LOWORD(wParam))
|
|
|
|
{
|
|
|
|
case IDC_HIBERNATEFILE:
|
|
|
|
if (HIWORD(wParam) == BN_CLICKED)
|
|
|
|
{
|
|
|
|
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WM_NOTIFY:
|
|
|
|
{
|
|
|
|
LPNMHDR lpnm = (LPNMHDR)lParam;
|
|
|
|
if (lpnm->code == (UINT)PSN_APPLY)
|
|
|
|
{
|
|
|
|
return Hib_SaveData(hwndDlg);
|
|
|
|
}
|
|
|
|
}
|
2007-12-02 14:25:17 +00:00
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|