// @pymethod |PyIStorage|CopyTo|Copies the entire contents of an open storage object to another storage object.
PyObject *PyIStorage::CopyTo(PyObject *self, PyObject *args)
{
	IStorage *pIS = GetI(self);
	if ( pIS == NULL )
		return NULL;
	// @pyparm [<o PyIID>,]|rgiidExclude||List of IID's to be excluded.
	// @pyparm <o SNB>|snbExclude||Reserved for later - Must be None
	// @pyparm <o PyIStorage>|stgDest||The open storage object into which this storage object is to be copied. 
	// The destination storage object can be a different implementation of the <o PyIStorage> interface from the source storage object. 
	// Thus, <om IStorage::CopyTo> can only use publicly available methods of the destination storage object. 
	// If stgDest is open in transacted mode, it can be reverted by calling its <om PyIStorage::Revert> method. 
	DWORD ciidExclude = 0;
	PyObject *obSeqExclude;
	PyObject *obpstgDest;
	char *temp;
	if ( !PyArg_ParseTuple(args, "OzO:CopyTo", &obSeqExclude, &temp, &obpstgDest) )
		return NULL;
	IID *pExclude;
	if (obSeqExclude==Py_None)
		pExclude = NULL;
	else {
		if (!PySequence_Check(obSeqExclude)) {
			PyErr_SetString(PyExc_TypeError, "Argument 1 must be a sequence of IID's, or None");
			return NULL;
		}
		ciidExclude = PySequence_Length(obSeqExclude);
		pExclude = new IID[ciidExclude];
		if (pExclude==NULL) {
			PyErr_SetString(PyExc_MemoryError, "Allocating array of IID's");
			return NULL;
		}
		for (DWORD i=0;i<ciidExclude;i++) {
			PyObject *ob = PySequence_GetItem(obSeqExclude, (int)i);
			BOOL ok = PyWinObject_AsIID(ob, pExclude+i);
			Py_XDECREF(ob);
			if (!ok) {
				delete [] pExclude;
				return NULL;
			}
		}
	}
	IStorage *pstgDest;
	BOOL bPythonIsHappy = TRUE;
	if (!PyCom_InterfaceFromPyObject(obpstgDest, IID_IStorage, (void **)&pstgDest, FALSE /* bNoneOK */))
		 bPythonIsHappy = FALSE;
	if (!bPythonIsHappy) {
		return NULL;
		delete [] pExclude;
	}
	PY_INTERFACE_PRECALL;
	HRESULT hr = pIS->CopyTo( ciidExclude, pExclude, NULL, pstgDest );
	delete [] pExclude;
	pstgDest->Release();
	PY_INTERFACE_POSTCALL;

	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pIS, IID_IStorage);
	Py_INCREF(Py_None);
	return Py_None;
}
static PyObject *pyBindIFilterFromStorage(PyObject *self, PyObject *args)
{
	HRESULT hr;
	IUnknown *pOb = NULL;
	PyObject *obStg;
	
	PyObject *ret;
	long lres = 0;
	if (!PyArg_ParseTuple(args, "O:BindIFilterFromStorage", &obStg)) 
		return NULL;

	IStorage *pstgDest;
	BOOL bPythonIsHappy = TRUE;
	if (!PyCom_InterfaceFromPyObject(obStg, IID_IStorage, (void **)&pstgDest, FALSE /* bNoneOK */))
	    bPythonIsHappy = FALSE;

	if (!bPythonIsHappy)
		return NULL;

	Py_BEGIN_ALLOW_THREADS;
    hr = BindIFilterFromStorage( pstgDest , NULL , (void**)&pOb ); 
	pstgDest->Release();
	Py_END_ALLOW_THREADS;
	if (FAILED(hr))
		ret = OleSetOleError(hr);

	else
		ret = PyCom_PyObjectFromIUnknown(pOb, IID_IFilter, FALSE);

	return ret;
}
// @pymethod |PyIStorage|RenameElement|Renames the specified substorage or stream in this storage object.
PyObject *PyIStorage::RenameElement(PyObject *self, PyObject *args)
{
	IStorage *pIS = GetI(self);
	if ( pIS == NULL )
		return NULL;
	// @pyparm string|oldName||The name of the substorage or stream to be changed.
	// @pyparm string|newName||The new name for the specified sustorage or stream.
	PyObject *obNewName, *obOldName;
	if ( !PyArg_ParseTuple(args, "OO:RenameElement", &obOldName, &obNewName) )
		return NULL;
	BOOL bPythonIsHappy = TRUE;
	BSTR bstrNewName, bstrOldName;
	bPythonIsHappy = PyWinObject_AsBstr(obOldName, &bstrOldName);
	if (!PyWinObject_AsBstr(obNewName, &bstrNewName))
		bPythonIsHappy = FALSE;
	if (!bPythonIsHappy) return NULL;
	PY_INTERFACE_PRECALL;
	HRESULT hr = pIS->RenameElement( bstrOldName, bstrNewName );
	PyWinObject_FreeBstr(bstrOldName);
	PyWinObject_FreeBstr(bstrNewName);
	PY_INTERFACE_POSTCALL;
	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pIS, IID_IStorage);
	Py_INCREF(Py_None);
	return Py_None;

}
// @pymethod <o PyIStorage>|pythoncom|StgOpenStorage|Opens an existing root storage object in the file system.
PyObject *pythoncom_StgOpenStorage(PyObject *self, PyObject *args)
{
	PyObject *temp = NULL;
	DWORD reserved = 0;
	PyObject *obName;
	DWORD mode;
	IStorage *pResult;
	PyObject *obOther;

	if (!PyArg_ParseTuple(args, "OOi|Oi:StgOpenStorage",
		               &obName, // @pyparm string|name||Name of the stream, or possibly None if storageOther is non None.
					   &obOther, // @pyparm <o PyIStorage>|other||Usually None, or another parent storage.
					   &mode, // @pyparm int|mode||Specifies the access mode used to open the storage.  A combination of the storagecon.STGM_* constants.
					   &temp, // @pyparm object|snbExclude|None|Not yet supported - must be None
					   &reserved)) // @pyparm int|reserved|0|A reserved value
		return NULL;
	PyWin_AutoFreeBstr bstrName;
	if ( !PyWinObject_AsAutoFreeBstr(obName, &bstrName, TRUE) )
		return NULL;
	IStorage *pOther;
	if (!PyCom_InterfaceFromPyObject(obOther, IID_IStorage, (void **)&pOther, TRUE))
		return NULL;
	PY_INTERFACE_PRECALL;
	HRESULT hr = StgOpenStorage(bstrName, pOther, mode, NULL, reserved, &pResult);
	if (pOther) pOther->Release();
	PY_INTERFACE_POSTCALL;
	if (FAILED(hr)) return PyCom_BuildPyException(hr);
	return PyCom_PyObjectFromIUnknown(pResult, IID_IStorage, FALSE);
}
// @pymethod <o PyIStream>|PyIStorage|CreateStream|Creates and opens a stream object with the specified name contained in this storage object. All elements within a storage object — both streams and other storage objects — are kept in the same name space.
PyObject *PyIStorage::CreateStream(PyObject *self, PyObject *args)
{
	IStorage *pIS = GetI(self);
	if ( pIS == NULL )
		return NULL;
	// @pyparm string|pwcsName||Name of the new stream
	// @pyparm int|grfMode||Specifies the access mode to use when opening the newly created stream.
	// @pyparm int|reserved1|0|Reserved - must be zero.
	// @pyparm int|reserved2|0|Reserved - must be zero.
	DWORD grfMode;
	DWORD reserved1 = 0;
	DWORD reserved2 = 0;
	PyObject *obName;
	if ( !PyArg_ParseTuple(args, "Oi|ii:CreateStream", &obName, &grfMode, &reserved1, &reserved2) )
		return NULL;
	IStream *ppstm;
	BOOL bPythonIsHappy = TRUE;
	BSTR bstrName;
	bPythonIsHappy = PyWinObject_AsBstr(obName, &bstrName);
	if (!bPythonIsHappy) return NULL;
	PY_INTERFACE_PRECALL;
	HRESULT hr = pIS->CreateStream( bstrName, grfMode, reserved1, reserved2, &ppstm );
	PyWinObject_FreeBstr(bstrName);
	PY_INTERFACE_POSTCALL;
	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pIS, IID_IStorage);

	return PyCom_PyObjectFromIUnknown(ppstm, IID_IStream, FALSE);
}
Exemple #6
0
long __stdcall FastIStorage::CopyTo(unsigned long,const struct _GUID *,WCHAR ** ,struct IStorage *pstgNew)
	{
	HRESULT hr;
	IStorage *pstgT;
	IStream *pstmT;

	for (int i=0;i<m_vstg.Size();i++)
		{
		FastIStorage *pstgCur = m_vstg.ElementAt(i);
		if(SUCCEEDED(hr = pstgNew->CreateStorage(pstgCur->m_wzName, STGM_DIRECT | STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE, 0, 0, &pstgT)))
			{
			pstgCur->CopyTo(0,NULL,NULL,pstgT);
			pstgT->Release();
			}
		}

	for (int i=0;i<m_vstm.Size();i++)
		{
		FastIStream *pstmCur = m_vstm.ElementAt(i);
		if(SUCCEEDED(hr = pstgNew->CreateStream(pstmCur->m_wzName, STGM_DIRECT | STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE, 0, 0, &pstmT)))
			{
			ULONG writ;
			//pstmCur->CopyTo(0,NULL,NULL,pstmT);
			pstmT->Write(pstmCur->m_rg, pstmCur->m_cSize, &writ);
			pstmT->Release();
			}
		}

	return S_OK;
	}
