Ejemplo n.º 1
0
static void
handleFile(TSession *   const sessionP,
           const char * const fileName,
           time_t       const fileModTime,
           MIMEType *   const mimeTypeP) {
/*----------------------------------------------------------------------------
   This is an HTTP request handler for a GET.  It does the classic
   web server thing: send the file named in the URL to the client.
-----------------------------------------------------------------------------*/
    TFile * fileP;
    bool success;
    
    success = FileOpen(&fileP, fileName, O_BINARY | O_RDONLY);
    if (!success)
        ResponseStatusErrno(sessionP);
    else {
        if (notRecentlyModified(sessionP, fileModTime)) {
            ResponseStatus(sessionP, 304);
            ResponseWriteStart(sessionP);
        } else
            sendFileAsResponse(sessionP, fileP,
                               fileName, fileModTime, mimeTypeP);

        FileClose(fileP);
    }
}
Ejemplo n.º 2
0
int mtFile::runRead( mtThreadWork::DataUser* pkDataUser )
{
	char*	pcFile	= getFileName(pkDataUser->pcAccount);

	if (NULL == pcFile)
	{
		return	mtProtocol::E_RESULT_FALT_FILE_INVALIDE_PATH;
	}

	if (0 == FileOpen(&pkDataUser->hFile, pcFile))
	{
		return	mtProtocol::E_RESULT_FALT_FILE_NOT_EXIST;
	}

	pkDataUser->iFileOffset			= getFileOffset(pkDataUser->pcAccount);
	pkDataUser->ulTransferBytes		= getDataFileBytes();

	pkDataUser->kOverlapped.Offset	= pkDataUser->iFileOffset;
	pkDataUser->eOverlappedType		= mtThread::E_OLT_LOCKFILEEx;
	pkDataUser->iFileRunType		= E_FILE_RUN_READ_FILE;
	
	if (0 == FileLock(pkDataUser->hFile, pkDataUser->ulTransferBytes, &pkDataUser->kOverlapped))
	{
		FileClose(&pkDataUser->hFile);
		return	mtProtocol::E_RESULT_FALT_FILE_LOCK;
	}

	return	mtProtocol::E_RESULT_SUCCESS;
}
Ejemplo n.º 3
0
DiskChunkReaderIteraror::DiskChunkReaderIteraror(const ChunkID& chunk_id,unsigned& chunk_size,const unsigned& block_size)
:ChunkReaderIterator(chunk_id,block_size,chunk_size){
	block_buffer_=new Block(block_size_);
	fd_=FileOpen(chunk_id_.partition_id.getPathAndName().c_str(),O_RDONLY);
	if(fd_==-1){
		printf("Failed to open file [%s], reason:%s\n",chunk_id_.partition_id.getPathAndName().c_str(),strerror(errno));
		number_of_blocks_=0;
	}
	else{
		const unsigned start_pos=CHUNK_SIZE*chunk_id_.chunk_off;
		const unsigned long length=lseek(fd_,0,SEEK_END);

		if(length<=start_pos){
			printf("fails to set the start offset %d for [%s]\n",start_pos,chunk_id.partition_id.getName().c_str());
			number_of_blocks_=0;
		}
		else{
			const unsigned offset=lseek(fd_,start_pos,SEEK_SET);
			printf("The file is set to be %d\n",offset);
//			sleep(1);
			if(start_pos+CHUNK_SIZE<length){
				number_of_blocks_=CHUNK_SIZE/block_size_;
			}
			else{
				number_of_blocks_=(length-start_pos)/block_size_;
				printf("This chunk has only %d blocks!\n",number_of_blocks_);
			}

		}
	}
}
Ejemplo n.º 4
0
void DumpNandPartitions(){
	int isEmuNand = checkEmuNAND() ? NandSwitch() : 0;
	if(isEmuNand == -1) return;
	char* p_name[] = { "twln.bin", "twlp.bin", "agb_save.bin", "firm0.bin", "firm1.bin", "ctrnand.bin" };
	unsigned int p_size[] = { 0x08FB5200, 0x020B6600, 0x00030000, 0x00400000, 0x00400000, 0x2F3E3600};
	unsigned int p_addr[] = { TWLN, TWLP, AGB_SAVE, FIRM0, FIRM1, CTRNAND };
	int sect_row = 0x80;

	ConsoleInit();
	ConsoleAddText(isEmuNand ? "EmuNAND Partitions Decryptor\n \n" : "NAND Partitions Decryptor\n \n");

	for(int i = 3; i < 6; i++){		//Cutting out twln, twlp and agb_save. Todo: Properly decrypt them
		File out;
		sprintf(myString, isEmuNand ? "nand/emu_%s" : "nand/%s", p_name[i]);
		FileOpen(&out, myString, 1);
		sprintf(myString, "Dumping %s ...", p_name[i]);
		ConsoleAddText(myString);
		ConsoleShow();

		for(int j = 0; j*0x200 < p_size[i]; j += sect_row){
			sprintf(myString, "%08X / %08X", j*0x200, p_size[i]);
			int x, y; ConsoleGetXY(&x, &y); y += CHAR_WIDTH * 4; x += CHAR_WIDTH*2;
			DrawString(TOP_SCREEN, myString, x, y, ConsoleGetTextColor(), ConsoleGetBackgroundColor());

			if(isEmuNand) emunand_readsectors(j, sect_row, BUF1, p_addr[i]);
			else nand_readsectors(j, sect_row, BUF1, p_addr[i]);
			FileWrite(&out, BUF1, sect_row*0x200, j*0x200);
		}
		FileClose(&out);
	}
	ConsoleAddText("\nPress A to exit"); ConsoleShow();
	WaitForButton(BUTTON_A);
}
Ejemplo n.º 5
0
void OnDropFile (DWORD wParam)
   {
   TCHAR FileName [FilePathLen + 1] ;
   LPTSTR         pFileNameStart ;
   HANDLE         hFindFile ;
   WIN32_FIND_DATA FindFileInfo ;
   int            NameOffset ;
   int            NumOfFiles = 0 ;

   NumOfFiles = DragQueryFile ((HDROP) wParam, 0xffffffff, NULL, 0) ;
   if (NumOfFiles > 0)
      {
      // we only open the first file for now
      DragQueryFile((HDROP) wParam, 0, FileName, FilePathLen) ;

      pFileNameStart = ExtractFileName (FileName) ;
      NameOffset = pFileNameStart - FileName ;

      // convert short filename to long NTFS filename if necessary
      hFindFile = FindFirstFile (FileName, &FindFileInfo) ;
      if (hFindFile && hFindFile != INVALID_HANDLE_VALUE)
         {
         // append the file name back to the path name
         lstrcpy (&FileName[NameOffset], FindFileInfo.cFileName) ;
         FindClose (hFindFile) ;
         }

      FileOpen (hWndMain, (int)0, (LPTSTR)FileName) ;
      PrepareMenu (GetMenu (hWndMain));
      }

   DragFinish ((HDROP) wParam) ;
   }
