示例#1
0
//---------------------------------------------------------------------------
void __fastcall TMainForm::LabeledEditKeyDown(TObject *Sender, WORD &Key, TShiftState Shift){
	if (Key !=0x0D) return;
	RichEditPrintTicket->Clear();
	LabeledEdit->ReadOnly =true;
	AnsiString binFileStr =controller->config->BinFileDir +"ticket\\" +LabeledEdit->Text +".bin";
	if (!FileExists(binFileStr)){
        ShowMessage("票号搞错了吧,没有找到这张票的数据,重新输入吧!");
		return;
	}
	int hBinFile = FileOpen(binFileStr, fmOpenRead);
	char bin[16384] ={0};
	int nRead =FileRead(hBinFile, bin, sizeof(bin));
	//解密文件
	char *srcBin =new char[nRead];
	controller->Decrypt(bin, nRead, srcBin);
	FileClose(hBinFile);
	char stubTxt[16384] ={0};
	//借用个对象,计算一下
	if (controller->terminalGroup->Count ==0) return;
	CTerminal *terminal =(CTerminal *)controller->terminalGroup->Objects[0];
	terminal->ParserVerifyStub(nRead, srcBin, stubTxt);
	delete srcBin;
	//显示票根,转换一下,避免单行超过1024字节,控件限制的错误
	TStringList *text =new TStringList();
	text->Text =AnsiString(stubTxt);
	RichEditPrintTicket->Clear();
	RichEditPrintTicket->Lines->AddStrings(text);
	RichEditPrintTicket->Perform(WM_VSCROLL, SB_TOP, 0); //光标归位,免得滚下去难看
	delete text;
	SpeedButtonPrinterPrint->Enabled =true;
}
示例#2
0
BOOLEAN ReadInFoodOpinionStats(STR fileName)
{
	HWFILE		hFile;
	UINT32		uiBytesRead;
	UINT32		uiFSize;
	CHAR8 *		lpcBuffer;
	XML_Parser	parser = XML_ParserCreate(NULL);

	foodopinionParseData pData;

	DebugMsg(TOPIC_JA2, DBG_LEVEL_3, "Loading FoodOpinion.xml" );

	// Open file
	hFile = FileOpen( fileName, FILE_ACCESS_READ, FALSE );

	// if the file does not exist, exit
	// Flugente: no need to quit the game if the xml does not exist - this data just won't be there, but the game will still work
	if ( !hFile )
		return( TRUE );

	uiFSize = FileGetSize(hFile);
	lpcBuffer = (CHAR8 *) MemAlloc(uiFSize+1);

	//Read in block
	if ( !FileRead( hFile, lpcBuffer, uiFSize, &uiBytesRead ) )
	{
		MemFree(lpcBuffer);
		return( FALSE );
	}

	lpcBuffer[uiFSize] = 0; //add a null terminator

	FileClose( hFile );

	XML_SetElementHandler(parser, foodopinionStartElementHandle, foodopinionEndElementHandle);
	XML_SetCharacterDataHandler(parser, foodopinionCharacterDataHandle);

	memset(&pData,0,sizeof(pData));
	pData.curArray = FoodOpinions;
	pData.maxArraySize = NUM_PROFILES;

	XML_SetUserData(parser, &pData);

	if(!XML_Parse(parser, lpcBuffer, uiFSize, TRUE))
	{
		CHAR8 errorBuf[511];

		sprintf(errorBuf, "XML Parser Error in FoodOpinion.xml: %s at line %d", XML_ErrorString(XML_GetErrorCode(parser)), XML_GetCurrentLineNumber(parser));
		LiveMessage(errorBuf);

		MemFree(lpcBuffer);
		return FALSE;
	}

	MemFree(lpcBuffer);

	XML_ParserFree(parser);

	return( TRUE );
}
示例#3
0
文件: buffile.c 项目: AnLingm/gpdb
/*
 * BufFileLoadBuffer
 *
 * Load some data into buffer, if possible, starting from curOffset.
 * At call, must have dirty = false, pos and nbytes = 0.
 * On exit, nbytes is number of bytes loaded.
 */
