You are on page 1of 8

windowsxp-kb932716-x86-jpn.

exe

imports imapi2
imports system.io
imports system

public class form1

private sub form1_load(byval sender as system.object, byval e as


system.eventargs) handles mybase.load

'find a recorder
dim recordername as string = findrecorder()
if recordername is nothing then
lblprocess1.text = "no recorder found."
txtpath.enabled = false
cmbdevice.enabled = false
btnbrowser.enabled = false
btnrecord.enabled = false
exit sub
end if

'initialize recorder
dim recorder as new msftdiscrecorder2
recorder.initializediscrecorder(recordername)

for each volpath as string in recorder.volumepathnames


cmbdevice.items.add(volpath)
cmbdevice.selectedindex = 0
next

end sub

private sub btnbrowser_click(byval sender as system.object, byval e as


system.eventargs) handles btnbrowser.click
if fbdbrowser.showdialog() = dialogresult.ok then
txtpath.text = fbdbrowser.selectedpath
end if
end sub

private sub btnrecord_click(byval sender as system.object, byval e as


system.eventargs) handles btnrecord.click

dim fpath
dim stream
dim drive as string = ""

try
'directory of files to burn
fpath = txtpath.text

if directory.exists(fpath) = false then


msgbox("data folder not exist.")
exit sub
end if
'find a recorder
dim recordername as string = findrecorder()

'initialize recorder
dim recorder as new msftdiscrecorder2
recorder.initializediscrecorder(recordername)

for each volpath as string in recorder.volumepathnames


drive = volpath
next

dim features as new list(of imapi_feature_page_type)


for each featurepage as imapi_feature_page_type in
recorder.supportedfeaturepages
features.add(featurepage)
next

'is there a better way to do this? doesn't look like a bitfield based
on the enums (saddened)
if (not
features.contains(imapi_feature_page_type.imapi_feature_page_type_bd_write) _
and not
features.contains(imapi_feature_page_type.imapi_feature_page_type_cd_rw_media_writ
e_support) _
and not
features.contains(imapi_feature_page_type.imapi_feature_page_type_cdrw_cav_write)
_
and not
features.contains(imapi_feature_page_type.imapi_feature_page_type_double_density_c
d_r_write) _
and not
features.contains(imapi_feature_page_type.imapi_feature_page_type_double_density_c
d_rw_write) _
and not
features.contains(imapi_feature_page_type.imapi_feature_page_type_dvd_dash_write)
_
and not
features.contains(imapi_feature_page_type.imapi_feature_page_type_dvd_plus_r) _
and not
features.contains(imapi_feature_page_type.imapi_feature_page_type_dvd_plus_r_dual_
layer) _
and not
features.contains(imapi_feature_page_type.imapi_feature_page_type_dvd_plus_rw) _
and not
features.contains(imapi_feature_page_type.imapi_feature_page_type_hd_dvd_write) _
and not
features.contains(imapi_feature_page_type.imapi_feature_page_type_cd_mastering)) _
then

