public void Open(string path) { string parentFolder = Path.GetDirectoryName(path); string baseFilename = Path.GetFileName(path); parentFolder ??= ""; var finderDatStream = new FileStream(Path.Combine(parentFolder, FINDER_INFO), FileMode.Open, FileAccess.Read); while (finderDatStream.Position + 0x5C <= finderDatStream.Length) { var datEntry = new PcExchangeEntry(); byte[] datEntryB = new byte[Marshal.SizeOf(datEntry)]; finderDatStream.Read(datEntryB, 0, Marshal.SizeOf(datEntry)); datEntry = Helpers.Marshal.ByteArrayToStructureBigEndian <PcExchangeEntry>(datEntryB); string macName = StringHandlers.PascalToString(datEntry.macName, Encoding.GetEncoding("macintosh")); byte[] tmpDosNameB = new byte[8]; byte[] tmpDosExtB = new byte[3]; Array.Copy(datEntry.dosName, 0, tmpDosNameB, 0, 8); Array.Copy(datEntry.dosName, 8, tmpDosExtB, 0, 3); string dosName = Encoding.ASCII.GetString(tmpDosNameB).Trim() + "." + Encoding.ASCII.GetString(tmpDosExtB).Trim(); string dosNameLow = dosName.ToLower(CultureInfo.CurrentCulture); if (baseFilename != macName && baseFilename != dosName && baseFilename != dosNameLow) { continue; } if (File.Exists(Path.Combine(parentFolder, macName ?? throw new InvalidOperationException()))) { _dataPath = Path.Combine(parentFolder, macName); }
public bool Identify(string path) { string parentFolder = Path.GetDirectoryName(path); parentFolder ??= ""; if (!File.Exists(Path.Combine(parentFolder, FINDER_INFO))) { return(false); } if (!Directory.Exists(Path.Combine(parentFolder, RESOURCES))) { return(false); } string baseFilename = Path.GetFileName(path); bool dataFound = false; bool rsrcFound = false; var finderDatStream = new FileStream(Path.Combine(parentFolder, FINDER_INFO), FileMode.Open, FileAccess.Read); while (finderDatStream.Position + 0x5C <= finderDatStream.Length) { var datEntry = new PcExchangeEntry(); byte[] datEntryB = new byte[Marshal.SizeOf(datEntry)]; finderDatStream.Read(datEntryB, 0, Marshal.SizeOf(datEntry)); datEntry = Helpers.Marshal.ByteArrayToStructureBigEndian <PcExchangeEntry>(datEntryB); // TODO: Add support for encoding on filters string macName = StringHandlers.PascalToString(datEntry.macName, Encoding.GetEncoding("macintosh")); byte[] tmpDosNameB = new byte[8]; byte[] tmpDosExtB = new byte[3]; Array.Copy(datEntry.dosName, 0, tmpDosNameB, 0, 8); Array.Copy(datEntry.dosName, 8, tmpDosExtB, 0, 3); string dosName = Encoding.ASCII.GetString(tmpDosNameB).Trim() + "." + Encoding.ASCII.GetString(tmpDosExtB).Trim(); string dosNameLow = dosName.ToLower(CultureInfo.CurrentCulture); if (baseFilename != macName && baseFilename != dosName && baseFilename != dosNameLow) { continue; } dataFound |= File.Exists(Path.Combine(parentFolder, macName ?? throw new InvalidOperationException())) || File.Exists(Path.Combine(parentFolder, dosName)) || File.Exists(Path.Combine(parentFolder, dosNameLow)); rsrcFound |= File.Exists(Path.Combine(parentFolder, RESOURCES, dosName)) || File.Exists(Path.Combine(parentFolder, RESOURCES, dosNameLow)); break; } finderDatStream.Close(); return(dataFound && rsrcFound); }