static int BufFileLoadBuffer(BufFile *file, void* buffer, size_t bufsize)
{
	int nb;

	/*
	 * May need to reposition physical file.
	 */
	if (FileSeek(file->file, file->offset, SEEK_SET) != file->offset)
	{
		elog(ERROR, "could not seek in temporary file: %m");
	}

	/*
	 * Read whatever we can get, up to a full bufferload.
	 */
	nb = FileRead(file->file, buffer, (int)bufsize);
	if (nb < 0)
	{
		elog(ERROR, "could not read from temporary file: %m");
	}

	/* we choose not to advance curOffset here */

	return nb;
}
示例#4
0
//// UploadKickstart() ////
char UploadKickstart(char *name)
{
  int keysize=0;
  char filename[12];

  strncpy(filename, name, 8); // copy base name
  strcpy(&filename[8], "ROM"); // add extension

  BootPrint("Checking for Amiga Forever key file:");
  if(FileOpen(&file,"ROM     KEY")) {
    keysize=file.size;
    if(file.size<sizeof(romkey)) {
      int c=0;
      while(c<keysize) {
        FileRead(&file, &romkey[c]);
        c+=512;
        FileNextSector(&file);
      }
      BootPrint("Loaded Amiga Forever key file");
    } else {
      BootPrint("Amiga Forever keyfile is too large!");
    }
  }
  BootPrint("Loading file: ");
  BootPrint(filename);

  if (RAOpen(&romfile, filename)) {
    if (romfile.size == 0x100000) {
      // 1MB Kickstart ROM
      BootPrint("Uploading 1MB Kickstart ...");
      SendFileV2(&romfile, NULL, 0, 0xe00000, romfile.size>>10);
      SendFileV2(&romfile, NULL, 0, 0xf80000, romfile.size>>10);
      return(1);
    } else if(romfile.size == 0x80000) {
示例#5
0
void		intelReadWord (
LPFILEBUF	ifd,	/* control block */
WORD FAR	*w)
{
    if (FileRead (ifd, (LPTR) w, sizeof (WORD)) != sizeof (WORD))
	ifd->err = -1;
}
示例#6
0
void getSystemVersion()
{
	File VersionFile;
	char sysver[16];
	if (FileOpen(&VersionFile, "/3ds/ASCFW/system.txt", 0)){
		FileRead(&VersionFile, sysver, 16, 0);
		FileClose(&VersionFile);
	}
	switch (sysver[0])
	{
	case '0': //Unsupported
		systemVersion = "unsupported"; type = 0;
		break;

	case '1':
		systemVersion = "Old 3DS V. 4.1 - 4.5";
		type = 1;
		break;

	case '2':
		systemVersion = "Old 3DS V. 8.0 - 8.1"; 
		type = 2;
		break;

	case '3':
		systemVersion = "Old 3DS V. 9.0-9.2"; 
		type = 3;
		break;

	case '4':
		systemVersion = "New 3DS V. 9.0 - 9.2";
		type = 4;
		break;
	}
}
// returns no of bytes of free memory  conform to sysinfo call
// return 0 if error occured
//we need /proc/meminfo for cached, which is not reported by sysinfo
int GetSysFreeMem( void )
{
#ifdef CYG
	return 0;
#else

	char szData[1024];

	int nLen = FileRead("/proc/meminfo", szData, sizeof(szData) - 1);

	if (nLen<=0)
	{	return -1;
	}
	szData[nLen] = 0;

	struct sysinfo inf;
	if ( sysinfo( &inf) )
	{
		LOG_ERR("ERROR GetSysFreeMem");
		inf.freeram=0;
	}

	struct statfs buf;
	long long nTmpUsed = 0;
	if( statfs( "/tmp", &buf)) {
		LOG_ERR( "GetSysFreeMem: statfs( \"tmp\") failed");
	}else{
		nTmpUsed= (buf.f_blocks-buf.f_bavail) * (long long) buf.f_bsize;
	}

	return inf.freeram * inf.mem_unit +
		( GetFreeMemFor( szData, "Buffers:") + GetFreeMemFor( szData, "Cached:")) * 1024 - nTmpUsed;

#endif
}
CIsa100Impl::SystemStatus* CIsa100Impl::getSystemStatus( void )
{
    struct sysinfo inf;
    struct statfs  buf;

    if ( sysinfo( &inf) )
    {
        LOG_ERR("ERROR getSystemStatus: sysinfo");
        inf.freeram = inf.totalram = 0;
    }
    if( statfs( "/access_node/", &buf))
    {
        LOG_ERR("ERROR getSystemStatus: statfs");
        buf.f_blocks = buf.f_bavail = buf.f_bsize = 0;
    }

    doProcessorStats();

    int nLen = FileRead("/proc/loadavg", m_systemStatus.load, sizeof(m_systemStatus.load) - 1);
    if (nLen<=0)
    {   nLen =0;
    }
    m_systemStatus.load[ nLen ] = 0;

    m_systemStatus.sysMemTotalKb = inf.totalram / 1024;
    m_systemStatus.sysMemFreeKb  = inf.freeram  / 1024;

    m_systemStatus.sysFlashTotalKb = buf.f_blocks * buf.f_bsize / 1024;
    m_systemStatus.sysFlashFreeKb  = buf.f_bavail * buf.f_bsize / 1024;

    return &m_systemStatus;
}
示例#9
0
文件: file.c 项目: smiley22/myPS2
char *FileGets( char *string, int num, FHANDLE fh )
{
	char	c;
	int		ret	= 0;
	int		i	= 0;

	while( i < num ) {
		ret = FileRead( fh, &c, 1 );

		if( ret < 1 )
			break;

		string[i] = c;
		i++;

		if( c == '\n' )
			break;
	}

	if( (i >= 2 ) && string[ i - 2 ] == '\r' ) {
		string[ i - 2 ] = '\n';
		string[ i - 1 ] = '\0';
	}
	else {
		string[i] = '\0';
	}

	if( ret < 1 )
		return NULL;

	return string;
}
示例#10
0
BOOLEAN IsSTCIETRLEFile( CHAR8 * ImageFile )
{
	HWFILE		hFile;
	STCIHeader	Header;
	UINT32		uiBytesRead;

	CHECKF( FileExists( ImageFile ) );

	// Open the file and read the header
	hFile = FileOpen( ImageFile, FILE_ACCESS_READ, FALSE );
	CHECKF( hFile );

	if (!FileRead( hFile, &Header, STCI_HEADER_SIZE, &uiBytesRead ) || uiBytesRead != STCI_HEADER_SIZE || memcmp( Header.cID, STCI_ID_STRING, STCI_ID_LEN ) != 0 )
	{
		DbgMessage( TOPIC_HIMAGE, DBG_LEVEL_3, "Problem reading STCI header." );
		FileClose( hFile );
		return( FALSE );
	}
	FileClose( hFile );
	if (Header.fFlags & STCI_ETRLE_COMPRESSED)
	{
	 return( TRUE );
	}
	else
	{
	 return( FALSE );
	}
}
示例#11
0
void		intelReadDWord (
LPFILEBUF	ifd,	/* control block */
DWORD FAR	*dw)
{
    if (FileRead (ifd, (LPTR) dw, sizeof (DWORD)) != sizeof (DWORD))
	ifd->err = -1;
}
示例#12
0
abyss_bool
ConnWriteFromFile(TConn *  const connectionP,
                  TFile *  const fileP,
                  uint64_t const start,
                  uint64_t const last,
                  void *   const buffer,
                  uint32_t const buffersize,
                  uint32_t const rate) {
    /*----------------------------------------------------------------------------
       Write the contents of the file stream *fileP, from offset 'start'
       up through 'last', to the HTTP connection *connectionP.

       Meter the reading so as not to read more than 'rate' bytes per second.

       Use the 'bufferSize' bytes at 'buffer' as an internal buffer for this.
    -----------------------------------------------------------------------------*/
    abyss_bool retval;
    uint32_t waittime;
    abyss_bool success;
    uint32_t readChunkSize;

    if (rate > 0) {
        readChunkSize = MIN(buffersize, rate);  /* One second's worth */
        waittime = (1000 * buffersize) / rate;
    } else {
        readChunkSize = buffersize;
        waittime = 0;
    }

    success = FileSeek(fileP, start, SEEK_SET);
    if (!success)
        retval = FALSE;
    else {
        uint64_t const totalBytesToRead = last - start + 1;
        uint64_t bytesread;

        bytesread = 0;  /* initial value */

        while (bytesread < totalBytesToRead) {
            uint64_t const bytesLeft = totalBytesToRead - bytesread;
            uint64_t const bytesToRead = MIN(readChunkSize, bytesLeft);

            uint64_t bytesReadThisTime;

            bytesReadThisTime = FileRead(fileP, buffer, bytesToRead);
            bytesread += bytesReadThisTime;

            if (bytesReadThisTime > 0)
                ConnWrite(connectionP, buffer, bytesReadThisTime);
            else
                break;

            if (waittime > 0)
                xmlrpc_millisecond_sleep(waittime);
        }
        retval = (bytesread >= totalBytesToRead);
    }
    return retval;
}
示例#13
0
文件: main.c 项目: Golui/rxTools
void LoadSettings(){
	char settings[]="000100";
	char str[100];
	File MyFile;
	if (FileOpen(&MyFile, "/rxTools/data/system.txt", 0))
	{
		if (FileGetSize(&MyFile) == 6)
		{
			FileRead(&MyFile, settings, 6, 0);
			bootGUI = (settings[0] == '1');
			agb_bios = (settings[2] == '1');
			theme_3d = (settings[3] == '1');
			silent_boot = (settings[4] == '1');
			
			/* Disable autostart after the first boot */
			if (first_boot && !bootGUI) bootGUI = true;
			
			/* Check if the Theme Number is valid */
			unsigned char theme_num = (settings[0] - 0x30);
			if (theme_num >= 0 && theme_num <= 9)
			{
				File Menu0;
				sprintf(str, "/rxTools/Theme/%c/menu0.bin", settings[1]);
				if (FileOpen(&Menu0, str, 0))
				{
					Theme = settings[1]; //check if the theme exists, else load theme 0 (default)
					FileClose(&Menu0);
				} else
					Theme = '0';
			} else {
				Theme = '0';
				FileWrite(&MyFile, &Theme, 1, 1);
			}

			/* Check if the Language Number is valid */
			if(settings[5] - 0x30 >= 0 && settings[5] - 0x30 <= N_LANG)
				language = settings[5] - 0x30;
			else
				language = 0;

			FileClose(&MyFile);
			return;
		} else {
			FileClose(&MyFile);
		}
	}
	
	/* Disable autostart after the first boot */
	bootGUI = first_boot;
	Theme = '0';
	agb_bios = false;
	
	/* Create system.txt */
	if (FileOpen(&MyFile, "/rxTools/data/system.txt", 1))
	{
		FileWrite(&MyFile, settings, 6, 0);
		FileClose(&MyFile);
	}
}
示例#14
0
文件: be-fsstubs.c 项目: GisKook/Gis
static Oid
lo_import_internal(text *filename, Oid lobjOid)
{
	File		fd;
	int			nbytes,
				tmp;
	char		buf[BUFSIZE];
	char		fnamebuf[MAXPGPATH];
	LargeObjectDesc *lobj;
	Oid			oid;

#ifndef ALLOW_DANGEROUS_LO_FUNCTIONS
	if (!superuser())
		ereport(ERROR,
				(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
				 errmsg("must be superuser to use server-side lo_import()"),
				 errhint("Anyone can use the client-side lo_import() provided by libpq.")));
#endif

	CreateFSContext();

	/*
	 * open the file to be read in
	 */
	text_to_cstring_buffer(filename, fnamebuf, sizeof(fnamebuf));
	fd = PathNameOpenFile(fnamebuf, O_RDONLY | PG_BINARY, S_IRWXU);
	if (fd < 0)
		ereport(ERROR,
				(errcode_for_file_access(),
				 errmsg("could not open server file \"%s\": %m",
						fnamebuf)));

	/*
	 * create an inversion object
	 */
	oid = inv_create(lobjOid);

	/*
	 * read in from the filesystem and write to the inversion object
	 */
	lobj = inv_open(oid, INV_WRITE, fscxt);

	while ((nbytes = FileRead(fd, buf, BUFSIZE)) > 0)
	{
		tmp = inv_write(lobj, buf, nbytes);
		Assert(tmp == nbytes);
	}

	if (nbytes < 0)
		ereport(ERROR,
				(errcode_for_file_access(),
				 errmsg("could not read server file \"%s\": %m",
						fnamebuf)));

	inv_close(lobj);
	FileClose(fd);

	return oid;
}
示例#15
0
int RARead(RAFile *file,unsigned char *pBuffer, unsigned long bytes)
{
	int result=1;
	// Since we can only read from the SD card on 512-byte aligned boundaries,
	// we need to copy in multiple pieces.
	unsigned long blockoffset=file->ptr&511;	// Offset within the current 512 block at which the previous read finished
												// Bytes blockoffset to 512 will be drained first, before reading new data.

	if(blockoffset)	// If blockoffset is zero we'll just use aligned reads and don't need to drain the buffer.
	{
		int i;
		int l=bytes;
		if(l>512)
			l=512;
		for(i=blockoffset;i<l;++i)
		{
			*pBuffer++=file->buffer[i];
		}
		file->ptr+=l-blockoffset;
		bytes-=l-blockoffset;
	}

	// We've now read any bytes left over from a previous read.  If any data remains to be read we can read it
	// in 512-byte aligned chunks, until the last block.
	while(bytes>511)
	{
		result&=FileRead(&file->file,pBuffer);	// Read direct to pBuffer
		FileNextSector(&file->file);
		bytes-=512;
		file->ptr+=512;
		pBuffer+=512;
	}

	if(bytes)	// Do we have any bytes left to read?
	{
		int i;
		result&=FileRead(&file->file,file->buffer);	// Read to temporary buffer, allowing us to preserve any leftover for the next read.
		FileNextSector(&file->file);
		for(i=0;i<bytes;++i)
		{
			*pBuffer++=file->buffer[i];
		}
		file->ptr+=bytes;
	}
	return(result);
}
示例#16
0
/*============================================================================

  Description: See documentation for standard C library fread

  ==========================================================================*/
size_t palm_fread( void* out_buf, size_t in_size, size_t in_count, PALM_FILE* io_pSF )
{
    Err err = 0;

    ChASSERT(io_pSF->volRef == ((UInt16)-1));

    return FileRead( io_pSF->file.fh, out_buf, in_size, in_count, &err );
}
示例#17
0
文件: file.c 项目: smiley22/myPS2
int FileGetc( FHANDLE fh )
{
	char c;

	FileRead( fh, &c, 1 );

	return c;
}
	// Return AAL_OK if chunk is found                                        //
	aalSBool ChunkFile::Find(const char * id)
	{
		aalUByte cc[4];

		FileSeek(file, offset, SEEK_CUR);

		while (FileRead(cc, 4, 1, file))
		{
			if (!FileRead(&offset, 4, 1, file)) return AAL_SFALSE;

			if (!memcmp(cc, id, 4)) return AAL_STRUE;

			if (FileSeek(file, offset, SEEK_CUR)) return AAL_SFALSE;
		}

		return AAL_SFALSE;
	}
示例#19
0
/**
 * @brief Takes a JSON document file path and parses its contents into a JsonDocument.
 *
 * Returns true iff successfull.
 */
bool JsonProcessor::FromFile (const std::string& fn, JsonDocument& document)
{
    if (!FileExists(fn)) {
        LOG_WARN << "JSON file '" << fn << "' does not exist.";
        return false;
    }
    return FromString(FileRead(fn), document);
}
	///////////////////////////////////////////////////////////////////////////////
	//                                                                           //
	// I/O                                                                       //
	//                                                                           //
	///////////////////////////////////////////////////////////////////////////////
	// Read!                                                                     //
	aalSBool ChunkFile::Read(aalVoid * buffer, const aalULong & size)
	{
		if (FileRead(buffer, 1, size, file) != size) return AAL_SFALSE;

		if (offset) offset -= size;

		return AAL_STRUE;
	}
示例#21
0
/**
 * @brief Reads a file and parses it as a Jplace document into a PlacementMap object.
 *
 * Returns true iff successful.
 */
bool JplaceProcessor::FromFile (const std::string& fn, PlacementMap& placements)
{
    if (!FileExists(fn)) {
        LOG_WARN << "Jplace file '" << fn << "' does not exist.";
        return false;
    }
    return FromString(FileRead(fn), placements);
}
示例#22
0
static bool
ConfReadLine(TFile *  const fileP,
             char *   const buffer,
             uint32_t const lenArg) {

    bool r;
    char c;
    char * p;
    char * z;
    uint32_t len;

    len = lenArg;  /* initial value */
    r = TRUE;  /* initial value */
    z = buffer;  /* initial value */

    while (--len > 0) {
        int32_t bytesRead;
        
        bytesRead = FileRead(fileP, z, 1);
        if (bytesRead < 1) {
            if (z == buffer)
                r = FALSE;
            break;
        };

        if (*z == CR || *z == LF)
            break;

        ++z;
    }

    if (len == 0)
        while (FileRead(fileP, &c, 1) == 1)
            if (c == CR || c == LF)
                break;

    *z = '\0';

    /* Discard comments */
    p = strchr(buffer, '#');
    if (p)
        *p = '\0';

    return r;
}
示例#23
0
//---------------------------------------------------------------------------
int __fastcall TSafeHandleStream::Read(void * Buffer, int Count)
{
  int Result = FileRead(FHandle, Buffer, Count);
  if (Result == -1)
  {
    RaiseLastOSError();
  }
  return Result;
}
示例#24
0
static void Nova_DumpSlots(void)
{
#define MAX_KEY_FILE_SIZE 16384  /* usually around 4000, cannot grow much */

    char filename[CF_BUFSIZE];
    int i;

    snprintf(filename, CF_BUFSIZE - 1, "%s%cts_key", GetStateDir(), FILE_SEPARATOR);

    char file_contents_new[MAX_KEY_FILE_SIZE] = {0};

    for (i = 0; i < CF_OBSERVABLES; i++)
    {
        char line[CF_MAXVARSIZE];

        if (NovaHasSlot(i))
        {
            snprintf(line, sizeof(line), "%d,%s,%s,%s,%.3lf,%.3lf,%d\n",
                    i,
                    NULLStringToEmpty((char*)NovaGetSlotName(i)),
                    NULLStringToEmpty((char*)NovaGetSlotDescription(i)),
                    NULLStringToEmpty((char*)NovaGetSlotUnits(i)),
                    NovaGetSlotExpectedMinimum(i), NovaGetSlotExpectedMaximum(i), NovaIsSlotConsolidable(i) ? 1 : 0);
        }
        else
        {
            snprintf(line, sizeof(line), "%d,spare,unused\n", i);
        }

        strlcat(file_contents_new, line, sizeof(file_contents_new));
    }

    bool contents_changed = true;

    Writer *w = FileRead(filename, MAX_KEY_FILE_SIZE, NULL);
    if (w)
    {
        if(strcmp(StringWriterData(w), file_contents_new) == 0)
        {
            contents_changed = false;
        }
        WriterClose(w);
    }

    if(contents_changed)
    {
        Log(LOG_LEVEL_VERBOSE, "Updating %s with new slot information", filename);

        if(!FileWriteOver(filename, file_contents_new))
        {
            Log(LOG_LEVEL_ERR, "Nova_DumpSlots: Could not write file '%s'. (FileWriteOver: %s)", filename,
                GetErrorStr());
        }
    }

    chmod(filename, 0600);
}
示例#25
0
/*============================================================================

  Description: See documentation for standard C library fgetc

  ==========================================================================*/
short palm_fgetc( PALM_FILE* io_pSF )
{
    Err err = 0;
    char cRet = 0;

    ChASSERT(io_pSF->volRef == ((UInt16)-1));

    return ( 1 == FileRead( io_pSF->file.fh, (void*)(&cRet), 1, 1, &err )) ? (short)cRet : EOF;
}
示例#26
0
BOOLEAN LoadContractRenewalDataFromSaveGameFile( HWFILE hFile )
{
	UINT32	uiNumBytesRead;

	FileRead( hFile, ContractRenewalList, sizeof( ContractRenewalList ), &uiNumBytesRead );
	if( uiNumBytesRead != sizeof( ContractRenewalList ) )
	{
		return( FALSE );
	}

	FileRead( hFile, &ubNumContractRenewals, sizeof( ubNumContractRenewals ), &uiNumBytesRead );
	if( uiNumBytesRead != sizeof( ubNumContractRenewals ) )
	{
		return( FALSE );
	}

  return( TRUE );
}
示例#27
0
BOOLEAN ReadInPatrolInfo(STR fileName)
{
	HWFILE		hFile;
	UINT32		uiBytesRead;
	UINT32		uiFSize;
	CHAR8 *		lpcBuffer;
	XML_Parser	parser = XML_ParserCreate(NULL);

	patrolParseData pData;


	// Open weapons file
	hFile = FileOpen( fileName, FILE_ACCESS_READ, FALSE );
	if ( !hFile )
		return( FALSE );

	uiFSize = FileGetSize(hFile);
	lpcBuffer = (CHAR8 *) MemAlloc(uiFSize+1);

	//Read in block
	if ( !FileRead( hFile, lpcBuffer, uiFSize, &uiBytesRead ) )
	{
		MemFree(lpcBuffer);
		return( FALSE );
	}

	lpcBuffer[uiFSize] = 0; //add a null terminator

	FileClose( hFile );


	XML_SetElementHandler(parser, patrolStartElementHandle, patrolEndElementHandle);
	XML_SetCharacterDataHandler(parser, patrolCharacterDataHandle);


	memset(&pData,0,sizeof(pData));
	XML_SetUserData(parser, &pData);
	iOrigPatrolArraySize = 0;

	if(!XML_Parse(parser, lpcBuffer, uiFSize, TRUE))
	{
		CHAR8 errorBuf[511];

		sprintf(errorBuf, "XML Parser Error in PatrolGroups.xml: %s at line %d", XML_ErrorString(XML_GetErrorCode(parser)), XML_GetCurrentLineNumber(parser));
		LiveMessage(errorBuf);

		MemFree(lpcBuffer);
		return FALSE;
	}

	MemFree(lpcBuffer);

	XML_ParserFree(parser);

	return TRUE;
}
示例#28
0
void HandleLimitedNumExecutions( )
{
	// Get system directory
  HWFILE     hFileHandle;
	UINT8	ubSysDir[ 512 ];
	INT8	bNumRuns;

	GetSystemDirectory( ubSysDir, sizeof( ubSysDir ) );

	// Append filename
	strcat( ubSysDir, "\\winaese.dll" );

	// Open file and check # runs...
	if ( FileExists( ubSysDir ) )
	{
		// Open and read
		if ( ( hFileHandle = FileOpen( ubSysDir, FILE_ACCESS_READ, FALSE)) == 0)
		{
			return;
		}

		// Read value
		FileRead( hFileHandle, &bNumRuns, sizeof( bNumRuns ) , NULL);

		// Close file
		FileClose( hFileHandle );

		if ( bNumRuns <= 0 )
		{
			// Fail!
			SET_ERROR( "Error 1054: Cannot execute - contact Sir-Tech Software." );
			return;
		}
		
	}
	else
	{
		bNumRuns = 10;
	}

	// OK, decrement # runs...
	bNumRuns--;

	// Open and write
	if ( ( hFileHandle = FileOpen( ubSysDir, FILE_ACCESS_WRITE, FALSE)) == 0)
	{
		return;
	}

	// Write value
	FileWrite( hFileHandle, &bNumRuns, sizeof( bNumRuns ) , NULL);

	// Close file
	FileClose( hFileHandle );

}
示例#29
0
文件: XmlConfig.cpp 项目: BMurri/wix3
static HRESULT BeginChangeFile(
    __in LPCWSTR pwzFile,
    __in int iCompAttributes,
    __inout LPWSTR* ppwzCustomActionData
    )
{
    Assert(pwzFile && *pwzFile && ppwzCustomActionData);

    HRESULT hr = S_OK;
    BOOL fIs64Bit = iCompAttributes & msidbComponentAttributes64bit;

    LPBYTE pbData = NULL;
    DWORD cbData = 0;

    LPWSTR pwzRollbackCustomActionData = NULL;

    if (fIs64Bit)
    {
        hr = WcaWriteIntegerToCaData((int)xaOpenFilex64, ppwzCustomActionData);
        ExitOnFailure(hr, "failed to write 64-bit file indicator to custom action data");
    }
    else
    {
        hr = WcaWriteIntegerToCaData((int)xaOpenFile, ppwzCustomActionData);
        ExitOnFailure(hr, "failed to write file indicator to custom action data");
    }

    hr = WcaWriteStringToCaData(pwzFile, ppwzCustomActionData);
    ExitOnFailure1(hr, "failed to write file to custom action data: %ls", pwzFile);

    // If the file already exits, then we have to put it back the way it was on failure
    if (FileExistsEx(pwzFile, NULL))
    {
        hr = FileRead(&pbData, &cbData, pwzFile);
        ExitOnFailure1(hr, "failed to read file: %ls", pwzFile);

        // Set up the rollback for this file
        hr = WcaWriteIntegerToCaData((int)fIs64Bit, &pwzRollbackCustomActionData);
        ExitOnFailure(hr, "failed to write component bitness to rollback custom action data");

        hr = WcaWriteStringToCaData(pwzFile, &pwzRollbackCustomActionData);
        ExitOnFailure1(hr, "failed to write file name to rollback custom action data: %ls", pwzFile);

        hr = WcaWriteStreamToCaData(pbData, cbData, &pwzRollbackCustomActionData);
        ExitOnFailure(hr, "failed to write file contents to rollback custom action data.");

        hr = WcaDoDeferredAction(PLATFORM_DECORATION(L"ExecXmlConfigRollback"), pwzRollbackCustomActionData, COST_XMLFILE);
        ExitOnFailure1(hr, "failed to schedule ExecXmlConfigRollback for file: %ls", pwzFile);

        ReleaseStr(pwzRollbackCustomActionData);
    }
LExit:
    ReleaseMem(pbData);

    return hr;
}
示例#30
0
//---------------------------------------------------------------------------
int __fastcall TSafeHandleStream::Read(System::DynamicArray<System::Byte> Buffer, int Offset, int Count)
{
  FAIL; // untested
  int Result = FileRead(FHandle, Buffer, Offset, Count);
  if (Result == -1)
  {
    RaiseLastOSError();
  }
  return Result;
}