public void CreateModPackFile() { PackFileService packFileService = new PackFileService(new PackFileDataBase(), null); var packContainer = packFileService.CreateNewPackFileContainer("MyTestPackFile", PackFileCAType.MOD); var packFile = new PackFile("ExampleFile.txt", new FileSystemSource(@"Data\FolderData\SubFolder0\Subfolder_0_file0.txt")); packFileService.AddFileToPack(packContainer, @"data\content\files", packFile); //var packFileContent = Encoding.UTF8.GetString(packFile.DataSource.ReadData()); using (MemoryStream ms0 = new MemoryStream()) { using (BinaryWriter writer = new BinaryWriter(ms0)) packFileService.Save(packContainer, writer); // Load it again var orgData = ms0.ToArray(); using (MemoryStream ms1 = new MemoryStream(orgData)) { Assert.AreEqual(ms1.Length, orgData.Length); using (BinaryReader reader = new BinaryReader(ms1)) { var loadedPackFile = new PackFileContainer("File", reader); Assert.AreEqual(packContainer.Header.Version, loadedPackFile.Header.Version); Assert.AreEqual(packContainer.Header.FileType, loadedPackFile.Header.FileType); Assert.AreEqual(1, loadedPackFile.Header.FileCount); Assert.AreEqual(0, loadedPackFile.Header.ReferenceFileCount); } } } }
public void AddFolderContent(PackFileContainer container, string path, string folderDir) { var originalFilePaths = Directory.GetFiles(folderDir, "*", SearchOption.AllDirectories); var filePaths = originalFilePaths.Select(x => x.Replace(folderDir + "\\", "")).ToList(); if (!string.IsNullOrWhiteSpace(path)) { path += "\\"; } var filesAdded = new List <PackFile>(); for (int i = 0; i < filePaths.Count; i++) { var currentPath = filePaths[i]; var filename = Path.GetFileName(currentPath); var source = MemorySource.FromFile(originalFilePaths[i]); var file = new PackFile(filename, source); filesAdded.Add(file); container.FileList[path.ToLower() + currentPath.ToLower()] = file; } _skeletonAnimationLookUpHelper.UnloadAnimationFromContainer(this, container); _skeletonAnimationLookUpHelper.LoadFromPackFileContainer(this, container); Database.TriggerPackFileAdded(container, filesAdded); }
public List <PackFile> FindAllFilesInDirectory(string dir, PackFileContainer packFileContainer = null) { dir = dir.ToLower(); List <PackFile> output = new List <PackFile>(); if (packFileContainer == null) { foreach (var pf in Database.PackFiles) { foreach (var file in pf.FileList) { if (file.Key.IndexOf(dir) == 0) { output.Add(file.Value as PackFile); } } } } else { foreach (var file in packFileContainer.FileList) { if (file.Key.IndexOf(dir) == 0) { output.Add(file.Value as PackFile); } } } return(output); }
public PackFileContainer Load(BinaryReader binaryReader, string packFileSystemPath) { var pack = new PackFileContainer(packFileSystemPath, binaryReader); Database.AddPackFile(pack); _skeletonAnimationLookUpHelper.LoadFromPackFileContainer(this, pack); return(pack); }
// Add // --------------------------- public PackFileContainer CreateNewPackFileContainer(string name, PackFileCAType type) { var newPackFile = new PackFileContainer(name) { Header = new PFHeader("PFH5", type), }; Database.AddPackFile(newPackFile); return(newPackFile); }
public bool LoadAllCaFiles(string gameDataFolder) { try { _logger.Here().Information($"Loading all ca packfiles located in {gameDataFolder}"); var allCaPackFiles = GetPackFilesFromManifest(gameDataFolder); var packList = new List <PackFileContainer>(); foreach (var packFilePath in allCaPackFiles) { var path = gameDataFolder + "\\" + packFilePath; if (File.Exists(path)) { using (var fileStram = File.OpenRead(path)) { using (var reader = new BinaryReader(fileStram, Encoding.ASCII)) { var pack = new PackFileContainer(path, reader); packList.Add(pack); _skeletonAnimationLookUpHelper.LoadFromPackFileContainer(this, pack); } } } else { _logger.Here().Warning($"Ca packfile '{path}' not found, loading skipped"); } } PackFileContainer caPackFileContainer = new PackFileContainer("All CA packs"); caPackFileContainer.IsCaPackFile = true; var packFilesOrderedByGroup = packList .GroupBy(x => x.Header.LoadOrder) .OrderBy(x => x.Key); foreach (var group in packFilesOrderedByGroup) { var packFilesOrderedByName = group.OrderBy(x => x.Name); foreach (var packfile in packFilesOrderedByName) { caPackFileContainer.MergePackFileContainer(packfile); } } Database.AddPackFile(caPackFileContainer); } catch (Exception e) { _logger.Here().Error($"Trying to all ca packs in {gameDataFolder}. Error : {e.ToString()}"); return(false); } return(true); }
public void UnloadAnimationFromContainer(PackFileService pfs, PackFileContainer packFileContainer) { int itemsRemoved = 0; var s = _skeletonNameToAnimationMap.Select(skeleton => (skeleton.Key, skeleton.Value.Where(animations => animations.Container == packFileContainer))).ToList(); foreach (var key in s) { var copy = key.Item2.Select(x => x).ToList(); foreach (var toRemove in copy) { _skeletonNameToAnimationMap[key.Key].Remove(toRemove); itemsRemoved++; } } }
public IPackFile FindFile(string path, PackFileContainer container) { var lowerPath = path.Replace('/', '\\').ToLower(); _logger.Here().Information($"Searching for file {lowerPath}"); if (container.FileList.ContainsKey(lowerPath)) { _logger.Here().Information($"File found"); return(container.FileList[lowerPath]); } _logger.Here().Warning($"File not found"); return(null); }
public void DeleteFile(PackFileContainer pf, IPackFile file) { if (pf.IsCaPackFile) { throw new Exception("Can not add files to ca pack file"); } var key = pf.FileList.FirstOrDefault(x => x.Value == file).Key; _logger.Here().Information($"Deleting file {key}"); Database.TriggerPackFileRemoved(pf, new List <PackFile>() { file as PackFile }); pf.FileList.Remove(key); }
public void DeleteFolder(PackFileContainer pf, string folder) { if (pf.IsCaPackFile) { throw new Exception("Can not add files to ca pack file"); } var folderLower = folder.ToLower(); var itemsToDelete = pf.FileList.Where(x => x.Key.StartsWith(folderLower)); Database.TriggerPackFileFolderRemoved(pf, folder); foreach (var item in itemsToDelete) { _logger.Here().Information($"Deleting file {item.Key} in directory {folder}"); pf.FileList.Remove(item.Key); } }
public void CopyFileFromOtherPackFile(PackFileContainer source, string path, PackFileContainer target) { var lowerPath = path.ToLower(); if (source.FileList.ContainsKey(lowerPath)) { var file = source.FileList[lowerPath] as PackFile; var newFile = new PackFile(file.Name, file.DataSource); target.FileList[lowerPath] = newFile; Database.TriggerPackFileAdded(target, new List <PackFile>() { newFile as PackFile }); } //Database.TriggerContainerUpdated(target); }
public void Save(PackFileContainer pf, string path, bool createBackup) { if (pf.IsCaPackFile) { throw new Exception("Can not save ca pack file"); } if (createBackup) { SaveHelper.CreateFileBackup(path); } pf.SystemFilePath = path; using (MemoryStream memoryStream = new MemoryStream()) { using (BinaryWriter writer = new BinaryWriter(memoryStream)) Save(pf, writer); File.WriteAllBytes(path, memoryStream.ToArray()); pf.UpdateAllDataSourcesAfterSave(); } }
// Modify // --------------------------- public void RenameFile(PackFileContainer pf, IPackFile file, string newName) { if (pf.IsCaPackFile) { throw new Exception("Can not add files to ca pack file"); } var key = pf.FileList.FirstOrDefault(x => x.Value == file).Key; pf.FileList.Remove(key); var dir = Path.GetDirectoryName(key); file.Name = newName; pf.FileList[dir + "\\" + file.Name] = file; Database.TriggerPackFilesUpdated(pf, new List <PackFile>() { file as PackFile }); }
public void LoadFromPackFileContainer(PackFileService pfs, PackFileContainer packFileContainer) { var allAnimations = pfs.FindAllWithExtentionIncludePaths(".anim", packFileContainer); foreach (var animation in allAnimations) { try { var animationSkeletonName = AnimationFile.GetAnimationHeader(animation.Item2).SkeletonName; if (_skeletonNameToAnimationMap.ContainsKey(animationSkeletonName) == false) { _skeletonNameToAnimationMap.Add(animationSkeletonName, new ObservableCollection <AnimationReference>()); } _skeletonNameToAnimationMap[animationSkeletonName].Add(new AnimationReference(pfs.GetFullPath(animation.Item2, packFileContainer), packFileContainer)); } catch (Exception e) { _logger.Here().Error("Parsing failed for " + pfs.GetFullPath(animation.Item2, packFileContainer) + "\n" + e.ToString()); } } var allNormalSkeletons = allAnimations.Where(x => x.Item1.Contains("animations\\skeletons", StringComparison.InvariantCultureIgnoreCase)); foreach (var item in allNormalSkeletons) { SkeletonFileNames.Add(item.Item1); } var techSkeletons = allAnimations.Where(x => x.Item1.Contains("tech", StringComparison.InvariantCultureIgnoreCase)); foreach (var item in techSkeletons) { SkeletonFileNames.Add(item.Item1); } _logger.Here().Information("Animations found =" + allAnimations.Count()); _logger.Here().Information("Skeletons found =" + SkeletonFileNames.Count()); }
public void AddFileToPack(PackFileContainer container, string directoryPath, IPackFile newFile) { if (container.IsCaPackFile) { throw new Exception("Can not add files to ca pack file"); } if (!string.IsNullOrWhiteSpace(directoryPath)) { directoryPath += "\\"; } directoryPath += newFile.Name; container.FileList[directoryPath.ToLower()] = newFile; _skeletonAnimationLookUpHelper.UnloadAnimationFromContainer(this, container); _skeletonAnimationLookUpHelper.LoadFromPackFileContainer(this, container); Database.TriggerPackFileAdded(container, new List <PackFile>() { newFile as PackFile }); }
public string GetFullPath(PackFile file, PackFileContainer container = null) { if (container == null) { foreach (var pf in Database.PackFiles) { var res = pf.FileList.FirstOrDefault(x => x.Value == file).Key; if (string.IsNullOrWhiteSpace(res) == false) { return(res); } } } else { var res = container.FileList.FirstOrDefault(x => x.Value == file).Key; if (string.IsNullOrWhiteSpace(res) == false) { return(res); } } throw new Exception("Unknown path for " + file.Name); }
public AnimationReference(string animationFile, PackFileContainer container) { AnimationFile = animationFile; Container = container; }
public List <ValueTuple <string, PackFile> > FindAllWithExtentionIncludePaths(string extention, PackFileContainer packFileContainer = null) { extention = extention.ToLower(); var output = new List <ValueTuple <string, PackFile> >(); if (packFileContainer == null) { foreach (var pf in Database.PackFiles) { foreach (var file in pf.FileList) { var fileExtention = Path.GetExtension(file.Key); if (fileExtention == extention) { output.Add(new ValueTuple <string, PackFile>(file.Key, file.Value as PackFile)); } } } } else { foreach (var file in packFileContainer.FileList) { var fileExtention = Path.GetExtension(file.Key); if (fileExtention == extention) { output.Add(new ValueTuple <string, PackFile>(file.Key, file.Value as PackFile)); } } } return(output); }
public List <PackFile> FindAllWithExtention(string extention, PackFileContainer packFileContainer = null) { return(FindAllWithExtentionIncludePaths(extention, packFileContainer).Select(x => x.Item2).ToList()); }
public void Save(PackFileContainer pf, BinaryWriter writer) { pf.SaveToByteArray(writer); _skeletonAnimationLookUpHelper.UnloadAnimationFromContainer(this, pf); _skeletonAnimationLookUpHelper.LoadFromPackFileContainer(this, pf); }
// Remove // --------------------------- public void UnloadPackContainer(PackFileContainer pf) { _skeletonAnimationLookUpHelper.UnloadAnimationFromContainer(this, pf); Database.RemovePackFile(pf); }
public void SetEditablePack(PackFileContainer pf) { Database.PackSelectedForEdit = pf; Database.TriggerContainerUpdated(pf); }