Beispiel #1
0
        /// <summary>
        ///     Saves the MBBSEmu representation of a Btrieve File to disk
        /// </summary>
        private void SaveJson()
        {
            var jsonFileName = LoadedFileName.ToUpper().Replace(".DAT", ".EMU");

            File.WriteAllText($"{LoadedFilePath}{jsonFileName}",
                              JsonConvert.SerializeObject(LoadedFile, Formatting.Indented));
        }
Beispiel #2
0
        /// <summary>
        ///     Constructor to load the specified Btrieve File at the given Path
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="path"></param>
        public BtrieveFileProcessor(string fileName, string path)
        {
            _fileFinder = DependencyInjection.ServiceResolver.GetService <IFileUtility>();

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

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

            LoadedFilePath = path;
            LoadedFileName = _fileFinder.FindFile(path, fileName);

            //If a .EMU version exists, load it over the .DAT file
            var jsonFileName = LoadedFileName.ToUpper().Replace(".DAT", ".EMU");

            if (File.Exists($"{LoadedFilePath}{jsonFileName}"))
            {
                LoadedFileName = jsonFileName;
                LoadJson(LoadedFilePath, LoadedFileName);
            }
            else
            {
                LoadBtrieve(LoadedFilePath, LoadedFileName);
                SaveJson();
            }

            //Ensure loaded records (regardless of source) are in order by their offset within the Btrieve file
            LoadedFile.Records = LoadedFile.Records.OrderBy(x => x.Offset).ToList();

            //Set Position to First Record
            Position = LoadedFile.Records.OrderBy(x => x.Offset).FirstOrDefault()?.Offset ?? 0;
        }