다중 디스크 만들기

IMAPI( Image Mastering API )는 다음과 같은 다중 디스크 유형에 대한 파일 추가 및 제거를 지원합니다.

  • CD-R/CD-RW
  • Single-Layer DVD+R/DVD-R
  • DVD+R 듀얼 레이어
  • BD-R
  • DVD-RW/DVD+RW(Windows 7에만 해당)
  • DVD-RAM(Windows 7에만 해당)
  • BD-RE(Windows 7에만 해당)

IMAPI를 사용하여 다중 디스크 만들기는 다음 단계로 구성됩니다. 이러한 문서화된 각 단계에는 최종 섹션에 제공된 전체 Visual Basic 스크립트 예제의 관련 부분이 포함됩니다.

디스크 레코더 초기화

디바이스를 초기화하기 전에 MsftDiscMaster2 개체는 시스템의 광학 디바이스 열거형을 제공합니다. IDiscMaster2 인터페이스는 적절한 기록 디바이스의 위치를 용이하게 하기 위해 이 디바이스 열거형에 대한 액세스를 제공합니다. 또한 MsftDiscMaster2 개체는 컴퓨터에서 광학 디바이스를 추가하거나 제거할 때 이벤트 알림을 제공합니다.

광학 레코더를 찾아 할당된 ID를 검색한 후 새 MsftDiscMaster2 개체를 만들고 특정 디바이스 ID를 사용하여 레코더를 초기화합니다.

IDiscRecorder2 인터페이스는 공급업체 ID, 제품 ID, 제품 수정 버전과 같은 기본 디바이스 정보와 미디어를 꺼내거나 트레이를 닫는 방법에 대한 액세스를 제공합니다.

참고

다음 샘플에서 선언된 추가 상수 및 차원은 이 문서의 마지막 섹션에 있는 전체 샘플 스크립트의 뒷부분에서 사용됩니다. 디스크 레코더를 초기화하는 작업에는 이러한 요소가 필요하지 않습니다.

 

' *** CD/DVD disc file system types
Const FsiFileSystemISO9660 = 1
Const FsiFileSystemJoliet  = 2
Const FsiFileSystemUDF102  = 4

WScript.Quit(Main)

Function Main
    Dim Index                ' Index to recording drive.
    Dim Recorder             ' Recorder object
    Dim Path                 ' Directory of files to add
    Dim Stream               ' Data stream for burning device
    
    Index = 0                ' First drive on the system
    Path = "G:\BurnDir"      ' Files to add to the disc

    ' Create a DiscMaster2 object to connect to optical drives.
    Dim DiscMaster
    Set DiscMaster = WScript.CreateObject("IMAPI2.MsftDiscMaster2")

    ' Create a DiscRecorder2 object for the specified burning device.
    Dim UniqueId
    set Recorder = WScript.CreateObject("IMAPI2.MsftDiscRecorder2")
    UniqueId = DiscMaster.Item(Index)
    Recorder.InitializeDiscRecorder(UniqueId)

데이터 작성기 만들기

MsftDiscFormat2Data 개체는 쓰기 메서드, 해당 속성 및 미디어별 속성을 제공합니다. IDiscFormat2Data 인터페이스는 이 개체에 대한 액세스를 제공합니다.

디스크 레코더는 IDiscFormat2Data::p ut_Recorder 속성을 사용하여 형식 작성기에 바인딩됩니다. 레코더가 형식 작성기에 바인딩된 후에는 IDiscFormat2Data::Write 메서드를 사용하여 결과 이미지를 디스크에 쓰기 전에 미디어 및 쓰기 관련 속성 쿼리를 수행할 수 있습니다.

참고

아래 샘플 코드에 지정된 클라이언트 이름 문자열은 특정 애플리케이션에 맞게 조정해야 합니다.

 

    ' Create a DiscFormat2Data object and set the recorder
    Dim DataWriter
    Set DataWriter = CreateObject ("IMAPI2.MsftDiscFormat2Data")
    DataWriter.Recorder = Recorder
    DataWriter.ClientName = "IMAPIv2 TEST"

파일 시스템 개체 만들기

새 세션을 기록하려면 먼저 굽기 이미지를 생성해야 합니다. ISO9660, JolietUDF 형식에 대한 굽기 이미지는 개별 파일 및 디렉터리 파일 시스템으로 구성됩니다. MsftFileSystemImage 개체는 광학 미디어에 배치할 파일 및 디렉터리를 포함하는 파일 시스템 개체입니다. IFileSystemImage 인터페이스는 파일 시스템 개체 및 설정에 대한 액세스를 제공합니다.

    ' Create a new file system image object
    Dim FSI
    Set FSI = CreateObject("IMAPI2FS.MsftFileSystemImage")