// @pymethod |pythoncom|WriteClassStg|Writes a CLSID to a storage object
PyObject *pythoncom_WriteClassStg(PyObject *self, PyObject *args)
{
	PyObject *obStg;
	PyObject *obCLSID;
	if (!PyArg_ParseTuple(args, "OO:WriteClassStg",
					   &obStg, // @pyparm <o PyIStorage>|storage||Storage object into which CLSID will be written.
					   &obCLSID)) // @pyparm <o PyIID>|iid||The IID to write
		return NULL;

	CLSID clsid;
	if (!PyWinObject_AsIID(obCLSID, &clsid))
		return NULL;

	IStorage *pStorage;
	if (!PyCom_InterfaceFromPyObject(obStg, IID_IStorage, (void **)&pStorage, FALSE))
		return NULL;

	PY_INTERFACE_PRECALL;
	HRESULT hr = WriteClassStg(pStorage, clsid);
	pStorage->Release();
	PY_INTERFACE_POSTCALL;
	if (FAILED(hr)) return PyCom_BuildPyException(hr);
	Py_INCREF(Py_None);
	return Py_None;
}
Exemple #8
0
HRESULT CDShowCtrl::LoadGraphFile(IGraphBuilder *pGraph, const WCHAR* wszName)
{
    IStorage *pStorage = 0;
    if (S_OK != StgIsStorageFile(wszName))
    {
        return E_FAIL;
    }
    HRESULT hr = StgOpenStorage(wszName, 0, 
        STGM_TRANSACTED | STGM_READ | STGM_SHARE_DENY_WRITE, 
        0, 0, &pStorage);
    if (FAILED(hr))
    {
        return hr;
    }
    IPersistStream *pPersistStream = 0;
    hr = pGraph->QueryInterface(IID_IPersistStream,
             reinterpret_cast<void**>(&pPersistStream));
    if (SUCCEEDED(hr))
    {
        IStream *pStream = 0;
        hr = pStorage->OpenStream(L"ActiveMovieGraph", 0, 
            STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &pStream);
        if(SUCCEEDED(hr))
        {
            hr = pPersistStream->Load(pStream);
            pStream->Release();
        }
        pPersistStream->Release();
    }
    pStorage->Release();
    return hr;
}
// @pymethod |PyIStorage|MoveElementTo|Copies or moves a substorage or stream from this storage object to another storage object.
PyObject *PyIStorage::MoveElementTo(PyObject *self, PyObject *args)
{
	IStorage *pIS = GetI(self);
	if ( pIS == NULL )
		return NULL;
	// @pyparm string|name||A string that contains the name of the element in this storage object to be moved or copied.
	// @pyparm <o PyIStorage>|stgDest||<o PyIStorage> for the destination storage object.
	// @pyparm string|newName||A string that contains the new name for the element in its new storage object.
	// @pyparm int|grfFlags||Specifies whether the operation should be a move (STGMOVE_MOVE) or a copy (STGMOVE_COPY). See the STGMOVE enumeration.
	PyObject *obName, *obNewName;
	PyObject *obpstgDest;
	DWORD grfFlags;
	if ( !PyArg_ParseTuple(args, "OOOi:MoveElementTo", &obName, &obpstgDest, &obNewName, &grfFlags) )
		return NULL;
	IStorage *pstgDest;
	BOOL bPythonIsHappy = TRUE;
	BSTR bstrName, bstrNewName;
	bPythonIsHappy = PyWinObject_AsBstr(obName, &bstrName);
	if (!PyWinObject_AsBstr(obNewName, &bstrNewName))
		bPythonIsHappy = FALSE;
	if (!PyCom_InterfaceFromPyObject(obpstgDest, IID_IStorage, (void **)&pstgDest, FALSE /* bNoneOK */))
		 bPythonIsHappy = FALSE;
	if (!bPythonIsHappy) return NULL;
	PY_INTERFACE_PRECALL;
	HRESULT hr = pIS->MoveElementTo( bstrName, pstgDest, bstrNewName, grfFlags );
	pstgDest->Release();
	PY_INTERFACE_POSTCALL;
	PyWinObject_FreeBstr(bstrName);
	PyWinObject_FreeBstr(bstrNewName);
	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pIS, IID_IStorage);
	Py_INCREF(Py_None);
	return Py_None;

}
// @pymethod <o PyIStorage>|PyIStorage|CreateStorage|Creates and opens a new storage object nested within this storage object.
PyObject *PyIStorage::CreateStorage(PyObject *self, PyObject *args)
{
	IStorage *pIS = GetI(self);
	if ( pIS == NULL )
		return NULL;
	// @pyparm string|pwcsName||The name of the newly created stream.
	// @pyparm int|grfMode||Specifies the access mode to use when opening the newly created storage object.
	// @pyparm int|dwStgFmt||Documented as "reserved"!
	// @pyparm int|reserved2|0|Description for reserved2
	PyObject *obName;
	DWORD grfMode;
	DWORD dwStgFmt;
	DWORD reserved2 = 0;
	if ( !PyArg_ParseTuple(args, "Oii|i:CreateStorage", &obName, &grfMode, &dwStgFmt, &reserved2) )
		return NULL;
	IStorage *ppstg;
	BOOL bPythonIsHappy = TRUE;
	BSTR name;
	bPythonIsHappy = PyWinObject_AsBstr(obName, &name);
	if (!bPythonIsHappy) return NULL;
	PY_INTERFACE_PRECALL;
	HRESULT hr = pIS->CreateStorage( name, grfMode, dwStgFmt, reserved2, &ppstg );
	PY_INTERFACE_POSTCALL;
	PyWinObject_FreeBstr(name);
	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pIS, IID_IStorage);

	return PyCom_PyObjectFromIUnknown(ppstg, IID_IStorage, FALSE);
}
// @pymethod <o PyIStream>|PyIStorage|OpenStream|Opens an existing stream object within this storage object in the specified access mode.
PyObject *PyIStorage::OpenStream(PyObject *self, PyObject *args)
{
	IStorage *pIS = GetI(self);
	if ( pIS == NULL )
		return NULL;
	// @pyparm string|pwcsName||Description for pwcsName
	// @pyparm object|reserved1||A reserved param.  Always pass None.  NULL is always passed to the COM function
	// @pyparm int|grfMode||Specifies the access mode to be assigned to the open stream. See the STGM enumeration values for descriptions of the possible values. . Whatever other modes you may choose, you must at least specify STGM_SHARE_EXCLUSIVE when calling this method.
	// @pyparm int|reserved2|0|Reserved - must be zero.
	PyObject *obName;
	DWORD grfMode;
	PyObject *obreserved1;
	DWORD reserved2 = 0;
	if ( !PyArg_ParseTuple(args, "OOi|i:OpenStream", &obName, &obreserved1, &grfMode, &reserved2) )
		return NULL;
	if (obreserved1 != Py_None) {
		PyErr_SetString(PyExc_TypeError, "The 'reserved' parameter (param 2) must be None");
		return NULL;
	}
	IStream *ppstm;
	BOOL bPythonIsHappy = TRUE;
	BSTR name;
	bPythonIsHappy = PyWinObject_AsBstr(obName, &name);
	if (!bPythonIsHappy) return NULL;
	PY_INTERFACE_PRECALL;
	HRESULT hr = pIS->OpenStream( name, NULL, grfMode, reserved2, &ppstm );
	PyWinObject_FreeBstr(name);
	PY_INTERFACE_POSTCALL;
	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pIS, IID_IStorage);

	return PyCom_PyObjectFromIUnknown(ppstm, IID_IStream, FALSE);
}
HRESULT CDropHandler::CopyShellIDListData(IDataObject *pDataObject,
	list<PastedFile_t> *pPastedFileList)
{
	STGMEDIUM stg;
	HRESULT hr;

	hr = pDataObject->GetData(&m_ftcShellIDList,&stg);

	if(hr == S_OK)
	{
		CIDA *pcida = (CIDA *)GlobalLock(stg.hGlobal);

		if(pcida != NULL)
		{
			IShellFolder *pShellFolder = NULL;
			HRESULT hr;

			LPCITEMIDLIST pidlDirectory = HIDA_GetPIDLFolder(pcida);

			hr = BindToShellFolder(pidlDirectory,&pShellFolder);

			if(SUCCEEDED(hr))
			{
				LPCITEMIDLIST pidlItem = NULL;
				IStorage *pStorage = NULL;

				for(unsigned int i = 0;i < pcida->cidl;i++)
				{
					pidlItem = HIDA_GetPIDLItem(pcida,i);

					hr = pShellFolder->BindToStorage(pidlItem,NULL,IID_IStorage,(LPVOID *)&pStorage);

					if(SUCCEEDED(hr))
					{
						/* TODO: Copy the files. */
						pStorage->Release();
					}
				}

				pShellFolder->Release();
			}

			GlobalUnlock(stg.hGlobal);
		}

		ReleaseStgMedium(&stg);
	}

	return hr;
}
Exemple #13
0
	virtual void Save()
	{
		if(!m_pStorage)
			return;
		m_ConfigFile = m_pStorage->OpenFile("settings.cfg", IOFLAG_WRITE, IStorage::TYPE_SAVE);
		
		if(!m_ConfigFile)
			return;
		
		char aLineBuf[1024*2];
		char aEscapeBuf[1024*2];

		#define MACRO_CONFIG_INT(Name,ScriptName,def,min,max,flags,desc) if((flags)&CFGFLAG_SAVE){ str_format(aLineBuf, sizeof(aLineBuf), "%s %i", #ScriptName, g_Config.m_##Name); WriteLine(aLineBuf); }
		#define MACRO_CONFIG_STR(Name,ScriptName,len,def,flags,desc) if((flags)&CFGFLAG_SAVE){ EscapeParam(aEscapeBuf, g_Config.m_##Name, sizeof(aEscapeBuf)); str_format(aLineBuf, sizeof(aLineBuf), "%s \"%s\"", #ScriptName, aEscapeBuf); WriteLine(aLineBuf); }

		#include "config_variables.h" 

		#undef MACRO_CONFIG_INT 
		#undef MACRO_CONFIG_STR 				
		
		for(int i = 0; i < m_NumCallbacks; i++)
			m_aCallbacks[i].m_pfnFunc(this, m_aCallbacks[i].m_pUserData);
		
		io_close(m_ConfigFile);
		m_ConfigFile = 0;
	}
