// Returns 0 on success, -1 on failure
// If a failure occurs the password will contain a description of the error
int Keygen(char const *_sysInfoData, int _sysInfoLen, char const *_userInfoFilename, char const **_password)
{
	int userInfoLen;
	char *userInfoData = ReadFileToBuf(_userInfoFilename, &userInfoLen);
	if (!userInfoData)
	{
		*_password = "******";
		return -1;
	}

	char const *validationResult = ValidateSysInfo(_sysInfoData, _sysInfoLen);
	if (validationResult)
	{
		*_password = validationResult;
		return -1;
	}
	validationResult = ValidateUserInfo(userInfoData, userInfoLen);
	if (validationResult)
	{
		*_password = validationResult;
		return -1;
	}

	unsigned int sysKey = GenerateKey(_sysInfoData, _sysInfoLen);
	unsigned int userKey = GenerateKey(userInfoData, userInfoLen);

	MakePasswordFromKey(userKey, sysKey, _password);

	delete [] userInfoData;

	return 0;
}
// Returns 0 on success, -1 on failure
// If a failure occurs the password will contain a description of the error
int Keygen(char const *_sysInfoFilename, char const *_userInfoFilename, char const **_password)
{
	int fileLen;
	char const *sysInfoData = ReadFileToBuf(_sysInfoFilename, &fileLen);
	if (!sysInfoData)
	{
		*_password = "******";
		return -1;
	}
	
	return Keygen(sysInfoData, fileLen, _userInfoFilename, _password);
}
Ejemplo n.º 3
0
  ///////////////////////////////////////////////////////////
  //
  //
  //  ReadRotationIntervalFile (a.k.a "omegafiles")
  //
  //  Given a filename, read in the range of data collection interval and
  //  the experimental file range
  //
  //  TODO:  Create a more flexible format to replace the omega files
  //
  bool ReadRotationIntervalFiles( vector<SRange> &oRotationRange,
                                  vector<SIntRange> &oFileRange,
                                  Size_Type nNumFileRange,
                                  const string & filename )
    
  {
    char *pBuffer = NULL;
    Size_Type nBufSize = 0;
    vector< vector<string> > vsTokens;
	
    pBuffer = ReadFileToBuf(nBufSize, filename);
    if(pBuffer == NULL){
      return false;
    }

    string sBuffStr( pBuffer, nBufSize );
    
    GeneralLib::Tokenize( vsTokens, sBuffStr, ",# \t\n");
    RUNTIME_ASSERT( vsTokens.size() >= 4,
                   "[ReadRotationIntervalFile] ERROR: Invalid file type (too short)\n");

    // conform to existing omega file format, the first line is ignored
    for ( Size_Type i = 1; i <= nNumFileRange; i ++)
    {
      SIntRange s;
      s.nLow  = atoi( vsTokens[i][0].c_str() );
      s.nHigh = atoi( vsTokens[i][1].c_str() );
      oFileRange.push_back( s );
    }

    //
    //  Get the omega ranges
    //
    for(Size_Type i = oFileRange.size() + 1; i < vsTokens.size(); i ++){
      
      RUNTIME_ASSERT( (vsTokens[i].size() >= 2), 
                      "[ReadRotationIntervalFiles] ERROR: Invalid file range\n");
      
      SRange s;
      s.fLow  = DEGREE_TO_RADIAN( atof( vsTokens[i][0].c_str() ) );
      s.fHigh = DEGREE_TO_RADIAN( atof( vsTokens[i][1].c_str() ) );
      oRotationRange.push_back( s );
    }


    delete [] pBuffer;
    return true;
    
  }