Ejemplo n.º 6
0
BOOLEAN WriteInActionItems(STR fileName)
{
	HWFILE		hFile;

	//Debug code; make sure that what we got from the file is the same as what's there
	// Open a new file
	hFile = FileOpen( fileName, FILE_ACCESS_WRITE | FILE_CREATE_ALWAYS, FALSE );
	if ( !hFile )
		return( FALSE );

	{
		UINT32 cnt;

		FilePrintf(hFile,"<ACTION_ITEM_LIST>\r\n");
		for(cnt = 0;cnt < /*501*/NUM_ACTIONITEMS;cnt++)
		{
			FilePrintf(hFile,"\t<ACTION_ITEM>\r\n");
			FilePrintf(hFile,"\t\t<uiIndex>%d</uiIndex>\r\n", cnt);
			FilePrintf(hFile,"\t\t<Name>Empty action</Name>\r\n");	
			FilePrintf(hFile,"\t\t<ActionID>%d</ActionID>\r\n", ActionItemsValues[cnt].ActionID);
			FilePrintf(hFile,"\t\t<Blow_up>%d</Blow_up>\r\n", ActionItemsValues[cnt].BlowUp);	
			FilePrintf(hFile,"\t\t<BombItem>%d</BombItem>\r\n", ActionItemsValues[cnt].BombItem);				
			FilePrintf(hFile,"\t</ACTION_ITEM>\r\n");
		}
		FilePrintf(hFile,"</ACTION_ITEM_LIST>\r\n");
	}
	FileClose( hFile );

	return( TRUE );
}
Ejemplo n.º 7
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 );
	}
}
Ejemplo n.º 8
0
STATIC
EFI_STATUS
DoDump(
  IN EFI_DEVICE_PATH_PROTOCOL *Device
  )
{
  EFI_STATUS Status;
  EFI_FILE_PROTOCOL *File;

  Status = FileOpen (Device,
                     mFvInstance->MappedFile,
                     &File,
                     EFI_FILE_MODE_WRITE |
                     EFI_FILE_MODE_READ);
  if (EFI_ERROR (Status)) {
    return Status;
  }

  Status = FileWrite (File,
                      mFvInstance->Offset,
                      mFvInstance->FvBase,
                      mFvInstance->FvLength);
  FileClose (File);
  return Status;
}
Ejemplo n.º 9
0
BOOLEAN WriteInGarrisonInfo(STR fileName)
{
	HWFILE		hFile;

	hFile = FileOpen( fileName, FILE_ACCESS_WRITE | FILE_CREATE_ALWAYS, FALSE );
	if ( !hFile )
		return( FALSE );

	{
		INT8 cnt;


		FilePrintf(hFile,"<GARRISON_INFO>\r\n");
		for(cnt = 0; cnt < 57; cnt++)
		{
			FilePrintf(hFile,"\t<GARRISON>\r\n");

			FilePrintf(hFile,"\t\t<Sector>%c%d</Sector>\r\n",
				(gOrigGarrisonGroup[cnt].ubSectorID / 16 + 0x41),
				(gOrigGarrisonGroup[cnt].ubSectorID % 16 + 1));

			FilePrintf(hFile,"\t\t<Composition>%d</Composition>\r\n",
				gOrigGarrisonGroup[cnt].ubComposition);

			FilePrintf(hFile,"\t</GARRISON>\r\n");
		}
		FilePrintf(hFile,"</GARRISON_INFO>\r\n");
	}
	FileClose( hFile );

	return TRUE;
}
Ejemplo n.º 10
0
int BlockManager::loadFromDisk(const ChunkID& chunk_id,void* const &desc,const unsigned & length)const{
	int ret;
	unsigned offset=chunk_id.chunk_off;
	int fd=FileOpen(chunk_id.partition_id.getPathAndName().c_str(),O_RDONLY);
	if(fd==-1){
		logging_->elog("Fail to open file [%s].Reason:%s",chunk_id.partition_id.getPathAndName().c_str(),strerror(errno));
		return -1;
	}
	else{
		logging_->log("file [%s] is opened for offset[%d]\n",chunk_id.partition_id.getPathAndName().c_str(),offset);
	}
	long int file_length=lseek(fd,0,SEEK_END);

	long start_pos=CHUNK_SIZE*offset;
	logging_->log("start_pos=%ld**********\n",start_pos);

	lseek(fd,start_pos,SEEK_SET);
	if(start_pos<file_length){
		ret=read(fd,desc,length);
	}
	else{
		ret=0;
	}
	FileClose(fd);
	return ret;
}
Ejemplo n.º 11
0
BOOLEAN WriteLoadScreenHints( STR fileName)
{
	HWFILE		hFile;

	//Debug code; make sure that what we got from the file is the same as what's there
	// Open a new file
	hFile = FileOpen( fileName, FILE_ACCESS_WRITE | FILE_CREATE_ALWAYS, FALSE );
	if ( !hFile )
		return( FALSE );

	{
		UINT32 cnt;

		FilePrintf(hFile,"<LOADSCREENHINTS>\r\n");
		for(cnt = 0; cnt < num_found_loadscreenhints; ++cnt)
		{
			FilePrintf(hFile,"\t<LOADSCREENHINT>\r\n");
			FilePrintf(hFile,"\t\t<uiIndex>%d</uiIndex>\r\n",				cnt);			
			FilePrintf(hFile,"\t\t<usFlags>%d</usFlags>\r\n",				zLoadScreenHint[cnt].usFlags);
			
			FilePrintf(hFile,"\t</LOADSCREENHINT>\r\n");
		}
		FilePrintf(hFile,"</LOADSCREENHINTS>\r\n");
	}
	FileClose( hFile );

	return( TRUE );
}
BOOLEAN WriteIncompatibleAttachmentStats()
{
	HWFILE		hFile;

	//Debug code; make sure that what we got from the file is the same as what's there
	// Open a new file
	hFile = FileOpen( "TABLEDATA\\IncompatibleAttachments out.xml", FILE_ACCESS_WRITE | FILE_CREATE_ALWAYS, FALSE );
	if ( !hFile )
		return( FALSE );

	{
		UINT32 cnt;

		FilePrintf(hFile,"<INCOMPATIBLEATTACHMENTLIST>\r\n");
		for(cnt = 0;cnt < MAXATTACHMENTS;cnt++)
		{
			FilePrintf(hFile,"\t<INCOMPATIBLEATTACHMENT>\r\n");

			FilePrintf(hFile,"\t\t<itemIndex>%d</itemIndex>\r\n",							IncompatibleAttachments[cnt][0]);
			FilePrintf(hFile,"\t\t<incompatibleattachmentIndex>%d</incompatibleattachmentIndex>\r\n",						IncompatibleAttachments[cnt][1]);

			FilePrintf(hFile,"\t</INCOMPATIBLEATTACHMENT>\r\n");
		}
		FilePrintf(hFile,"</INCOMPATIBLEATTACHMENTLIST>\r\n");
	}
	FileClose( hFile );

	return( TRUE );
}
Ejemplo n.º 13
0
BOOLEAN WriteFoodStats()
{
	//DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"writefoodsstats");
	HWFILE		hFile;

	//Debug code; make sure that what we got from the file is the same as what's there
	// Open a new file
	hFile = FileOpen( "TABLEDATA\\Food out.xml", FILE_ACCESS_WRITE | FILE_CREATE_ALWAYS, FALSE );
	if ( !hFile )
		return( FALSE );

	{
		UINT32 cnt;

		FilePrintf(hFile,"<FOODSLIST>\r\n");
		for(cnt = 0; cnt < FOOD_TYPE_MAX; ++cnt)
		{
			FilePrintf(hFile,"\t<FOOD>\r\n");

			FilePrintf(hFile,"\t\t<uiIndex>%d</uiIndex>\r\n",				cnt );
			FilePrintf(hFile,"\t\t<bFoodPoints>%d</bFoodPoints>\r\n",		Food[cnt].bFoodPoints	);
			FilePrintf(hFile,"\t\t<bDrinkPoints>%d</bDrinkPoints>\r\n",		Food[cnt].bDrinkPoints	);
			FilePrintf(hFile,"\t\t<usDecayRate>%4.2f</usDecayRate>\r\n",	Food[cnt].usDecayRate	);

			FilePrintf(hFile,"\t</FOOD>\r\n");
		}
		FilePrintf(hFile,"</FOODSLIST>\r\n");
	}
	FileClose( hFile );

	return( TRUE );
}
Ejemplo n.º 14
0
vi_rc OpenFcbData( file *f )
{
    int         handle;
    vi_rc       rc;
    fcb         *cfcb;

    /*
     * open file handle if we need to
     */
    rc = ERR_NO_ERR;
    if( !f->is_stdio ) {
        handle = -1;
        ConditionalChangeDirectory( f->home );
        rc = FileOpen( f->name, false, O_BINARY | O_RDONLY, 0, &handle );
        if( rc != ERR_NO_ERR ) {
            return( ERR_FILE_OPEN );
        }
        if( handle == -1 ) {
            rc = ERR_FILE_NOT_FOUND;
        } else if( f->size == 0 ) {
            close( handle );
            rc = END_OF_FILE;
        } else {
            f->handle = handle;
        }
        if( rc != ERR_NO_ERR ) {
            cfcb = FcbAlloc( f );
            AddLLItemAtEnd( (ss **)&(f->fcbs.head), (ss **)&(f->fcbs.tail), (ss *)cfcb );
            CreateNullLine( cfcb );
        }
    }
    return( rc );
}
Ejemplo n.º 15
0
int CheckInstallationData(){
	File file;
	char str[32];
	if(!FileOpen(&file, "rxTools/data/0004013800000002.bin", 0)) return -1;
	FileClose(&file);
	if(!FileOpen(&file, "rxTools/data/0004013800000202.bin", 0)) return -2;
	FileClose(&file);
	if(!FileOpen(&file, "rxTools/data/0004013800000102.bin", 0)) return -3;
	FileClose(&file);
	if(!FileOpen(&file, "rxTools/data/data.bin", 0)) return -4;
	FileRead(&file, str, 32, 0);
	FileClose(&file);
	if(memcmp(str, __DATE__, 11)) return -5;
	if(memcmp(&str[12], __TIME__, 8)) return -5;
	return 0;
}
Ejemplo n.º 16
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;
}
Ejemplo n.º 17
0
Archivo: cfw.c Proyecto: nastys/rxTools
int applyPatch(void *file, const char *patch, const FirmInfo *info)
{
	File fd;
	Elf32_Ehdr ehdr;
	Elf32_Shdr shdr;
	unsigned int cur, off;

	if (!FileOpen(&fd, patch, 0))
		return 1;

	if (FileRead(&fd, &ehdr, sizeof(ehdr), 0) < 0)
		return 1;

	cur = ehdr.e_shoff;
	for (; ehdr.e_shnum; ehdr.e_shnum--, cur += sizeof(shdr)) {
		if (FileRead(&fd, &shdr, sizeof(shdr), cur) < 0)
			continue;

		if (shdr.sh_type != SHT_PROGBITS || !(shdr.sh_flags & SHF_ALLOC))
			continue;

		off = addrToOff(shdr.sh_addr, info);
		if (off == 0)
			continue;

		FileRead(&fd, (void *)((uintptr_t)file + off), shdr.sh_size, shdr.sh_offset);
	}

	return 0;
}
Ejemplo n.º 18
0
void SavePack(){
	File FilePack; FileOpen(&FilePack, "rxTools.dat", 0);
	DecryptPartition(&packInfo);
	FileWrite(&FilePack, FILEPACK_ADDR, FILEPACK_SIZE, FILEPACK_OFF);
	FileClose(&FilePack);
	DecryptPartition(&packInfo);
}
Ejemplo n.º 19
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) {
Ejemplo n.º 20
0
MultiViewerMain::MultiViewerMain( wxWindow* parent )
:MainFrame( parent )
{
	m_nGridEventRow = m_nGridEventCol = 0;
	m_eProgramState = eStateInit;
	m_eGridState = eGridCommon;
	m_bDirty = false;
	m_nSelectedTable = 0;
	m_pSQLReader = NULL;

	m_nEditRow = -1;
	m_nEditRowCount = 0;
	m_nAddRow = -1;
	m_nCancelRow = -1;

	////// Trace 를 볼 수 있게 하기 위해  Log 를 연결함
#if wxUSE_LOG
	mLogger = new wxLogTextCtrl( m_pLOGTextCtrl);

	mLogOld = wxLog::SetActiveTarget( mLogger );
	wxLog::SetTimestamp( "" );

	MidInter* pMid = NULL;
	pMid = MidInter::GetInstance();
	pMid->SetTraceCB(MultiViewerMain::TraceMessage);
#endif // wxUSE_LOG

#if	DEBUG_AUTO_FILE_LOAD
	m_pSQLReader = new SqliteReader();
	FileOpen( "..\\db\\test.db" );
#endif 
}
Ejemplo n.º 21
0
acoral_32 acoral_open(const acoral_char *pathname,acoral_32 oflag)
{
	acoral_u32 ret;
	acoral_32 fd;
	acoral_u8 len;
	acoral_char flag[3];
	acoral_char *pflag=flag;
	acoral_char *path;
	len=acoral_str_len(pathname);
	if(path=(acoral_char *)acoral_malloc2(len+1))
	{
		acoral_str_cpy(path,pathname);
		path[len]=0;
	}
	else
		return -1;
		
	if(oflag&O_RDONLY)
		*pflag++='r';
	if(oflag&O_WRONLY)
		*pflag++='w';
	*pflag='\0';
	ret=acoral_mutex_pend(fs_mutex,0);
	if(ret!=MUTEX_SUCCED)
	{
		acoral_free2(path);
		return -1;
	}
	fd=FileOpen(path,flag);
	acoral_mutex_post(fs_mutex);
	acoral_free2(path);
	return fd;
}
Ejemplo n.º 22
0
void MultiViewerMain::OnUIFileOpen(wxCommandEvent& )
{
    //wxMessageBox(_("Test"), _("OnMenuFileOpen"));

	Trace(emTraceProgramProcess, "File Open");

	if(!ConfirmNewDialog())
	{
		return;
	}

    wxString wxstrFileNmae;
    wxFileDialog fileDlg(this);
	if(fileDlg.ShowModal() != wxID_OK)
	{
		fileDlg.Destroy();
		return;
	}
	m_pSQLReader = new SqliteReader();


	wxstrFileNmae = fileDlg.GetDirectory();
	wxstrFileNmae.Append(wxFileName::GetPathSeparator());
	wxstrFileNmae += fileDlg.GetFilename();
	std::string strFileName = SQLUtil::wxstr2str(wxstrFileNmae);
	FileOpen( strFileName.c_str() );
	fileDlg.Destroy();

}
Ejemplo n.º 23
0
INT32 GetNumberOfHistoryPages()
{
	HWFILE hFileHandle;
	UINT32	uiFileSize=0;
	UINT32  uiSizeOfRecordsOnEachPage = 0;
	INT32		iNumberOfHistoryPages = 0;
	
	if ( ! (FileExists( HISTORY_DATA_FILE ) ) )
		return( 0 );

	// open file
 	hFileHandle=FileOpen( HISTORY_DATA_FILE,( FILE_OPEN_EXISTING |  FILE_ACCESS_READ ), FALSE );

	// failed to get file, return
	if(!hFileHandle)
	{
		return( 0 );
  }

	// make sure file is more than 0 length
  if ( FileGetSize( hFileHandle ) == 0 )
	{
    FileClose( hFileHandle );
		return( 0 );
	}

	uiFileSize = FileGetSize( hFileHandle ) - 1;
	uiSizeOfRecordsOnEachPage = ( NUM_RECORDS_PER_PAGE * ( sizeof( UINT8 ) + sizeof( UINT32 ) + 3*sizeof( UINT8 )+ sizeof(INT16) + sizeof( INT16 ) ) );

	iNumberOfHistoryPages = (INT32)( uiFileSize / uiSizeOfRecordsOnEachPage );

	FileClose( hFileHandle );

	return( iNumberOfHistoryPages );
}
Ejemplo n.º 24
0
void fileProcessing(void)
{
	Int16  key;

	if((taskList & FILEPROCESSING) == 0)	return;

//	key = EZDSP5535_SAR_getKey();
	key = -1;
	if(key == SW1)
	if(FHandle == Not_Open_FILE) {
		LCD_print("RECORDING......", 0);
		FHandle = FileOpen("A:\\VOICE000.TXT", FILE_FLAGS_WRITE);
	}

	if(key == SW2)
	if(FHandle != Not_Open_FILE) {
		LCD_print("SAVE VOICE000.DAT", 0); 
		FileClose(FHandle);
		AllCacheWriteBack();
		FHandle = Not_Open_FILE;
	}

//	if (FHandle != Not_Open_FILE)
//		FileWrite(&RfByte[2], number_of_bytes_per_frame, FHandle);

	taskList &= ~FILEPROCESSING;
}
Ejemplo n.º 25
0
static Int2 LIBCALLBACK VSMGenericAsnSave (OMProcControlPtr ompcp, CharPtr mode )
{
    Char filename[255];
    SelStructPtr  ssp, sel;
#ifdef WIN_MAC
    FILE * fp;
#endif
  ValNodePtr entity_list = NULL, vnp;
  SelectedSaveData ssd;

  ssp = ObjMgrGetSelected();
  if (ssp == NULL)
    {
        return OM_MSG_RET_ERROR;
    }
    
    for (sel = ssp; sel != NULL; sel = sel->next)
    {
      for (vnp = entity_list;
           vnp != NULL && vnp->data.intvalue != sel->entityID;
           vnp = vnp->next)
      {}
      if (vnp == NULL)
      {
        ValNodeAddInt (&entity_list, 0, sel->entityID);
      }
    }

    ssd.omp = ObjMgrGet();

  /* get file name to use */    
    filename[0] = '\0';
    if (GetOutputFileName(filename, (size_t)254, NULL))
    {
        WatchCursor();
#ifdef WIN_MAC
        fp = FileOpen (filename, "r");
        if (fp != NULL) {
            FileClose (fp);
        } else {
            FileCreate (filename, "TEXT", "ttxt");
        }
#endif

        ssd.aip = AsnIoOpen(filename, mode);
        ssd.ssp = ssp;
    
      for (vnp = entity_list; vnp != NULL; vnp = vnp->next)
      {
        SaveSeqLocEntity (vnp->data.intvalue, &ssd);
      GatherObjectsInEntity (vnp->data.intvalue, 0, NULL, SaveOneSelectedItem, (Pointer) &ssd, NULL);
      }

    ValNodeFree (entity_list);
        AsnIoClose(ssd.aip);
        ArrowCursor();
    }
    
    return OM_MSG_RET_DONE;
}
Ejemplo n.º 26
0
void __fastcall TFrmMain::btRowSaveClick(TObject* Sender)
{
    if (OpenOk == false) return;

    int iFileHandle; //文件句柄
    char Txtbuf[255];
    int iVal;
    char buf[4];
    float fVal;
    FILE* stream;
    long curpos, length;
    DWORD dwRows, dwCols, dwRowLen, dwTextLen;

    DWORD dwTextStartPos;
    char* pTextPtr ;


    //if ((stream = fopen(CurrentOpenFile.c_str(), "r+"))
    //    == NULL)
    //{
    //   ShowMessage("打开文件出错");
    //   return;
    //}

    //curpos = ftell(stream);
    //fseek(stream, 0L, SEEK_END);
    //length = ftell(stream);
    iFileHandle = FileOpen(CurrentOpenFile, fmOpenRead | fmOpenWrite); //打开文件

    for (int i = 0; i < sgEdit->ColCount - 1; i++)
    {
        switch (thOpen->ColType[i])
        {
            case 0: //整型值             sgEdit->Row
                //fseek(stream, 0x14+((sgEdit->Row-1)*(sgEdit->ColCount-1)+i)*4, 0);
                //iVal=StrToInt(sgEdit->Cells[i+1][sgEdit->Row]);
                //fwrite(&iVal, 4, 1, stream);
                iVal = StrToInt(sgEdit->Cells[i + 1][sgEdit->Row]);
                memcpy(buf, &iVal, 4);
                FileSeek(iFileHandle, 0x14 + ((sgEdit->Row - 1) * (sgEdit->ColCount - 1) + i) * 4, 0);
                FileWrite(iFileHandle, buf, 4);
                break;
            case 1: //浮点值
                //fseek(stream, 0x14+((sgEdit->Row-1)*(sgEdit->ColCount-1)+i)*4, 0);
                //fVal=StrToFloat(sgEdit->Cells[i+1][sgEdit->Row]);
                //fwrite(&fVal, 4, 1, stream);
                fVal = StrToFloat(sgEdit->Cells[i + 1][sgEdit->Row]);
                memcpy(buf, &fVal, 4);
                FileSeek(iFileHandle, 0x14 + ((sgEdit->Row - 1) * (sgEdit->ColCount - 1) + i) * 4, 0);
                FileWrite(iFileHandle, buf, 4);
                break;
            case 2: //文本   不存
                break;
        }
    }
    //fclose(stream);
    FileClose(iFileHandle);
    ShowMessage("The " + IntToStr(sgEdit->Row) + " Row Write Ok!");
}
Ejemplo n.º 27
0
Archivo: dem.c Proyecto: staring/RosFE
static VOID WINAPI DosSystemBop(LPWORD Stack)
{
    /* Get the Function Number and skip it */
    BYTE FuncNum = *(PBYTE)SEG_OFF_TO_PTR(getCS(), getIP());
    setIP(getIP() + 1);

    switch (FuncNum)
    {
        case 0x11:  // Load the DOS kernel
        {
            BOOLEAN Success = FALSE;
            HANDLE  hDosKernel;
            ULONG   ulDosKernelSize = 0;

            DPRINT1("You are loading Windows NT DOS!\n");

            /* Open the DOS kernel file */
            hDosKernel = FileOpen("ntdos.sys", &ulDosKernelSize);

            /* If we failed, bail out */
            if (hDosKernel == NULL) goto Quit;

            /*
             * Attempt to load the DOS kernel into memory.
             * The segment where to load the DOS kernel is defined
             * by the DOS BIOS and is found in DI:0000 .
             */
            Success = FileLoadByHandle(hDosKernel,
                                       REAL_TO_PHYS(TO_LINEAR(getDI(), 0x0000)),
                                       ulDosKernelSize,
                                       &ulDosKernelSize);

            DPRINT1("Windows NT DOS loading %s at %04X:%04X, size 0x%X ; GetLastError() = %u\n",
                    (Success ? "succeeded" : "failed"),
                    getDI(), 0x0000,
                    ulDosKernelSize,
                    GetLastError());

            /* Close the DOS kernel file */
            FileClose(hDosKernel);

Quit:
            if (!Success)
            {
                /* We failed everything, stop the VDM */
                EmulatorTerminate();
            }

            break;
        }

        default:
        {
            DPRINT1("Unknown DOS System BOP Function: 0x%02X\n", FuncNum);
            // setCF(1); // Disable, otherwise we enter an infinite loop
            break;
        }
    }
}
Ejemplo n.º 28
0
/**
* Parse and execute a simple command, by either creating a new processing or
* internally process it.
*/
bool parse_simple(simple_command_t *s, int level, command_t *father, HANDLE *h)
{
  BOOL ret;
  SECURITY_ATTRIBUTES sa;
  STARTUPINFO siStartupInfo;
  PROCESS_INFORMATION piProcessInfo;
  HANDLE hOutFile = INVALID_HANDLE_VALUE;
  HANDLE hInFile = INVALID_HANDLE_VALUE;
  HANDLE hErrFile = INVALID_HANDLE_VALUE;
  BOOL changed = FALSE;
  int f_ret;

  ZeroMemory(&sa, sizeof(SECURITY_ATTRIBUTES));
  sa.nLength = sizeof(SECURITY_ATTRIBUTES);
  sa.bInheritHandle = TRUE;

  ZeroMemory(&siStartupInfo, sizeof(siStartupInfo));
  ZeroMemory(&piProcessInfo, sizeof(piProcessInfo));

  siStartupInfo.cb = sizeof(siStartupInfo); 
  /* TODO sanity checks */

  if(s->verb->next_part != NULL){
    ret = SetEnvironmentVariable((LPCTSTR)s->verb->string, (LPCTSTR)s->verb->next_part->next_part->string);
    return ret-1;
  }

  /* TODO if builtin command, execute the command */
  if(strcmp(s->verb->string, "exit") == 0 || strcmp(s->verb->string, "quit") == 0){
    exit(0);
  }
  if(strcmp(s->verb->string, "cd") == 0){
    if(s->params){
      changed = SetCurrentDirectory(get_word(s->params));
    }
    if(changed){
      return 0;
    }
    else{
      hOutFile = FileOpen((LPCSTR)get_word(s->out), "w");
      CloseHandle(hOutFile);
      return 0;
    }
  }
  /* TODO if variable assignment, execute the assignment and return
  * the exit status */

  /* TODO if external command:
  *  1. set handles
  *  2. redirect standard input / output / error
  *  3. run command
  *  4. get exit code
  */

  redirrect_command(s, &siStartupInfo, &hInFile, &hOutFile, &hErrFile);
  f_ret = exec_simple_proc(s, hErrFile, sa, siStartupInfo, piProcessInfo); /* TODO replace with actual exit status */
  close_handles(hInFile, hOutFile, hErrFile);
  return f_ret;
}
Ejemplo n.º 29
0
int FileCopy(char* dest, char* source)
{
	File out;
	File in;
	if (!FileOpen(&in, source, 0)) return -1;
	if (!FileOpen(&out, dest, 1)) return -1;
	
	unsigned int size = FileGetSize(&in);
	if (size == 0)
	{
		FileClose(&in);
		FileClose(&out);
		return -1;
	}
	
	int pos = 0, res = 1;
	unsigned int i, chunk_size = 0x4000;
	unsigned char* buf = 0x26000200;
	
	for (i = 0; i < size; i += chunk_size)
	{
		if (chunk_size > (size - i)) chunk_size = (size - i);
		
		int rb = FileRead(&in, buf, chunk_size, i);
		if (rb != chunk_size)
		{
			/* error or eof */
			res = -1;
			break;
		}
		
		int wb = FileWrite(&out, buf, chunk_size, i);
		if (wb != chunk_size)
		{
			/* error or disk full */
			res = -2;
			break;
		}
		
		pos += wb;
	}
	
	FileClose(&in);
	FileClose(&out);
	return res;
}
Ejemplo n.º 30
0
/* -- SSH --
   Create file <database_name> (without extention), which is concatenation
   of all FASTA files used. Used by RPS Blast.
*/
Boolean RPSConcatSequences(FILE *sfp, CharPtr fastaname)
{
    FILE *fasta_fp, *fd;
    Char oneFileName[MAXLINELEN]; /*for reading one line per file*/
    Char buffer[1024];
    Int4 bytes;
    CharPtr chptr, last_non_space;

    if((fasta_fp = FileOpen(fastaname, "w")) == NULL) {
        ErrPostEx(SEV_FATAL, 1, 0, "concatenate sequences: "
                  "Unable to open target fasta file %s: %s\n",
                  fastaname, strerror(errno));
        return FALSE;
    }

    rewind(sfp);
    
    while (fgets(oneFileName, MAXLINELEN, sfp)) {

        /* Remove trailing whitespace */
        last_non_space = NULL;
        for(chptr = oneFileName; *chptr != NULLB; chptr++) {
            if (!isspace(*chptr))
                last_non_space = chptr;
        }
        if (last_non_space != NULL)
            last_non_space[1] = NULLB;
        
        if((fd = FileOpen(oneFileName, "r")) == NULL) {
            ErrPostEx(SEV_FATAL, 1, 0, "concatenate sequences: "
                      "Unable to open source fasta file %s: %s\n",
                      oneFileName, strerror(errno));
            FileClose(fasta_fp);
            return FALSE;
        }
        
        /* Now concatenating this file into set */
        while((bytes = FileRead(buffer, 1, 1024, fd)) > 0)
            FileWrite(buffer, 1, bytes, fasta_fp);
        FileClose(fd);
    }
    
    FileClose(fasta_fp);
    
    return TRUE;
}