Exemple #14
0
	virtual int Save()
	{
		IOHANDLE File;

		if(!m_pStorage)
			return -1;

		// try to open file
		File = m_pStorage->OpenFile("masters.cfg", IOFLAG_WRITE, IStorage::TYPE_SAVE);
		if(!File)
			return -1;

		for(int i = 0; i < MAX_MASTERSERVERS; i++)
		{
			char aAddrStr[NETADDR_MAXSTRSIZE];
			net_addr_str(&m_aMasterServers[i].m_Addr, aAddrStr, sizeof(aAddrStr));
			char aBuf[1024];
			str_format(aBuf, sizeof(aBuf), "%s %s\n", m_aMasterServers[i].m_aHostname, aAddrStr);

			io_write(File, aBuf, str_length(aBuf));
		}

		io_close(File);
		return 0;
	}
// @pymethod |PyIStorage|Revert|Discards all changes that have been made to the storage object since the last commit.
PyObject *PyIStorage::Revert(PyObject *self, PyObject *args)
{
	IStorage *pIS = GetI(self);
	if ( pIS == NULL )
		return NULL;
	if ( !PyArg_ParseTuple(args, ":Revert") )
		return NULL;
	PY_INTERFACE_PRECALL;
	HRESULT hr = pIS->Revert( );
	PY_INTERFACE_POSTCALL;
	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pIS, IID_IStorage);
	Py_INCREF(Py_None);
	return Py_None;

}
	virtual int Save()
	{
		if(!m_pStorage)
			return -1;

		// try to open file
		IOHANDLE File = m_pStorage->OpenFile("masters.cfg", IOFLAG_WRITE, IStorage::TYPE_SAVE);
		if(!File)
			return -1;

		for(int i = 0; i < MAX_MASTERSERVERS; i++)
		{
			char aAddrStr[NETADDR_MAXSTRSIZE];
			if(m_aMasterServers[i].m_Addr.type != NETTYPE_INVALID)
				net_addr_str(&m_aMasterServers[i].m_Addr, aAddrStr, sizeof(aAddrStr), true);
			else
				aAddrStr[0] = 0;
			char aBuf[256];
			str_format(aBuf, sizeof(aBuf), "%s %s", m_aMasterServers[i].m_aHostname, aAddrStr);
			io_write(File, aBuf, str_length(aBuf));
			io_write_newline(File);
		}

		io_close(File);
		return 0;
	}
