public void SetAttributes(string path, PrimaryVolumeDescriptor pvd) { const int yearOffset = 1900; sio.DirectoryInfo di; sio.FileInfo fi; sio.FileSystemInfo fsi; FileDirectoryDescriptor fd; byte utc; int i; utc = misc.GetLocalUtc15(); foreach (var rec in recs) { for (i = 0; i < rec.files.Count; i++) { fd = rec.files[i]; if (fd.isDirectory) { di = new sio.DirectoryInfo(path + fd.fullName); if (di.Exists) fsi = di; else throw new sio.DirectoryNotFoundException(string.Format("Directory '{0}' not found")); fd.hdr.filFlags = 0x2; } else { fi = new sio.FileInfo(path + fd.fullName); if (fi.Exists) fsi = fi; else throw new sio.FileNotFoundException(string.Format("File '{0}' not found")); } fd.hdr.recdDatTim.year = (byte)(fsi.LastWriteTimeUtc.Year - yearOffset); fd.hdr.recdDatTim.month = (byte)fsi.LastWriteTimeUtc.Month; fd.hdr.recdDatTim.day = (byte)fsi.LastWriteTimeUtc.Day; fd.hdr.recdDatTim.hour = (byte)fsi.LastWriteTimeUtc.Hour; fd.hdr.recdDatTim.min = (byte)fsi.LastWriteTimeUtc.Minute; fd.hdr.recdDatTim.sec = (byte)fsi.LastWriteTimeUtc.Second; fd.hdr.recdDatTim.gmt = utc; } SetHiddenAttr(0, false); } pvd.hdr3.rootDir.recdDatTim = recs[0].files[0].hdr.recdDatTim; fsi = new sio.DirectoryInfo(path); pvd.hdr3.volCreDatTim = new VolumeDateTime(fsi.CreationTimeUtc).hdr; pvd.hdr3.volModDatTim = new VolumeDateTime(fsi.LastWriteTimeUtc).hdr; pvd.hdr3.volEffDatTim = new VolumeDateTime(new DateTime(0)).hdr; pvd.hdr3.volExpDatTim = new VolumeDateTime(new DateTime(0)).hdr; }
public void CalcSizeLocs(string path, PrimaryVolumeDescriptor pvd) { List<FileDirectoryDescriptor> files, dirs; sio.FileInfo fi; int filStart; int logSize; int mod; int i; long l; logSize = ISO9660.logSize - 1; files = new List<FileDirectoryDescriptor>(); foreach (var rec in recs) for (i = 0; i < rec.files.Count; i++) if (!rec.files[i].isDirectory) files.Add(rec.files[i]); files.Sort(misc.CompareLocs); filStart = ISO9660.fsStart; filStart++; //prim desc filStart++; //terminator i = RecSize; if ((mod = i & logSize) > 0) i += ISO9660.logSize - mod; i = i / ISO9660.logSize; pvd.hdr3.locLTbl = filStart; pvd.hdr3.locOptLTbl = 0; filStart += i; pvd.hdr3.locMTbl = filStart.ChangeEndian(); pvd.hdr3.locOptMTbl = 0; filStart += i; foreach (var rec in recs) { i = rec.files.RecSize; if ((mod = i & logSize) > 0) i += ISO9660.logSize - mod; rec.hdr.locExtent = filStart; rec.files[0].hdr.locL = filStart; rec.files[0].hdr.locM = filStart.ChangeEndian(); rec.files[0].hdr.datLenL = i; rec.files[0].hdr.datLenM = i.ChangeEndian(); filStart += (i / ISO9660.logSize); //fil/dir descs } dirs = new List<FileDirectoryDescriptor>(); foreach (var rec in recs) for (i = 0; i < rec.files.Count; i++) if (rec.files[i].isDirectory) dirs.Add(rec.files[i]); foreach (var dir in dirs) foreach (var rec in recs) if (rec.fullName.Length > 0) if (rec.fullName.Length == dir.fullName.Length) if (rec.fullName == dir.fullName) { mod = rec.files.RecSize & logSize; dir.hdr.datLenL = (mod > 0) ? rec.files.RecSize + (ISO9660.logSize - mod) : rec.files.RecSize; dir.hdr.datLenM = dir.hdr.datLenL.ChangeEndian(); dir.hdr.locL = rec.hdr.locExtent; dir.hdr.locM = dir.hdr.locL.ChangeEndian(); } pvd.hdr3.rootDir.locL = recs[0].files[0].hdr.locL; pvd.hdr3.rootDir.locM = pvd.hdr3.rootDir.locL.ChangeEndian(); pvd.hdr3.rootDir.datLenL = recs[0].files[0].hdr.datLenL; pvd.hdr3.rootDir.datLenM = pvd.hdr3.rootDir.datLenL.ChangeEndian(); foreach (var fil in files) { fi = new sio.FileInfo(path + fil.fullName); if (fi.Exists) { fil.hdr.datLenL = (int)((fi.Length << 0x20) >> 0x20); fil.hdr.datLenM = fil.hdr.datLenL.ChangeEndian(); fil.hdr.locL = filStart; fil.hdr.locM = filStart.ChangeEndian(); l = fi.Length; if ((mod = (int)(l & logSize)) > 0) l += ISO9660.logSize - mod; filStart += (int)(l / ISO9660.logSize); //fil/dir descs } else throw new sio.FileNotFoundException(string.Format("File '{0}' not found", fi.FullName)); } pvd.hdr3.volSizeL = filStart; pvd.hdr3.volSizeM = pvd.hdr3.volSizeL.ChangeEndian(); pvd.hdr3.volSetSizeL = 1; pvd.hdr3.volSetSizeM = pvd.hdr3.volSetSizeL.ChangeEndian(); pvd.hdr3.volSeqNumL = 1; pvd.hdr3.volSeqNumM = pvd.hdr3.volSeqNumL.ChangeEndian(); pvd.hdr3.logBlkSizeL = ISO9660.logSize; pvd.hdr3.logBlkSizeM = pvd.hdr3.logBlkSizeL.ChangeEndian(); pvd.hdr3.pthTblSizeL = RecSize; pvd.hdr3.pthTblSizeM = pvd.hdr3.pthTblSizeL.ChangeEndian(); }
public VolumePartition(PrimaryVolumeDescriptor pvd, PathTableRecords paths) { this.primary = pvd; this.paths = paths; terminator = new VolumeDescriptorSetTerminator(); }
private void FillDirFils(string iniPath, out PrimaryVolumeDescriptor pvd, out PathTableRecords paths) { sio.FileInfo fi; sio.StreamReader sr; PathTableRecord pth; List<string> files; string[] file; string[] sep; int sepPos; string str; int i, j; fi = new sio.FileInfo(iniPath + "partition.inf"); if (fi.Exists) sr = new sio.StreamReader(fi.FullName); else sr = new sio.StreamReader(new sio.MemoryStream(new byte[] { 0x0d, 0x0a, 0x0d, 0x0a, 0x0d, 0x0a, 0x0d, 0x0a, 0x0d, 0x0a, 0x0d, 0x0a })); pvd = new PrimaryVolumeDescriptor(); pvd.hdr2.sysId = misc.GetPadResChars(sr.ReadLine(), pvd.hdr2.sysId.Length); pvd.hdr2.volId = misc.GetPadResChars(sr.ReadLine(), pvd.hdr2.volId.Length); pvd.hdr3.volSetId = misc.GetPadResChars(sr.ReadLine(), pvd.hdr3.volSetId.Length); pvd.hdr3.publId = misc.GetPadResChars(sr.ReadLine(), pvd.hdr3.publId.Length); pvd.hdr3.prepId = misc.GetPadResChars(sr.ReadLine(), pvd.hdr3.prepId.Length); pvd.hdr3.appId = misc.GetPadResChars(sr.ReadLine(), pvd.hdr3.appId.Length); pvd.hdr3.copFileId = misc.GetPadResChars("", pvd.hdr3.copFileId.Length); pvd.hdr3.absFileId = misc.GetPadResChars("", pvd.hdr3.absFileId.Length); pvd.hdr3.bibFileId = misc.GetPadResChars("", pvd.hdr3.bibFileId.Length); files = new List<string>(); if (fi.Exists) { str = sr.ReadLine(); while (str != null) { if (str.Length > 0) files.Add(str); str = sr.ReadLine(); } } else { files.AddRange(sio.Directory.GetDirectories(iniPath, "*", sio.SearchOption.AllDirectories)); for (i = 0; i < files.Count; i++) files[i] += config.dirSep; files.AddRange(sio.Directory.GetFiles(iniPath, "*.*", sio.SearchOption.AllDirectories)); for (i = 0; i < files.Count; i++) files[i] = string.Format("0, 0, 0, {0}", files[i].Remove(0, iniPath.Length)); } sr.Close(); paths = new PathTableRecords(); paths.Add(new PathTableRecord("", false)); sep = new string[] { ", " }; for (i = 0; i < files.Count; i++) { file = files[i].Split(sep, StringSplitOptions.None); str = file[3]; if (str[str.Length - 1] == config.dirSep) if (sio.Directory.Exists(iniPath + str)) paths.Add(new PathTableRecord(str, Convert.ToBoolean(int.Parse(file[1])))); else throw new sio.DirectoryNotFoundException(string.Format("Directory '{0}' not found", iniPath + str)); } paths.SortDirs(); paths.SetParentDirNums(); for (i = 0; i < paths.Count; i++) { pth = paths[i]; pth.files = new FileRecords(); pth.files.Add(new FileDirectoryDescriptor("", true, 0, false, false)); for (j = i + 1; j < paths.Count; j++) if (paths[j].hdr.parDirNum == i) pth.files.Add(new FileDirectoryDescriptor(paths[j].fullName, true, 0, false, false)); } for (i = 0; i < files.Count; i++) { file = files[i].Split(sep, StringSplitOptions.None); str = file[3]; if (str[str.Length - 1] != config.dirSep) if (sio.File.Exists(iniPath + str)) { sepPos = str.LastIndexOf(config.dirSep) + 1; for (j = 0; j < paths.Count; j++) if (paths[j].fullName.Length == sepPos) if (str.IndexOf(paths[j].fullName) == 0) { paths[j].files.Add(new FileDirectoryDescriptor(str, false, i, Convert.ToBoolean(int.Parse(file[1])), Convert.ToBoolean(int.Parse(file[2])))); break; } if (j == paths.Count) throw new ArgumentException(string.Format("Parent directory not found for '{0}'", str)); } else throw new sio.FileNotFoundException(string.Format("File '{0}' not found", iniPath + str)); } }
public VolumePartition(sio.FileStream fs) { bool termFound; termFound = false; while (!termFound) { switch (fs.ReadByte()) { case 0: throw new NotImplementedException("Boot records are not supported"); case 1: primary = new PrimaryVolumeDescriptor(fs); break; case 2: throw new NotImplementedException("Supplementary descriptors are not supported"); case 3: partition = new VolumePartitionDescriptor(fs); break; case 255: terminator = new VolumeDescriptorSetTerminator(fs); termFound = true; break; default: throw new NotImplementedException(string.Format("{0:x}: descriptor is not supported", fs.Position - 1)); } } fs.Position = (long)primary.hdr3.locLTbl * ISO9660.logSize + ISO9660.fsOff; paths = new PathTableRecords(fs, primary.hdr3.pthTblSizeL); for (int i = 0; i < paths.Count; i++) { fs.Position = (long)paths[i].hdr.locExtent * ISO9660.logSize + ISO9660.fsOff; paths[i].files = new FileRecords(fs, paths[i].name, paths[i].fullName); } }