question

gilt avatar image
0 Votes"
gilt asked ·

Local burn fails when burning files in sub folders

hi all, I'm trying to perform a local burn on windows 10 using IMAPI(using v1, to support legacy code)
the burn process fails when I'm trying to burn files in subfolders, when everything is on the root folder, the burn works. needless to say,
I need the burn to work with a specific folder structure, so using subfolders is a must.
I think that maybe something with the iStorage objects is wrong. here is some of the code of a test tool I've created to debug this issue, it contains a simplified version of the code I use in the actual program, maybe someone could have an idea for what is wrong with it:

     CComQIPtr<IStorage>    pParentStorage;
     LPWSTR convImageFileName = A2W(imageFileName);
        
     // IStorage represents a directory, IStream represents a file
     hr = StgCreateDocfile(convImageFileName,
                           STGM_DIRECT|STGM_CREATE|STGM_READWRITE|STGM_SHARE_EXCLUSIVE,
                           NULL,
                           &pParentStorage);

     printf("after StgCreateDocfile hr = %x\n",HRESULT_CODE(hr));

     CComQIPtr<IStorage> pStorage;
     LPWSTR convFileName = A2W(sFileshortPathForDIR);
     hr = pParentStorage->CreateStorage(convFileName,
         STGM_DIRECT | STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
         0,
         0,
         &pStorage);
     printf("after CreateStorage hr = %x\n", HRESULT_CODE(hr));

     printf("after Adding Directory to iso\n");

     struct _stat buf;

     int result = _stat(sFileFullPathForFILE, &buf);
     printf("stat result %d\n", result);
     if (result == -1) {

         printf("stat %s failed errorno = %s\n", sFileFullPathForFILE, std::strerror(errno));
     }
     if (buf.st_size > 0) {
         int fh;
         unsigned int nbytes;
         unsigned int    bytesread;
         ULONG bytes_written;

         if ((fh = _open(sFileFullPathForFILE, _O_RDONLY | _O_BINARY)) == -1) {
             printf("Unable open file %s\n", sFileFullPathForFILE);
             return FAILURE;
         }

         nbytes = buf.st_size;
         if ((m_pFileDataBuf == NULL) || (m_iFileDataBufLen < nbytes)) {
             delete m_pFileDataBuf;
             m_pFileDataBuf = new char[nbytes];
             m_iFileDataBufLen = nbytes;
         }


         if ((bytesread = _read(fh, m_pFileDataBuf, nbytes)) <= 0)
         {
             printf("Problem reading file %s\n", sFileFullPathForFILE);
             _close(fh);
             return FAILURE;
         }
        

         printf("before Adding Directory to iso\n");

     LPWSTR convFileNameshort = A2W(sFileshortPathForFILE);
     printf("convFileNameshort = %ls\n", convFileNameshort);
     CComQIPtr<IStream> pStream;

     if ((hr = pStorage->CreateStream(convFileNameshort,
         STGM_DIRECT | STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
         0,
         0,
         &pStream)) != S_OK) {
         printf("Unable to create IStream object. File: %s  Error: %d \n",
             sFileFullPathForDIR, HRESULT_CODE(hr));
         return FAILURE;
     }

     if ((hr = pStream->Write(m_pFileDataBuf, bytesread, &bytes_written)) != S_OK) {
         printf("Unable to write to IStream. File: %s  Error: %d \n",
             sFileFullPathForDIR, HRESULT_CODE(hr));
         return FAILURE;
     }

     printf("bytes_written = %d\n", bytes_written);
     if ((hr = pStream->Commit(STGC_DEFAULT)) != S_OK) {
         printf("Unable to commit IStream object. File: %s  Error: %d \n",
             sFileFullPathForDIR, HRESULT_CODE(hr));
     }

     close(fh);
     }

     printf("after commit file to iso\n");

     // release work buffer
        
     if (m_pFileDataBuf != NULL)
     {
         delete m_pFileDataBuf;
     }
     m_pFileDataBuf = NULL;
     m_iFileDataBufLen = 0;
        
        

        
     if ((hr = pParentStorage->Commit(STGC_DEFAULT)) != S_OK) 
     {
         printf("Unable to commit IStorage: %d \n", 
                HRESULT_CODE(hr));
         return FAILURE;
     }
     printf("after commit directory to iso\n");

     CComQIPtr<IPropertyStorage> pPropStg;
     if ((hr = pJolietDiscMaster->GetJolietProperties(&pPropStg)) != S_OK)
     {
         printf("Unable to get joliet properties: %d \n",hr);
         hr = pDiskMaster->Close();
         return FAILURE;
     }
     printf("after GetJolietProperties\n");

     // set label name
     PROPVARIANT propvar;
     PROPSPEC propspec;

     propspec.ulKind = PRSPEC_LPWSTR;
     propspec.lpwstr = W2OLE((LPWSTR)L"VolumeName");

     PropVariantInit(&propvar);
     propvar.vt = VT_LPWSTR;
     //propvar.pwszVal = A2W(labelText);


     pPropStg->WriteMultiple(1, &propspec, &propvar, PID_FIRST_USABLE);

     pPropStg->Commit(STGC_DEFAULT);

     hr = pJolietDiscMaster->SetJolietProperties(pPropStg);
     if (hr != IMAPI_S_PROPERTIESIGNORED && hr != S_OK)
     {
         printf("Unable to set joliet properties: %ls \n", hr);
         hr = pDiskMaster->Close();
            
         return FAILURE;
     }

     printf("after SetJolietProperties\n");

     // set the maximum burner speed
     CComQIPtr<IPropertyStorage> pDiscPropStg;
     if ((hr = pDiscRecorder->GetRecorderProperties(&pDiscPropStg)) != S_OK)
     {
         printf("Unable to get recorder properties: %ls \n", hr);
         hr = pDiskMaster->Close();

         return FAILURE;
     }

     printf("after GetRecorderProperties\n");

     PROPVARIANT propvar2;
     PROPSPEC propspec2;

     propspec2.ulKind = PRSPEC_LPWSTR;
     propspec2.lpwstr = W2OLE((LPWSTR)L"WriteSpeed");

     PropVariantInit(&propvar2);
     propvar2.vt = VT_I4;
     propvar2.lVal = -1;

     if ((hr = pDiscPropStg->WriteMultiple(1, &propspec2, &propvar2, PID_FIRST_USABLE)) != S_OK)
     {

         printf("Unable to set recorder properties: %ls \n", hr);
         hr = pDiskMaster->Close();

         return FAILURE;
     }

     printf("after WriteMultiple\n");

     pDiscPropStg->Commit(STGC_DEFAULT);

     printf("after pDiscPropStg->Commit\n");

     hr = pDiscRecorder->SetRecorderProperties(pDiscPropStg);
     if (hr != IMAPI_S_PROPERTIESIGNORED && hr != S_OK)
     {

         printf("Unable to set recorder properties: %ls \n", hr);
         hr = pDiskMaster->Close();

         return FAILURE;
     }

     printf("after SetRecorderProperties\n");
    
     StgOpenStorage(convImageFileName, NULL,
         STGM_DIRECT | STGM_READ | STGM_SHARE_DENY_WRITE,
         NULL, 0,
         &pStorage);

     printf("after StgOpenStorage\n");

     if ((hr = pDiskMaster->SetActiveDiscRecorder(pDiscRecorder)) !=
         S_OK)
     {

         printf("Unable to set active disc recorder: %ls \n",hr);
         hr = pDiskMaster->Close();
         return FAILURE;
     }

     printf("after SetActiveDiscRecorder\n");
     // single-session
     pDiskMaster->ClearFormatContent();

     printf("after ClearFormatContent\n");

     //if ((hr = pJolietDiscMaster->AddData(pStorage, 1L)) != S_OK) {
     if ((hr = pJolietDiscMaster->AddData(pParentStorage, 1L)) != S_OK) {
         printf("Unable to AddData disc %d\n", _HRESULT_TYPEDEF_(hr));

     }

Blockquote

it this code i get and error in GetData : -2147287035

winapi-general
· 1
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello, @gilt I don't see the GetData. Which api returned -2147287035?

0 Votes 0 ·

1 Answer

gilt avatar image
0 Votes"
gilt answered ·

hi,
sorry, i meant addData no get data (line 219)

· 1 · Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Please check the return value of each api in the code to ensure that all apis can be called successfully. If there are APIs that cannot be called normally, please check their error messages.

See: IMAPIv1 Result Codes

IJolietDiscMaster::AddData also introduced some content,

Adds the contents of a root storage to the staged image file. This storage will be enumerated to place all substorages and streams in the root file system of the stage image file. Substorages become folders and streams become files.

Is your pParentStorage parameter the root directory or the sub-file directory?





0 Votes 0 ·