Exemple #17
0
	virtual void Save(const char *pFilename)
	{
		if(!m_pStorage)
			return;
		
		if(!pFilename)
			pFilename = "settings.cfg";
		m_ConfigFile = m_pStorage->OpenFile(pFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE);

		if(!m_ConfigFile)
			return;

		char aLineBuf[1024*2];
		char aEscapeBuf[1024*2];

		#define MACRO_CONFIG_INT(Name,ScriptName,def,min,max,flags,desc) if(((flags)&(CFGFLAG_SAVE))&&((flags)&(m_FlagMask))){ str_format(aLineBuf, sizeof(aLineBuf), "%s %i", #ScriptName, g_Config.m_##Name); WriteLine(aLineBuf); }
		#define MACRO_CONFIG_STR(Name,ScriptName,len,def,flags,desc) if(((flags)&(CFGFLAG_SAVE))&&((flags)&(m_FlagMask))){ EscapeParam(aEscapeBuf, g_Config.m_##Name, sizeof(aEscapeBuf)); str_format(aLineBuf, sizeof(aLineBuf), "%s \"%s\"", #ScriptName, aEscapeBuf); WriteLine(aLineBuf); }

		#include "config_variables.h"

		#undef MACRO_CONFIG_INT
		#undef MACRO_CONFIG_STR

		for(int i = 0; i < m_NumCallbacks; i++)
			m_aCallbacks[i].m_pfnFunc(this, m_aCallbacks[i].m_pUserData);

		io_close(m_ConfigFile);

		if(m_pConsole)
		{
			char aBuf[256];
			str_format(aBuf, sizeof(aBuf), "saved config to '%s'", pFilename);
			m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "config", aBuf);
		}
	}
