Synchronize with trunk revision 59636 (just before Alex's CreateProcess revamp).
[reactos.git] / base / setup / usetup / fslist.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2003 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 /*
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS text-mode setup
22 * FILE: subsys/system/usetup/fslist.c
23 * PURPOSE: Filesystem list functions
24 * PROGRAMMER: Eric Kohl
25 * Casper S. Hornstrup (chorns@users.sourceforge.net)
26 */
27
28 #include "usetup.h"
29
30 #define NDEBUG
31 #include <debug.h>
32
33 /* FUNCTIONS ****************************************************************/
34
35 VOID
36 FS_AddProvider(
37 IN OUT PFILE_SYSTEM_LIST List,
38 IN LPCWSTR FileSystem,
39 IN FORMATEX FormatFunc,
40 IN CHKDSKEX ChkdskFunc)
41 {
42 PFILE_SYSTEM_ITEM Item;
43
44 Item = (PFILE_SYSTEM_ITEM)RtlAllocateHeap(ProcessHeap, 0, sizeof(FILE_SYSTEM_ITEM));
45 if (!Item)
46 return;
47
48 Item->FileSystem = FileSystem;
49 Item->FormatFunc = FormatFunc;
50 Item->ChkdskFunc = ChkdskFunc;
51 Item->QuickFormat = FALSE;
52 InsertTailList(&List->ListHead, &Item->ListEntry);
53
54 if (!FormatFunc)
55 return;
56
57 Item = (PFILE_SYSTEM_ITEM)RtlAllocateHeap(ProcessHeap, 0, sizeof(FILE_SYSTEM_ITEM));
58 if (!Item)
59 return;
60
61 Item->FileSystem = FileSystem;
62 Item->FormatFunc = FormatFunc;
63 Item->ChkdskFunc = ChkdskFunc;
64 Item->QuickFormat = TRUE;
65 InsertTailList(&List->ListHead, &Item->ListEntry);
66 }
67
68 PFILE_SYSTEM_LIST
69 CreateFileSystemList(
70 IN SHORT Left,
71 IN SHORT Top,
72 IN BOOLEAN ForceFormat,
73 IN LPCWSTR ForceFileSystem)
74 {
75 PFILE_SYSTEM_LIST List;
76 PFILE_SYSTEM_ITEM Item;
77 PLIST_ENTRY ListEntry;
78
79 List = (PFILE_SYSTEM_LIST)RtlAllocateHeap(ProcessHeap, 0, sizeof(FILE_SYSTEM_LIST));
80 if (List == NULL)
81 return NULL;
82
83 List->Left = Left;
84 List->Top = Top;
85 List->Selected = NULL;
86 InitializeListHead(&List->ListHead);
87
88 HOST_CreateFileSystemList(List);
89
90 if (!ForceFormat)
91 {
92 /* Add 'Keep' provider */
93 FS_AddProvider(List, NULL, NULL, NULL);
94 }
95
96 /* Search for ForceFileSystem in list */
97 ListEntry = List->ListHead.Flink;
98 while (ListEntry != &List->ListHead)
99 {
100 Item = CONTAINING_RECORD(ListEntry, FILE_SYSTEM_ITEM, ListEntry);
101 if (Item->FileSystem && wcscmp(ForceFileSystem, Item->FileSystem) == 0)
102 {
103 List->Selected = Item;
104 break;
105 }
106 ListEntry = ListEntry->Flink;
107 }
108 if (!List->Selected)
109 List->Selected = CONTAINING_RECORD(List->ListHead.Flink, FILE_SYSTEM_ITEM, ListEntry);
110
111 return List;
112 }
113
114 VOID
115 DestroyFileSystemList(
116 IN PFILE_SYSTEM_LIST List)
117 {
118 PLIST_ENTRY ListEntry = List->ListHead.Flink;
119 PFILE_SYSTEM_ITEM Item;
120 PLIST_ENTRY Next;
121
122 while (ListEntry != &List->ListHead)
123 {
124 Item = CONTAINING_RECORD(ListEntry, FILE_SYSTEM_ITEM, ListEntry);
125 Next = ListEntry->Flink;
126
127 RtlFreeHeap(ProcessHeap, 0, Item);
128
129 ListEntry = Next;
130 }
131 RtlFreeHeap(ProcessHeap, 0, List);
132 }
133
134 VOID
135 DrawFileSystemList(
136 IN PFILE_SYSTEM_LIST List)
137 {
138 PLIST_ENTRY ListEntry;
139 PFILE_SYSTEM_ITEM Item;
140 COORD coPos;
141 DWORD Written;
142 ULONG Index = 0;
143 CHAR Buffer[70];
144
145 ListEntry = List->ListHead.Flink;
146 while (ListEntry != &List->ListHead)
147 {
148 Item = CONTAINING_RECORD(ListEntry, FILE_SYSTEM_ITEM, ListEntry);
149
150 coPos.X = List->Left;
151 coPos.Y = List->Top + (SHORT)Index;
152 FillConsoleOutputAttribute(StdOutput,
153 FOREGROUND_WHITE | BACKGROUND_BLUE,
154 sizeof(Buffer),
155 coPos,
156 &Written);
157 FillConsoleOutputCharacterA(StdOutput,
158 ' ',
159 sizeof(Buffer),
160 coPos,
161 &Written);
162
163 if (Item->FileSystem)
164 {
165 if (Item->QuickFormat)
166 sprintf(Buffer, MUIGetString(STRING_FORMATDISK1), Item->FileSystem);
167 else
168 sprintf(Buffer, MUIGetString(STRING_FORMATDISK2), Item->FileSystem);
169 }
170 else
171 sprintf(Buffer, MUIGetString(STRING_KEEPFORMAT));
172
173 if (ListEntry == &List->Selected->ListEntry)
174 CONSOLE_SetInvertedTextXY(List->Left,
175 List->Top + (SHORT)Index,
176 Buffer);
177 else
178 CONSOLE_SetTextXY(List->Left,
179 List->Top + (SHORT)Index,
180 Buffer);
181 Index++;
182 ListEntry = ListEntry->Flink;
183 }
184 }
185
186 VOID
187 ScrollDownFileSystemList(
188 IN PFILE_SYSTEM_LIST List)
189 {
190 if (List->Selected->ListEntry.Flink != &List->ListHead)
191 {
192 List->Selected = CONTAINING_RECORD(List->Selected->ListEntry.Flink, FILE_SYSTEM_ITEM, ListEntry);
193 DrawFileSystemList(List);
194 }
195 }
196
197 VOID
198 ScrollUpFileSystemList(
199 IN PFILE_SYSTEM_LIST List)
200 {
201 if (List->Selected->ListEntry.Blink != &List->ListHead)
202 {
203 List->Selected = CONTAINING_RECORD(List->Selected->ListEntry.Blink, FILE_SYSTEM_ITEM, ListEntry);
204 DrawFileSystemList(List);
205 }
206 }
207
208 /* EOF */