msgbox("the drive " + drive + " does not appear to support


writing.")
exit sub

end if

dim dfd as msftdiscformat2data = new msftdiscformat2data()


dfd.recorder = recorder
if not dfd.mediaheuristicallyblank then
msgbox("the disk in drive " + drive + " isn't blank. no media was
written.")
exit sub
end if

'disc file system


dim fsi as new imapi2fs.msftfilesystemimage
'root directory of the disc file system
dim dir = fsi.root

dim datawriter as idiscformat2data = new msftdiscformat2data


datawriter.recorder = recorder
datawriter.clientname = "imapiv2 test"

fsi.chooseimagedefaults(recorder)

'add the directory and its contents to the file system


dir.addtree(fpath, false)

'create an image from the file system


dim result = fsi.createresultimage()
'data stream for burning device
stream = result.imagestream

'write stream to disc using the specified recorder.


lblprocess1.text = "writing content to disc..."

datawriter.write(stream)

for i as integer = 0 to 10
prbprocess.performstep()
next
lblprocess1.text = "----- finished writing content -----"

catch ex as exception
msgbox(ex.message)
end try

end sub

function findrecorder() as string


dim master as new msftdiscmaster2
for each devicename as string in master
return devicename
next
return nothing
end function

private sub discformatdata_update(byval obj as object, byval prog as object)

'update the status progress of the write.


try

dim progress as idiscformat2dataeventargs = ctype(prog,


idiscformat2dataeventargs)
dim strtimestatus as string = "time: " + progress.elapsedtime + " / "
+ progress.totaltime

select case progress.currentaction

case
imapi2.imapi_format2_data_write_action.imapi_format2_data_write_action_validating_
media
strtimestatus = "validating media " + strtimestatus
exit select

case
imapi2.imapi_format2_data_write_action.imapi_format2_data_write_action_formatting_
media
strtimestatus = "formatting media " + strtimestatus
exit select

case
imapi2.imapi_format2_data_write_action.imapi_format2_data_write_action_initializin
g_hardware
strtimestatus = "initializing hardware " + strtimestatus
exit select

case
imapi2.imapi_format2_data_write_action.imapi_format2_data_write_action_calibrating
_power
strtimestatus = "calibrating power (opc) " + strtimestatus
exit select

case
imapi2.imapi_format2_data_write_action.imapi_format2_data_write_action_writing_dat
a
dim totalsectors as long
dim writtensectors as long
dim percentdone as double

totalsectors = progress.sectorcount
writtensectors = progress.lastwrittenlba - progress.startlba
percentdone = writtensectors * 100
percentdone /= totalsectors
strtimestatus = "progress: " + percentdone.tostring("0.00") +
"% " + strtimestatus
exit select

case
imapi2.imapi_format2_data_write_action.imapi_format2_data_write_action_finalizatio
n
strtimestatus = "finishing the writing " + strtimestatus
exit select

case
imapi2.imapi_format2_data_write_action.imapi_format2_data_write_action_completed
strtimestatus = "completed the burn."
exit select

case else
strtimestatus = "unknown action: " + progress.currentaction
exit select
end select

'program.log(strtimestatus)

catch ex as exception
msgbox(ex.message)
'program.log("update exception: message: {0}\nstack trace: {1}",
e.message, e.stacktrace.tostring());
end try

end sub

end class

///////////////////--------------------////////////////////

imports system.runtime.interopservices
imports imapi2

module module1

sub main()
'find a recorder
dim recordername as string = findrecorder()
if recordername is nothing then
console.writeline("no recorder found. exiting")
return
end if

'initialize recorder
dim recorder as new msftdiscrecorder2
recorder.initializediscrecorder(recordername)

'get recorder info


console.writeline("general info")
console.writeline("===============================")
console.writeline("model: {0}", recorder.productid)
console.writeline("revision: {0}", recorder.productrevision)
console.writeline("manufacturer: {0}", recorder.vendorid)
console.writeline("volume name: {0}", recorder.volumename)
for each volpath as string in recorder.volumepathnames
console.writeline(vbtab + volpath)
next

console.writeline(vbcrlf + "supported formats:")


console.writeline("===============================")
for each profile as imapi_profile_type in recorder.supportedprofiles
console.writeline(vbtab + profile.tostring())
next

console.writeline(vbcrlf + "supported feature pages:")


console.writeline("===============================")
for each featurepage as imapi_feature_page_type in
recorder.supportedfeaturepages
console.writeline(vbtab + featurepage.tostring())
next
' get media info
console.writeline(vbcrlf + "current formats:")
console.writeline("===============================")
for each profile as imapi_profile_type in recorder.currentprofiles
console.writeline(vbtab + profile.tostring())
next

console.writeline(vbcrlf + "current feature pages:")


console.writeline("===============================")
for each featurepage as imapi_feature_page_type in
recorder.currentfeaturepages
console.writeline(vbtab + featurepage.tostring())
next

dim mediatype as imapi_media_physical_type


dim status as mediastatus

dim formatdata as idiscformat2data = new msftdiscformat2data


formatdata.recorder = recorder
mediatype = formatdata.currentphysicalmediatype
status = ctype(formatdata.currentmediastatus, mediastatus)

console.writeline(vbcrlf + "media type: " + mediatype.tostring())


console.writeline(vbcrlf + "media status: " + status.tostring())

for each desc as iwritespeeddescriptor in


formatdata.supportedwritespeeddescriptors
console.writeline(vbtab + "supported speed {0} for media type {1}",
desc.writespeed, desc.mediatype)
next

end sub

function findrecorder() as string


dim master as new msftdiscmaster2
for each devicename as string in master
return devicename
next
return nothing
end function

<flags()> _
public enum mediastatus : imapi_format2_data_media_state
appendable =
imapi2.imapi_format2_data_media_state.imapi_format2_data_media_state_appendable
blank =
imapi2.imapi_format2_data_media_state.imapi_format2_data_media_state_blank
erase_required =
imapi2.imapi_format2_data_media_state.imapi_format2_data_media_state_erase_require
d
final_session =
imapi2.imapi_format2_data_media_state.imapi_format2_data_media_state_final_session
finalized =
imapi2.imapi_format2_data_media_state.imapi_format2_data_media_state_finalized
non_empty_session =
imapi2.imapi_format2_data_media_state.imapi_format2_data_media_state_non_empty_ses
sion
overwrite_only =
imapi2.imapi_format2_data_media_state.imapi_format2_data_media_state_overwrite_onl
y
'unknown =
imapi2.imapi_format2_data_media_state.imapi_format2_data_media_state_unknown
randomly_writable =
imapi2.imapi_format2_data_media_state.imapi_format2_data_media_state_randomly_writ
able
end enum
end module

///////////////////----------------------

imports imapi2
imports imapi2fs

public class form1

private sub form1_load(byval sender as system.object, byval e as


system.eventargs) handles mybase.load
for each recorderid as string in new msftdiscmaster2()
dim recorder as new msftdiscrecorder2
recorder.initializediscrecorder(recorderid)
cbrecorder.items.add(new comboitem(recorder))
cbrecorder.selectedindex = 0
next
end sub

private sub cbrecorder_selectedindexchanged(byval sender as system.object,


byval e as system.eventargs) handles cbrecorder.selectedindexchanged
dim recorder as imapi2.idiscrecorder2 = ctype(cbrecorder.selecteditem,
comboitem).recorder
lbsupported.items.clear()
lbcurrent.items.clear()
for each profile as imapi_profile_type in recorder.supportedprofiles
lbsupported.items.add(profile)
next
dim currentprofile as imapi_profile_type
for each profile as imapi_profile_type in recorder.currentprofiles
lbcurrent.items.add(profile)
currentprofile = profile
next
btnerase.visible = currentprofile =
imapi_profile_type.imapi_profile_type_cd_rewritable or currentprofile =
imapi_profile_type.imapi_profile_type_dvd_dash_rewritable or currentprofile =
imapi_profile_type.imapi_profile_type_dvd_plus_rw
end sub
end class

class comboitem
public recorder as imapi2.idiscrecorder2
public sub new(byval rec as imapi2.idiscrecorder2)
recorder = rec
end sub

public overrides function tostring() as string


return recorder.productid
end function
end class

//////////////////-------------------

<comclass(comclass1.classid, comclass1.interfaceid, comclass1.eventsid)> _


public class comclass1

#region "com guid"


' ������ guid �́a���̃n���x����т��� com �c���^�[�t�f�c�x�� com id ��
' �w�肵�‫��܂‬b���̒l��ύx����Ɓa

' ��̃n���c�a���g�̓n���x� a�n�z�x�ł��Ȃ��Ȃ�‫��܂‬b


public const classid as string = "6c45e286-e6bc-4862-a044-2b623d6b708e"
public const interfaceid as string = "7305b3f8-eea8-4bcc-8319-6a68902ff53a"
public const eventsid as string = "d170940f-4594-4c68-9171-3a87033d2633"
#end region

' �쐬�”\�� com �n���x� p


̓ �����[�^�Ȃ��� public sub new() ��w�肵�Ȃ����

' �Ȃ�‫���܂‬B�����s��Ȃ��Ɓa�n���x�� com ���w�x�g���ɓo�^��� �a


' createobject �o�r��
' �쐬�ł��‫���܂‬B
public sub new()
mybase.new()
end sub

end class