// @pymethod <o PyIID>|pythoncom|ReadClassStg|Reads a CLSID from a storage object.
PyObject *pythoncom_ReadClassStg(PyObject *self, PyObject *args)
{
	PyObject *obStg;
	if (!PyArg_ParseTuple(args, "O:ReadClassStg",
					   &obStg)) // @pyparm <o PyIStorage>|storage||The storage to read the CLSID from.
		return NULL;
	IStorage *pStorage;
	if (!PyCom_InterfaceFromPyObject(obStg, IID_IStorage, (void **)&pStorage, FALSE))
		return NULL;
	CLSID clsidRet;
	PY_INTERFACE_PRECALL;
	HRESULT hr = ReadClassStg(pStorage, &clsidRet);
	pStorage->Release();
	PY_INTERFACE_POSTCALL;
	if (FAILED(hr)) return PyCom_BuildPyException(hr);
	return PyWinObject_FromIID(clsidRet);
}
// @pymethod |PyIStorage|SetElementTimes|Sets the modification, access, and creation times of the specified storage element, if supported by the underlying file system.
PyObject *PyIStorage::SetElementTimes(PyObject *self, PyObject *args)
{
	IStorage *pIS = GetI(self);
	if ( pIS == NULL )
		return NULL;
	// @pyparm string|name||The name of the storage object element whose times are to be modified. If NULL, the time is set on the root storage rather than one of its elements. 
	// @pyparm <o PyTime>|ctime||Either the new creation time for the element or None if the creation time is not to be modified.
	// @pyparm <o PyTime>|atime||Either the new access time for the element or None if the access time is not to be modified.
	// @pyparm <o PyTime>|mtime||Either the new modification time for the element or None if the modification time is not to be modified.
	PyObject *obName;
	PyObject *obpctime;
	PyObject *obpatime;
	PyObject *obpmtime;
	if ( !PyArg_ParseTuple(args, "OOOO:SetElementTimes", &obName, &obpctime, &obpatime, &obpmtime) )
		return NULL;
	FILETIME *pctime=NULL, ctime;
	FILETIME *patime=NULL, atime;
	FILETIME *pmtime=NULL, mtime;
	if (obpctime!=Py_None) {
		if (!PyWinObject_AsFILETIME(obpctime, &ctime))
			return NULL;
		pctime = &ctime;
	}
	if (obpatime != Py_None) {
		if (!PyWinObject_AsFILETIME(obpatime, &atime))
			return NULL;
		patime = &atime;
	}
	if (obpmtime != Py_None) {
		if (!PyWinObject_AsFILETIME(obpmtime, &mtime))
			return NULL;
		pmtime = &mtime;
	}
	BSTR bstrName;
	if (!PyWinObject_AsBstr(obName, &bstrName))
		return NULL;
	PY_INTERFACE_PRECALL;
	HRESULT hr = pIS->SetElementTimes( bstrName, pctime, patime, pmtime );
	PyWinObject_FreeBstr(bstrName);
	PY_INTERFACE_POSTCALL;
	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pIS, IID_IStorage);
	Py_INCREF(Py_None);
	return Py_None;
}
Exemple #20
0
void CompleteAutoSave(HANDLE hEvent, LPARAM lParam)
	{
	AutoSavePackage *pasp = (AutoSavePackage *)lParam;

	FastIStorage *pstgroot = pasp->pstg;

	IStorage *pstgDisk;

	WCHAR *wzSaveName = L"AutoSave";
	WCHAR *wzSaveExtension = L".vpx";
	WCHAR wzSuffix[32];
	_itow_s(pasp->tableindex, wzSuffix, sizeof(wzSuffix)/sizeof(WCHAR), 10);

	WCHAR * const wzT = new WCHAR[MAX_PATH + 32 + lstrlenW(wzSaveName) + lstrlenW(wzSaveExtension)+ 1];

	WideStrCopy(g_pvp->m_wzMyPath, wzT);
	WideStrCat(wzSaveName, wzT);
	WideStrCat(wzSuffix, wzT);
	WideStrCat(wzSaveExtension, wzT);
	
	//MAKE_WIDEPTR_FROMANSI(wszCodeFile, m_szFileName);

	STGOPTIONS stg;
	stg.usVersion = 1;
	stg.reserved = 0;
	stg.ulSectorSize = 4096;

	HRESULT hr;
	if(SUCCEEDED(hr = StgCreateStorageEx(wzT, STGM_TRANSACTED | STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE,
		STGFMT_DOCFILE, 0, &stg, 0, IID_IStorage, (void**)&pstgDisk)))
		{
		pstgroot->CopyTo(0, NULL, NULL, pstgDisk);
		hr = pstgDisk->Commit(STGC_DEFAULT);
		pstgDisk->Release();
		}

	pstgroot->Release();

	SetEvent(hEvent);

	PostMessage(pasp->HwndTable, DONE_AUTOSAVE, (WPARAM)hEvent, hr);

	delete [] wzT;
	delete pasp;
	}
