1 /*=============================================================================
\r
5 ===============================================================================
\r
6 / Copyright (C) 1997-2007 Sota. All rights reserved.
\r
8 / Redistribution and use in source and binary forms, with or without
\r
9 / modification, are permitted provided that the following conditions
\r
12 / 1. Redistributions of source code must retain the above copyright
\r
13 / notice, this list of conditions and the following disclaimer.
\r
14 / 2. Redistributions in binary form must reproduce the above copyright
\r
15 / notice, this list of conditions and the following disclaimer in the
\r
16 / documentation and/or other materials provided with the distribution.
\r
18 / THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
\r
19 / IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
\r
20 / OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
\r
21 / IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
\r
22 / INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
\r
23 / BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
\r
24 / USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
\r
25 / ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
\r
26 / (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
\r
27 / THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
28 /============================================================================*/
\r
32 #include <winsock2.h>
\r
33 #include <windows.h>
\r
37 #include <mbstring.h>
\r
39 #include <windowsx.h>
\r
41 //#include <winsock.h>
\r
44 #include "resource.h"
\r
47 typedef DWORD (WINAPI*FUNC_GETDISKFREESPACEEX) (LPCTSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER);
\r
49 /*===== ローカルなワーク =====*/
\r
51 static HINSTANCE m_hDll = NULL;
\r
53 static FUNC_GETDISKFREESPACEEX m_GetDiskFreeSpaceEx = NULL;
\r
57 /*----- KERNEL32をロードする --------------------------------------------------
\r
64 *----------------------------------------------------------------------------*/
\r
66 void LoadKernelLib(void)
\r
68 OSVERSIONINFO VerInfo;
\r
70 VerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
\r
71 GetVersionEx(&VerInfo);
\r
72 if(((VerInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) && (VerInfo.dwBuildNumber > 1000)) ||
\r
73 (VerInfo.dwPlatformId == VER_PLATFORM_WIN32_NT))
\r
75 if((m_hDll = LoadLibrary("kernel32.dll")) != NULL)
\r
77 m_GetDiskFreeSpaceEx = (FUNC_GETDISKFREESPACEEX)GetProcAddress(m_hDll, "GetDiskFreeSpaceExA");
\r
79 if(m_GetDiskFreeSpaceEx == NULL)
\r
81 FreeLibrary(m_hDll);
\r
90 /*----- KERNEL32をリリースする -------------------------------------------------
\r
97 *----------------------------------------------------------------------------*/
\r
99 void ReleaseKernelLib(void)
\r
102 FreeLibrary(m_hDll);
\r
109 /*----- フリーエリアのサイズを表わす文字列を返す-------------------------------
\r
116 *----------------------------------------------------------------------------*/
\r
118 char *AskLocalFreeSpace(char *Path)
\r
128 static char Buf[40];
\r
131 if(*(Path+1) == ':')
\r
133 strncpy(Buf, Path, 2);
\r
134 strcpy(Buf+2, "\\");
\r
136 if(m_GetDiskFreeSpaceEx != NULL)
\r
138 if((*m_GetDiskFreeSpaceEx)(Buf, &a, &b, &c) != 0)
\r
140 _ui64toa(a.QuadPart, Buf, 10);
\r
142 MakeSizeString(Free, Buf);
\r
149 if(GetDiskFreeSpace(Buf, &SectClus, &ByteSect, &FreeClus, &AllClus) == TRUE)
\r
151 Free = SectClus * ByteSect * FreeClus;
\r
152 MakeSizeString(Free, Buf);
\r