3 * Copyright (C) 2009 Hervé Poussineau <hpoussin@reactos.org>
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.
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.
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.
22 DBG_DEFAULT_CHANNEL(INIFILE
);
24 static ARC_STATUS
IniOpenIniFile(ULONG
* FileId
)
26 CHAR FreeldrPath
[MAX_PATH
];
29 // Create full freeldr.ini path
31 MachDiskGetBootPath(FreeldrPath
, sizeof(FreeldrPath
));
32 strcat(FreeldrPath
, "\\freeldr.ini");
34 // Try to open freeldr.ini
35 return ArcOpen(FreeldrPath
, OpenReadOnly
, FileId
);
38 BOOLEAN
IniFileInitialize(VOID
)
40 FILEINFORMATION FileInformation
;
41 ULONG FileId
; // File handle for freeldr.ini
42 PCHAR FreeLoaderIniFileData
;
43 ULONG FreeLoaderIniFileSize
, Count
;
46 TRACE("IniFileInitialize()\n");
51 Status
= IniOpenIniFile(&FileId
);
52 if (Status
!= ESUCCESS
)
54 UiMessageBoxCritical("Error opening freeldr.ini or file not found.\nYou need to re-install FreeLoader.");
61 Status
= ArcGetFileInformation(FileId
, &FileInformation
);
62 if (Status
!= ESUCCESS
|| FileInformation
.EndingAddress
.HighPart
!= 0)
64 UiMessageBoxCritical("Error while getting informations about freeldr.ini.\nYou need to re-install FreeLoader.");
67 FreeLoaderIniFileSize
= FileInformation
.EndingAddress
.LowPart
;
70 // Allocate memory to cache the whole freeldr.ini
72 FreeLoaderIniFileData
= FrLdrTempAlloc(FreeLoaderIniFileSize
, TAG_INI_FILE
);
73 if (!FreeLoaderIniFileData
)
75 UiMessageBoxCritical("Out of memory while loading freeldr.ini.");
81 // Read freeldr.ini off the disk
83 Status
= ArcRead(FileId
, FreeLoaderIniFileData
, FreeLoaderIniFileSize
, &Count
);
84 if (Status
!= ESUCCESS
|| Count
!= FreeLoaderIniFileSize
)
86 UiMessageBoxCritical("Error while reading freeldr.ini.");
88 FrLdrTempFree(FreeLoaderIniFileData
, TAG_INI_FILE
);
93 // Parse the .ini file data
95 Success
= IniParseFile(FreeLoaderIniFileData
, FreeLoaderIniFileSize
);
98 // Do some cleanup, and return
101 FrLdrTempFree(FreeLoaderIniFileData
, TAG_INI_FILE
);