// @pymethod |PyIStorage|Commit|Ensures that any changes made to a storage object open in transacted mode are reflected in the parent storage; 
// for a root storage, reflects the changes in the actual device, for example, a file on disk. 
// For a root storage object opened in direct mode, this method has no effect except to flush all memory buffers to the disk. For non-root storage objects in direct mode, this method has no effect.
PyObject *PyIStorage::Commit(PyObject *self, PyObject *args)
{
	IStorage *pIS = GetI(self);
	if ( pIS == NULL )
		return NULL;
	// @pyparm int|grfCommitFlags||Controls how the changes are committed to the storage object. See the STGC enumeration for a definition of these values. 
	DWORD grfCommitFlags;
	if ( !PyArg_ParseTuple(args, "i:Commit", &grfCommitFlags) )
		return NULL;
	PY_INTERFACE_PRECALL;
	HRESULT hr = pIS->Commit( grfCommitFlags );
	PY_INTERFACE_POSTCALL;
	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pIS, IID_IStorage);
	Py_INCREF(Py_None);
	return Py_None;

}
Exemple #22
0
int _tmain(int argc, _TCHAR* argv[])
{
	CLSID wid;
	CoInitialize(NULL);
	CLSIDFromString(const_cast<wchar_t*>(default_guid), &wid);
	IInitializeWithFile *oo;
	HRESULT hr;
	if ((hr = CoCreateInstance(wid, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&oo))) != S_OK)
		fail();
#if 0
	IStorage *isto;
	if ((hr = StgCreateDocfile(L"t.mp3", STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_DIRECT, 0, &isto)) != S_OK)
		fail();
	IStream *is;
	if ((hr = isto->CreateStream(L"lol", STGM_DIRECT | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &is)) != S_OK)
		fail();
