protected override IEnumerable <HpiArchive.FileInfo> EnumerateFiles(HpiArchive r) { return(r.GetFilesRecursive("objects3d") .Where(x => x.Name.EndsWith(".3do", StringComparison.OrdinalIgnoreCase) && this.objectMap.ContainsKey(HpiPath.GetFileNameWithoutExtension(x.Name)))); }
public UndoableMapModel CreateFromHpi(string hpipath, string mappath, bool readOnly) { MapModel m; using (var hpi = new HpiArchive(hpipath)) { var otaPath = HpiPath.ChangeExtension(mappath, ".ota"); TdfNode n; var otaFileInfo = hpi.FindFile(otaPath); var otaFileBuffer = new byte[otaFileInfo.Size]; hpi.Extract(otaFileInfo, otaFileBuffer); using (var ota = new MemoryStream(otaFileBuffer)) { n = TdfNode.LoadTdf(ota); } var tntFileInfo = hpi.FindFile(mappath); var tntFileBuffer = new byte[tntFileInfo.Size]; hpi.Extract(tntFileInfo, tntFileBuffer); using (var s = new TntReader(new MemoryStream(tntFileBuffer))) { m = this.mapModelFactory.FromTntAndOta(s, n); } } return(new UndoableMapModel(m, hpipath, readOnly)); }
protected override void LoadFile(HpiArchive archive, HpiArchive.FileInfo file) { // extract and read the file var fileBuffer = new byte[file.Size]; archive.Extract(file, fileBuffer); var adapter = new GafEntryArrayAdapter(); using (var b = new GafReader(new MemoryStream(fileBuffer), adapter)) { b.Read(); } var gaf = adapter.Entries; var records = this.filenameFeatureMap[HpiPath.GetFileNameWithoutExtension(file.Name)]; // retrieve the anim for each record foreach (var record in records) { var sequenceName = record.SequenceName; if (string.IsNullOrEmpty(sequenceName)) { // Skip if this record has no sequence name. continue; } var entry = gaf.FirstOrDefault( x => string.Equals(x.Name, sequenceName, StringComparison.OrdinalIgnoreCase)); if (entry == null) { // skip if the sequence is not in this gaf file continue; } var frame = entry.Frames[0]; Bitmap bmp; if (frame.Data == null || frame.Width == 0 || frame.Height == 0) { bmp = new Bitmap(50, 50); } else { bmp = BitmapConvert.ToBitmap( frame.Data, frame.Width, frame.Height, frame.TransparencyIndex); } var offsetImage = new OffsetBitmap(-frame.OffsetX, -frame.OffsetY, bmp); this.Records.Add(new KeyValuePair <string, OffsetBitmap>(record.Name, offsetImage)); } }
protected override void LoadFile(HpiArchive archive, HpiArchive.FileInfo file) { var fileBuffer = new byte[file.Size]; archive.Extract(file, fileBuffer); TdfNode n; using (var tdf = new MemoryStream(fileBuffer)) { n = TdfNode.LoadTdf(tdf); } this.Records.AddRange( n.Keys.Values.Select(FeatureRecord.FromTdfNode)); }
protected override void LoadFile(HpiArchive archive, HpiArchive.FileInfo file) { var records = this.objectMap[HpiPath.GetFileNameWithoutExtension(file.Name)]; var fileBuffer = new byte[file.Size]; archive.Extract(file, fileBuffer); using (var b = new MemoryStream(fileBuffer)) { var adapter = new ModelEdgeReaderAdapter(); var reader = new ModelReader(b, adapter); reader.Read(); var wire = Util.RenderWireframe(adapter.Edges); foreach (var record in records) { this.Records.Add(new KeyValuePair <string, OffsetBitmap>(record.Name, wire)); } } }
private void OpenFromHapi(string filename) { List <string> maps; bool readOnly; using (var h = new HpiArchive(filename)) { maps = GetMapNames(h).ToList(); } string mapName; switch (maps.Count) { case 0: this.dialogService.ShowError("No maps found in " + filename); return; case 1: mapName = maps.First(); readOnly = false; break; default: maps.Sort(); mapName = this.dialogService.AskUserToChooseMap(maps); readOnly = true; break; } if (mapName == null) { return; } var tntPath = HpiPath.Combine("maps", mapName + ".tnt"); this.model.Map = Maybe.Some(this.mapLoadingService.CreateFromHpi(filename, tntPath, readOnly)); }
protected override void LoadFile(HpiArchive archive, HpiArchive.FileInfo file) { var fileBuffer = new byte[file.Size]; archive.Extract(file, fileBuffer); using (var s = new SctReader(new MemoryStream(fileBuffer))) { var section = new Section(archive.FileName, file.FullPath); section.Name = HpiPath.GetFileNameWithoutExtension(file.Name); section.Minimap = SectionFactory.MinimapFromSct(s); section.DataWidth = s.DataWidth; section.DataHeight = s.DataHeight; var directoryString = HpiPath.GetDirectoryName(file.FullPath); Debug.Assert(directoryString != null, "Null directory for section in HPI."); var directories = directoryString.Split('\\'); section.World = directories[1]; section.Category = directories[2]; this.Records.Add(section); } }
private void LoadHpi(string hpiFile) { try { using (var s = new HpiArchive(hpiFile)) { foreach (var file in this.EnumerateFiles(s)) { try { this.LoadFile(s, file); } catch (Exception e) { this.OnError(hpiFile, file.FullPath, e); } } } } catch (Exception e) { this.OnHpiError(hpiFile, e); } }
private MapTile LoadSectionFromDisk(string hpiFileName, string sctFileName) { var outpath = Path.GetTempFileName(); try { byte[] fileBuffer; using (var h = new HpiArchive(hpiFileName)) { var fileInfo = h.FindFile(sctFileName); fileBuffer = new byte[fileInfo.Size]; h.Extract(fileInfo, fileBuffer); } using (var s = new SctReader(new MemoryStream(fileBuffer))) { return(this.sectionFactory.TileFromSct(s)); } } finally { File.Delete(outpath); } }
protected override IEnumerable <HpiArchive.FileInfo> EnumerateFiles(HpiArchive r) { return(r.GetFilesRecursive("sections") .Where(x => x.Name.EndsWith(".sct", StringComparison.OrdinalIgnoreCase))); }
protected abstract void LoadFile(HpiArchive archive, HpiArchive.FileInfo file);
protected abstract IEnumerable <HpiArchive.FileInfo> EnumerateFiles(HpiArchive r);
public List <ListViewItem> GetListViewGroupItens(string fullPath) { var listColection = new List <ListViewItem>(); //Check if path is a directory or file FileAttributes fileAtt = File.GetAttributes(fullPath); if (fileAtt.HasFlag(FileAttributes.Directory)) //Directory { var fileList = Directory.GetFiles(fullPath, "*", SearchOption.AllDirectories); var group = new ListViewGroup(fullPath, "Dir: " + fullPath); foreach (var file in fileList) { var finfo = new FileInfo(file); if (finfo.Length > Int32.MaxValue) { throw new Exception(finfo.Name + " is too large. File maximum size is 2GB (2 147 483 647 bytes)."); } ListViewItem lvItem = new ListViewItem(group); lvItem.Tag = fullPath; var subItems = new ListViewItem.ListViewSubItem[3]; for (int i = 0; i < subItems.Length; i++) { subItems[i] = new ListViewItem.ListViewSubItem(); } subItems[0].Text = file.Substring(fullPath.Length + 1); subItems[0].Tag = fullPath; subItems[1].Text = Path.GetExtension(file).ToUpper(); subItems[2].Text = finfo.Length.ToString("N0"); subItems[2].Tag = (int)finfo.Length; lvItem.SubItems.AddRange(subItems); listColection.Add(lvItem); } } else //HPI File or Files { var group = new ListViewGroup(fullPath, Path.GetExtension(fullPath).ToUpper() + " File: " + fullPath); using (HpiArchive hpia = HpiFile.Open(fullPath)) foreach (var entry in hpia.Entries) { ListViewItem lvItem = new ListViewItem(group); lvItem.Tag = fullPath; var subItems = new ListViewItem.ListViewSubItem[5]; for (int i = 0; i < subItems.Length; i++) { subItems[i] = new ListViewItem.ListViewSubItem(); } subItems[0].Text = entry.Key; subItems[0].Tag = fullPath; subItems[1].Text = Path.GetExtension(entry.Key).ToUpper(); subItems[2].Text = entry.Value.UncompressedSize.ToString("N0"); subItems[2].Tag = entry.Value.UncompressedSize; subItems[3].Text = entry.Value.CompressedSizeCount().ToString("N0"); subItems[3].Tag = entry.Value.CompressedSizeCount(); subItems[4].Text = entry.Value.Ratio().ToString("P1"); subItems[4].Tag = entry.Value.Ratio(); lvItem.SubItems.AddRange(subItems); listColection.Add(lvItem); } } return(listColection); }
private static IEnumerable <string> GetMapNames(HpiArchive hpi) { return(hpi.GetFiles("maps") .Where(x => x.Name.EndsWith(".tnt", StringComparison.OrdinalIgnoreCase)) .Select(x => HpiPath.GetFileNameWithoutExtension(x.Name))); }
protected override IEnumerable <HpiArchive.FileInfo> EnumerateFiles(HpiArchive r) { return(r.GetFilesRecursive("anims").Where(this.IsNeededFile)); }