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: base/setup/usetup/fslist.c 23 * PURPOSE: Filesystem list functions 24 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net) 25 */ 26 27 #include "usetup.h" 28 29 #define NDEBUG 30 #include <debug.h> 31 32 /* FUNCTIONS ****************************************************************/ 33 34 static VOID 35 AddProvider( 36 IN OUT PFILE_SYSTEM_LIST List, 37 IN PCWSTR FileSystemName, // Redundant, I need to check whether this is reaaaaally needed.... 38 IN PFILE_SYSTEM FileSystem) 39 { 40 PFILE_SYSTEM_ITEM Item; 41 42 Item = (PFILE_SYSTEM_ITEM)RtlAllocateHeap(ProcessHeap, 0, sizeof(*Item)); 43 if (!Item) 44 return; 45 46 Item->FileSystemName = FileSystemName; 47 Item->FileSystem = FileSystem; 48 Item->QuickFormat = TRUE; 49 InsertTailList(&List->ListHead, &Item->ListEntry); 50 51 if (!FileSystem) 52 return; 53 54 Item = (PFILE_SYSTEM_ITEM)RtlAllocateHeap(ProcessHeap, 0, sizeof(*Item)); 55 if (!Item) 56 return; 57 58 Item->FileSystemName = FileSystemName; 59 Item->FileSystem = FileSystem; 60 Item->QuickFormat = FALSE; 61 InsertTailList(&List->ListHead, &Item->ListEntry); 62 } 63 64 static VOID 65 InitializeFileSystemList( 66 IN PFILE_SYSTEM_LIST List) 67 { 68 ULONG Count; 69 PFILE_SYSTEM FileSystems; 70 71 FileSystems = GetRegisteredFileSystems(&Count); 72 if (!FileSystems || Count == 0) 73 return; 74 75 while (Count--) 76 { 77 AddProvider(List, FileSystems->FileSystemName, FileSystems); 78 ++FileSystems; 79 } 80 } 81 82 PFILE_SYSTEM_LIST 83 CreateFileSystemList( 84 IN SHORT Left, 85 IN SHORT Top, 86 IN BOOLEAN ForceFormat, 87 IN PCWSTR SelectFileSystem) 88 { 89 PFILE_SYSTEM_LIST List; 90 PFILE_SYSTEM_ITEM Item; 91 PLIST_ENTRY ListEntry; 92 93 List = (PFILE_SYSTEM_LIST)RtlAllocateHeap(ProcessHeap, 0, sizeof(*List)); 94 if (List == NULL) 95 return NULL; 96 97 List->Left = Left; 98 List->Top = Top; 99 List->Selected = NULL; 100 InitializeListHead(&List->ListHead); 101 102 InitializeFileSystemList(List); 103 if (!ForceFormat) 104 { 105 /* Add the 'Keep existing filesystem' dummy provider */ 106 AddProvider(List, NULL, NULL); 107 } 108 109 /* Search for SelectFileSystem in list */ 110 ListEntry = List->ListHead.Flink; 111 while (ListEntry != &List->ListHead) 112 { 113 Item = CONTAINING_RECORD(ListEntry, FILE_SYSTEM_ITEM, ListEntry); 114 if (Item->FileSystemName && wcscmp(SelectFileSystem, Item->FileSystemName) == 0) 115 { 116 List->Selected = Item; 117 break; 118 } 119 ListEntry = ListEntry->Flink; 120 } 121 if (!List->Selected) 122 List->Selected = CONTAINING_RECORD(List->ListHead.Flink, FILE_SYSTEM_ITEM, ListEntry); 123 124 return List; 125 } 126 127 VOID 128 DestroyFileSystemList( 129 IN PFILE_SYSTEM_LIST List) 130 { 131 PLIST_ENTRY ListEntry; 132 PFILE_SYSTEM_ITEM Item; 133 134 ListEntry = List->ListHead.Flink; 135 while (!IsListEmpty(&List->ListHead)) 136 { 137 ListEntry = RemoveHeadList(&List->ListHead); 138 Item = CONTAINING_RECORD(ListEntry, FILE_SYSTEM_ITEM, ListEntry); 139 RtlFreeHeap(ProcessHeap, 0, Item); 140 } 141 142 RtlFreeHeap(ProcessHeap, 0, List); 143 } 144 145 VOID 146 DrawFileSystemList( 147 IN PFILE_SYSTEM_LIST List) 148 { 149 PLIST_ENTRY ListEntry; 150 PFILE_SYSTEM_ITEM Item; 151 COORD coPos; 152 DWORD Written; 153 ULONG Index = 0; 154 CHAR Buffer[128]; 155 156 ListEntry = List->ListHead.Flink; 157 while (ListEntry != &List->ListHead) 158 { 159 Item = CONTAINING_RECORD(ListEntry, FILE_SYSTEM_ITEM, ListEntry); 160 161 coPos.X = List->Left; 162 coPos.Y = List->Top + (SHORT)Index; 163 FillConsoleOutputAttribute(StdOutput, 164 FOREGROUND_WHITE | BACKGROUND_BLUE, 165 sizeof(Buffer), 166 coPos, 167 &Written); 168 FillConsoleOutputCharacterA(StdOutput, 169 ' ', 170 sizeof(Buffer), 171 coPos, 172 &Written); 173 174 if (Item->FileSystemName) 175 { 176 if (Item->QuickFormat) 177 snprintf(Buffer, sizeof(Buffer), MUIGetString(STRING_FORMATDISK1), Item->FileSystemName); 178 else 179 snprintf(Buffer, sizeof(Buffer), MUIGetString(STRING_FORMATDISK2), Item->FileSystemName); 180 } 181 else 182 { 183 snprintf(Buffer, sizeof(Buffer), MUIGetString(STRING_KEEPFORMAT)); 184 } 185 186 if (ListEntry == &List->Selected->ListEntry) 187 CONSOLE_SetInvertedTextXY(List->Left, 188 List->Top + (SHORT)Index, 189 Buffer); 190 else 191 CONSOLE_SetTextXY(List->Left, 192 List->Top + (SHORT)Index, 193 Buffer); 194 Index++; 195 ListEntry = ListEntry->Flink; 196 } 197 } 198 199 VOID 200 ScrollDownFileSystemList( 201 IN PFILE_SYSTEM_LIST List) 202 { 203 if (List->Selected->ListEntry.Flink != &List->ListHead) 204 { 205 List->Selected = CONTAINING_RECORD(List->Selected->ListEntry.Flink, FILE_SYSTEM_ITEM, ListEntry); 206 DrawFileSystemList(List); 207 } 208 } 209 210 VOID 211 ScrollUpFileSystemList( 212 IN PFILE_SYSTEM_LIST List) 213 { 214 if (List->Selected->ListEntry.Blink != &List->ListHead) 215 { 216 List->Selected = CONTAINING_RECORD(List->Selected->ListEntry.Blink, FILE_SYSTEM_ITEM, ListEntry); 217 DrawFileSystemList(List); 218 } 219 } 220 221 /* EOF */ 222