public static IEnumerable SummarizeTpfFile(SqlInt32 fileId) { Byte[] bytes = GetFileContents("CollarParameterFiles", fileId, 'A'); var tpf = new TpfFile(bytes); var resultCollection = new ArrayList(); foreach (var tpfCollar in tpf.GetCollars()) resultCollection.Add(new Row(fileId, tpfCollar)); return resultCollection; }
public void CreateFetexFromDDSs(string fetexExportedFolderPath) { string[] ddsPaths = Directory.GetFiles(fetexExportedFolderPath, "*.dds", SearchOption.AllDirectories); TpfFile[] tpfArray = new TpfFile[ddsPaths.Length]; for (int i = 0; i < ddsPaths.Length; i++) { TpfFile tpf = new TpfFile(); string ddsPath = ddsPaths[i].Substring(0, ddsPaths[i].LastIndexOf("\\")); string tpfPath = ddsPath + ".tpf"; tpf.Create(ddsPath, tpfPath); tpf.fileName = Path.GetFileNameWithoutExtension(ddsPath) + ".tpf"; tpfArray[i] = tpf; } string fetexPath = fetexExportedFolderPath + ".fetexbnd"; fileCount = (uint)tpfArray.Length; MemoryStream bnddata = new MemoryStream(); byte[] orjFetex = File.ReadAllBytes(fetexPath); bnddata.Write(orjFetex, 0, 2048); using (BinaryWriter binwr = new BinaryWriter(bnddata, Encoding.ASCII)) { //no changes on fist 64 byte header, skipping binwr.BaseStream.Position = 64; int headerPos = (int)binwr.BaseStream.Position; int nameOffsets = (int)binwr.BaseStream.Position + 36 * (int)fileCount; for (int i = 0; i < fileCount; i++) { binwr.Write((int)64); binwr.Write(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF }); binwr.Write((long)tpfArray[i].data.Length); binwr.Write((long)tpfArray[i].data.Length); binwr.Write((int)0); //fileoffset, for now 0, coming later binwr.BaseStream.Position += 4; //skip id binwr.Write((int)nameOffsets); //nameoffset nameOffsets += Encoding.ASCII.GetByteCount(tpfArray[i].fileName) + 1; } binwr.BaseStream.Position = 2048; headerPos += 24;//fileOffset for (int i = 0; i < fileCount; i++) { uint tempOffset = (uint)binwr.BaseStream.Position; binwr.Write(tpfArray[i].data); binwr.BaseStream.Position = headerPos + i * 36; binwr.Write(tempOffset); binwr.BaseStream.Position = tempOffset + tpfArray[i].data.Length; } } Console.Write("."); bndByteData = bnddata.ToArray(); filePath = fetexExportedFolderPath + ".fetexbnd"; //File.WriteAllBytes(fetexExportedFolderPath+".MINECAMP", bnddata.ToArray()); }
public static IEnumerable SummarizeTpfFile(SqlInt32 fileId) { Byte[] bytes = GetFileContents("CollarParameterFiles", fileId, 'A'); var tpf = new TpfFile(bytes); var resultCollection = new ArrayList(); foreach (var tpfCollar in tpf.GetCollars()) { resultCollection.Add(new Row(fileId, tpfCollar)); } return(resultCollection); }
private static void UnpackTpfFile(Options options) { using (FileStream inputStream = new FileStream(options.InputPath, FileMode.Open, FileAccess.Read)) { TpfFile tpfFile = TpfFile.OpenTpfFile(inputStream); foreach (var entry in tpfFile.Entries) { string outputFilePath = Path.Combine(options.OutputPath, entry.FileName); Directory.CreateDirectory(Path.GetDirectoryName(outputFilePath)); File.WriteAllBytes(outputFilePath, entry.Data); } } }
private void CreateParameters(ProjectInvestigator owner, CollarParameterFile paramFile) { var tpfFile = new TpfFile(_fileContents); foreach (TpfCollar tpfCollar in tpfFile.GetCollars()) { if (IgnoreSuffixCheckBox.Checked && tpfCollar.Ctn.Length > 6) { tpfCollar.Ctn = tpfCollar.Ctn.Substring(0, 6); } //Does this collar exist? var collar = Database.Collars.FirstOrDefault(c => c.CollarManufacturer == "Telonics" && c.CollarId == tpfCollar.Ctn); if (collar == null && !CreateCollarsCheckBox.Checked) { continue; } if (collar == null) { collar = CreateTpfCollar(owner, tpfCollar.Ctn, tpfCollar.Frequency); if (collar == null) { continue; } } //Does this Argos platform exist? var fileHasArgos = !String.IsNullOrEmpty(tpfCollar.PlatformId) && tpfCollar.Platform == "Argos" && !tpfCollar.PlatformId.Trim().Normalize().Equals("?", StringComparison.OrdinalIgnoreCase); if (fileHasArgos) { var platform = Database.ArgosPlatforms.FirstOrDefault(p => p.PlatformId == tpfCollar.PlatformId && tpfCollar.Platform == "Argos"); if (platform == null && CreateCollarsCheckBox.Checked) { platform = CreatePlatform(tpfCollar.PlatformId); } if (platform != null) { //If not paired, then try to parit the collar and platform. If it fails, or the the dates are wrong, they can correct that later if (!Database.ArgosDeployments.Any(d => d.Collar == collar && d.ArgosPlatform == platform)) { CreateDeployment(collar, platform, tpfCollar.TimeStamp); } } } CreateParameter(collar, paramFile, tpfCollar.TimeStamp); } }
public void CreateFontFromFiles(string fontExportedFolderPath) { string ccmXmlPath = Path.Combine(fontExportedFolderPath, Path.GetFileName(fontExportedFolderPath + ".ccm.xml")); string ccmPath = Path.Combine(fontExportedFolderPath, Path.GetFileName(fontExportedFolderPath + ".ccm")); CcmFile ccmFile; if (File.Exists(ccmXmlPath)) { ccmFile = new CcmFile(); ccmFile.CreateCcm(ccmPath, ccmXmlPath); } else { ccmFile = new CcmFile(ccmPath); } string[] ddsPaths = Directory.GetFiles(fontExportedFolderPath, "*.dds", SearchOption.AllDirectories); TpfFile[] tpfArray = new TpfFile[ddsPaths.Length]; for (int i = 0; i < ddsPaths.Length; i++) { TpfFile tpf = new TpfFile(); string ddsPath = Path.GetDirectoryName(ddsPaths[i]); string tpfPath = ddsPath + ".tpf"; tpf.Create(ddsPath, tpfPath); tpf.fileName = Path.GetFileNameWithoutExtension(ddsPath) + ".tpf"; tpfArray[i] = tpf; } List <BndEntry> bndEntries = new List <BndEntry>(); bndEntries.Add(ccmFile); bndEntries.AddRange(tpfArray); string orjBndPath = fontExportedFolderPath + ".fontbnd"; fileCount = (uint)bndEntries.Count; MemoryStream newBndData = new MemoryStream(); int firstFileOffset = 0; using (BinaryReader binred = new BinaryReader(File.Open(orjBndPath, FileMode.Open, FileAccess.Read))) { //Copy orginal bnd file's first 1024 byte //why 1024?: first file starts at 1024 binred.BaseStream.Position = 88; firstFileOffset = binred.ReadInt32(); binred.BaseStream.Position = 0; newBndData.Write(binred.ReadBytes(firstFileOffset), 0, firstFileOffset); } using (BinaryWriter binwr = new BinaryWriter(newBndData, Encoding.ASCII)) { //no changes on first 64 byte header, skipping binwr.BaseStream.Position = 64; int headerPos = (int)binwr.BaseStream.Position; int nameOffsets = (int)binwr.BaseStream.Position + 36 * (int)fileCount; for (int i = 0; i < fileCount; i++) { binwr.Write((int)64); binwr.Write(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF }); binwr.Write((long)bndEntries[i].data.Length); binwr.Write((long)bndEntries[i].data.Length); binwr.Write((int)0); //fileoffset, for now 0, coming later binwr.BaseStream.Position += 4; //skip id binwr.Write((int)nameOffsets); //nameoffset nameOffsets += Encoding.ASCII.GetByteCount(bndEntries[i].fileName) + 1; } binwr.BaseStream.Position = firstFileOffset; headerPos += 24;//fileOffset for (int i = 0; i < fileCount; i++) { uint tempOffset = (uint)binwr.BaseStream.Position; binwr.Write(bndEntries[i].data); binwr.BaseStream.Position = headerPos + i * 36; binwr.Write(tempOffset); binwr.BaseStream.Position = tempOffset + bndEntries[i].data.Length; } } Console.Write("."); bndByteData = newBndData.ToArray(); filePath = fontExportedFolderPath + ".fontbnd"; //File.WriteAllBytes(filePath+".MINECAMP", bndByteData.ToArray()); }