파일 시스템 가져오기

계속하기 전에 IDiscFormat2::get_MediaHeuristicallyBlank 속성을 확인하여 디스크가 비어 있지 않은지 확인합니다.

MsftFileSystemImage 개체를 만든 후 마지막으로 기록된 세션에서 파일 시스템을 가져오려면 IFileSystemImage::ImportFileSystem 또는 IFileSystemImage::ImportSpecificFileSystem 메서드를 호출하기 전에 IFileSystemImage::p ut_MultisessionInterfaces 속성을 초기화해야 합니다. 이러한 메서드는 MsftFileSystemImage 개체를 이전에 기록된 파일 및 디렉터리를 설명하는 정보로 자동으로 채웁니다.

참고

IFileSystemImage::p ut_MultisessionInterfaces 속성은 일반적으로 IDiscFormat2Data::get_MultisessionInterfaces 속성을 통해 데이터 작성기에서 제공하는 다중 인터페이스를 사용하여 초기화됩니다.

 

IFileSystemImage::p ut_MultisessionInterfaces 속성을 설정하려고 하면 IMAPI가 현재 삽입된 미디어에 대한 다중 설정을 지원하지 않거나 다른 이유로 미디어를 추가할 수 없는 경우(예: 닫혔기 때문에) 실패합니다.

이전 굽기 세션에 둘 이상의 파일 시스템 형식이 포함된 경우 IFileSystemImage::ImportFileSystem 메서드는 가장 고급 파일 시스템 형식의 정보를 가져옵니다. 예를 들어 이 항목에 제공된 예제에서 UDF는 가져온 파일 시스템입니다. 그러나 IFileSystemImage::ImportSpecificFileSystem 메서드를 사용하면 파일 시스템의 특정 선택을 가져올 수 있습니다.

참고

IFileSystemImage::IdentifyFileSystemsOnDisc 메서드를 사용하여 디스크에서 사용할 수 있는 파일 시스템을 확인할 수 있습니다.

 

    ' Import the last session, if the disc is not empty, or initialize
    ' the file system, if the disc is empty
    If Not DataWriter.MediaHeuristicallyBlank _
    Then
        On Error Resume Next
        FSI.MultisessionInterfaces = DataWriter.MultisessionInterfaces
        If Err.Number <> 0 _
        Then
            WScript.Echo "Multisession is not supported for this disc"
            Main = 1
            Exit Function
        End If
        On Error Goto 0

        WScript.Echo "Importing data from the previous session..."
        FSI.ImportFileSystem()
    Else 
        FSI.ChooseImageDefaults(Recorder)
    End If

파일 시스템에 파일 추가 또는 제거

파일 시스템 개체를 만들고 이전 세션에서 파일 시스템을 가져온 후 IFileSystemImage::CreateFileItemIFileSystemImage::CreateDirectoryItem 메서드를 호출하여 각각 새 파일 및 디렉터리 개체를 만듭니다. 파일 및 디렉터리 개체는 파일 및 디렉터리에 대한 특정 세부 정보를 제공합니다. 또는 IFsiDirectoryItem 인터페이스를 통해 표현되는 디렉터리 개체의 IFsiDirectoryItem ::AddTree 메서드를 사용하여 다른 스토리지 디바이스(즉, 하드 드라이브)에서 기존 파일 및 디렉터리를 추가할 수 있습니다.

IFileSystemImage에 사용할 수 있는 이벤트 처리기 업데이트 메서드는 파일 시스템 이미지에 추가되는 현재 파일, 이미 복사된 섹터 수 및 복사할 총 섹터 수를 식별합니다.

파일 시스템에서 기존 파일 및 디렉터리를 제거하려면 IFsiDirectoryItem 인터페이스를 통해 표시되는 디렉터리 개체의 IFsiDirectoryItem::Remove 및 IFsiDirectoryItem::RemoveTree 메서드를 사용합니다. IFileSystemImage::get_Root 속성은 파일 시스템의 루트 디렉터리와 IFsiDirectoryItem 인터페이스에 대한 포인터를 가져와 디렉터리 트리를 통과하는 데 사용됩니다.

참고

