int DLLEXPORT SMO_open(SMOutputAPI* smoapi, const char* path)
//
//  Purpose: Open the output binary file and read epilogue.
//
{
	int version, err, errorcode = 0;
	F_OFF offset;

	strncpy(smoapi->name, path, MAXFILENAME);

	// --- open the output file
	if ((smoapi->file = fopen(path, "rb")) == NULL) errorcode = 434;
    // --- validate the output file
	else if ((err = validateFile(smoapi)) != 0) errorcode = err;

	else {
		// --- otherwise read additional parameters from start of file
		fread(&version, RECORDSIZE, 1, smoapi->file);
		fread(&(smoapi->FlowUnits), RECORDSIZE, 1, smoapi->file);
		fread(&(smoapi->Nsubcatch), RECORDSIZE, 1, smoapi->file);
		fread(&(smoapi->Nnodes), RECORDSIZE, 1, smoapi->file);
		fread(&(smoapi->Nlinks), RECORDSIZE, 1, smoapi->file);
		fread(&(smoapi->Npolluts), RECORDSIZE, 1, smoapi->file);

		// Skip over saved subcatch/node/link input values
		offset = (smoapi->Nsubcatch + 2) * RECORDSIZE  // Subcatchment area
			  + (3 * smoapi->Nnodes + 4) * RECORDSIZE  // Node type, invert & max depth
			  + (5 * smoapi->Nlinks + 6) * RECORDSIZE; // Link type, z1, z2, max depth & length
		offset += smoapi->ObjPropPos;

		fseeko64(smoapi->file, offset, SEEK_SET);

		// Read number & codes of computed variables
		fread(&(smoapi->SubcatchVars), RECORDSIZE, 1, smoapi->file); // # Subcatch variables
		fseeko64(smoapi->file, smoapi->SubcatchVars*RECORDSIZE, SEEK_CUR);
		fread(&(smoapi->NodeVars), RECORDSIZE, 1, smoapi->file);     // # Node variables
		fseeko64(smoapi->file, smoapi->NodeVars*RECORDSIZE, SEEK_CUR);
		fread(&(smoapi->LinkVars), RECORDSIZE, 1, smoapi->file);     // # Link variables
		fseeko64(smoapi->file, smoapi->LinkVars*RECORDSIZE, SEEK_CUR);
		fread(&(smoapi->SysVars), RECORDSIZE, 1, smoapi->file);     // # System variables

		// --- read data just before start of output results
		offset = smoapi->ResultsPos - 3 * RECORDSIZE;
		fseeko64(smoapi->file, offset, SEEK_SET);
		fread(&(smoapi->StartDate), DATESIZE, 1, smoapi->file);
		fread(&(smoapi->ReportStep), RECORDSIZE, 1, smoapi->file);

		// --- compute number of bytes of results values used per time period
		smoapi->BytesPerPeriod = DATESIZE +      // date value (a double)
			(smoapi->Nsubcatch*smoapi->SubcatchVars +
			smoapi->Nnodes*smoapi->NodeVars +
			smoapi->Nlinks*smoapi->LinkVars +
			smoapi->SysVars)*RECORDSIZE;
	}

	if (errorcode) SMO_close(smoapi);

	return errorcode;

}
	void FileIterator::next()
	{
		do
		{
			if(_findnext(handle, &findData) == -1)
				validFile = false;
		} while(!validateFile(findData.name) && validFile);
	}
