コード例 #1
0
        /// <summary>
        ///     Constructor to load the specified Btrieve File at the given Path
        /// </summary>
        /// <param name="fileUtility"></param>
        /// <param name="path"></param>
        /// <param name="fileName"></param>
        public BtrieveFileProcessor(IFileUtility fileUtility, string path, string fileName)
        {
            _fileFinder = fileUtility;

            Keys = new Dictionary <ushort, BtrieveKey>();
            AutoincrementedKeys = new Dictionary <ushort, BtrieveKey>();

            if (string.IsNullOrEmpty(path))
            {
                path = Directory.GetCurrentDirectory();
            }

            if (!Path.EndsInDirectorySeparator(path))
            {
                path += Path.DirectorySeparatorChar;
            }

            var loadedFileName = _fileFinder.FindFile(path, fileName);

            // hack for MUTANTS which tries to load a DATT file
            if (Path.GetExtension(loadedFileName).ToUpper() == ".DATT")
            {
                loadedFileName = Path.ChangeExtension(loadedFileName, ".DAT");
            }

            // If a .DB version exists, load it over the .DAT file
            var dbFileName = loadedFileName.ToUpper().Replace(".DAT", ".DB");
            var fullPath   = Path.Combine(path, dbFileName);

            if (File.Exists(fullPath))
            {
                LoadSqlite(fullPath);
            }
            else
            {
                var btrieveFile = new BtrieveFile();
                btrieveFile.LoadFile(_logger, path, loadedFileName);
                CreateSqliteDB(fullPath, btrieveFile);
            }

            //Set Position to First Record
            StepFirst();
        }
コード例 #2
0
        /// <summary>
        ///     Loads a Btrieve .DAT File
        /// </summary>
        /// <param name="path"></param>
        /// <param name="fileName"></param>
        private void LoadBtrieve(string path, string fileName)
        {
            //Sanity Check if we're missing .DAT files and there are available .VIR files that can be used
            var virginFileName = fileName.Replace(".DAT", ".VIR");

            if (!File.Exists($"{path}{fileName}") && File.Exists($"{path}{virginFileName}"))
            {
                File.Copy($"{path}{virginFileName}", $"{path}{fileName}");
                _logger.Warn($"Created {fileName} by copying {virginFileName} for first use");
            }

            //If we're missing a DAT file, just bail. Because we don't know the file definition, we can't just create a "blank" one.
            if (!File.Exists($"{path}{fileName}"))
            {
                _logger.Error($"Unable to locate existing btrieve file {fileName}");
                throw new FileNotFoundException($"Unable to locate existing btrieve file {fileName}");
            }

            var fileData = File.ReadAllBytes($"{path}{fileName}");

            LoadedFile = new BtrieveFile(fileData)
            {
                FileName = LoadedFileName
            };
            LoadedFileSize = fileData.Length;
#if DEBUG
            _logger.Info($"Opened {fileName} and read {LoadedFile.Data.Length} bytes");
#endif
            //Only Parse Keys if they are defined
            if (LoadedFile.KeyCount > 0)
            {
                LoadBtrieveKeyDefinitions();
            }

            //Only load records if there are any present
            if (LoadedFile.RecordCount > 0)
            {
                LoadBtrieveRecords();
            }
        }