IFsiDirectoryItem::RemoveIFsiDirectoryItem::RemoveTree 메서드를 통해 제거된 파일 및 디렉터리는 디스크에서 물리적으로 제거되지 않으며 고급 소프트웨어는 삭제된 정보를 쉽게 복구할 수 있습니다.

 

    ' Add the directory and its contents to the file system 
    WScript.Echo "Adding " & Path & " directory to the disc..."
    FSI.Root.AddTree Path, false

파일 시스템 이미지 생성

마지막 단계는 IFileSystemImage::CreateResultImage 를 호출하여 굽기 이미지에 대한 데이터 스트림을 만들고 IFileSystemImageResult 인터페이스를 통해 액세스 권한을 제공하는 것입니다. 이 데이터 스트림은 IDiscFormat2Data::Write 메서드에 직접 제공하거나 나중에 사용할 수 있도록 파일에 저장할 수 있습니다.

    ' Create an image from the file system image object
    Dim Result
    Set Result = FSI.CreateResultImage()
    Stream = Result.ImageStream

예제 요약

다음 Visual Basic 스크립트 예제에서는 IMAPI 개체를 사용하여 다중 디스크를 만드는 방법을 보여 줍니다. 이 예제에서는 새 세션을 만들고 디스크에 디렉터리를 추가합니다. 간단히 하기 위해 코드는 광범위한 오류 검사를 수행하지 않으며 다음을 가정합니다.

  • 호환되는 디스크 디바이스가 시스템에 설치됩니다.
  • 디스크 디바이스는 시스템의 첫 번째 드라이브입니다.
  • 호환되는 디스크가 디스크 디바이스에 삽입됩니다.
  • 디스크에 추가할 파일은 "g:\burndir"에 있습니다.

광범위한 오류 검사, 디바이스 및 미디어 호환성, 이벤트 알림 및 디스크의 여유 공간 계산과 같은 추가 기능을 스크립트에 추가할 수 있습니다.

' This script adds data files from a single directory tree to a
' disc (a new session is added, if the disc already contains data)

' Copyright (C) Microsoft. All rights reserved.

Option Explicit

' *** CD/DVD disc file system types
Const FsiFileSystemISO9660 = 1
Const FsiFileSystemJoliet  = 2
Const FsiFileSystemUDF102  = 4

WScript.Quit(Main)

Function Main
    Dim Index                ' Index to recording drive.
    Dim Recorder             ' Recorder object
    Dim Path                 ' Directory of files to add
    Dim Stream               ' Data stream for burning device
    
    Index = 0                ' First drive on the system
    Path = "G:\BurnDir"      ' Files to add to the disc

    ' Create a DiscMaster2 object to connect to optical drives.
    Dim DiscMaster
    Set DiscMaster = WScript.CreateObject("IMAPI2.MsftDiscMaster2")

    ' Create a DiscRecorder2 object for the specified burning device.
    Dim UniqueId
    set Recorder = WScript.CreateObject("IMAPI2.MsftDiscRecorder2")
    UniqueId = DiscMaster.Item(Index)
    Recorder.InitializeDiscRecorder(UniqueId)

    ' Create a DiscFormat2Data object and set the recorder
    Dim DataWriter
    Set DataWriter = CreateObject ("IMAPI2.MsftDiscFormat2Data")
    DataWriter.Recorder = Recorder
    DataWriter.ClientName = "IMAPIv2 TEST"

    ' Create a new file system image object
    Dim FSI
    Set FSI = CreateObject("IMAPI2FS.MsftFileSystemImage")

    ' Import the last session, if the disc is not empty, or initialize
    ' the file system, if the disc is empty
    If Not DataWriter.MediaHeuristicallyBlank _
    Then
        On Error Resume Next
        FSI.MultisessionInterfaces = DataWriter.MultisessionInterfaces
        If Err.Number <> 0 _
        Then
            WScript.Echo "Multisession is not supported for this disc"
            Main = 1
            Exit Function
        End If
        On Error Goto 0

        WScript.Echo "Importing data from the previous session..."
        FSI.ImportFileSystem()
    Else 
        FSI.ChooseImageDefaults(Recorder)
    End If

    ' Add the directory and its contents to the file system 
    WScript.Echo "Adding " & Path & " directory to the disc..."
    FSI.Root.AddTree Path, false

    ' Create an image from the file system image object
    Dim Result
    Set Result = FSI.CreateResultImage()
    Stream = Result.ImageStream
    
    ' Write stream to disc using the specified recorder
    WScript.Echo "Writing content to the disc..."
    DataWriter.Write(Stream)

    WScript.Echo "Finished writing content."
    Main = 0
End Function

IMAPI 사용

IStream

IDiscMaster2

IDiscFormat2Data

IFileSystemImage