Ejemplo n.º 4
0
  //------------------------------
  //
  //  ReadFundamentalZoneFile
  //
  //------------------------------
  bool ReadFundamentalZoneFile( vector<SVector3> & vFZEulerAngleList,
                                const string & sFilename )
  {
    char *pBuffer = NULL;
    Size_Type nBufSize = 0;
    vector< vector<string> > vsTokens;
	
    pBuffer = ReadFileToBuf(nBufSize, sFilename);
    if(pBuffer == NULL){
      return false;
    }

    string sBuffStr( pBuffer, nBufSize );
    
    GeneralLib::Tokenize( vsTokens, sBuffStr, ",# \t\n");
    
    for(Size_Type i = 0; i < vsTokens.size(); i ++){
      
      RUNTIME_ASSERT( (vsTokens[i].size() >= 3), 
                      "[ReadFundamentalZoneFile] ERROR: Invalid Euler Angles\n");
      
      
      Float fPhi   = DEGREE_TO_RADIAN( atof( vsTokens[i][0].c_str() ) );
      Float fTheta = DEGREE_TO_RADIAN( atof( vsTokens[i][1].c_str() ) );
      Float fPsi   = DEGREE_TO_RADIAN( atof( vsTokens[i][2].c_str() ) );

      SVector3 newAngles;

      newAngles.Set( fPhi, fTheta, fPsi );

      vFZEulerAngleList.push_back( newAngles );
    }


    delete [] pBuffer;
    return true;
  }
Ejemplo n.º 5
0
   void
   FileUtilities::ReadFileToBuf(const String &sFilename, BYTE *OutBuf, int iStart, int iCount)
   {
      // --- Open the file for writing.
      int iBefore = GetTickCount();
      HANDLE handleFile = CreateFile(sFilename, 
         GENERIC_READ, 
         FILE_SHARE_READ, 
         NULL, // LPSECURITY_ATTRIBUTES
         OPEN_EXISTING, // -- open or create.
         FILE_ATTRIBUTE_NORMAL, // attributes
         NULL // file template
         );

      if (handleFile == INVALID_HANDLE_VALUE) 
      { 
         // This is not good. We failed to get a handle to the file.
         return;
      } 

      ReadFileToBuf(handleFile, (char*) OutBuf, iStart, iCount);

      CloseHandle(handleFile);
   }
Ejemplo n.º 6
0
  ////////////////////////////////////////////////////////////////////////////////////////////////////////
  //
  //
  //
  //  ReadCrystalStructureFile
  // 
  //  Note:  Units used in this file is angstrom as opposed to mm everywhere else.  This is because
  //  the actual measurement of the scattering vector is rarely used in conjunction with the geometric aspect.
  // (Typically unit vectors are used)
  //
  //////////////////////////////////////////////////////////////////////////////////////////////////////////
  bool ReadCrystalStructureFile(CUnitCell &oCell, const string &filename)
  {
    char *pBuffer = NULL;
    Size_Type nBufSize = 0;
    vector< vector<string> > vsTokens;
	
    pBuffer = ReadFileToBuf(nBufSize, filename);
    if(pBuffer == NULL){
      return false;
    }

    string sBuffStr( pBuffer, nBufSize );
    
    // RUNTIME_ASSERT(oCell.oTranslationVector.size() == 0, "Vector screwed up\n");
    GeneralLib::Tokenize( vsTokens, sBuffStr, ",# \t\n");
    RUNTIME_ASSERT( vsTokens.size() >= 4,
                   "[ReadCrystalStructureFile] ERROR: Invalid file type (too short)\n" );
	
    // parse a, b, c unit cell lengths
    RUNTIME_ASSERT( vsTokens[0].size() >= 3,
                   "[ReadCrystalStructureFile] ERROR: failed to parse a, b, c\n" );

    oCell.SetUnitCellLength(  atof( vsTokens[0][0].c_str() ),
                              atof( vsTokens[0][1].c_str() ),
                              atof( vsTokens[0][2].c_str() ) );
                              
    // parse alpha, beta, gamma unit cell angles
    RUNTIME_ASSERT(vsTokens[1].size() >= 3,
                   "[ReadCrystalStructureFile] ERROR: failed to parse alpha, beta, gamma\n");

    oCell.SetUnitCellBasisAngles( DEGREE_TO_RADIAN( atof(vsTokens[1][0].c_str()) ),
                                  DEGREE_TO_RADIAN( atof(vsTokens[1][1].c_str()) ),
                                  DEGREE_TO_RADIAN( atof(vsTokens[1][2].c_str()) )  );
    
    // parse number of basis atoms
    RUNTIME_ASSERT(vsTokens[2].size() >= 1,
                   "[ReadCrystalStructureFile] ERROR: failed to parse number of atoms \n");
    //    oCell.nNumAtoms = atoi(vsTokens[2][0].c_str());	

    oCell.SetNumAtoms( atoi( vsTokens[2][0].c_str() ) );
    
    // parse Z, number of protons in the atom, and the three coordinates
    //          of the Premitive Translation Vectors
    for(Size_Type i = 3; i < vsTokens.size(); i ++){
      
      RUNTIME_ASSERT( (vsTokens[i].size() >= 4), 
                      "[ReadCrystalStructureFile] ERROR: Invalid translation vector\n");
      CAtom pVector;		

      SVector3 oPos ( atof( vsTokens[i][1].c_str() ), 
                      atof( vsTokens[i][2].c_str() ), 
                      atof( vsTokens[i][3].c_str() ) );
      // oCell.oTranslationVector.push_back( pVector );
  
      oCell.AddAtom( atoi( vsTokens[i][0].c_str() ), oPos );
    }
	
    oCell.InitializeCoordinateSystem();

    delete [] pBuffer;
    return true;
  }
