Пример #1
0
        public UnpackedRenamedFileMapping LoadMappingData()
        {
            if (!fileInfo.Exists)
            {
                throw new Exception("Can't read from null file!");
            }

            log.Info("Loading renamed file mapping from file: " + fileInfo.FullName);

            UnpackedRenamedFileMapping mapping = new UnpackedRenamedFileMapping();

            using (FileStream fs = File.OpenRead(fileInfo.FullName))
            {
                int sig = fs.ReadByte();
                while (sig != -1)
                {
                    UnpackedRenamedFileMapping.RenamedFileMappingData data = new UnpackedRenamedFileMapping.RenamedFileMappingData();

                    data.ReadFromStream(fs, tempBuffer);

                    mapping[data.Key] = data;

                    sig = fs.ReadByte();
                }
            }

            return(mapping);
        }
Пример #2
0
        public UnpackedRenamedFileMapping CreateRenamedFileMapping(BigFileFolder folder, UnpackedRenamedFileMapping mapping = null, Dictionary <string, int> fileRenameCounts = null)
        {
            bool isFirst = mapping == null;

            if (isFirst)
            {
                mapping          = new UnpackedRenamedFileMapping();
                fileRenameCounts = new Dictionary <string, int>();
                stopwatch.Reset();
                stopwatch.Start();
            }

            foreach (BigFileFile file in folder.Files)
            {
                string fullName = file.FullFolderPath + file.Name;

                //if (extensionsList != null && extensionsList.ContainsKey(file.FileInfo.FileType))
                //{
                //    fullName += "." + extensionsList[file.FileInfo.FileType];
                //}
                //else
                //{
                fullName += string.Format(".{0}", file.FileInfo.FileType);
                //}

                string fullNameLower = fullName.ToLowerInvariant();

                if (fileRenameCounts.ContainsKey(fullNameLower))
                {
                    fileRenameCounts[fullNameLower]++;
                    fullName += "_" + fileRenameCounts[fullNameLower];
                }
                else
                {
                    fileRenameCounts.Add(fullNameLower, 1);
                }

                log.Debug(file.Name + " remapped to " + fullName);

                UnpackedRenamedFileMapping.RenamedFileMappingData data = new UnpackedRenamedFileMapping.RenamedFileMappingData()
                {
                    Key          = file.FileInfo.Key,
                    OriginalName = file.Name,
                    FileName     = fullName
                };

                mapping[file.FileInfo.Key] = data;
            }

            foreach (BigFileFolder childFolder in folder.SubFolders)
            {
                CreateRenamedFileMapping(childFolder, mapping, fileRenameCounts);
            }

            if (isFirst)
            {
                stopwatch.Stop();
                diagData.CreateRenamedFileMapping = stopwatch.ElapsedMilliseconds;
            }

            return(mapping);
        }
Пример #3
0
        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(),
            });
        }