[FORMATTING]
[reactos.git] / reactos / 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
69 PFILE_SYSTEM_LIST
70 CreateFileSystemList(
71 IN SHORT Left,
72 IN SHORT Top,
73 IN BOOLEAN ForceFormat,
74 IN LPCWSTR ForceFileSystem)
75 {
76 PFILE_SYSTEM_LIST List;
77 PFILE_SYSTEM_ITEM Item;
78 PLIST_ENTRY ListEntry;
79
80 List = (PFILE_SYSTEM_LIST)RtlAllocateHeap(ProcessHeap, 0, sizeof(FILE_SYSTEM_LIST));
81 if (List == NULL)
82 return NULL;
83
84 List->Left = Left;
85 List->Top = Top;
86 List->Selected = NULL;
87 InitializeListHead(&List->ListHead);
88
89 HOST_CreateFileSystemList(List);
90
91 if (!ForceFormat)
92 {
93 /* Add 'Keep' provider */
94 FS_AddProvider(List, NULL, NULL, NULL);
95 }
96
97 /* Search for ForceFileSystem in list */
98 ListEntry = List->ListHead.Flink;
99 while (ListEntry != &List->ListHead)
100 {
101 Item = CONTAINING_RECORD(ListEntry, FILE_SYSTEM_ITEM, ListEntry);
102 if (Item->FileSystem && wcscmp(ForceFileSystem, Item->FileSystem) == 0)
103 {
104 List->Selected = Item;
105 break;
106 }
107 ListEntry = ListEntry->Flink;
108 }
109 if (!List->Selected)
110 List->Selected = CONTAINING_RECORD(List->ListHead.Flink, FILE_SYSTEM_ITEM, ListEntry);
111
112 return List;
113 }
114
115
116 VOID
117 DestroyFileSystemList(
118 IN PFILE_SYSTEM_LIST List)
119 {
120 PLIST_ENTRY ListEntry = List->ListHead.Flink;
121 PFILE_SYSTEM_ITEM Item;
122 PLIST_ENTRY Next;
123
124 while (ListEntry != &List->ListHead)
125 {
126 Item = CONTAINING_RECORD(ListEntry, FILE_SYSTEM_ITEM, ListEntry);
127 Next = ListEntry->Flink;
128
129 RtlFreeHeap(ProcessHeap, 0, Item);
130
131 ListEntry = Next;
132 }
133 RtlFreeHeap(ProcessHeap, 0, List);
134 }
135
136
137 VOID
138 DrawFileSystemList(
139 IN PFILE_SYSTEM_LIST List)
140 {
141 PLIST_ENTRY ListEntry;
142 PFILE_SYSTEM_ITEM Item;
143 COORD coPos;
144 DWORD Written;
145 ULONG Index = 0;
146 CHAR Buffer[70];
147
148 ListEntry = List->ListHead.Flink;
149 while (ListEntry != &List->ListHead)
150 {
151 Item = CONTAINING_RECORD(ListEntry, FILE_SYSTEM_ITEM, ListEntry);
152
153 coPos.X = List->Left;
154 coPos.Y = List->Top + (SHORT)Index;
155 FillConsoleOutputAttribute(StdOutput,
156 FOREGROUND_WHITE | BACKGROUND_BLUE,
157 sizeof(Buffer),
158 coPos,
159 &Written);
160 FillConsoleOutputCharacterA(StdOutput,
161 ' ',
162 sizeof(Buffer),
163 coPos,
164 &Written);
165
166 if (Item->FileSystem)
167 {
168 if (Item->QuickFormat)
169 sprintf(Buffer, MUIGetString(STRING_FORMATDISK1), Item->FileSystem);
170 else
171 sprintf(Buffer, MUIGetString(STRING_FORMATDISK2), Item->FileSystem);
172 }
173 else
174 sprintf(Buffer, MUIGetString(STRING_KEEPFORMAT));
175
176 if (ListEntry == &List->Selected->ListEntry)
177 CONSOLE_SetInvertedTextXY(List->Left,
178 List->Top + (SHORT)Index,
179 Buffer);
180 else
181 CONSOLE_SetTextXY(List->Left,
182 List->Top + (SHORT)Index,
183 Buffer);
184 Index++;
185 ListEntry = ListEntry->Flink;
186 }
187 }
188
189
190 VOID
191 ScrollDownFileSystemList(
192 IN PFILE_SYSTEM_LIST List)
193 {
194 if (List->Selected->ListEntry.Flink != &List->ListHead)
195 {
196 List->Selected = CONTAINING_RECORD(List->Selected->ListEntry.Flink, FILE_SYSTEM_ITEM, ListEntry);
197 DrawFileSystemList(List);
198 }
199 }
200
201
202 VOID
203 ScrollUpFileSystemList(
204 IN PFILE_SYSTEM_LIST List)
205 {
206 if (List->Selected->ListEntry.Blink != &List->ListHead)
207 {
208 List->Selected = CONTAINING_RECORD(List->Selected->ListEntry.Blink, FILE_SYSTEM_ITEM, ListEntry);
209 DrawFileSystemList(List);
210 }
211 }
212
213 /* EOF */