void CDiskReadMasterBase::init()
{
    IHThorDiskReadBaseArg *helper = (IHThorDiskReadBaseArg *) queryHelper();
    fileName.setown(helper->getFileName());
    file.setown(queryThorFileManager().lookup(container.queryJob(), fileName, 0 != ((TDXtemporary|TDXjobtemp) & helper->getFlags()), 0 != (TDRoptional & helper->getFlags()), true));

    if (file)
    {
        if (file->numParts() > 1)
            fileDesc.setown(getConfiguredFileDescriptor(*file));
        else
            fileDesc.setown(file->getFileDescriptor());
        reInit = 0 != (helper->getFlags() & (TDXvarfilename|TDXdynamicfilename));
        if (container.queryLocal() || helper->canMatchAny()) // if local, assume may match
        {
            bool local;
            if (0 == (TDXtemporary & helper->getFlags())) // don't add temp files
            {
                queryThorFileManager().noteFileRead(container.queryJob(), file);
                local = container.queryLocal();
            }
            else
                local = false;
            mapping.setown(getFileSlaveMaps(file->queryLogicalName(), *fileDesc, container.queryJob().queryUserDescriptor(), container.queryJob().querySlaveGroup(), local, false, hash, file->querySuperFile()));
        }
        if (0 != (helper->getFlags() & TDRfilenamecallback)) // only get/serialize if using virtual file name fields
        {
            IDistributedSuperFile *super = file->querySuperFile();
            if (super)
            {
                unsigned numsubs = super->numSubFiles(true);
                unsigned s=0;
                for (; s<numsubs; s++)
                {
                    IDistributedFile &subfile = super->querySubFile(s, true);
                    subfileLogicalFilenames.append(subfile.queryLogicalName());
                }
            }
        }
        validateFile(file);
        void *ekey;
        size32_t ekeylen;
        helper->getEncryptKey(ekeylen,ekey);
        bool encrypted = fileDesc->queryProperties().getPropBool("@encrypted");
        if (0 != ekeylen)
        {
            memset(ekey,0,ekeylen);
            free(ekey);
            if (!encrypted)
            {
                Owned<IException> e = MakeActivityWarning(&container, TE_EncryptionMismatch, "Ignoring encryption key provided as file '%s' was not published as encrypted", fileName.get());
                container.queryJob().fireException(e);
            }
        }
        else if (encrypted)
            throw MakeActivityException(this, 0, "File '%s' was published as encrypted but no encryption key provided", fileName.get());
    }
}
void DialogSpectraTemplates::on_pushExport_clicked()
{
  QString fileName = CustomSaveFileDialog(this, "Save template spectra",
                                          root_dir_, "Template set (*.tem)");
  if (validateFile(this, fileName, true)) {
    PL_INFO << "Writing templates to xml file " << fileName.toStdString();
    templates_.write_xml(fileName.toStdString());
  }
}
	FileIterator::FileIterator(const std::string &searchString, bool _foldersOnly)
	{
		foldersOnly = _foldersOnly;

		ZeroMemory(&findData, sizeof(_finddata_t));
		validFile = true;

		handle = _findfirst(searchString.c_str() , &findData);
		if(!validateFile(findData.name) && handle >= 0)
			next();
	}
Exemple #6
0
void copy(char* args) {
    char fileA[7], fileB[7], buffer[13312];
    int i = 0, sectors;

    // Get name for fileA
    while(args[i] == ' ') args += 1;
    while(args[i] != 0x0 && args[i] != ' ') {
        if(i < 6) {
            fileA[i] = args[i];
        }
        i += 1;
    }
    args += i;
    if(i < 6) fileA[i] = 0x0;
    else fileA[6] = 0x0;
    i = 0;

    // Get name for fileB
    while(args[i] == ' ') args += 1;
    while(args[i] != 0x0 && args[i] != ' ') {
        if(i < 6) {
            fileB[i] = args[i];
        }
        i += 1;
    }
    args += i;
    if(i < 6) fileB[i] = 0x0;
    else fileB[6] = 0x0;
    i = 0;

    // Validate file names
    validateFile(fileA);
    validateFile(fileB);

    // Read fileA into buffer
    interrupt(33, 3, fileA, buffer, &sectors);

    // Write buffer to fileB
    interrupt(33, 8, fileB, buffer, sectors);
}
Exemple #7
0
Fichier : cw.c Projet : tom-wr/FMP
/*
 * open and read lines from file
 *
 * params:
 * char * filename - name of file to be opened
 * returns:
 * int - 0 if file was not valid; 1 if operation completes
 */
 int read(char *filename)
 {
 	FILE * pfile;
 	
 	pfile = fopen(filename, "r");
 	if(!validateFile(pfile, filename))
		return 0;
	
	readlines(pfile);
 	
 	fclose(pfile);
 	return 1;
 }
