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 /* Enable this define to hide FAT32 choice in case FAT is already present */ 33 #define HIDE_FAT32_CHOICE 34 35 /* FUNCTIONS ****************************************************************/ 36 37 static VOID 38 AddProvider( 39 IN OUT PFILE_SYSTEM_LIST List, 40 IN PCWSTR FileSystem) 41 { 42 PFILE_SYSTEM_ITEM Item; 43 44 Item = (PFILE_SYSTEM_ITEM)RtlAllocateHeap(ProcessHeap, 0, sizeof(*Item)); 45 if (!Item) 46 return; 47 48 Item->FileSystem = FileSystem; 49 Item->QuickFormat = TRUE; 50 InsertTailList(&List->ListHead, &Item->ListEntry); 51 52 if (!FileSystem) 53 return; 54 55 Item = (PFILE_SYSTEM_ITEM)RtlAllocateHeap(ProcessHeap, 0, sizeof(*Item)); 56 if (!Item) 57 return; 58 59 Item->FileSystem = FileSystem; 60 Item->QuickFormat = FALSE; 61 InsertTailList(&List->ListHead, &Item->ListEntry); 62 } 63 64 static VOID 65 InitializeFileSystemList( 66 IN OUT PFILE_SYSTEM_LIST List, 67 IN BOOLEAN ForceFormat) 68 { 69 PCWSTR FileSystemName; 70 ULONG Index; 71 72 #ifdef HIDE_FAT32_CHOICE 73 BOOLEAN FatPresent = FALSE; 74 75 /* Check whether the FAT filesystem is present */ 76 Index = 0; 77 while (GetRegisteredFileSystems(Index++, &FileSystemName)) 78 { 79 if (_wcsicmp(FileSystemName, L"FAT") == 0) 80 { 81 FatPresent = TRUE; 82 break; 83 } 84 } 85 86 #endif 87 88 Index = 0; 89 while (GetRegisteredFileSystems(Index++, &FileSystemName)) 90 { 91 #ifdef HIDE_FAT32_CHOICE 92 /* USETUP only: If the FAT filesystem is present, show it, but 93 * don't display FAT32. The FAT formatter will automatically 94 * determine whether to use FAT12/16 or FAT32. */ 95 if (FatPresent && _wcsicmp(FileSystemName, L"FAT32") == 0) 96 continue; 97 #endif 98 AddProvider(List, FileSystemName); 99 } 100 101 if (!ForceFormat) 102 { 103 /* Add the 'Keep existing filesystem' dummy provider */ 104 AddProvider(List, NULL); 105 } 106 } 107 108 PFILE_SYSTEM_LIST 109 CreateFileSystemList( 110 IN SHORT Left, 111 IN SHORT Top, 112 IN BOOLEAN ForceFormat, 113 IN PCWSTR SelectFileSystem) 114 { 115 PFILE_SYSTEM_LIST List; 116 PFILE_SYSTEM_ITEM Item; 117 PLIST_ENTRY ListEntry; 118 119 List = (PFILE_SYSTEM_LIST)RtlAllocateHeap(ProcessHeap, 0, sizeof(*List)); 120 if (List == NULL) 121 return NULL; 122 123 List->Left = Left; 124 List->Top = Top; 125 List->Selected = NULL; 126 InitializeListHead(&List->ListHead); 127 128 InitializeFileSystemList(List, ForceFormat); 129 130 /* Search for SelectFileSystem in list */ 131 ListEntry = List->ListHead.Flink; 132 while (ListEntry != &List->ListHead) 133 { 134 Item = CONTAINING_RECORD(ListEntry, FILE_SYSTEM_ITEM, ListEntry); 135 if (Item->FileSystem && _wcsicmp(SelectFileSystem, Item->FileSystem) == 0) 136 { 137 List->Selected = Item; 138 break; 139 } 140 ListEntry = ListEntry->Flink; 141 } 142 if (!List->Selected) 143 List->Selected = CONTAINING_RECORD(List->ListHead.Flink, FILE_SYSTEM_ITEM, ListEntry); 144 145 return List; 146 } 147 148 VOID 149 DestroyFileSystemList( 150 IN PFILE_SYSTEM_LIST List) 151 { 152 PLIST_ENTRY ListEntry; 153 PFILE_SYSTEM_ITEM Item; 154 155 ListEntry = List->ListHead.Flink; 156 while (!IsListEmpty(&List->ListHead)) 157 { 158 ListEntry = RemoveHeadList(&List->ListHead); 159 Item = CONTAINING_RECORD(ListEntry, FILE_SYSTEM_ITEM, ListEntry); 160 RtlFreeHeap(ProcessHeap, 0, Item); 161 } 162 163 RtlFreeHeap(ProcessHeap, 0, List); 164 } 165 166 VOID 167 DrawFileSystemList( 168 IN PFILE_SYSTEM_LIST List) 169 { 170 PLIST_ENTRY ListEntry; 171 PFILE_SYSTEM_ITEM Item; 172 COORD coPos; 173 DWORD Written; 174 ULONG Index = 0; 175 CHAR Buffer[128]; 176 177 ListEntry = List->ListHead.Flink; 178 while (ListEntry != &List->ListHead) 179 { 180 Item = CONTAINING_RECORD(ListEntry, FILE_SYSTEM_ITEM, ListEntry); 181 182 coPos.X = List->Left; 183 coPos.Y = List->Top + (SHORT)Index; 184 FillConsoleOutputAttribute(StdOutput, 185 FOREGROUND_WHITE | BACKGROUND_BLUE, 186 sizeof(Buffer), 187 coPos, 188 &Written); 189 FillConsoleOutputCharacterA(StdOutput, 190 ' ', 191 sizeof(Buffer), 192 coPos, 193 &Written); 194 195 if (Item->FileSystem) 196 { 197 snprintf(Buffer, sizeof(Buffer), 198 MUIGetString(Item->QuickFormat ? STRING_FORMATDISK1 199 : STRING_FORMATDISK2), 200 Item->FileSystem); 201 } 202 else 203 { 204 snprintf(Buffer, sizeof(Buffer), MUIGetString(STRING_KEEPFORMAT)); 205 } 206 207 if (ListEntry == &List->Selected->ListEntry) 208 { 209 CONSOLE_SetInvertedTextXY(List->Left, 210 List->Top + (SHORT)Index, 211 Buffer); 212 } 213 else 214 { 215 CONSOLE_SetTextXY(List->Left, 216 List->Top + (SHORT)Index, 217 Buffer); 218 } 219 Index++; 220 ListEntry = ListEntry->Flink; 221 } 222 } 223 224 VOID 225 ScrollDownFileSystemList( 226 IN PFILE_SYSTEM_LIST List) 227 { 228 if (List->Selected->ListEntry.Flink != &List->ListHead) 229 { 230 List->Selected = CONTAINING_RECORD(List->Selected->ListEntry.Flink, FILE_SYSTEM_ITEM, ListEntry); 231 DrawFileSystemList(List); 232 } 233 } 234 235 VOID 236 ScrollUpFileSystemList( 237 IN PFILE_SYSTEM_LIST List) 238 { 239 if (List->Selected->ListEntry.Blink != &List->ListHead) 240 { 241 List->Selected = CONTAINING_RECORD(List->Selected->ListEntry.Blink, FILE_SYSTEM_ITEM, ListEntry); 242 DrawFileSystemList(List); 243 } 244 } 245 246 /* EOF */ 247