Ejemplo n.º 7
0
  bool ReadPeakFile(vector<CPeak> &vPeaks, const string &filename)
  {

    char *pBuffer = NULL;
    Size_Type nBufSize = 0;
    vector< vector<string> > vsTokens;
	
    pBuffer = ReadFileToBuf(nBufSize, filename);
    if(pBuffer == NULL){
      return false;
    }
	
	
    GeneralLib::Tokenize(vsTokens, pBuffer, "# \t\n");
	
    if(vsTokens[0].size() > 3){
      cerr << "ERROR: " << filename << " is not a peak file." << endl;
      return false;
    }
	

    // for each line
    CPeak currentPeak;
    Pixel p;
    Int peakID;
    Int currentID = 0;

    // get current peak ID
    if(vsTokens[1].size() < 4 ){
      cerr << "[CMicFile::ReadMicFile] Error: Incorrect number of columns, line: "
           << 1  << endl;
      return false;
    }
    peakID =  atoi(vsTokens[1][3].c_str());
	
    for(UInt i = 1; i < vsTokens.size(); i ++){
      if(vsTokens[i].size() < 4 ){
        cerr << "[CMicFile::ReadMicFile] Error: Incorrect number of columns, line: "
             << i  << endl;
        return false;
      }else{


        p.x = atoi(vsTokens[i][0].c_str());
        p.y = atoi(vsTokens[i][1].c_str());
        p.fIntensity = atof(vsTokens[i][2].c_str());
        currentID = atoi(vsTokens[i][3].c_str());
      }
		
      // add when either new ID or last pixel
      if( ( currentID != peakID )|| (i == (vsTokens.size() -1 ))){
        vPeaks.push_back(currentPeak);
        currentPeak.vPixelList.clear();
        currentPeak.vPixelList.push_back(p);
        peakID = currentID;			
      }else{
        currentPeak.vPixelList.push_back(p);
      }
    }

    cerr << "NumPeaks Read: " << vPeaks.size() << endl;

    delete[] pBuffer;
	
    return true;

  }
