annotate netinstall/diskfull.cc @ 2619:935833be8506

[xemacs-hg @ 2005-02-28 17:02:09 by aidan] Register the source window as an Xt drawable when receiving an incremental selection transfer. This stops XEmacs looping until interrupted.
author aidan
date Mon, 28 Feb 2005 17:02:10 +0000
parents 3078fd1074e8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
1 /*
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
2 * Copyright (c) 2000, Red Hat, Inc.
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
3 *
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
7 * (at your option) any later version.
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
8 *
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
9 * A copy of the GNU General Public License can be found at
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
10 * http://www.gnu.org/
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
11 *
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
12 * Written by DJ Delorie <dj@cygnus.com>
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
13 *
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
14 */
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
15
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
16 /* The purpose of this file is to hide the mess needed just to figure
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
17 out how full a given disk is. There is an old API that can't
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
18 handle disks bigger than 2G, and a new API that isn't always
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
19 available. */
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
20
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
21 #include "win32.h"
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
22 #include "diskfull.h"
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
23
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
24 typedef BOOL (WINAPI * GDFS)(LPCTSTR, PULARGE_INTEGER, PULARGE_INTEGER,
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
25 PULARGE_INTEGER);
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
26
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
27 int
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
28 diskfull (char *path)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
29 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
30 GDFS gdfs = 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
31
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
32 HINSTANCE k = LoadLibrary ("KERNEL32.DLL");
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
33 if (k)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
34 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
35 gdfs = (GDFS) GetProcAddress (k, "GetDiskFreeSpaceExA");
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
36
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
37 if (gdfs)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
38 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
39 ULARGE_INTEGER avail, total, free;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
40 if (gdfs (path, &avail, &total, &free))
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
41 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
42 int perc = avail.QuadPart * 100 / total.QuadPart;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
43 return 100-perc;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
44 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
45 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
46 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
47
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
48 char root[4];
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
49 if (path[1] != ':')
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
50 return 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
51
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
52 root[0] = path[0];
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
53 root[1] = ':';
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
54 root[2] = '\\';
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
55 root[3] = 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
56
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
57 DWORD junk, free_clusters, total_clusters;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
58
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
59 if (GetDiskFreeSpace (root, &junk, &junk, &free_clusters, &total_clusters))
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
60 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
61 int perc = free_clusters * 100 / total_clusters;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
62 return 100-perc;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
63 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
64
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
65 return 0;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents:
diff changeset
66 }