Beispiel #1
0
static HRESULT OpenInputStream(const char* filename, IStream** stream) {
  HRESULT hr = S_OK;
  if (!strcmp(filename, "-")) {
    const uint8_t* data = NULL;
    size_t data_size = 0;
    const int ok = ImgIoUtilReadFile(filename, &data, &data_size);
    if (ok) {
      HGLOBAL image = GlobalAlloc(GMEM_MOVEABLE, data_size);
      if (image != NULL) {
        void* const image_mem = GlobalLock(image);
        if (image_mem != NULL) {
          memcpy(image_mem, data, data_size);
          GlobalUnlock(image);
          IFS(CreateStreamOnHGlobal(image, TRUE, stream));
        } else {
          hr = E_FAIL;
        }
      } else {
        hr = E_OUTOFMEMORY;
      }
      free((void*)data);
    } else {
      hr = E_FAIL;
    }
  } else {
    IFS(SHCreateStreamOnFileA(filename, STGM_READ, stream));
  }

  if (FAILED(hr)) {
    fprintf(stderr, "Error opening input file %s (%08lx)\n", filename, hr);
  }
  return hr;
}
Beispiel #2
0
static HRESULT OpenInputStream(const char* filename, IStream** ppStream) {
  HRESULT hr = S_OK;
  IFS(SHCreateStreamOnFileA(filename, STGM_READ, ppStream));
  if (FAILED(hr))
    printf("Error opening input file %s (%08x)\n", filename, hr);
  return hr;
}
static HRESULT CreateOutputStream(const char* out_file_name, IStream** stream) {
  HRESULT hr = S_OK;
  IFS(SHCreateStreamOnFileA(out_file_name, STGM_WRITE | STGM_CREATE, stream));
  if (FAILED(hr)) {
    fprintf(stderr, "Error opening output file %s (%08lx)\n",
            out_file_name, hr);
  }
  return hr;
}
Beispiel #4
0
static HRESULT CreateOutputStream(const char* out_file_name,
                                  int write_to_mem, IStream** stream) {
  HRESULT hr = S_OK;
  if (write_to_mem) {
    // Output to a memory buffer. This is freed when 'stream' is released.
    IFS(CreateStreamOnHGlobal(NULL, TRUE, stream));
  } else {
    IFS(SHCreateStreamOnFileA(out_file_name, STGM_WRITE | STGM_CREATE, stream));
  }
  if (FAILED(hr)) {
    fprintf(stderr, "Error opening output file %s (%08lx)\n",
            out_file_name, hr);
  }
  return hr;
}
Beispiel #5
0
bool SFXmlReader::initFrameByXsd(string xsdPath)
{
	HRESULT hr = S_OK;
	CComPtr<IStream> pFileStream;
	CComPtr<IXmlReader> pReader;
	XmlNodeType nodeType = XmlNodeType_None;
	LPCWSTR nodeName;
	LPCWSTR name;
	LPCWSTR value;
	bool ret;

	//Open read-only input stream
	hr = SHCreateStreamOnFileA(xsdPath.c_str(), STGM_READ, &pFileStream);
	if (SUCCEEDED(hr))
	{
		hr = CreateXmlReader(__uuidof(IXmlReader), (void**)&pReader, NULL);
	}
	else
	{
		sf_cout(DEBUG_COM, "Error: Can't find the XSD file. (\"" << xsdPath << "\")" << endl);

		return false;
	}
	pReader->SetInput(pFileStream);
	hr = pReader->Read(NULL);

	UINT tabs = 0;
	vector<string> arrNodeBuffer;
	for (; S_OK == hr; hr = pReader->Read(NULL))
	{
		pReader->GetLocalName(&nodeName, NULL);
		if (nodeName[0] > L' ')
		{
			if (wcscmp(nodeName, L"element") == 0 || wcscmp(nodeName, L"attribute") == 0)
			{
				pReader->GetNodeType(&nodeType);
				if (nodeType == XmlNodeType_Element)
				{
					sf_wcout(DEBUG_RES_LOAD, endl);
					for (UINT i = 0; i < tabs; i++)
					{
						sf_wcout(DEBUG_RES_LOAD, L"\t");
					}
					sf_wcout(DEBUG_RES_LOAD, nodeName << L" ");

					POLL_XML_ATTR_BEGIN
						if (wcscmp(nodeName, L"element") == 0)
						{
							if (tabs >= arrNodeBuffer.size())
							{
								arrNodeBuffer.insert(arrNodeBuffer.end(), utfValue);
							}
							if (utfName == "name" || utfName == "ref")
							{
								arrNodeBuffer[tabs] = utfValue;
								if (m_frame.find(utfValue) == m_frame.end())
								{
									m_frame[utfValue].m_name = utfValue;
									m_frame[utfValue].m_index = 0;
									m_frame[utfValue].m_depth = 0;
									m_frame[utfValue].m_isOnly = true;
									m_frame[utfValue].m_parent = NULL;
									m_frame[utfValue].m_attrData = map<string, XsdAttrData>{};
									m_frame[utfValue].m_nodeData = {};
								}
								if (tabs > 0)
								{
									string parent = arrNodeBuffer[tabs - 1];

									m_frame[utfValue].m_parent = &m_frame[parent];
									m_frame[parent].m_nodeData.insert(m_frame[parent].m_nodeData.end(), &m_frame[utfValue]);
								}
								if (m_pFrameRootNode == NULL)
								{
									m_pFrameRootNode = &m_frame[utfValue];
								}
							}
							else if (utfName == "maxOccurs")
							{
								if (utfValue == "unbounded")
								{
									m_frame[arrNodeBuffer[tabs]].m_isOnly = false;
								}
							}
						}
						else if (wcscmp(nodeName, L"attribute") == 0)
						{
							if (utfName == "name")
							{
								map<string, XsdAttrData>& mapAttr = m_frame[arrNodeBuffer[tabs - 1]].m_attrData;

								mapAttr[utfName].m_name = utfValue;
								mapAttr[utfName].m_index = mapAttr.size();
							}
						}
					POLL_XML_ATTR_END
					if (!(pReader->IsEmptyElement()) && wcscmp(nodeName, L"element") == 0)
					{
						tabs++;
					}
				}
				else if (nodeType == XmlNodeType_EndElement)
				{
					tabs--;
				}
			}
Beispiel #6
0
static void test_SHCreateStreamOnFileA(DWORD mode, DWORD stgm)
{
    IStream * stream;
    HRESULT ret;
    ULONG refcount;
    char test_file[MAX_PATH];
    static const CHAR testA_txt[] = "\\testA.txt";

    trace("SHCreateStreamOnFileA: testing mode %d, STGM flags %08x\n", mode, stgm);

    /* Don't used a fixed path for the testA.txt file */
    GetTempPathA(MAX_PATH, test_file);
    lstrcatA(test_file, testA_txt);

    /* invalid arguments */

    stream = NULL;
    ret = SHCreateStreamOnFileA(NULL, mode | stgm, &stream);
    if (ret == E_INVALIDARG) /* Win98 SE */ {
        win_skip("Not supported\n");
        return;
    }

    ok(ret == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) /* NT */ ||
       ret == HRESULT_FROM_WIN32(ERROR_BAD_PATHNAME) /* 9x */,
       "SHCreateStreamOnFileA: expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) "
       "or HRESULT_FROM_WIN32(ERROR_BAD_PATHNAME), got 0x%08x\n", ret);
    ok(stream == NULL, "SHCreateStreamOnFileA: expected a NULL IStream object, got %p\n", stream);

if (0) /* This test crashes on WinXP SP2 */
{
    ret = SHCreateStreamOnFileA(test_file, mode | stgm, NULL);
    ok(ret == E_INVALIDARG, "SHCreateStreamOnFileA: expected E_INVALIDARG, got 0x%08x\n", ret);
}

    stream = NULL;
    ret = SHCreateStreamOnFileA(test_file, mode | STGM_CONVERT | stgm, &stream);
    ok(ret == E_INVALIDARG, "SHCreateStreamOnFileA: expected E_INVALIDARG, got 0x%08x\n", ret);
    ok(stream == NULL, "SHCreateStreamOnFileA: expected a NULL IStream object, got %p\n", stream);

    stream = NULL;
    ret = SHCreateStreamOnFileA(test_file, mode | STGM_DELETEONRELEASE | stgm, &stream);
    ok(ret == E_INVALIDARG, "SHCreateStreamOnFileA: expected E_INVALIDARG, got 0x%08x\n", ret);
    ok(stream == NULL, "SHCreateStreamOnFileA: expected a NULL IStream object, got %p\n", stream);

    stream = NULL;
    ret = SHCreateStreamOnFileA(test_file, mode | STGM_TRANSACTED | stgm, &stream);
    ok(ret == E_INVALIDARG, "SHCreateStreamOnFileA: expected E_INVALIDARG, got 0x%08x\n", ret);
    ok(stream == NULL, "SHCreateStreamOnFileA: expected a NULL IStream object, got %p\n", stream);

    /* file does not exist */

    stream = NULL;
    ret = SHCreateStreamOnFileA(test_file, mode | STGM_FAILIFTHERE | stgm, &stream);
    ok(ret == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "SHCreateStreamOnFileA: expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got 0x%08x\n", ret);
    ok(stream == NULL, "SHCreateStreamOnFileA: expected a NULL IStream object, got %p\n", stream);

    stream = NULL;
    ret = SHCreateStreamOnFileA(test_file, mode | STGM_CREATE | stgm, &stream);
    ok(ret == S_OK, "SHCreateStreamOnFileA: expected S_OK, got 0x%08x\n", ret);
    ok(stream != NULL, "SHCreateStreamOnFileA: expected a valid IStream object, got NULL\n");

    if (stream) {
        test_IStream_invalid_operations(stream, mode);

        refcount = IStream_Release(stream);
        ok(refcount == 0, "SHCreateStreamOnFileA: expected 0, got %d\n", refcount);
    }

    /* NOTE: don't delete the file, as it will be used for the file exists tests. */

    /* file exists */

    stream = NULL;
    ret = SHCreateStreamOnFileA(test_file, mode | STGM_FAILIFTHERE | stgm, &stream);
    ok(ret == S_OK, "SHCreateStreamOnFileA: expected S_OK, got 0x%08x\n", ret);
    ok(stream != NULL, "SHCreateStreamOnFileA: expected a valid IStream object, got NULL\n");

    if (stream) {
        test_IStream_invalid_operations(stream, mode);

        refcount = IStream_Release(stream);
        ok(refcount == 0, "SHCreateStreamOnFileA: expected 0, got %d\n", refcount);
    }

    stream = NULL;
    ret = SHCreateStreamOnFileA(test_file, mode | STGM_CREATE | stgm, &stream);
    ok(ret == S_OK, "SHCreateStreamOnFileA: expected S_OK, got 0x%08x\n", ret);
    ok(stream != NULL, "SHCreateStreamOnFileA: expected a valid IStream object, got NULL\n");

    if (stream) {
        BOOL delret;

        test_stream_read_write(stream, mode);
        test_IStream_invalid_operations(stream, mode);

        refcount = IStream_Release(stream);
        ok(refcount == 0, "SHCreateStreamOnFileA: expected 0, got %d\n", refcount);

        delret = DeleteFileA(test_file);
        ok(delret, "SHCreateStreamOnFileA: could not delete file '%s', got error %d\n",
           test_file, GetLastError());
    }
}