Rudimentiary drivebar support added.
[reactos.git] / rosapps / winfile / drivebar.c
1 /*
2 * ReactOS winfile
3 *
4 * drivebar.c
5 *
6 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #ifdef _MSC_VER
24 #include "stdafx.h"
25 #else
26 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
27 #include <windows.h>
28 #include <commctrl.h>
29 #include <stdlib.h>
30 #include <malloc.h>
31 #include <memory.h>
32 #include <tchar.h>
33 #include <process.h>
34 #include <stdio.h>
35 #endif
36
37 #include "main.h"
38 #include "settings.h"
39 #include "framewnd.h"
40 #include "childwnd.h"
41
42
43 ////////////////////////////////////////////////////////////////////////////////
44 // Global Variables:
45 //
46
47
48 void ConfigureDriveBar(HWND hDriveBar)
49 {
50 static DWORD dwLogicalDrivesSaved;
51 DWORD dwLogicalDrives = GetLogicalDrives();
52
53 if (!hDriveBar) return;
54
55 if (dwLogicalDrives != dwLogicalDrivesSaved) {
56 TBBUTTON drivebarBtn = {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP};
57 COMBOBOXEXITEM cbei;
58 int btn = 1;
59 PTSTR p;
60 int count = SendMessage(hDriveBar, TB_BUTTONCOUNT, 0, 0);
61 while (count) {
62 SendMessage(hDriveBar, TB_DELETEBUTTON, (WPARAM)--count, 0);
63 }
64 count = SendMessage(Globals.hDriveCombo, CB_GETCOUNT, 0, 0);
65 while (count) {
66 // SendMessage(Globals.hDriveCombo, CB_DELETESTRING, (WPARAM)--count, 0);
67 }
68 SendMessage(Globals.hDriveCombo, CB_RESETCONTENT, 0, 0);
69
70 memset(Globals.drives, 0, BUFFER_LEN);
71 GetLogicalDriveStrings(BUFFER_LEN, Globals.drives);
72 drivebarBtn.fsStyle = TBSTYLE_BUTTON;
73 drivebarBtn.idCommand = ID_DRIVE_FIRST;
74 for (p = Globals.drives; *p;) {
75 // insert drive letter
76 // TCHAR b[3] = { tolower(*p) };
77 // SendMessage(hDriveBar, TB_ADDSTRING, 0, (LPARAM)b);
78 TCHAR szVolumeNameBuffer[MAX_PATH];
79 TCHAR vol[MAX_PATH] = { tolower(*p) };
80 SendMessage(hDriveBar, TB_ADDSTRING, 0, (LPARAM)vol);
81 switch(GetDriveType(p)) {
82 case DRIVE_REMOVABLE: drivebarBtn.iBitmap = 1; break;
83 case DRIVE_CDROM: drivebarBtn.iBitmap = 3; break;
84 case DRIVE_REMOTE: drivebarBtn.iBitmap = 4; break;
85 case DRIVE_RAMDISK: drivebarBtn.iBitmap = 5; break;
86 default:/*DRIVE_FIXED*/ drivebarBtn.iBitmap = 2;
87 }
88 SendMessage(hDriveBar, TB_INSERTBUTTON, btn, (LPARAM)&drivebarBtn);
89
90 vol[0] = toupper(vol[0]);
91 vol[1] = _T(':'); vol[2] = _T('\\'); vol[3] = _T('\0');
92 if (drivebarBtn.iBitmap != 1 /*DRIVE_REMOVABLE*/ &&
93 GetVolumeInformation(vol, szVolumeNameBuffer,
94 sizeof(szVolumeNameBuffer)/sizeof(TCHAR),
95 NULL, NULL, NULL, NULL, 0) &&
96 szVolumeNameBuffer[0] != _T('\0')) {
97 vol[2] = _T(' '); vol[3] = _T('['); vol[4] = _T('\0');
98 _tcscat(vol, szVolumeNameBuffer);
99 _tcscat(vol, _T("] "));
100 } else {
101 vol[2] = _T(' ');
102 }
103 // cbei.mask = CBEIF_TEXT | CBEIF_INDENT | CBEIF_IMAGE| CBEIF_SELECTEDIMAGE;
104 cbei.mask = CBEIF_TEXT/* | CBEIF_IMAGE*/;
105 cbei.iItem = btn - 1;
106 cbei.pszText = vol;
107 cbei.cchTextMax = _tcslen(cbei.pszText);
108 cbei.iImage = drivebarBtn.iBitmap;
109 // cbei.iSelectedImage = IInf[iCnt].iSelectedImage;
110 // cbei.iIndent = IInf[iCnt].iIndent;
111 SendMessage(Globals.hDriveCombo, CBEM_INSERTITEM, 0, (LPARAM)&cbei);
112
113 drivebarBtn.idCommand++;
114 drivebarBtn.iString++;
115 while(*p++);
116 ++btn;
117 }
118 dwLogicalDrivesSaved = dwLogicalDrives;
119 // SendMessage(Globals.hDriveCombo, CB_SHOWDROPDOWN, (WPARAM)TRUE, (LPARAM)0);
120 }
121 }
122 /*
123 #ifndef __GNUC__
124 {
125 #define MAX_ITEMS 7
126
127 typedef struct {
128 int iImage;
129 int iSelectedImage;
130 int iIndent;
131 LPTSTR pszText;
132 } ITEMINFO, *PITEMINFO;
133
134 ITEMINFO IInf[] = {
135 { 0, 3, 0, _T("A:")},
136 { 1, 4, 1, _T("C: [SYSTEM]")},
137 { 2, 5, 2, _T("D:")},
138 { 0, 3, 0, _T("E: [SOFT_RAID_1]")},
139 { 1, 4, 1, _T("F: [DATAVOL]")},
140 { 2, 5, 2, _T("sixth")},
141 { 0, 3, 0, _T("seventh")},
142 };
143
144 COMBOBOXEXITEM cbei;
145 int iCnt;
146
147 for (iCnt = 0; iCnt < MAX_ITEMS; iCnt++) {
148 // cbei.mask = CBEIF_TEXT | CBEIF_INDENT | CBEIF_IMAGE| CBEIF_SELECTEDIMAGE;
149 cbei.mask = CBEIF_TEXT;
150 cbei.iItem = iCnt;
151 cbei.pszText = IInf[iCnt].pszText;
152 // cbei.cchTextMax = sizeof(IInf[iCnt].pszText);
153 cbei.cchTextMax = _tcslen(IInf[iCnt].pszText);
154 // cbei.iImage = IInf[iCnt].iImage;
155 // cbei.iSelectedImage = IInf[iCnt].iSelectedImage;
156 // cbei.iIndent = IInf[iCnt].iIndent;
157 SendMessage(Globals.hDriveCombo, CBEM_INSERTITEM, 0, (LPARAM)&cbei);
158 }
159 }
160 }
161 #endif
162 */
163
164 void _GetFreeSpaceEx(void)
165 {
166 BOOL fResult;
167 TCHAR szDrive[MAX_PATH];
168 ULARGE_INTEGER i64FreeBytesToCaller;
169 ULARGE_INTEGER i64TotalBytes;
170 ULARGE_INTEGER i64FreeBytes;
171
172 fResult = GetDiskFreeSpaceEx(szDrive,
173 (PULARGE_INTEGER)&i64FreeBytesToCaller,
174 (PULARGE_INTEGER)&i64TotalBytes,
175 (PULARGE_INTEGER)&i64FreeBytes);
176 }
177