示例#1
0
        public DbFsIndices()
        {
            RootDirectory = Services <InteractionService> .Instance.DataDirectoryPath;
            _mode         = DbFsIndicesMode.OnAny;

            if ((_mode & DbFsIndicesMode.OnInitialize) != 0)
            {
                _dic = IndexDirectory(RootDirectory);
            }
            else
            {
                _dic = new BilateralDictionary <DbRecordId, String>();
            }
        }
示例#2
0
        private void StoreResourcePath(BilateralDictionary <DbRecordId, String> dic, DbRecordId dbRecordId, String currentPath)
        {
            if (dic.TryGetValue(dbRecordId, out var existingPath))
            {
                String existingName = Path.GetFileName(existingPath);
                String currentName  = Path.GetFileName(currentPath);

                _errorMessage.Clear();
                _errorMessage.AppendLine($"There is two files with the same DbRecordId [{dbRecordId:X8}].");
                _errorMessage.AppendLine($"Existing: {existingName} Path: {existingPath}");
                _errorMessage.AppendLine($"New: {currentName} Path: {currentPath}");
                _errorMessage.Append($"The new file [{currentName}] will replace the old one [{existingName}]. But be careful, this is probably a mistake. Only one of these files can be used by the game at the same time.");

                Log.Error(_errorMessage.ToString());
                _errorMessage.Clear();
            }

            dic.Add(dbRecordId, currentPath);
        }
示例#3
0
        private BilateralDictionary <DbRecordId, String> IndexDirectory(String directoryPath)
        {
            BilateralDictionary <DbRecordId, String> dic = new BilateralDictionary <DbRecordId, String>(capacity: 7000);

            foreach (String currentPath in Directory.EnumerateFiles(RootDirectory, "????????*", SearchOption.AllDirectories))
            {
                String currentName = Path.GetFileName(currentPath);
                String prefix      = currentName?.Substring(startIndex: 0, length: 8); // 0BEBC200
                if (!DbRecordId.TryParse(prefix, out var dbRecordId))
                {
                    Log.Warning($"Cannot parse DbRecordId from the name of file {currentPath}. Expected hexadecimal prefix like 0BEBC200.");
                    continue;
                }

                StoreResourcePath(dic, dbRecordId, currentPath);
            }

            return(dic);
        }