[pywin32-checkins] pywin32/win32/src win32file.i,1.76,1.77
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Roger U. <ru...@us...> - 2007-04-14 08:27:50
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4563/win32/src Modified Files: win32file.i Log Message: Add Sfc functions Index: win32file.i =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32file.i,v retrieving revision 1.76 retrieving revision 1.77 diff -C2 -d -r1.76 -r1.77 *** win32file.i 17 Mar 2007 03:41:53 -0000 1.76 --- win32file.i 14 Apr 2007 08:27:50 -0000 1.77 *************** *** 17,20 **** --- 17,21 ---- #include "assert.h" #include <stddef.h> + #include "sfc.h" #endif *************** *** 2767,2770 **** --- 2768,2777 ---- */ + // From sfc.dll + typedef BOOL (WINAPI *SfcGetNextProtectedFilefunc)(HANDLE,PPROTECTED_FILE_DATA); + static SfcGetNextProtectedFilefunc pfnSfcGetNextProtectedFile = NULL; + typedef BOOL (WINAPI *SfcIsFileProtectedfunc)(HANDLE,LPCWSTR); + static SfcIsFileProtectedfunc pfnSfcIsFileProtected = NULL; + // @pyswig <o PyUnicode>|SetVolumeMountPoint|Mounts the specified volume at the specified volume mount point. *************** *** 4781,4784 **** --- 4788,4849 ---- } PyCFunction pfnpy_GetFinalPathNameByHandle=(PyCFunction)py_GetFinalPathNameByHandle; + + // @pyswig [<o PyUnicode>,...]|SfcGetNextProtectedFile|Returns list of protected operating system files + // @pyseeapi SfcGetNextProtectedFile + static PyObject *py_SfcGetNextProtectedFile(PyObject *self, PyObject *args) + { + CHECK_PFN(SfcGetNextProtectedFile); + PROTECTED_FILE_DATA pfd; + DWORD err=0; + HANDLE rpchandle=NULL; // reserved + PyObject *ret, *ret_item; + + if (!PyArg_ParseTuple(args, ":SfcGetNextProtectedFile")) + return NULL; + ret=PyList_New(0); + if (ret==NULL) + return NULL; + pfd.FileNumber=0; + + while ((*pfnSfcGetNextProtectedFile)(rpchandle, &pfd)){ + ret_item=PyWinObject_FromWCHAR(pfd.FileName); + if (ret_item==NULL || PyList_Append(ret, ret_item)==-1){ + Py_XDECREF(ret_item); + Py_DECREF(ret); + return NULL; + } + Py_DECREF(ret_item); + } + err=GetLastError(); + if (err==ERROR_NO_MORE_FILES) + return ret; + Py_DECREF(ret); + return PyWin_SetAPIError("SfcGetNextProtectedFile",err); + } + + // @pyswig boolean|SfcIsFileProtected|Checks if a file is protected + static PyObject *py_SfcIsFileProtected(PyObject *self, PyObject *args) + { + CHECK_PFN(SfcIsFileProtected); + PyObject *obfname; + WCHAR *fname; + HANDLE rpchandle=NULL; // reserved + BOOL ret; + + if (!PyArg_ParseTuple(args, "O:SfcIsFileProtected", + &obfname)) // @pyparm <o PyUnicode>|ProtFileName||Name of file to be checked + return NULL; + if (!PyWinObject_AsWCHAR(obfname, &fname, FALSE)) + return NULL; + + ret=(*pfnSfcIsFileProtected)(rpchandle, fname); + PyWinObject_FreeWCHAR(fname); + if (!ret){ + DWORD err=GetLastError(); + if (err!=ERROR_FILE_NOT_FOUND) + return PyWin_SetAPIError("SfcIsFileProtected",err); + } + return PyBool_FromLong(ret); + } %} *************** *** 4829,4832 **** --- 4894,4899 ---- %native (GetFinalPathNameByHandle) pfnpy_GetFinalPathNameByHandle; + %native (SfcGetNextProtectedFile) py_SfcGetNextProtectedFile; + %native (SfcIsFileProtected) py_SfcIsFileProtected; %init %{ *************** *** 4834,4838 **** PyDict_SetItemString(d, "INVALID_HANDLE_VALUE", PyWinLong_FromHANDLE(INVALID_HANDLE_VALUE)); ! for (PyMethodDef *pmd = win32fileMethods;pmd->ml_name;pmd++) if ((strcmp(pmd->ml_name, "CreateFileTransacted")==0) ||(strcmp(pmd->ml_name, "DeleteFileTransacted")==0) --- 4901,4905 ---- PyDict_SetItemString(d, "INVALID_HANDLE_VALUE", PyWinLong_FromHANDLE(INVALID_HANDLE_VALUE)); ! for (PyMethodDef *pmd = win32fileMethods;pmd->ml_name;pmd++) if ((strcmp(pmd->ml_name, "CreateFileTransacted")==0) ||(strcmp(pmd->ml_name, "DeleteFileTransacted")==0) *************** *** 4866,4870 **** ||(strcmp(pmd->ml_name, "GetFileInformationByHandleEx")==0) // not impl yet ) ! pmd->ml_flags = METH_VARARGS | METH_KEYWORDS; HMODULE hmodule; --- 4933,4937 ---- ||(strcmp(pmd->ml_name, "GetFileInformationByHandleEx")==0) // not impl yet ) ! pmd->ml_flags = METH_VARARGS | METH_KEYWORDS; HMODULE hmodule; *************** *** 4934,4937 **** --- 5001,5012 ---- } + hmodule=GetModuleHandle("sfc.dll"); + if (hmodule==NULL) + hmodule=LoadLibrary("sfc.dll"); + if (hmodule){ + pfnSfcGetNextProtectedFile=(SfcGetNextProtectedFilefunc)GetProcAddress(hmodule, "SfcGetNextProtectedFile"); + pfnSfcIsFileProtected=(SfcIsFileProtectedfunc)GetProcAddress(hmodule, "SfcIsFileProtected"); + } + %} |