예제 #1
1
        public void Exists()
        {
            CDBuilder builder = new CDBuilder();

            builder.AddFile(@"dir\foo.txt", new byte[] { 1 });
            CDReader fs = new CDReader(builder.Build(), false);

            Assert.IsFalse(fs.GetFileInfo("unknown.txt").Exists);
            Assert.IsTrue(fs.GetFileInfo(@"dir\foo.txt").Exists);
            Assert.IsFalse(fs.GetFileInfo(@"dir").Exists);
        }
예제 #2
0
 public void FileSystemInfo()
 {
     CDBuilder builder = new CDBuilder();
     CDReader fs = new CDReader(builder.Build(), false);
     DiscFileSystemInfo fi = fs.GetFileSystemInfo(@"SOMEDIR\SOMEFILE");
     Assert.IsNotNull(fi);
 }
        public void GetDirectories()
        {
            CDBuilder builder = new CDBuilder();

            builder.AddDirectory(@"SOMEDIR\CHILD\GCHILD");
            builder.AddDirectory(@"A.DIR");
            CDReader fs = new CDReader(builder.Build(), false);


            Assert.AreEqual(2, fs.Root.GetDirectories().Length);

            DiscDirectoryInfo someDir = fs.Root.GetDirectories(@"SoMeDir")[0];

            Assert.AreEqual(1, fs.Root.GetDirectories("SOMEDIR").Length);
            Assert.AreEqual("SOMEDIR", someDir.Name);

            Assert.AreEqual(1, someDir.GetDirectories("*.*").Length);
            Assert.AreEqual("CHILD", someDir.GetDirectories("*.*")[0].Name);
            Assert.AreEqual(2, someDir.GetDirectories("*.*", SearchOption.AllDirectories).Length);

            Assert.AreEqual(4, fs.Root.GetDirectories("*.*", SearchOption.AllDirectories).Length);
            Assert.AreEqual(2, fs.Root.GetDirectories("*.*", SearchOption.TopDirectoryOnly).Length);

            Assert.AreEqual(1, fs.Root.GetDirectories("*.DIR", SearchOption.AllDirectories).Length);
            Assert.AreEqual(@"A.DIR\", fs.Root.GetDirectories("*.DIR", SearchOption.AllDirectories)[0].FullName);

            Assert.AreEqual(1, fs.Root.GetDirectories("GCHILD", SearchOption.AllDirectories).Length);
            Assert.AreEqual(@"SOMEDIR\CHILD\GCHILD\", fs.Root.GetDirectories("GCHILD", SearchOption.AllDirectories)[0].FullName);
        }
예제 #4
0
        public void BootImage()
        {
            byte[] memoryStream = new byte[33 * 512];
            for(int i = 0; i < memoryStream.Length; ++i)
            {
                memoryStream[i] = (byte)i;
            }

            CDBuilder builder = new CDBuilder();
            builder.SetBootImage(new MemoryStream(memoryStream), BootDeviceEmulation.HardDisk, 0x543);

            CDReader fs = new CDReader(builder.Build(), false);
            Assert.IsTrue(fs.HasBootImage);

            using (Stream bootImg = fs.OpenBootImage())
            {
                Assert.AreEqual(memoryStream.Length, bootImg.Length);
                for (int i = 0; i < bootImg.Length; ++i)
                {
                    if (memoryStream[i] != bootImg.ReadByte())
                    {
                        Assert.Fail("Boot image corrupted");
                    }
                }
            }

            Assert.AreEqual(BootDeviceEmulation.HardDisk, fs.BootEmulation);
            Assert.AreEqual(0x543, fs.BootLoadSegment);
        }
        public void Parent_Root()
        {
            CDBuilder builder = new CDBuilder();
            CDReader  fs      = new CDReader(builder.Build(), false);

            Assert.IsNull(fs.Root.Parent);
        }
예제 #6
0
        public void Equals()
        {
            CDBuilder builder = new CDBuilder();
            CDReader fs = new CDReader(builder.Build(), false);

            Assert.AreEqual(fs.GetFileInfo("foo.txt"), fs.GetFileInfo("foo.txt"));
        }
        public void CanWrite()
        {
            CDBuilder builder = new CDBuilder();
            CDReader  fs      = new CDReader(builder.Build(), false);

            Assert.IsFalse(fs.CanWrite);
        }
예제 #8
0
        public void Equals()
        {
            CDBuilder builder = new CDBuilder();
            CDReader  fs      = new CDReader(builder.Build(), false);

            Assert.AreEqual(fs.GetFileInfo("foo.txt"), fs.GetFileInfo("foo.txt"));
        }
예제 #9
0
        protected override void DoRun()
        {
            DirectoryInfo di = new DirectoryInfo(_srcDir.Value);
            if (!di.Exists)
            {
                Console.WriteLine("The source directory doesn't exist!");
                Environment.Exit(1);
            }

            CDBuilder builder = new CDBuilder();

            if (_volLabelSwitch.IsPresent)
            {
                builder.VolumeIdentifier = _volLabelSwitch.Value;
            }

            if (_bootImage.IsPresent)
            {
                builder.SetBootImage(new FileStream(_bootImage.Value, FileMode.Open, FileAccess.Read), BootDeviceEmulation.NoEmulation, 0);
            }

            PopulateFromFolder(builder, di, di.FullName);

            builder.Build(_isoFileParam.Value);
        }
예제 #10
0
 public void DirectoryInfo()
 {
     CDBuilder builder = new CDBuilder();
     CDReader fs = new CDReader(builder.Build(), false);
     DiscDirectoryInfo fi = fs.GetDirectoryInfo(@"SOMEDIR");
     Assert.IsNotNull(fi);
 }
예제 #11
0
        public void BootImage()
        {
            byte[] memoryStream = new byte[33 * 512];
            for (int i = 0; i < memoryStream.Length; ++i)
            {
                memoryStream[i] = (byte)i;
            }

            CDBuilder builder = new CDBuilder();

            builder.SetBootImage(new MemoryStream(memoryStream), BootDeviceEmulation.HardDisk, 0x543);

            CDReader fs = new CDReader(builder.Build(), false);

            Assert.IsTrue(fs.HasBootImage);

            using (Stream bootImg = fs.OpenBootImage())
            {
                Assert.AreEqual(memoryStream.Length, bootImg.Length);
                for (int i = 0; i < bootImg.Length; ++i)
                {
                    if (memoryStream[i] != bootImg.ReadByte())
                    {
                        Assert.Fail("Boot image corrupted");
                    }
                }
            }

            Assert.AreEqual(BootDeviceEmulation.HardDisk, fs.BootEmulation);
            Assert.AreEqual(0x543, fs.BootLoadSegment);
        }
        public void Extension()
        {
            CDBuilder builder = new CDBuilder();
            CDReader  fs      = new CDReader(builder.Build(), false);

            Assert.AreEqual("dir", fs.GetDirectoryInfo("fred.dir").Extension);
            Assert.AreEqual("", fs.GetDirectoryInfo("fred").Extension);
        }
        public void FileSystemInfo()
        {
            CDBuilder          builder = new CDBuilder();
            CDReader           fs      = new CDReader(builder.Build(), false);
            DiscFileSystemInfo fi      = fs.GetFileSystemInfo(@"SOMEDIR\SOMEFILE");

            Assert.IsNotNull(fi);
        }
        public void DirectoryInfo()
        {
            CDBuilder         builder = new CDBuilder();
            CDReader          fs      = new CDReader(builder.Build(), false);
            DiscDirectoryInfo fi      = fs.GetDirectoryInfo(@"SOMEDIR");

            Assert.IsNotNull(fi);
        }
예제 #15
0
        public void Extension()
        {
            CDBuilder builder = new CDBuilder();
            CDReader fs = new CDReader(builder.Build(), false);

            Assert.AreEqual("dir", fs.GetDirectoryInfo("fred.dir").Extension);
            Assert.AreEqual("", fs.GetDirectoryInfo("fred").Extension);
        }
예제 #16
0
        public void AddFileStream()
        {
            CDBuilder builder = new CDBuilder();
            builder.AddFile(@"ADIR\AFILE.TXT", new MemoryStream());
            CDReader fs = new CDReader(builder.Build(), false);

            Assert.IsTrue(fs.Exists(@"ADIR\AFILE.TXT"));
        }
예제 #17
0
        public void AddFileBytes()
        {
            CDBuilder builder = new CDBuilder();
            builder.AddFile(@"ADIR\AFILE.TXT", new byte[] {});
            CDReader fs = new CDReader(builder.Build(), false);

            Assert.IsTrue(fs.Exists(@"ADIR\AFILE.TXT"));
        }
예제 #18
0
        public void Open_FileNotFound()
        {
            CDBuilder builder = new CDBuilder();
            CDReader  fs      = new CDReader(builder.Build(), false);

            DiscFileInfo di = fs.GetFileInfo("foo.txt");

            using (Stream s = di.Open(FileMode.Open)) { }
        }
예제 #19
0
        public void CreationTimeUtc()
        {
            CDBuilder builder = new CDBuilder();
            builder.AddFile(@"foo.txt", new byte[] { 1 });
            CDReader fs = new CDReader(builder.Build(), false);

            Assert.GreaterOrEqual(DateTime.UtcNow, fs.GetFileInfo("foo.txt").CreationTimeUtc);
            Assert.LessOrEqual(DateTime.UtcNow.Subtract(TimeSpan.FromSeconds(10)), fs.GetFileInfo("foo.txt").CreationTimeUtc);
        }
        public void Parent()
        {
            CDBuilder builder = new CDBuilder();

            builder.AddDirectory(@"SOMEDIR");
            CDReader fs = new CDReader(builder.Build(), false);

            Assert.AreEqual(fs.Root, fs.Root.GetDirectories("SOMEDIR")[0].Parent);
        }
예제 #21
0
        public void Name()
        {
            CDBuilder builder = new CDBuilder();
            CDReader  fs      = new CDReader(builder.Build(), false);

            Assert.AreEqual("foo.txt", fs.GetFileInfo("foo.txt").Name);
            Assert.AreEqual("foo.txt", fs.GetFileInfo(@"path\foo.txt").Name);
            Assert.AreEqual("foo.txt", fs.GetFileInfo(@"\foo.txt").Name);
        }
예제 #22
0
        public void AddFileStream()
        {
            CDBuilder builder = new CDBuilder();

            builder.AddFile(@"ADIR\AFILE.TXT", new MemoryStream());
            CDReader fs = new CDReader(builder.Build(), false);

            Assert.IsTrue(fs.Exists(@"ADIR\AFILE.TXT"));
        }
        public void FullName()
        {
            CDBuilder builder = new CDBuilder();
            CDReader  fs      = new CDReader(builder.Build(), false);

            Assert.AreEqual(@"\", fs.Root.FullName);
            Assert.AreEqual(@"SOMEDIR\", fs.GetDirectoryInfo(@"SOMEDIR").FullName);
            Assert.AreEqual(@"SOMEDIR\CHILDDIR\", fs.GetDirectoryInfo(@"SOMEDIR\CHILDDIR").FullName);
        }
예제 #24
0
        public void AddFileBytes()
        {
            CDBuilder builder = new CDBuilder();

            builder.AddFile(@"ADIR\AFILE.TXT", new byte[] {});
            CDReader fs = new CDReader(builder.Build(), false);

            Assert.IsTrue(fs.Exists(@"ADIR\AFILE.TXT"));
        }
예제 #25
0
        public void CreationTimeUtc()
        {
            CDBuilder builder = new CDBuilder();

            builder.AddFile(@"foo.txt", new byte[] { 1 });
            CDReader fs = new CDReader(builder.Build(), false);

            Assert.GreaterOrEqual(DateTime.UtcNow, fs.GetFileInfo("foo.txt").CreationTimeUtc);
            Assert.LessOrEqual(DateTime.UtcNow.Subtract(TimeSpan.FromSeconds(10)), fs.GetFileInfo("foo.txt").CreationTimeUtc);
        }
        public void Root()
        {
            CDBuilder builder = new CDBuilder();
            CDReader  fs      = new CDReader(builder.Build(), false);

            Assert.IsNotNull(fs.Root);
            Assert.IsTrue(fs.Root.Exists);
            Assert.IsEmpty(fs.Root.Name);
            Assert.IsNull(fs.Root.Parent);
        }
예제 #27
0
        public void Exists()
        {
            CDBuilder builder = new CDBuilder();
            builder.AddFile(@"dir\foo.txt", new byte[] { 1 });
            CDReader fs = new CDReader(builder.Build(), false);

            Assert.IsFalse(fs.GetFileInfo("unknown.txt").Exists);
            Assert.IsTrue(fs.GetFileInfo(@"dir\foo.txt").Exists);
            Assert.IsFalse(fs.GetFileInfo(@"dir").Exists);
        }
예제 #28
0
        public void Attributes()
        {
            CDBuilder builder = new CDBuilder();
            builder.AddFile("foo.txt", new byte[] { 1 });
            CDReader fs = new CDReader(builder.Build(), false);

            DiscFileInfo fi = fs.GetFileInfo("foo.txt");

            // Check default attributes
            Assert.AreEqual(FileAttributes.ReadOnly, fi.Attributes);
        }
        public void SimpleSearch()
        {
            CDBuilder builder = new CDBuilder();

            builder.AddFile(@"SOMEDIR\CHILDDIR\GCHILDIR\FILE.TXT", new byte[0]);
            CDReader fs = new CDReader(builder.Build(), false);

            DiscDirectoryInfo di = fs.GetDirectoryInfo(@"SOMEDIR\CHILDDIR");

            DiscFileInfo[] fis = di.GetFiles("*.*", SearchOption.AllDirectories);
        }
예제 #30
0
        public void Parent()
        {
            CDBuilder builder = new CDBuilder();

            builder.AddFile(@"SOMEDIR\ADIR\FILE.TXT", new byte[] { 1 });
            CDReader fs = new CDReader(builder.Build(), false);

            DiscFileInfo fi = fs.GetFileInfo(@"SOMEDIR\ADIR\FILE.TXT");

            Assert.AreEqual(fs.GetDirectoryInfo(@"SOMEDIR\ADIR"), fi.Parent);
            Assert.AreEqual(fs.GetDirectoryInfo(@"SOMEDIR\ADIR"), fi.Directory);
        }
예제 #31
0
        public void Attributes()
        {
            CDBuilder builder = new CDBuilder();

            builder.AddFile("foo.txt", new byte[] { 1 });
            CDReader fs = new CDReader(builder.Build(), false);

            DiscFileInfo fi = fs.GetFileInfo("foo.txt");

            // Check default attributes
            Assert.AreEqual(FileAttributes.ReadOnly, fi.Attributes);
        }
        public void BuildCVM(Stream CVM, List<string> filesToReplace, List<string>names)
        {
            CDReader cd = new CDReader(CVM, true);
            CDBuilder cb = new CDBuilder();
            foreach (DiscFileInfo file in cd.Root.GetFiles("*.*", SearchOption.AllDirectories))
            {
                foreach (DiscDirectoryInfo dir in cd.Root.GetDirectories("*.*", SearchOption.AllDirectories))
                {

                }
            }
        }
예제 #33
0
        public void Exists()
        {
            CDBuilder builder = new CDBuilder();
            builder.AddFile(@"SOMEDIR\CHILDDIR\FILE.TXT", new byte[0]);
            CDReader fs = new CDReader(builder.Build(), false);

            Assert.IsTrue(fs.GetDirectoryInfo(@"\").Exists);
            Assert.IsTrue(fs.GetDirectoryInfo(@"SOMEDIR").Exists);
            Assert.IsTrue(fs.GetDirectoryInfo(@"SOMEDIR\CHILDDIR").Exists);
            Assert.IsTrue(fs.GetDirectoryInfo(@"SOMEDIR\CHILDDIR\").Exists);
            Assert.IsFalse(fs.GetDirectoryInfo(@"NONDIR").Exists);
            Assert.IsFalse(fs.GetDirectoryInfo(@"SOMEDIR\NONDIR").Exists);
        }
        public void Exists()
        {
            CDBuilder builder = new CDBuilder();

            builder.AddFile(@"SOMEDIR\CHILDDIR\FILE.TXT", new byte[0]);
            CDReader fs = new CDReader(builder.Build(), false);

            Assert.IsTrue(fs.GetDirectoryInfo(@"\").Exists);
            Assert.IsTrue(fs.GetDirectoryInfo(@"SOMEDIR").Exists);
            Assert.IsTrue(fs.GetDirectoryInfo(@"SOMEDIR\CHILDDIR").Exists);
            Assert.IsTrue(fs.GetDirectoryInfo(@"SOMEDIR\CHILDDIR\").Exists);
            Assert.IsFalse(fs.GetDirectoryInfo(@"NONDIR").Exists);
            Assert.IsFalse(fs.GetDirectoryInfo(@"SOMEDIR\NONDIR").Exists);
        }
 public void BuildISO(Stream ISOOpen, string pathSave)
 {
     CDReader cd = new CDReader(ISOOpen, true);
     CDBuilder cb = new CDBuilder(); cb.UseJoliet = true;
     foreach (DiscFileInfo file in cd.Root.GetFiles("*.*", SearchOption.AllDirectories))
     {
         foreach (DiscDirectoryInfo dir in cd.Root.GetDirectories("*.*", SearchOption.AllDirectories))
         {
             cb.AddDirectory(dir.Name);
             cb.AddFile(file.FullName, cd.OpenFile(file.FullName, FileMode.Open));
         }
     }
     cb.Build(pathSave);
 }
        public void LargeDirectory()
        {
            CDBuilder builder = new CDBuilder();

            builder.UseJoliet = true;

            for (int i = 0; i < 3000; ++i)
            {
                builder.AddFile("FILE" + i + ".TXT", new byte[] { });
            }

            CDReader reader = new CDReader(builder.Build(), true);

            Assert.AreEqual(3000, reader.Root.GetFiles().Length);
        }
예제 #37
0
        public void Length()
        {
            CDBuilder builder = new CDBuilder();

            builder.AddFile(@"FILE.TXT", new byte[0]);
            builder.AddFile(@"FILE2.TXT", new byte[1]);
            builder.AddFile(@"FILE3.TXT", new byte[10032]);
            builder.AddFile(@"FILE3.TXT;2", new byte[132]);
            CDReader fs = new CDReader(builder.Build(), false);

            Assert.AreEqual(0, fs.GetFileInfo("FILE.txt").Length);
            Assert.AreEqual(1, fs.GetFileInfo("FILE2.txt").Length);
            Assert.AreEqual(10032, fs.GetFileInfo("FILE3.txt;1").Length);
            Assert.AreEqual(132, fs.GetFileInfo("FILE3.txt;2").Length);
            Assert.AreEqual(132, fs.GetFileInfo("FILE3.txt").Length);
        }
        public void GetFileSystemInfos()
        {
            CDBuilder builder = new CDBuilder();

            builder.AddDirectory(@"SOMEDIR\CHILD\GCHILD");
            builder.AddDirectory(@"AAA.EXT");
            builder.AddFile(@"FOO.TXT", new byte[10]);
            builder.AddFile(@"SOMEDIR\CHILD.TXT", new byte[10]);
            builder.AddFile(@"SOMEDIR\FOO.TXT", new byte[10]);
            builder.AddFile(@"SOMEDIR\CHILD\GCHILD\BAR.TXT", new byte[10]);
            CDReader fs = new CDReader(builder.Build(), false);

            Assert.AreEqual(3, fs.Root.GetFileSystemInfos().Length);

            Assert.AreEqual(1, fs.Root.GetFileSystemInfos("*.EXT").Length);
            Assert.AreEqual(2, fs.Root.GetFileSystemInfos("*.?XT").Length);
        }
예제 #39
0
        public void Open_Read()
        {
            CDBuilder builder = new CDBuilder();

            builder.AddFile("foo.txt", new byte[] { 1 });
            CDReader fs = new CDReader(builder.Build(), false);

            DiscFileInfo di = fs.GetFileInfo("foo.txt");

            using (Stream s = di.Open(FileMode.Open, FileAccess.Read))
            {
                Assert.IsFalse(s.CanWrite);
                Assert.IsTrue(s.CanRead);

                Assert.AreEqual(1, s.ReadByte());
            }
        }
예제 #40
0
        public void HideVersions()
        {
            CDBuilder builder = new CDBuilder();
            builder.UseJoliet = true;
            builder.AddFile("FILE.TXT;1", new byte[] { });

            MemoryStream ms = new MemoryStream();
            SparseStream.Pump(builder.Build(), ms);

            CDReader reader = new CDReader(ms, true, false);
            Assert.AreEqual("\\FILE.TXT;1", reader.GetFiles("")[0]);
            Assert.AreEqual("\\FILE.TXT;1", reader.GetFileSystemEntries("")[0]);

            reader = new CDReader(ms, true, true);
            Assert.AreEqual("\\FILE.TXT", reader.GetFiles("")[0]);
            Assert.AreEqual("\\FILE.TXT", reader.GetFileSystemEntries("")[0]);
        }
        public void RootBehaviour()
        {
            // Start time rounded down to whole seconds
            DateTime start = DateTime.UtcNow;

            start = new DateTime(start.Year, start.Month, start.Day, start.Hour, start.Minute, start.Second);

            CDBuilder builder = new CDBuilder();
            CDReader  fs      = new CDReader(builder.Build(), false);
            DateTime  end     = DateTime.UtcNow;

            Assert.AreEqual(FileAttributes.Directory | FileAttributes.ReadOnly, fs.Root.Attributes);
            Assert.GreaterOrEqual(fs.Root.CreationTimeUtc, start);
            Assert.LessOrEqual(fs.Root.CreationTimeUtc, end);
            Assert.GreaterOrEqual(fs.Root.LastAccessTimeUtc, start);
            Assert.LessOrEqual(fs.Root.LastAccessTimeUtc, end);
            Assert.GreaterOrEqual(fs.Root.LastWriteTimeUtc, start);
            Assert.LessOrEqual(fs.Root.LastWriteTimeUtc, end);
        }
        public void GetFiles()
        {
            CDBuilder builder = new CDBuilder();

            builder.AddDirectory(@"SOMEDIR\CHILD\GCHILD");
            builder.AddDirectory(@"AAA.DIR");
            builder.AddFile(@"FOO.TXT", new byte[10]);
            builder.AddFile(@"SOMEDIR\CHILD.TXT", new byte[10]);
            builder.AddFile(@"SOMEDIR\FOO.TXT", new byte[10]);
            builder.AddFile(@"SOMEDIR\CHILD\GCHILD\BAR.TXT", new byte[10]);
            CDReader fs = new CDReader(builder.Build(), false);

            Assert.AreEqual(1, fs.Root.GetFiles().Length);
            Assert.AreEqual("FOO.TXT", fs.Root.GetFiles()[0].FullName);

            Assert.AreEqual(2, fs.Root.GetDirectories("SOMEDIR")[0].GetFiles("*.TXT").Length);
            Assert.AreEqual(4, fs.Root.GetFiles("*.TXT", SearchOption.AllDirectories).Length);

            Assert.AreEqual(0, fs.Root.GetFiles("*.DIR", SearchOption.AllDirectories).Length);
        }
        public void HideVersions()
        {
            CDBuilder builder = new CDBuilder();

            builder.UseJoliet = true;
            builder.AddFile("FILE.TXT;1", new byte[] { });

            MemoryStream ms = new MemoryStream();

            SparseStream.Pump(builder.Build(), ms);

            CDReader reader = new CDReader(ms, true, false);

            Assert.AreEqual("\\FILE.TXT;1", reader.GetFiles("")[0]);
            Assert.AreEqual("\\FILE.TXT;1", reader.GetFileSystemEntries("")[0]);

            reader = new CDReader(ms, true, true);
            Assert.AreEqual("\\FILE.TXT", reader.GetFiles("")[0]);
            Assert.AreEqual("\\FILE.TXT", reader.GetFileSystemEntries("")[0]);
        }
예제 #44
0
        public void Attributes()
        {
            // Start time rounded down to whole seconds
            DateTime start = DateTime.UtcNow;
            start = new DateTime(start.Year, start.Month, start.Day, start.Hour, start.Minute, start.Second);

            CDBuilder builder = new CDBuilder();
            builder.AddDirectory("Foo");
            CDReader fs = new CDReader(builder.Build(), false);
            DateTime end = DateTime.UtcNow;

            DiscDirectoryInfo di = fs.GetDirectoryInfo("Foo");

            Assert.AreEqual(FileAttributes.Directory | FileAttributes.ReadOnly, di.Attributes);
            Assert.GreaterOrEqual(di.CreationTimeUtc, start);
            Assert.LessOrEqual(di.CreationTimeUtc, end);
            Assert.GreaterOrEqual(di.LastAccessTimeUtc, start);
            Assert.LessOrEqual(di.LastAccessTimeUtc, end);
            Assert.GreaterOrEqual(di.LastWriteTimeUtc, start);
            Assert.LessOrEqual(di.LastWriteTimeUtc, end);
        }
        public void Attributes()
        {
            // Start time rounded down to whole seconds
            DateTime start = DateTime.UtcNow;

            start = new DateTime(start.Year, start.Month, start.Day, start.Hour, start.Minute, start.Second);

            CDBuilder builder = new CDBuilder();

            builder.AddDirectory("Foo");
            CDReader fs  = new CDReader(builder.Build(), false);
            DateTime end = DateTime.UtcNow;

            DiscDirectoryInfo di = fs.GetDirectoryInfo("Foo");

            Assert.AreEqual(FileAttributes.Directory | FileAttributes.ReadOnly, di.Attributes);
            Assert.GreaterOrEqual(di.CreationTimeUtc, start);
            Assert.LessOrEqual(di.CreationTimeUtc, end);
            Assert.GreaterOrEqual(di.LastAccessTimeUtc, start);
            Assert.LessOrEqual(di.LastAccessTimeUtc, end);
            Assert.GreaterOrEqual(di.LastWriteTimeUtc, start);
            Assert.LessOrEqual(di.LastWriteTimeUtc, end);
        }
예제 #46
0
        public void Length()
        {
            CDBuilder builder = new CDBuilder();
            builder.AddFile(@"FILE.TXT", new byte[0]);
            builder.AddFile(@"FILE2.TXT", new byte[1]);
            builder.AddFile(@"FILE3.TXT", new byte[10032]);
            builder.AddFile(@"FILE3.TXT;2", new byte[132]);
            CDReader fs = new CDReader(builder.Build(), false);

            Assert.AreEqual(0, fs.GetFileInfo("FILE.txt").Length);
            Assert.AreEqual(1, fs.GetFileInfo("FILE2.txt").Length);
            Assert.AreEqual(10032, fs.GetFileInfo("FILE3.txt;1").Length);
            Assert.AreEqual(132, fs.GetFileInfo("FILE3.txt;2").Length);
            Assert.AreEqual(132, fs.GetFileInfo("FILE3.txt").Length);
        }
예제 #47
0
        private static void PopulateFromFolder(CDBuilder builder, DirectoryInfo di, string basePath)
        {
            foreach (FileInfo file in di.GetFiles())
            {
                builder.AddFile(file.FullName.Substring(basePath.Length), file.FullName);
            }

            foreach (DirectoryInfo dir in di.GetDirectories())
            {
                PopulateFromFolder(builder, dir, basePath);
            }
        }
예제 #48
0
        public List<DiscTrack> BuildGDROM(string data, string ipbin, List<string> cdda)
        {
            string bootBin;
            byte[] ipbinData = new byte[0x8000];
            CDBuilder builder = new CDBuilder();
            builder.VolumeIdentifier = VolumeIdentifier;
            builder.SystemIdentifier = SystemIdentifier;
            builder.VolumeSetIdentifier = VolumeSetIdentifier;
            builder.PublisherIdentifier = PublisherIdentifier;
            builder.DataPreparerIdentifier = DataPreparerIdentifier;
            builder.ApplicationIdentifier = ApplicationIdentifier;
            builder.UseJoliet = false; //A stupid default, mkisofs won't do this by default.
            builder.LBAoffset = GD_START_LBA;
            builder.EndSector = GD_END_LBA;

            using (FileStream ipfs = new FileStream(ipbin, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                if (ipfs.Length != ipbinData.Length)
                {
                    throw new Exception("IP.BIN is the wrong size. Possibly the wrong file? Cannot continue.");
                }
                bootBin = GetBootBin(ipfs);
                ipfs.Seek(0, SeekOrigin.Begin);
                ipfs.Read(ipbinData, 0, ipbinData.Length);
            }
            List<DiscTrack> retval = new List<DiscTrack>();
            if (cdda != null && cdda.Count > 0)
            {
                retval = ReadCDDA(cdda);
            }
            DirectoryInfo di = new DirectoryInfo(data);
            PopulateFromFolder(builder, di, di.FullName, bootBin);

            using (BuiltStream isoStream = (BuiltStream)builder.Build())
            {
                _lastProgress = 0;
                if (retval.Count > 0 || (TruncateData && !string.IsNullOrEmpty(LastTrackPath)))
                {
                    if (RawMode)
                    {
                        ExportMultiTrackRaw(isoStream, ipbinData, retval);
                    }
                    else
                    {
                        ExportMultiTrack(isoStream, ipbinData, retval);
                    }
                }
                else
                {
                    if (RawMode)
                    {
                        ExportSingleTrackRaw(isoStream, ipbinData, retval);
                    }
                    else
                    {
                        ExportSingleTrack(isoStream, ipbinData, retval);
                    }
                }
            }
            return retval;
        }
예제 #49
0
        private void PopulateFromFolder(CDBuilder builder, DirectoryInfo di, string basePath, string bootBin)
        {
            FileInfo bootBinFile = null;
            foreach (FileInfo file in di.GetFiles())
            {
                string filePath = file.FullName.Substring(basePath.Length);
                if (bootBin != null && file.Name.Equals(bootBin, StringComparison.OrdinalIgnoreCase))
                {
                    bootBinFile = file; //Ignore this for now, we want it last
                }
                else
                {
                    builder.AddFile(filePath, file.FullName);
                }
            }

            foreach (DirectoryInfo dir in di.GetDirectories())
            {
                PopulateFromFolder(builder, dir, basePath, null);
            }

            if (bootBinFile != null && bootBin != null)
            {
                builder.AddFile(bootBin, bootBinFile.FullName);
                long sectorSize = RoundUp(bootBinFile.Length, DATA_SECTOR_SIZE);
                builder.LastFileStartSector = (uint)(GD_END_LBA - 150 - (sectorSize / DATA_SECTOR_SIZE));
            }
            else if (bootBin != null)
            {
                //User doesn't know what they're doing and gave us bad data.
                throw new FileNotFoundException("IP.BIN requires the boot file " + bootBin +
                    " which was not found in the data directory.");
            }
        }
예제 #50
0
 public void Root()
 {
     CDBuilder builder = new CDBuilder();
     CDReader fs = new CDReader(builder.Build(), false);
     Assert.IsNotNull(fs.Root);
     Assert.IsTrue(fs.Root.Exists);
     Assert.IsEmpty(fs.Root.Name);
     Assert.IsNull(fs.Root.Parent);
 }
예제 #51
0
 public void CanWrite()
 {
     CDBuilder builder = new CDBuilder();
     CDReader fs = new CDReader(builder.Build(), false);
     Assert.IsFalse(fs.CanWrite);
 }
예제 #52
0
        public void LargeDirectory()
        {
            CDBuilder builder = new CDBuilder();
            builder.UseJoliet = true;

            for (int i = 0; i < 3000; ++i)
            {
                builder.AddFile("FILE" + i + ".TXT", new byte[] { });
            }

            CDReader reader = new CDReader(builder.Build(), true);

            Assert.AreEqual(3000, reader.Root.GetFiles().Length);
        }
예제 #53
0
        public void Name()
        {
            CDBuilder builder = new CDBuilder();
            CDReader fs = new CDReader(builder.Build(), false);

            Assert.AreEqual("foo.txt", fs.GetFileInfo("foo.txt").Name);
            Assert.AreEqual("foo.txt", fs.GetFileInfo(@"path\foo.txt").Name);
            Assert.AreEqual("foo.txt", fs.GetFileInfo(@"\foo.txt").Name);
        }
예제 #54
0
        public void Open_FileNotFound()
        {
            CDBuilder builder = new CDBuilder();
            CDReader fs = new CDReader(builder.Build(), false);

            DiscFileInfo di = fs.GetFileInfo("foo.txt");
            using (Stream s = di.Open(FileMode.Open)) { }
        }
예제 #55
0
        public void Open_Read()
        {
            CDBuilder builder = new CDBuilder();
            builder.AddFile("foo.txt", new byte[] { 1 });
            CDReader fs = new CDReader(builder.Build(), false);

            DiscFileInfo di = fs.GetFileInfo("foo.txt");
            using (Stream s = di.Open(FileMode.Open, FileAccess.Read))
            {
                Assert.IsFalse(s.CanWrite);
                Assert.IsTrue(s.CanRead);

                Assert.AreEqual(1, s.ReadByte());
            }
        }
예제 #56
0
        public void Parent()
        {
            CDBuilder builder = new CDBuilder();
            builder.AddFile(@"SOMEDIR\ADIR\FILE.TXT", new byte[] { 1 });
            CDReader fs = new CDReader(builder.Build(), false);

            DiscFileInfo fi = fs.GetFileInfo(@"SOMEDIR\ADIR\FILE.TXT");
            Assert.AreEqual(fs.GetDirectoryInfo(@"SOMEDIR\ADIR"), fi.Parent);
            Assert.AreEqual(fs.GetDirectoryInfo(@"SOMEDIR\ADIR"), fi.Directory);
        }
예제 #57
0
        private string Run(int revision, string additionalFilePath, bool autoStartChecked)
        {
            string filename = string.Format("bootcd-{0}-dbg", revision);

            string filename7z = filename + ".7z";
            string filenameIso = filename + ".iso";

            if (!File.Exists(filenameIso))
            {
                string filename7zTemp = filename7z + ".temp";
                string filenameIsoTemp = filenameIso + ".temp";

                if (!File.Exists(filename7z))
                {
                    File.Delete(filename7zTemp);

                    WebClient wc = new WebClient();
                    try
                    {
                        wc.DownloadFile(revToUrl[revision], filename7zTemp);
                    }
                    catch (WebException)
                    {
                        return "File download failed:\n  '" + revToUrl[revision] + "'";
                    }

                    File.Move(filename7zTemp, filename7z);
                }

                File.Delete(filenameIsoTemp);

                FileStream isotmpfs = File.Create(filenameIsoTemp);
                FileStream szfs = File.Open(filename7z, FileMode.Open, FileAccess.Read);
                SevenZipExtractor sze = new SevenZipExtractor(szfs);
                sze.ExtractFile(filenameIso, isotmpfs);
                isotmpfs.Close();
                szfs.Close();

                File.Move(filenameIsoTemp, filenameIso);
                File.Delete(filename7z);
            }

            string vmName = string.Format("ReactOS_r{0}", revision);
            string diskName = Environment.CurrentDirectory + "\\" + vmName + "\\" + vmName + ".vdi";

            if (File.Exists(diskName))
            {
                FileStream fs = null;
                try
                {
                    fs = File.Open(diskName, FileMode.Open, FileAccess.Read, FileShare.None);
                }
                catch (IOException)
                {
                    return "Virtual machine '" + vmName + "' is already running";
                }
                finally
                {
                    if (fs != null)
                        fs.Close();
                }
            }

            string filenameIsoUnatt = filename + "_unatt.iso";
            string filenameIsoUnattTemp = filenameIsoUnatt + ".temp";
            File.Delete(filenameIsoUnattTemp);
            File.Delete(filenameIsoUnatt);

            FileStream isofs = File.Open(filenameIso, FileMode.Open, FileAccess.Read);
            CDReader cdr = new CDReader(isofs, true);
            CDBuilder cdb = new CDBuilder();
            cdb.VolumeIdentifier = cdr.VolumeLabel;
            CloneCdDirectory("", cdr, cdb);

            if (!File.Exists("unattend.inf"))
                File.WriteAllText("unattend.inf", RosRegTest.Resources.unattend, Encoding.ASCII);

            string additionalFileName = null;
            if (additionalFilePath != null)
                additionalFileName = Path.GetFileName(additionalFilePath);

            string unattText = File.ReadAllText("unattend.inf", Encoding.ASCII);
            if (autoStartChecked && (additionalFileName != null))
                unattText = unattText + "[GuiRunOnce]\n" + "cmd.exe /c start d:\\" + additionalFileName + "\n\n";

            cdb.AddFile("reactos\\unattend.inf", Encoding.ASCII.GetBytes(unattText));
            if (additionalFileName != null)
                cdb.AddFile(additionalFileName, additionalFilePath);

            Stream bootImgStr = cdr.OpenBootImage();
            cdb.SetBootImage(bootImgStr, cdr.BootEmulation, cdr.BootLoadSegment);
            bootImgStr.Close();

            cdb.Build(filenameIsoUnattTemp);
            isofs.Close();

            File.Move(filenameIsoUnattTemp, filenameIsoUnatt);

            string fullIsoName = Environment.CurrentDirectory + "\\" + filenameIsoUnatt;
            string deleteVmCmd = string.Format("unregistervm --name {0}", vmName);
            string createVmCmd = string.Format(
                "createvm --name {0} --basefolder {1} --ostype WindowsXP --register",
                vmName, Environment.CurrentDirectory);
            string modifyVmCmd = string.Format("modifyvm {0} --memory 256 --vram 16 --nictype1 Am79C973 --audio none --boot1 disk --boot2 dvd", vmName);
            string storageCtlCmd = string.Format("storagectl {0} --name \"IDE Controller\" --add ide", vmName);
            string createMediumCmd = string.Format("createmedium disk --filename {0} --size 2048", diskName);
            string storageAttachCmd1 = string.Format("storageattach {0} --port 0 --device 0 --storagectl \"IDE Controller\" --type hdd --medium {1}", vmName, diskName);
            string storageAttachCmd2 = string.Format("storageattach {0} --port 1 --device 0 --storagectl \"IDE Controller\" --type dvddrive --medium {1}", vmName, fullIsoName);
            string startCmd = string.Format("startvm {0}", vmName);

            Exec(vboxManagePath, deleteVmCmd);
            Exec(vboxManagePath, createVmCmd);
            Exec(vboxManagePath, modifyVmCmd);
            Exec(vboxManagePath, storageCtlCmd);
            Exec(vboxManagePath, createMediumCmd);
            Exec(vboxManagePath, storageAttachCmd1);
            Exec(vboxManagePath, storageAttachCmd2);
            Exec(vboxManagePath, startCmd);

            return null;
        }
예제 #58
0
        private void CloneCdDirectory(string dir, CDReader cdr, CDBuilder cdb)
        {
            foreach (string fileName in cdr.GetFiles(dir))
            {
                if (fileName == "\\reactos\\unattend.inf")
                    continue;

                var stream = cdr.OpenFile(fileName, FileMode.Open);
                cdb.AddFile(fileName.Remove(0, 1), stream);
                stream.Close();
            }
            foreach (string dirName in cdr.GetDirectories(dir))
            {
                CloneCdDirectory(dirName, cdr, cdb);
            }
        }
예제 #59
0
        public override bool Execute()
        {
            Log.LogMessage(MessageImportance.Normal, "Creating ISO file: '{0}'", FileName.ItemSpec);

            try
            {
                CDBuilder builder = new CDBuilder();
                builder.UseJoliet = UseJoliet;

                if (!string.IsNullOrEmpty(VolumeLabel))
                {
                    builder.VolumeIdentifier = VolumeLabel;
                }

                Stream bootImageStream = null;
                if (BootImage != null)
                {
                    bootImageStream = new FileStream(BootImage.GetMetadata("FullPath"), FileMode.Open, FileAccess.Read);
                    builder.SetBootImage(bootImageStream, BootDeviceEmulation.NoEmulation, 0);
                    builder.UpdateIsolinuxBootTable = UpdateIsolinuxBootTable;
                }

                foreach (var sourceFile in SourceFiles)
                {
                    builder.AddFile(GetDestinationPath(sourceFile), sourceFile.GetMetadata("FullPath"));
                }

                try
                {
                    builder.Build(FileName.ItemSpec);
                }
                finally
                {
                    if (bootImageStream != null)
                    {
                        bootImageStream.Dispose();
                    }
                }
            }
            catch(Exception e)
            {
                Log.LogErrorFromException(e, true, true, null);
                return false;
            }

            return !Log.HasLoggedErrors;
        }