#endif
	IPropertyStore *ips;
	IPropertyStoreCapabilities *ipcs;
	if ((hr = oo->QueryInterface(IID_PPV_ARGS(&ips))) != S_OK)
		fail();

	if ((hr = oo->QueryInterface(IID_PPV_ARGS(&ipcs))) != S_OK)
		fail();

	//iws->Initialize(is, STGM_READWRITE);
	if ((hr = oo->Initialize(L"t.mp3", STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_DIRECT)) != S_OK)
		fail();

	DWORD props;
	if ((hr = ips->GetCount(&props)) != S_OK)
		fail();

	for (DWORD i = 0; i < props; ++i)
	{
		PROPERTYKEY pkey;
		ips->GetAt(i, &pkey);
		WCHAR *sz;
		PSGetNameFromPropertyKey(pkey, &sz);
		std::wcout << (ipcs->IsPropertyWritable(pkey) == S_OK) << "\t" << sz << std::endl;
	}
	return 0;
}
    ~Pimpl()
    {
        if (control != 0)
        {
            control->Close (OLECLOSE_NOSAVE);
            control->Release();
        }

        clientSite->Release();
        storage->Release();
    }
// @pymethod |PyIStorage|SetStateBits|Stores up to 32 bits of state information in this storage object.
PyObject *PyIStorage::SetStateBits(PyObject *self, PyObject *args)
{
	IStorage *pIS = GetI(self);
	if ( pIS == NULL )
		return NULL;
	// @pyparm int|grfStateBits||Specifies the new values of the bits to set. No legal values are defined for these bits; they are all reserved for future use and must not be used by applications.
	// @pyparm int|grfMask||A binary mask indicating which bits in grfStateBits are significant in this call. 
	DWORD grfStateBits;
	DWORD grfMask;
	if ( !PyArg_ParseTuple(args, "ii:SetStateBits", &grfStateBits, &grfMask) )
		return NULL;
	PY_INTERFACE_PRECALL;
	HRESULT hr = pIS->SetStateBits( grfStateBits, grfMask );
	PY_INTERFACE_POSTCALL;
	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pIS, IID_IStorage);
	Py_INCREF(Py_None);
	return Py_None;

}
// This code was also brazenly stolen from the DX9 SDK
// Pass it a file name in wszPath, and it will save the filter graph to that file.
HRESULT SaveGraphFile(IGraphBuilder *pGraph, WCHAR *wszPath) 
{
    const WCHAR wszStreamName[] = L"ActiveMovieGraph"; 
    HRESULT hr;
    IStorage *pStorage = NULL;

	// First, create a document file which will hold the GRF file
	hr = StgCreateDocfile(
        wszPath,
        STGM_CREATE | STGM_TRANSACTED | STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
        0, &pStorage);
    if(FAILED(hr)) 
    {
        return hr;
    }

	// Next, create a stream to store.
    IStream *pStream;
    hr = pStorage->CreateStream(
		wszStreamName,
        STGM_WRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE,
        0, 0, &pStream);
    if (FAILED(hr)) 
    {
        pStorage->Release();    
        return hr;
    }

	// The IPersistStream converts a stream into a persistent object.
    IPersistStream *pPersist = NULL;
    pGraph->QueryInterface(IID_IPersistStream, reinterpret_cast<void**>(&pPersist));
    hr = pPersist->Save(pStream, TRUE);
    pStream->Release();
    pPersist->Release();
    if (SUCCEEDED(hr)) 
    {
        hr = pStorage->Commit(STGC_DEFAULT);
    }
    pStorage->Release();
    return hr;
}
// @pymethod <o STATSTG>|PyIStorage|Stat|Retrieves the STATSTG structure for this open storage object.
PyObject *PyIStorage::Stat(PyObject *self, PyObject *args)
{
	IStorage *pIS = GetI(self);
	if ( pIS == NULL )
		return NULL;
	// @pyparm int|grfStatFlag||Specifies that some of the fields in the STATSTG structure are not returned, thus saving a memory allocation operation. Values are taken from the STATFLAG enumeration. 
	DWORD grfStatFlag = 0;
	if ( !PyArg_ParseTuple(args, "|i:Stat", &grfStatFlag) )
		return NULL;
	STATSTG pstatstg;
	PY_INTERFACE_PRECALL;
	HRESULT hr = pIS->Stat( &pstatstg, grfStatFlag );
	PY_INTERFACE_POSTCALL;
	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pIS, IID_IStorage);

	PyObject *obpstatstg = PyCom_PyObjectFromSTATSTG(&pstatstg);
	// STATSTG doco says our responsibility to free
	if ((pstatstg).pwcsName) CoTaskMemFree((pstatstg).pwcsName);
	return obpstatstg;
}
	virtual int Load()
	{
		if(!m_pStorage)
			return -1;

		// try to open file
		IOHANDLE File = m_pStorage->OpenFile("masters.cfg", IOFLAG_READ, IStorage::TYPE_SAVE);
		if(!File)
			return -1;

		CLineReader LineReader;
		LineReader.Init(File);
		while(1)
		{
			CMasterInfo Info = {{0}};
			const char *pLine = LineReader.Get();
			if(!pLine)
				break;

			// parse line
			char aAddrStr[NETADDR_MAXSTRSIZE];
			if(sscanf(pLine, "%127s %47s", Info.m_aHostname, aAddrStr) == 2 && net_addr_from_str(&Info.m_Addr, aAddrStr) == 0)
			{
				Info.m_Addr.port = 8300;
				bool Added = false;
				for(int i = 0; i < MAX_MASTERSERVERS; ++i)
					if(str_comp(m_aMasterServers[i].m_aHostname, Info.m_aHostname) == 0)
					{
						m_aMasterServers[i] = Info;
						Added = true;
						break;
					}

				if(!Added)
				{
					for(int i = 0; i < MAX_MASTERSERVERS; ++i)
						if(m_aMasterServers[i].m_Addr.type == NETTYPE_INVALID)
						{
							m_aMasterServers[i] = Info;
							Added = true;
							break;
						}
				}

				if(!Added)
					break;
			}
		}

		io_close(File);
		return 0;
	}
