返回顶部

收藏

DiscUtils源代码单文件版,适合项目开发

更多

DiscUtils源代码单文件版

创建 ISO 镜像文件

CDBuilder builder = new CDBuilder();
builder.UseJoliet = true;
builder.VolumeIdentifier = "A_SAMPLE_DISK";
builder.AddFile(@"Folder\Hello.txt", Encoding.ASCII.GetBytes("Hello World!"));
builder.Build(@"C:\temp\sample.iso");

从 ISO 镜像文件中提取文件

using (FileStream isoStream = File.Open(@"C:\temp\sample.iso"))
{
  CDReader cd = new CDReader(isoStream, true);
  Stream fileStream = cd.OpenFile(@"Folder\Hello.txt", FileMode.Open);
  // Use fileStream...
}

创建虚拟磁盘文件

long diskSize = 30 * 1024 * 1024; //30MB
using (Stream vhdStream = File.Create(@"C:\TEMP\mydisk.vhd"))
{
    Disk disk = Disk.InitializeDynamic(vhdStream, diskSize);
    BiosPartitionTable.Initialize(disk, WellKnownPartitionType.WindowsFat);
    using (FatFileSystem fs = FatFileSystem.FormatPartition(disk, 0, null))
    {
        fs.CreateDirectory(@"TestDir\CHILD");
        // do other things with the file system...
    }
}

创建虚拟软盘文件

using (FileStream fs = File.Create(@"myfloppy.vfd"))
{
    using (FatFileSystem floppy = FatFileSystem.FormatFloppy(fs, FloppyDiskType.HighDensity, "MY FLOPPY  "))
    {
        using (Stream s = floppy.OpenFile("foo.txt", FileMode.Create))
        {
            // Use stream...
        }
    }
}

创建 ISO 目录镜像文件,并进行版本管理

CDBuilder builder = new CDBuilder();
builder.UseJoliet = true;
string buildfrompath = @"C:\7zip";
Queue<FileSystemInfo> copyfolders = new Queue<FileSystemInfo>(new DirectoryInfo(buildfrompath).GetFileSystemInfos());
string folderName = Path.GetFileName(buildfrompath);
builder.VolumeIdentifier = folderName;
builder.AddDirectory(folderName);
int sourcedirlen = buildfrompath.Length - folderName.Length;
while (copyfolders.Count > 0)
{
    FileSystemInfo atom = copyfolders.Dequeue();
    FileInfo file = atom as FileInfo;
    if (file == null)
    {
        DirectoryInfo directory = atom as DirectoryInfo;
        builder.AddDirectory(directory.FullName.Substring(sourcedirlen));
        foreach (FileSystemInfo fi in directory.GetFileSystemInfos())
            copyfolders.Enqueue(fi);
    }
    else
        builder.AddFile(file.FullName.Substring(sourcedirlen), file.FullName);
}
string isoname = @"C:\" + folderName;
string isofile;
int num = 2;
if (System.IO.File.Exists(isofile = isoname + ".iso"))
    while (System.IO.File.Exists(isofile = isoname + num++ + ".iso")) ;
builder.Build(isofile);

标签:c#

收藏

0人收藏

支持

0

反对

0

发表评论