@@ -14,11 +14,11 @@ namespace IMAPI2
14
14
public class ImageMaster : IDisposable
15
15
{
16
16
private const string ClientName = "IMAPI2 Wrapper" ;
17
-
17
+
18
18
private ReadOnlySelectableCollection < DiscRecorder > _recorders ;
19
19
private bool _isWriting ;
20
20
private long _mediaCapacity ;
21
- private bool _mediaLoaded ;
21
+ private bool _mediaLoaded ;
22
22
private PhysicalMedia _media ;
23
23
private ReadOnlyCollection < MediaState > _mediaStates ;
24
24
private List < IMediaNode > _nodes ;
@@ -60,11 +60,11 @@ public string VolumeLabel
60
60
}
61
61
62
62
public ImageMaster ( )
63
- {
64
- List < DiscRecorder > recorders = new List < DiscRecorder > ( ) ;
63
+ {
64
+ List < DiscRecorder > recorders = new List < DiscRecorder > ( ) ;
65
65
_media = PhysicalMedia . Unknown ;
66
66
_nodes = new List < IMediaNode > ( ) ;
67
- _mediaStates = new ReadOnlyCollection < MediaState > ( new List < MediaState > { MediaState . Unknown } ) ;
67
+ _mediaStates = new ReadOnlyCollection < MediaState > ( new List < MediaState > { MediaState . Unknown } ) ;
68
68
69
69
MsftDiscMaster2 discMaster = null ;
70
70
try
@@ -163,11 +163,13 @@ public void FormatMedia(bool quick, bool eject)
163
163
if ( ! _mediaLoaded )
164
164
throw new InvalidOperationException ( "LoadMedia must be called first." ) ;
165
165
166
- IDiscRecorder2 recorder = _recorders . SelectedItem . Internal ;
166
+ MsftDiscRecorder2 recorder = null ;
167
167
MsftDiscFormat2Erase discFormatErase = null ;
168
168
169
169
try
170
170
{
171
+ recorder = new MsftDiscRecorder2 ( ) ;
172
+ recorder . InitializeDiscRecorder ( _recorders . SelectedItem . InternalUniqueId ) ;
171
173
discFormatErase = new MsftDiscFormat2Erase
172
174
{
173
175
Recorder = recorder ,
@@ -183,6 +185,7 @@ public void FormatMedia(bool quick, bool eject)
183
185
finally
184
186
{
185
187
if ( discFormatErase != null ) Marshal . ReleaseComObject ( discFormatErase ) ;
188
+ if ( recorder != null ) Marshal . ReleaseComObject ( recorder ) ;
186
189
}
187
190
}
188
191
@@ -196,15 +199,14 @@ public void LoadMedia()
196
199
if ( _recorders . SelectedIndex == - 1 )
197
200
throw new InvalidOperationException ( "No DiscRecorder selected on the DiscRecorders list." ) ;
198
201
199
- MsftDiscRecorder2 recorder = _recorders . SelectedItem . Internal ;
202
+ MsftDiscRecorder2 recorder = null ;
200
203
MsftFileSystemImage image = null ;
201
204
MsftDiscFormat2Data format = null ;
202
205
203
206
try
204
207
{
205
- //
206
- // Create and initialize the IDiscFormat2Data
207
- //
208
+ recorder = new MsftDiscRecorder2 ( ) ;
209
+ recorder . InitializeDiscRecorder ( _recorders . SelectedItem . InternalUniqueId ) ;
208
210
format = new MsftDiscFormat2Data ( ) ;
209
211
if ( ! format . IsCurrentMediaSupported ( recorder ) )
210
212
throw new MediaNotSupportedException ( "There is no media in the device." ) ;
@@ -214,7 +216,7 @@ public void LoadMedia()
214
216
//
215
217
format . Recorder = recorder ;
216
218
_media = ( PhysicalMedia ) format . CurrentPhysicalMediaType ;
217
-
219
+
218
220
mediaStateFlags = ( long ) format . CurrentMediaStatus ;
219
221
foreach ( MediaState state in Enum . GetValues ( typeof ( MediaState ) ) )
220
222
{
@@ -229,7 +231,7 @@ public void LoadMedia()
229
231
//
230
232
// Create a file system and select the media type
231
233
//
232
- image = new MsftFileSystemImage ( ) ;
234
+ image = new MsftFileSystemImage ( ) ;
233
235
image . ChooseImageDefaultsForMediaType ( ( IMAPI_MEDIA_PHYSICAL_TYPE ) _media ) ;
234
236
235
237
//
@@ -246,8 +248,9 @@ public void LoadMedia()
246
248
}
247
249
finally
248
250
{
249
- if ( format != null ) Marshal . ReleaseComObject ( format ) ;
250
251
if ( image != null ) Marshal . ReleaseComObject ( image ) ;
252
+ if ( format != null ) Marshal . ReleaseComObject ( format ) ;
253
+ if ( recorder != null ) Marshal . ReleaseComObject ( recorder ) ;
251
254
}
252
255
}
253
256
@@ -256,14 +259,13 @@ public void LoadRecorder()
256
259
if ( _recorders . SelectedIndex == - 1 )
257
260
throw new InvalidOperationException ( "No DiscRecorder selected from the DiscRecorders list." ) ;
258
261
259
- var recorder = _recorders . SelectedItem . Internal ;
260
-
261
- //
262
- // Verify recorder is supported
263
- //
262
+ MsftDiscRecorder2 recorder = null ;
264
263
IDiscFormat2Data discFormatData = null ;
265
264
try
266
265
{
266
+ recorder = new MsftDiscRecorder2 ( ) ;
267
+ recorder . InitializeDiscRecorder ( _recorders . SelectedItem . InternalUniqueId ) ;
268
+
267
269
discFormatData = new MsftDiscFormat2Data ( ) ;
268
270
switch ( discFormatData . IsRecorderSupported ( recorder ) )
269
271
{
@@ -277,10 +279,8 @@ public void LoadRecorder()
277
279
}
278
280
finally
279
281
{
280
- if ( discFormatData != null )
281
- {
282
- Marshal . ReleaseComObject ( discFormatData ) ;
283
- }
282
+ if ( discFormatData != null ) Marshal . ReleaseComObject ( discFormatData ) ;
283
+ if ( recorder != null ) Marshal . ReleaseComObject ( recorder ) ;
284
284
}
285
285
}
286
286
@@ -294,7 +294,8 @@ public void WriteImage(BurnVerificationLevel verification, bool finalize, bool e
294
294
295
295
try
296
296
{
297
- recorder = _recorders . SelectedItem . Internal ;
297
+ recorder = new MsftDiscRecorder2 ( ) ;
298
+ recorder . InitializeDiscRecorder ( _recorders . SelectedItem . InternalUniqueId ) ;
298
299
299
300
discFormatData = new MsftDiscFormat2Data
300
301
{
@@ -333,22 +334,18 @@ public void WriteImage(BurnVerificationLevel verification, bool finalize, bool e
333
334
}
334
335
finally
335
336
{
336
- if ( fileSystem != null )
337
- {
338
- Marshal . FinalReleaseComObject ( fileSystem ) ;
339
- }
337
+ if ( fileSystem != null ) Marshal . FinalReleaseComObject ( fileSystem ) ;
340
338
}
341
339
342
340
discFormatData . Update -= _discFormatWrite_Update ;
343
341
344
- if ( eject )
345
- recorder . EjectMedia ( ) ;
342
+ if ( eject ) recorder . EjectMedia ( ) ;
346
343
}
347
344
finally
348
345
{
349
- if ( recorder != null ) Marshal . ReleaseComObject ( recorder ) ;
350
- if ( discFormatData != null ) Marshal . ReleaseComObject ( discFormatData ) ;
351
346
_isWriting = false ;
347
+ if ( discFormatData != null ) Marshal . ReleaseComObject ( discFormatData ) ;
348
+ if ( recorder != null ) Marshal . ReleaseComObject ( recorder ) ;
352
349
}
353
350
}
354
351
@@ -371,7 +368,7 @@ void IDisposable.Dispose()
371
368
if ( ( _writerThread != null ) && ( _writerThread . IsAlive ) ) _writerThread . Join ( ) ;
372
369
foreach ( DiscRecorder recorder in _recorders )
373
370
{
374
- Marshal . ReleaseComObject ( recorder . Internal ) ;
371
+ Marshal . ReleaseComObject ( recorder . InternalUniqueId ) ;
375
372
}
376
373
}
377
374
}
0 commit comments