// @pymethod <o PyIStorage>|PyIStorage|OpenStorage|Opens an existing storage object with the specified name in the specified access mode.
PyObject *PyIStorage::OpenStorage(PyObject *self, PyObject *args)
{
	IStorage *pIS = GetI(self);
	if ( pIS == NULL )
		return NULL;
	// @pyparm string|pwcsName||Name of the storage, or None.
	// @pyparm <o PyIStorage>|pstgPriority||If the pstgPriority parameter is not None, it is a <o PyIStorage> object to a previous opening of an element of the storage object, 
	// usually one that was opened in priority mode. The storage object should be closed and re-opened 
	// according to grfMode. When the <om PyIStorage.OpenStorage> method returns, pstgPriority is no longer valid - use the result value. 
	// If the pstgPriority parameter is None, it is ignored.
	// @pyparm int|grfMode||Specifies the access mode to use when opening the storage object. See the STGM enumeration values for descriptions of the possible values. Whatever other modes you may choose, you must at least specify STGM_SHARE_EXCLUSIVE when calling this method. 
	// @pyparm <o SNB>|snbExclude||Reserved for later - Must be None
	// @pyparm int|reserved|0|Reserved integer param.
	PyObject *obName;
	PyObject *obpstgPriority;
	DWORD grfMode;
	DWORD reserved = 0;
	char *temp = NULL;
	if ( !PyArg_ParseTuple(args, "OOi|zi:OpenStorage", &obName, &obpstgPriority, &grfMode, &temp, &reserved) )
		return NULL;
	IStorage *pstgPriority;
	IStorage *ppstg;
	BOOL bPythonIsHappy = TRUE;
	BSTR bstrName;
	bPythonIsHappy = PyWinObject_AsBstr(obName, &bstrName, TRUE);
	if (!PyCom_InterfaceFromPyObject(obpstgPriority, IID_IStorage, (void **)&pstgPriority, TRUE /* bNoneOK */))
		 bPythonIsHappy = FALSE;
	if (!bPythonIsHappy) return NULL;
	PY_INTERFACE_PRECALL;
	HRESULT hr = pIS->OpenStorage( bstrName, pstgPriority, grfMode, NULL, reserved, &ppstg );
	if ( pstgPriority != NULL )
		pstgPriority->Release();
	PyWinObject_FreeBstr(bstrName);
	PY_INTERFACE_POSTCALL;
	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pIS, IID_IStorage);

	return PyCom_PyObjectFromIUnknown(ppstg, IID_IStorage, FALSE);
}
// @pymethod <o PyIEnumSTATSTG>|PyIStorage|EnumElements|Retrieves an enumerator object that can be used to enumerate the storage and stream objects contained within this storage object.
PyObject *PyIStorage::EnumElements(PyObject *self, PyObject *args)
{
	IStorage *pIS = GetI(self);
	if ( pIS == NULL )
		return NULL;
	// @pyparm int|reserved1|0|Reserved - must be zero.
	// @pyparm object|reserved2|None|A reserved param.  Always pass None.  NULL is always passed to the COM function
	// @pyparm int|reserved3|0|Reserved - must be zero.
	DWORD reserved1 = 0;
	char *szreserved2 = NULL;
	DWORD reserved3 = 0;
	if ( !PyArg_ParseTuple(args, "|izi:EnumElements", &reserved1, &szreserved2, &reserved3) )
		return NULL;
	IEnumSTATSTG *ppenum;
	PY_INTERFACE_PRECALL;
	HRESULT hr = pIS->EnumElements( reserved1, NULL, reserved3, &ppenum );
	PY_INTERFACE_POSTCALL;
	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pIS, IID_IStorage);

	return PyCom_PyObjectFromIUnknown(ppenum, IID_IEnumSTATSTG, FALSE);
}
// @pymethod |PyIStorage|SetClass|Assigns the specified CLSID to this storage object.
PyObject *PyIStorage::SetClass(PyObject *self, PyObject *args)
{
	IStorage *pIS = GetI(self);
	if ( pIS == NULL )
		return NULL;
	// @pyparm <o PyIID>|clsid||The class identifier (CLSID) that is to be associated with the storage object.
	PyObject *obclsid;
	if ( !PyArg_ParseTuple(args, "O:SetClass", &obclsid) )
		return NULL;
	IID clsid;
	BOOL bPythonIsHappy = TRUE;
	if (!PyWinObject_AsIID(obclsid, &clsid)) bPythonIsHappy = FALSE;
	if (!bPythonIsHappy) return NULL;
	PY_INTERFACE_PRECALL;
	HRESULT hr = pIS->SetClass( clsid );
	PY_INTERFACE_POSTCALL;
	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pIS, IID_IStorage);
	Py_INCREF(Py_None);
	return Py_None;

}