How to increase the burning speed when there are a large number of files (call imapi2 to implement the DVD burning function)

Source: Internet
Author: User

When imapi2 is called to implement the DVD burning function, if a large number of files are used, the burning time is also long. Therefore, you should first make the burning file into ISO files, and then burn it to the DVD. To optimize the burning function.

 

Call the imapi2 method in www.codeproject.com for example can be referred to, the URL is http://www.codeproject.com/KB/winsdk/IMAPI2.aspx. Here, I will not make a shift. Next I will talk about the creating ISO files method.

1. Create an image file

Using system. runtime. interopservices;

Using system. runtime. interopservices. comtypes;

Using imapi2.interop;

// Import this legacy WIN32API...

[Dllimport ("shlwapi. dll", charset = charset. Unicode)] static internal extern uint shcreatestreamonfile (string pszfile, uint grfmode, out istream ppstm );

 

// Create

Ifilesystemimage ifsi = new msftfilesystemimage ();
Ifsi. chooseimagedefaultsformediatype (imapi_media_physical_type.imapi_media_type_disk );
Ifsi. filesystemstocreate =
Fsifilesystems. fsifilesystemjoliet | fsifilesystems. fsifilesystemiso9660;
Ifsi. volumename = "yourvolume ";
Ifsi. Root. addtree ("C: \ yourdirtoarchive", true); // use a valid folder
// This will implement the write Method for The formatter
Istream imagestream = ifsi. createresultimage (). imagestream;
If (imagestream! = NULL)
{
System. runtime. interopservices. comtypes. statstg Stat;
Imagestream. Stat (out stat, 0x01 );
Istream newstream;
If (0 = shcreatestreamonfile
("C: \ yourimage. ISO", 0x00001001, out newstream) & newstream! = NULL)
{
Intptr inbytes = marshal. allochglobal (marshal. sizeof (typeof (long )));
Intptr outbytes = marshal. allochglobal (marshal. sizeof (typeof (long )));
Try
{
Imagestream. copyto (newstream, stat. cbsize, inbytes, outbytes );
Marshal. releasecomobject (imagestream );
Imagestream = NULL;
Newstream. Commit (0 );
}
Finally
{
Marshal. releasecomobject (newstream );
Marshal. freehglobal (inbytes );
Marshal. freehglobal (outbytes );
If (imagestream! = NULL)
Marshal. releasecomobject (imagestream );
}
}
}
Marshal. releasecomobject (ifsi );

2. Add a separate file to the image.

Use ifsidirectoryitem to record the original path of the file and update the event to track the process.

Private void createfsifile (fileinfo file, ifsidirectoryitem diritem)
{
String realpath = uniquelistfilesysteminfo. getphysicalpath (file. fullname );
Int Index = realpath. indexof (": \") + 1;
If (_ sysimage. exists (realpath. substring (INDEX) = fsiitemtype. fsiitemnotfound)
{
Ifsidirectoryitem crtdiritem = diritem as ifsidirectoryitem;
String name = path. getfilename (realpath );
If (string. Compare (diritem. fullpath,
Path. getdirectoryname (realpath). substring (INDEX), true )! = 0)
{
String fsipath = path. getdirectoryname (realpath). substring
(Index + 1 + diritem. fullpath. Length );
String [] dirs = fsipath. Split ('\\');

// Create the subdirs one by one
Foreach (string dir in dirs)
{
If (dir. Length = 0)
Continue; // In the root like c :\
Try
{
String newpath = string. Format ("{0 }\\ {1}", crtdiritem. fullpath, DIR );
If (_ sysimage. exists (newpath )! = Fsiitemtype. fsiitemdirectory)
Crtdiritem. adddirectory (DIR );
}
Catch
{
Cancel = true;
Throw;
}
Crtdiritem = crtdiritem [dir] As ifsidirectoryitem;
}
}

System. runtime. interopservices. comtypes. istream newstream = NULL;

try
{< br> newstream = loadcomstream (realpath);
crtdiritem. addFile (name, newstream);
}< br> finally
{< br> marshal. releasecomobject (newstream);
}

_ Actualsize + = (fileinfo) file). length;
If (update! = NULL & Update. getinvocationlist (). length> 0)
Update (file. fullname, (fileinfo) file). Length );
}
Else
Throw new ioexception ("invalid file or folder ");
}

ReferenceArticle: Http://www.codeproject.com/KB/miscctrl/ISOImage.aspx? MSG = 2464574

For more ISO production functions, see how to create optical file Images Using imapiv2.0 and how to burn optical file images with imapi 2.0 from managed code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.