public void Open(string path) { FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); fs.Seek(0, SeekOrigin.Begin); byte[] hdr_b = new byte[26]; fs.Read(hdr_b, 0, 26); header = Marshal.ByteArrayToStructureBigEndian <AppleSingleHeader>(hdr_b); AppleSingleEntry[] entries = new AppleSingleEntry[header.entries]; for (int i = 0; i < header.entries; i++) { byte[] entry = new byte[12]; fs.Read(entry, 0, 12); entries[i] = Marshal.ByteArrayToStructureBigEndian <AppleSingleEntry>(entry); } creationTime = DateTime.UtcNow; lastWriteTime = creationTime; foreach (AppleSingleEntry entry in entries) { switch ((AppleSingleEntryID)entry.id) { case AppleSingleEntryID.DataFork: dataFork = entry; break; case AppleSingleEntryID.FileDates: fs.Seek(entry.offset, SeekOrigin.Begin); byte[] dates_b = new byte[16]; fs.Read(dates_b, 0, 16); AppleSingleFileDates dates = Marshal.ByteArrayToStructureBigEndian <AppleSingleFileDates>(dates_b); creationTime = DateHandlers.MacToDateTime(dates.creationDate); lastWriteTime = DateHandlers.MacToDateTime(dates.modificationDate); break; case AppleSingleEntryID.FileInfo: fs.Seek(entry.offset, SeekOrigin.Begin); byte[] finfo = new byte[entry.length]; fs.Read(finfo, 0, finfo.Length); if (MacintoshHome.SequenceEqual(header.homeFilesystem)) { AppleSingleMacFileInfo macinfo = Marshal.ByteArrayToStructureBigEndian <AppleSingleMacFileInfo>(finfo); creationTime = DateHandlers.MacToDateTime(macinfo.creationDate); lastWriteTime = DateHandlers.MacToDateTime(macinfo.modificationDate); } else if (ProDOSHome.SequenceEqual(header.homeFilesystem)) { AppleSingleProDOSFileInfo prodosinfo = Marshal.ByteArrayToStructureBigEndian <AppleSingleProDOSFileInfo>(finfo); creationTime = DateHandlers.MacToDateTime(prodosinfo.creationDate); lastWriteTime = DateHandlers.MacToDateTime(prodosinfo.modificationDate); } else if (UNIXHome.SequenceEqual(header.homeFilesystem)) { AppleSingleUNIXFileInfo unixinfo = Marshal.ByteArrayToStructureBigEndian <AppleSingleUNIXFileInfo>(finfo); creationTime = DateHandlers.UnixUnsignedToDateTime(unixinfo.creationDate); lastWriteTime = DateHandlers.UnixUnsignedToDateTime(unixinfo.modificationDate); } else if (DOSHome.SequenceEqual(header.homeFilesystem)) { AppleSingleDOSFileInfo dosinfo = Marshal.ByteArrayToStructureBigEndian <AppleSingleDOSFileInfo>(finfo); lastWriteTime = DateHandlers.DosToDateTime(dosinfo.modificationDate, dosinfo.modificationTime); } break; case AppleSingleEntryID.ResourceFork: rsrcFork = entry; break; } } fs.Close(); opened = true; isPath = true; basePath = path; }
public void Open(Stream stream) { stream.Seek(0, SeekOrigin.Begin); byte[] hdrB = new byte[26]; stream.Read(hdrB, 0, 26); _header = Marshal.ByteArrayToStructureBigEndian <AppleSingleHeader>(hdrB); AppleSingleEntry[] entries = new AppleSingleEntry[_header.entries]; for (int i = 0; i < _header.entries; i++) { byte[] entry = new byte[12]; stream.Read(entry, 0, 12); entries[i] = Marshal.ByteArrayToStructureBigEndian <AppleSingleEntry>(entry); } _creationTime = DateTime.UtcNow; _lastWriteTime = _creationTime; foreach (AppleSingleEntry entry in entries) { switch ((AppleSingleEntryID)entry.id) { case AppleSingleEntryID.DataFork: _dataFork = entry; break; case AppleSingleEntryID.FileDates: stream.Seek(entry.offset, SeekOrigin.Begin); byte[] datesB = new byte[16]; stream.Read(datesB, 0, 16); AppleSingleFileDates dates = Marshal.ByteArrayToStructureBigEndian <AppleSingleFileDates>(datesB); _creationTime = DateHandlers.MacToDateTime(dates.creationDate); _lastWriteTime = DateHandlers.MacToDateTime(dates.modificationDate); break; case AppleSingleEntryID.FileInfo: stream.Seek(entry.offset, SeekOrigin.Begin); byte[] finfo = new byte[entry.length]; stream.Read(finfo, 0, finfo.Length); if (_macintoshHome.SequenceEqual(_header.homeFilesystem)) { AppleSingleMacFileInfo macinfo = Marshal.ByteArrayToStructureBigEndian <AppleSingleMacFileInfo>(finfo); _creationTime = DateHandlers.MacToDateTime(macinfo.creationDate); _lastWriteTime = DateHandlers.MacToDateTime(macinfo.modificationDate); } else if (_proDosHome.SequenceEqual(_header.homeFilesystem)) { AppleSingleProDOSFileInfo prodosinfo = Marshal.ByteArrayToStructureBigEndian <AppleSingleProDOSFileInfo>(finfo); _creationTime = DateHandlers.MacToDateTime(prodosinfo.creationDate); _lastWriteTime = DateHandlers.MacToDateTime(prodosinfo.modificationDate); } else if (_unixHome.SequenceEqual(_header.homeFilesystem)) { AppleSingleUnixFileInfo unixinfo = Marshal.ByteArrayToStructureBigEndian <AppleSingleUnixFileInfo>(finfo); _creationTime = DateHandlers.UnixUnsignedToDateTime(unixinfo.creationDate); _lastWriteTime = DateHandlers.UnixUnsignedToDateTime(unixinfo.modificationDate); } else if (_dosHome.SequenceEqual(_header.homeFilesystem)) { AppleSingleDOSFileInfo dosinfo = Marshal.ByteArrayToStructureBigEndian <AppleSingleDOSFileInfo>(finfo); _lastWriteTime = DateHandlers.DosToDateTime(dosinfo.modificationDate, dosinfo.modificationTime); } break; case AppleSingleEntryID.ResourceFork: _rsrcFork = entry; break; } } stream.Seek(0, SeekOrigin.Begin); _opened = true; _isStream = true; _stream = stream; }