Ejemplo n.º 8
0
//---------------------------------------------------------
//
//  Public:
//  Read
//
//
//---------------------------------------------------------
//      MIC file format
//
// line 1: a0, the fundamental lattice constant for the triangular mesh
//
// others:
//
// columns 1 -3: xyz location of left vertex of a triangle
// column 4: 1/2 for triangle type -- 1 for upward pointing or 2 for downward
// pointing
// column 5: generation number -- triangle side length = a0/(2^generation),
// generation = 0,1,2,...
// column 6: 0/1 for phase -- 0 mean it wasn't (or hasn't yet) fitted to an
// orientation, 1 means it was
// columns 7 -9: Eulers in degrees
// column 10: confidence parameter: fraction of simulated Bragg peaks that hit
// experimental peaks
//---------------------------------------------------------
bool CMic::ReadEffient( const string &filename )
{
 
  vector< vector<string> > vsTokens;

  if( !ReadFileToBuf(filename))
  {
    return false;
  }

  std::ifstream InputStream;
  if( !InputStream.open( filename ) )
    return false;


  std::string Tokens = " \t\n";
  //  GeneralLib::Tokenize( vsTokens, string( pBuffer, nBufferSize ), " \t\n");
  // we expect side length for the first line
	
  if(vsTokens[0].size() > 1){
    cerr << "[CMic::ReadMicFile] Incorrect Mic File Format " << filename << endl;
    exit(0);
  }
	
  //  fInitialSideLength = atof(vsTokens[0][0].c_str());
  //  for( Size_Type i = 1; i < vsTokens.size(); i ++){

  while()
  {
    if(vsTokens[i].size() < 9 )
    {
      cerr << "[CMic::ReadMicFile] Error: Incorrect number of columns, line: "
           << i  << filename << endl;
    }
    else
    {
      DEBUG_ALERT( vsTokens[i].size() >= 10, "CMic::Read:  Warning!  Old format MIC file with only 9 columns\n" );
      SVoxel v;

      v.nGeneration = atoi( vsTokens[i][4].c_str() );
      v.fSideLength = fInitialSideLength / pow( 2,  v.nGeneration ) ;
      v.nPhase = atoi( vsTokens[i][5].c_str() );

      Float fX, fY, fZ;

      fX = atof( vsTokens[i][0].c_str() );
      fY = atof( vsTokens[i][1].c_str() );
      fZ = atof( vsTokens[i][2].c_str() );

      if ( atoi( vsTokens[i][3].c_str() ) == UP  ) 
      {
        // Winding order, counter clockwise
        v.pVertex[0].Set( fX,                 fY, fZ );
        v.pVertex[1].Set( fX + v.fSideLength, fY, fZ );
        v.pVertex[2].Set( fX + v.fSideLength / (Float) 2.0 , fY + v.fSideLength / (Float) 2.0 * sqrt( (Float) 3.0 ) , fZ);
        v.bVoxelPointsUp = true;
      }
      else
      {
        // Winding order, counter clockwise
        v.pVertex[0].Set( fX,                 fY, fZ );
        v.pVertex[1].Set( fX + v.fSideLength / (Float) 2.0 , fY - v.fSideLength / (Float) 2.0 * sqrt( (Float) 3.0 ) , fZ);
        v.pVertex[2].Set( fX + v.fSideLength, fY, fZ );
        v.bVoxelPointsUp = false;
      }

      SVector3 oOrientation;
      oOrientation.Set(  DEGREE_TO_RADIAN( atof(vsTokens[i][6].c_str()) ),
                         DEGREE_TO_RADIAN( atof(vsTokens[i][7].c_str()) ),
                         DEGREE_TO_RADIAN( atof(vsTokens[i][8].c_str()) ) );
      
      // note that orientation matrix assigned here - the choice of active vs. passive
      // transform is made by the file format

      v.oOrientMatrix.BuildActiveEulerMatrix( oOrientation.m_fX,
                                              oOrientation.m_fY,
                                              oOrientation.m_fZ );
      
      if( vsTokens[i].size() > 9 )
        v.fConfidence = atof( vsTokens[i][9].c_str() );
      else
        v.fConfidence = 0;
      
      if( vsTokens[i].size() == 19 )   //  Defining our strain tensor to be ( I)
      {
        v.fCost                = atof( vsTokens[i][10].c_str() );
        v.fPixelOverlapRatio   = atof( vsTokens[i][11].c_str() );
        v.oDeformation.m[0][0] = atof( vsTokens[i][13].c_str() );
        v.oDeformation.m[1][1] = atof( vsTokens[i][14].c_str() );
        v.oDeformation.m[2][2] = atof( vsTokens[i][15].c_str() );
        
        v.oDeformation.m[0][1] = v.oDeformation.m[1][0] = atof( vsTokens[i][16].c_str() );
        v.oDeformation.m[1][2] = v.oDeformation.m[2][1] = atof( vsTokens[i][17].c_str() );
        v.oDeformation.m[0][2] = v.oDeformation.m[2][0] = atof( vsTokens[i][18].c_str() );
      }
      else
      {
        v.oDeformation.SetIdentity();
      }
      
      oVoxelList.push_back(v);
    }	

  }

  ClearBuffer();  // clear buffer after use
  return true;
}