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