Beispiel #1
0
        private static IEnumerable <Idx.Entry> OpenIdx(string fileName)
        {
            using var idxStream = File.OpenRead(fileName);
            if (!Idx.IsValid(idxStream))
            {
                throw new CustomException($"The IDX {fileName} is invalid or not recognized.");
            }

            return(Idx.Read(idxStream));
        }
Beispiel #2
0
        public static List <Msg.Entry> ReadMsgFromIdx(string fileName) => File.OpenRead(fileName).Using(stream =>
        {
            if (!Idx.IsValid(stream))
            {
                throw new InvalidFileException(typeof(Idx));
            }

            var imgFileName = $"{Path.GetFileNameWithoutExtension(fileName)}.img";
            var imgFilePath = Path.Combine(Path.GetDirectoryName(fileName), imgFileName);

            if (!File.Exists(imgFilePath))
            {
                throw new FileNotFoundException($"Unable to find {imgFileName} in the same directory of the IDX.");
            }

            return(File.OpenRead(imgFilePath).Using(imgStream => ReadMsgFromIdx(stream, imgStream)));
        });