Example #1
0
        public void DebugLogRootFolderTree(BigFileFolder rootFolder)
        {
            Action <BigFileFolder, int> recursion = null;

            recursion = (folder, depth) =>
            {
                string folderString = "";
                string fileString   = "     ";
                for (int i = 0; i < depth; i++)
                {
                    folderString += "-";
                    fileString   += " ";
                }
                log.Debug(folderString + Encoding.Default.GetString(folder.InfoStruct.Name));
                foreach (BigFileFile file in folder.Files)
                {
                    log.Debug(fileString + file.Name);
                }
                foreach (BigFileFolder subFolder in folder.SubFolders)
                {
                    recursion.Invoke(subFolder, depth + 1);
                }
            };

            recursion.Invoke(rootFolder, 0);
        }
Example #2
0
        public void SortFolderTree(BigFileFolder folder, bool recursive = true, bool sortFiles = true)
        {
            List <BigFileFolder> newFolder = folder.SubFolders.OrderBy(f => f.Name).ToList();

            for (int i = 0; i < folder.SubFolders.Count; i++)
            {
                folder.SubFolders[i] = newFolder[i];
            }

            if (sortFiles)
            {
                List <BigFileFile> newFiles = folder.Files.OrderBy(f => f.Name).ToList();
                for (int i = 0; i < folder.Files.Count; i++)
                {
                    folder.Files[i] = newFiles[i];
                }
            }

            if (recursive)
            {
                foreach (BigFileFolder folder2 in folder.SubFolders)
                {
                    SortFolderTree(folder2);
                }
            }
        }
Example #3
0
 public BigFileFile(IBigFileFileInfo _fileInfo, BigFileFolder _parentFolder)
 {
     FileInfo       = _fileInfo;
     ParentFolder   = _parentFolder;
     name           = FileInfo.Name.EncodeToGoodString();
     Archetype      = this.CreateArchetype();
     Archetype.File = this;
 }
Example #4
0
        public void CreateDirectoriesFromTree(DirectoryInfo dir, BigFileFolder rootFolder)
        {
            stopwatch.Reset();
            stopwatch.Start();
            string str = "";

            foreach (KeyValuePair <short, BigFileFolder> kvp in bigFile.RootFolder.FolderMap)
            {
                str = dir + "\\" + kvp.Value.FullDirectoryName;
                if (!Directory.Exists(str))
                {
                    log.Debug("   Creating directory: " + str);
                    Directory.CreateDirectory(str);
                }
            }
            stopwatch.Stop();
            diagData.CreateDirectories = stopwatch.ElapsedMilliseconds;
        }
Example #5
0
        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();
        }
Example #6
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);
        }
Example #7
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(),
            });
        }
Example #8
0
        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);
        }