System.TermInfo.Database.ReadDatabase C# (CSharp) Méthode

ReadDatabase() private static méthode

Read the database for the specified terminal from the specified directory.
private static ReadDatabase ( string term, string directoryPath ) : Database
term string The identifier for the terminal.
directoryPath string The path to the directory containing terminfo database files.
Résultat Database
            private static Database ReadDatabase(string term, string directoryPath)
            {
                if (string.IsNullOrEmpty(term) || string.IsNullOrEmpty(directoryPath))
                {
                    return null;
                }

                SafeFileHandle fd;
                if (!TryOpen(directoryPath + "/" + term[0].ToString() + "/" + term, out fd) &&          // /directory/termFirstLetter/term      (Linux)
                    !TryOpen(directoryPath + "/" + ((int)term[0]).ToString("X") + "/" + term, out fd))  // /directory/termFirstLetterAsHex/term (Mac)
                {
                    return null;
                }

                using (fd)
                {
                    // Read in all of the terminfo data
                    long termInfoLength = Interop.CheckIo(Interop.Sys.LSeek(fd, 0, Interop.Sys.SeekWhence.SEEK_END)); // jump to the end to get the file length
                    Interop.CheckIo(Interop.Sys.LSeek(fd, 0, Interop.Sys.SeekWhence.SEEK_SET)); // reset back to beginning
                    const int MaxTermInfoLength = 4096; // according to the term and tic man pages, 4096 is the terminfo file size max
                    const int HeaderLength = 12;
                    if (termInfoLength <= HeaderLength || termInfoLength > MaxTermInfoLength)
                    {
                        throw new InvalidOperationException(SR.IO_TermInfoInvalid);
                    }
                    int fileLen = (int)termInfoLength;

                    byte[] data = new byte[fileLen];
                    if (ConsolePal.Read(fd, data, 0, fileLen) != fileLen)
                    {
                        throw new InvalidOperationException(SR.IO_TermInfoInvalid);
                    }

                    // Create the database from the data
                    return new Database(term, data);
                }
            }

Same methods

TermInfo.Database::ReadDatabase ( string term ) : Database