public void MapFilesToFolders(BigFileFolder rootFolder, FileMappingData mapping) { log.Info("Mapping files to folders..."); stopwatch.Reset(); stopwatch.Start(); for (int i = 0; i < mapping.FilesList.Length; i++) { BigFileFile file = mapping.FilesList[i]; if (file != null) { BigFileFolder folder = rootFolder.FolderMap[mapping.FilesList[i].FileInfo.Folder]; if (folder != null) { folder.Files.Add(mapping.FilesList[i]); } } } diagData.MapFilesToFolders = stopwatch.ElapsedMilliseconds; stopwatch.Reset(); }
public UnpackedFolderMapAndFilesList CreateFolderTreeAndFilesListFromDirectory(DirectoryInfo dir, UnpackedRenamedFileMapping mapping, FileMappingData defaultMappingData) { log.Info("Creating folder tree and files list from directory " + dir.FullName); IBigFileFileInfo[] fileInfos = new IBigFileFileInfo[mapping.KeyMap.Count]; List <IBigFileFolderInfo> folderInfos = new List <IBigFileFolderInfo>(); Dictionary <short, BigFileFolder> folderMap = new Dictionary <short, BigFileFolder>(); short folderCount = 0; int fileCount = 0; Dictionary <string, UnpackedRenamedFileMapping.RenamedFileMappingData> temp = new Dictionary <string, UnpackedRenamedFileMapping.RenamedFileMappingData>(mapping.RenamedMap); BigFileFolder recursion(DirectoryInfo directory, string dirName, BigFileFolder parentFolder) { IBigFileFolderInfo folderInfo = version.CreateFolderInfo(); folderInfo.Unknown_01 = 0; folderInfo.PreviousFolder = parentFolder != null ? parentFolder.FolderIndex : (short)-1; folderInfo.NextFolder = -1; folderInfo.Unknown_02 = 0; folderInfo.Name = parentFolder == null ? //oh my lawdy what is this EDIT 4/5/2018: what the f**k "/".EncodeToBadString(length: 54) : directory.Name.EncodeToBadString(length: 54); folderInfos.Add(folderInfo); BigFileFolder thisFolder = new BigFileFolder(folderCount, folderInfo, folderMap); folderMap.Add(folderCount, thisFolder); foreach (FileInfo file in directory.GetFiles()) { if (file.Name.EndsWith(".header")) { continue; } string fileName = dirName + "//" + file.Name; UnpackedRenamedFileMapping.RenamedFileMappingData mappingData = mapping[fileName]; temp.Remove(fileName); IBigFileFileInfo fileInfo = version.CreateFileInfo(); defaultMappingData[mappingData.Key].FileInfo.Copy(fileInfo); fileInfo.Key = mappingData.Key; //fileInfo.FileNumber = fileCount; fileInfo.Name = mappingData.OriginalName.EncodeToBadString(length: 60); fileInfo.Folder = folderCount; log.Debug("Add file " + file.FullName); fileInfos[fileCount] = fileInfo; fileCount++; } folderCount++; foreach (DirectoryInfo dirInfo in directory.GetDirectories()) { if (parentFolder == null) //ONLY THE FIRST RECURSION, PREVENTS ADDING WRONG FOLDERS WHEN PACKING { thisFolder.SubFolders.Add(recursion(dirInfo, dirInfo.Name, thisFolder)); } else { thisFolder.SubFolders.Add(recursion(dirInfo, dirName + "/" + dirInfo.Name, thisFolder)); } } return(thisFolder); } recursion(dir, "", null); if (fileCount != mapping.KeyMap.Count) { log.Error(string.Format("Missing {0} files!", temp.Count)); foreach (KeyValuePair <string, UnpackedRenamedFileMapping.RenamedFileMappingData> kvp in temp) { log.Error(string.Format(" >{0}", kvp.Value.FileName)); } } return(new UnpackedFolderMapAndFilesList() { folderMap = folderMap, filesList = fileInfos, foldersList = folderInfos.ToArray(), }); }
public FileMappingData CreateFileMappingData(BigFileFolder rootFolder, IBigFileFileInfo[] fileInfos) { log.Info("Creating mapping data..."); log.Info("Creating files list... Count: " + fileInfos.Length); stopwatch.Reset(); stopwatch.Start(); FileMappingData mappingData = new FileMappingData(); BigFileFile[] filesList = new BigFileFile[fileInfos.Length]; for (int i = 0; i < fileInfos.Length; i++) { BigFileFile newFile = null; if (fileInfos[i] != null) { newFile = new BigFileFile(fileInfos[i], rootFolder.FolderMap[fileInfos[i].Folder]); newFile.MappingData = mappingData; filesList[i] = newFile; } else { log.Error(string.Format("File info at index {0} is null!", i)); } } diagData.CreateFilesList = stopwatch.ElapsedMilliseconds; log.Info("List created!"); log.Info("Creating file mappings..."); stopwatch.Reset(); stopwatch.Start(); Dictionary <int, BigFileFile> fileKeyMapping = new Dictionary <int, BigFileFile>(); for (int i = 0; i < filesList.Length; i++) { if (fileInfos[i]?.Name == null) { continue; } if (!fileKeyMapping.ContainsKey(fileInfos[i].Key)) { fileKeyMapping.Add(fileInfos[i].Key, filesList[i]); } else { log.Error("File key mapping already contains key " + fileInfos[i].Key + " (File: " + filesList[i].Name + ")"); } if (filesList[i].FileInfo.FileNumber == -1) { log.Debug(string.Format("File number is -1! (key:{0:X8}) (offset:{1:X8})", fileInfos[i].Key, fileInfos[i].Offset)); } } log.Info("Mappings created!"); foreach (KeyValuePair <short, BigFileFolder> kvp in rootFolder.FolderMap) { kvp.Value.FileMap = mappingData; } diagData.CreateKeyAndNumMappings = stopwatch.ElapsedMilliseconds; stopwatch.Reset(); mappingData.FilesList = filesList; mappingData.KeyMapping = fileKeyMapping; log.Info("mappingData count: {0}", mappingData.FilesList.Length); return(mappingData); }