void DialogSpectraTemplates::on_pushImport_clicked()
{
  //ask clear or append?
  QString fileName = QFileDialog::getOpenFileName(this, "Load template spectra",
                                                  root_dir_, "Template set (*.tem)");
  if (validateFile(this, fileName, false)) {
    PL_INFO << "Reading templates from xml file " << fileName.toStdString();
    templates_.read_xml(fileName.toStdString());
    selection_model_.reset();
    table_model_.update();
    toggle_push();

    ui->spectraSetupView->horizontalHeader()->setStretchLastSection(true);
    ui->spectraSetupView->resizeColumnsToContents();
  }
}
Exemple #9
0
void Vpz::parseFile(const std::string& filename)
{
    m_filename.assign(filename);
    vpz::SaxParser saxparser(*this);

    try {
        saxparser.parseFile(filename);
    } catch(const std::exception& sax) {
        try {
            validateFile(filename);
        } catch(const std::exception& dom) {
            saxparser.clearParserState();
            throw utils::SaxParserError(fmt(_("%2%\n\n%1%")) % dom.what() %
                                        sax.what());
        }
        throw utils::SaxParserError(sax.what());
    }
}
Exemple #10
0
void menuUp1(uint8_t event)
{
	FRESULT fr ;
	struct fileControl *fc = &FileControl ;
  static uint8_t mounted = 0 ;
	static uint32_t state ;
	static uint32_t firmwareAddress ;
	uint32_t i ;
	uint32_t width ;
	 
	if (UpdateItem == UPDATE_TYPE_BOOTLOADER )		// Bootloader
	{
  	TITLE( "UPDATE BOOT" ) ;
	}
	else
	{
#ifdef PCBX9D
		if (UpdateItem == UPDATE_TYPE_SPORT_INT )
		{
  		TITLE( "UPDATE Int. XJT" ) ;
		}
		else
		{
  		TITLE( "UPDATE Ext. SPort" ) ;
		}
#endif

#ifdef PCBSKY
 #ifndef REVX
 		if (UpdateItem == UPDATE_TYPE_COPROCESSOR )
		{
  		TITLE( "UPDATE COPROC" ) ;
		}
		else
		{
  		TITLE( "UPDATE SPort" ) ;
		}
 #else
 		if (UpdateItem == UPDATE_TYPE_SPORT_EXT )
		{
  		TITLE( "UPDATE SPort" ) ;
		}
 #endif
#endif
	}
	switch(event)
	{
    case EVT_ENTRY:
			state = UPDATE_NO_FILES ;
			if ( mounted == 0 )
			{
#if defined(PCBTARANIS)
  			fr = f_mount(0, &g_FATFS_Obj) ;
#else				
  			fr = f_mount(0, &g_FATFS) ;
#endif
#ifdef PCBX9D
				unlockFlash() ;
#endif
			}
			else
			{
				fr = FR_OK ;
			}
			if ( fr == FR_OK)
			{
				mounted = 1 ;
			}
			if ( mounted )
			{
				fr = f_chdir( (TCHAR *)"\\firmware" ) ;
				if ( fr == FR_OK )
				{
					state = UPDATE_NO_FILES ;
					fc->index = 0 ;
					fr = f_opendir( &Dj, (TCHAR *) "." ) ;
					if ( fr == FR_OK )
					{
 						if ( (UpdateItem > 1 ) )
						{
							fc->ext[0] = 'F' ;
							fc->ext[1] = 'R' ;
							fc->ext[2] = 'K' ;
						}
						else
						{
							fc->ext[0] = 'B' ;
							fc->ext[1] = 'I' ;
							fc->ext[2] = 'N' ;
						}
						fc->ext[3] = 0 ;
						fc->index = 0 ;
						fc->nameCount = fillNames( 0, fc ) ;
						fc->hpos = 0 ;
						fc->vpos = 0 ;
						if ( fc->nameCount )
						{
							state = UPDATE_FILE_LIST ;
						}
					}
				}
			}
    break ;
    
		case EVT_KEY_FIRST(KEY_EXIT):
			if ( state < UPDATE_ACTION )
			{
      	chainMenu(menuUpdate) ;
    		killEvents(event) ;
			}
    break ;
	}

	switch ( state )
	{
		case UPDATE_NO_FILES :
			lcd_puts_Pleft( 4*FH, "\005No Files" ) ;
	    lcd_outdez( 21*FW, 4*FH, mounted ) ;
    break ;
		
		case UPDATE_FILE_LIST :
			SportVerValid = 0 ;
			if ( fileList( event, &FileControl ) == 1 )
			{
				state = UPDATE_CONFIRM ;
			}
    break ;
		case UPDATE_CONFIRM :
 			if ( (UpdateItem > UPDATE_TYPE_BOOTLOADER ) )
			{
#ifdef PCBX9D
 				if ( (UpdateItem == UPDATE_TYPE_SPORT_INT ) )
				{
					lcd_puts_Pleft( 2*FH, "Flash Int. XJT from" ) ;
				}
				else
				{
					lcd_puts_Pleft( 2*FH, "Flash Ext.SP from" ) ;
				}
				SportVerValid = 0 ;
#else
 #ifndef REVX
 				if ( (UpdateItem == UPDATE_TYPE_COPROCESSOR ) )
				{
					lcd_puts_Pleft( 2*FH, "Flash Co-Proc. from" ) ;
				}
				else
				{
					lcd_puts_Pleft( 2*FH, "Flash SPort from" ) ;
				}
				CoProcReady = 0 ;
 #else
				lcd_puts_Pleft( 2*FH, "Flash SPort from" ) ;
 #endif
#endif
			}
			else
			{
				lcd_puts_Pleft( 2*FH, "Flash Bootloader from" ) ;
			}
			cpystr( cpystr( (uint8_t *)FlashFilename, (uint8_t *)"\\firmware\\" ), (uint8_t *)Filenames[fc->vpos] ) ;
#if defined(PCBTARANIS)
			lcd_putsnAtt( 0, 4*FH, Filenames[fc->vpos], DISPLAY_CHAR_WIDTH, 0 ) ;
#else
			lcd_putsnAtt0( 0, 4*FH, Filenames[fc->vpos], DISPLAY_CHAR_WIDTH, 0 ) ;
#endif
			if ( event == EVT_KEY_LONG(KEY_MENU) )
			{
				state = UPDATE_SELECTED ;
			}
			if ( event == EVT_KEY_LONG(KEY_EXIT) )
			{
				state = UPDATE_FILE_LIST ;		// Canceled
			}
    break ;
		case UPDATE_SELECTED :
			f_open( &FlashFile, FlashFilename, FA_READ ) ;
			f_read( &FlashFile, (BYTE *)FileData, 1024, &BlockCount ) ;
			i = 1 ;
			if (UpdateItem == UPDATE_TYPE_BOOTLOADER )		// Bootloader
			{
				i = validateFile( (uint32_t *) FileData ) ;
			}
			if ( i == 0 )
			{
				state = UPDATE_INVALID ;
			}
			else
			{
				if (UpdateItem == UPDATE_TYPE_BOOTLOADER )		// Bootloader
				{
#ifdef PCBX9D
					firmwareAddress = 0x08000000 ;
#endif
#ifdef PCBSKY
					firmwareAddress = 0x00400000 ;
#endif
				}
#ifdef PCBSKY
 #ifndef REVX
				else if (UpdateItem == UPDATE_TYPE_COPROCESSOR )		// Bootloader
				{
					firmwareAddress = 0x00000080 ;
					if ( check_ready() == 0 )
					{
						CoProcReady = 1 ;
					}
				}
 #endif
#endif
				else
				{
// SPort update
					SportState = SPORT_START ;
					FirmwareSize = FileSize[fc->vpos] ;
					BlockInUse = 0 ;
					f_read( &FlashFile, (BYTE *)ExtraFileData, 1024, &XblockCount ) ;
				}
				BytesFlashed = 0 ;
				BlockOffset = 0 ;
				ByteEnd = 1024 ;
				state = UPDATE_ACTION ;
			}
    break ;
		case UPDATE_INVALID :
			lcd_puts_Pleft( 2*FH, "Invalid File" ) ;
			lcd_puts_Pleft( 4*FH, "Press EXIT" ) ;
			if ( event == EVT_KEY_FIRST(KEY_EXIT) )
			{
				state = UPDATE_FILE_LIST ;		// Canceled
    		killEvents(event) ;
			}
    break ;
		case UPDATE_ACTION :
			// Do the flashing
			lcd_puts_Pleft( 3*FH, "Flashing" ) ;
			if (UpdateItem == UPDATE_TYPE_BOOTLOADER )		// Bootloader
			{
				width = ByteEnd >> 9 ;
				if ( BytesFlashed < ByteEnd )
				{
					program( (uint32_t *)firmwareAddress, &((uint32_t *)FileData)[BlockOffset] ) ;	// size is 256 bytes
					BlockOffset += 64 ;		// 32-bit words (256 bytes)
					firmwareAddress += 256 ;
					BytesFlashed += 256 ;
				}
				else
				{
					if ( ByteEnd >= 32768 )
					{
						state = UPDATE_COMPLETE ;
					}
					else
					{
						f_read( &FlashFile, (BYTE *)FileData, 1024, &BlockCount ) ;
						ByteEnd += 1024 ;
						BlockOffset = 0 ;
					}
				}
			}

#ifdef PCBSKY
 #ifndef REVX
			else if (UpdateItem == UPDATE_TYPE_COPROCESSOR )		// CoProcessor