Пример #1
0
void
CDragInformation::parseDragInfo(CDragFileList& dragFileList, UInt32 fileNum, CString data)
{
	size_t startPos = 0;
	size_t findResult1 = 0;
	size_t findResult2 = 0;
	dragFileList.clear();
	CString slash("\\");
	if (data.find("/", startPos) != -1) {
		slash = "/";
	}

	while (fileNum) {
		findResult1 = data.find('\0', startPos);
		findResult2 = data.find_last_of(slash, findResult1);

		if (findResult1 == startPos) {
			//TODO: file number does not match, something goes wrong
			break;
		}
		if (findResult1 - findResult2 > 1) {
			dragFileList.push_back(data.substr(findResult2 + 1, findResult1 - findResult2));
		}
		startPos = findResult1 + 1;
		--fileNum;
	}
}
void
CDragInformation::parseDragInfo(CDragFileList& dragFileList, UInt32 fileNum, CString data)
{
	size_t startPos = 0;
	size_t findResult1 = 0;
	size_t findResult2 = 0;
	dragFileList.clear();
	CString slash("\\");
	if (data.find("/", startPos) != string::npos) {
		slash = "/";
	}
	
	UInt32 index = 0;
	while (index < fileNum) {
		findResult1 = data.find(',', startPos);
		findResult2 = data.find_last_of(slash, findResult1);

		if (findResult1 == startPos) {
			//TODO: file number does not match, something goes wrong
			break;
		}
		
		// set filename
		if (findResult1 - findResult2 > 1) {
			CString filename = data.substr(findResult2 + 1,
				findResult1 - findResult2 - 1);
			CDragInformation di;
			di.setFilename(filename);
			dragFileList.push_back(di);
		}
		startPos = findResult1 + 1;
		
		//set filesize
		findResult2 = data.find(',', startPos);
		if (findResult2 - findResult1 > 1) {
			CString filesize = data.substr(findResult1 + 1,
										   findResult2 - findResult1 - 1);
			size_t size = stringToNum(filesize);
			dragFileList.at(index).setFilesize(size);
		}
		startPos = findResult1 + 1;
		
		++index;
	}

	LOG((CLOG_DEBUG "drag info received, total drag file number: %i",
		dragFileList.size()));

	for (size_t i = 0; i < dragFileList.size(); ++i) {
		LOG((CLOG_DEBUG2 "dragging file %i name: %s",
			i + 1,
			dragFileList.at(i).getFilename().c_str()));
	}
}
Пример #3
0
CString
CDragInformation::getDragFileExtension(CString fileName)
{
	size_t findResult = -1;
	findResult = fileName.find_last_of(".", fileName.size());
	if (findResult != -1) {
		return fileName.substr(findResult + 1, fileName.size() - findResult - 1);
	}
	else {
		return "";
	}
}
static CString GetDirOfExecutable( CString argv0 )
{
#ifdef _XBOX
	return "D:\\";
#else
	/* argv[0] can be wrong in most OS's; try to avoid using it. */

	CString sPath;
#if defined(_WIN32)
	char buf[MAX_PATH];
	GetModuleFileName( NULL, buf, sizeof(buf) );
	sPath = buf;
#else
	sPath = argv0;
#endif

	sPath.Replace( "\\", "/" );

	bool IsAbsolutePath = false;
	if( sPath.size() == 0 || sPath[0] == '/' )
		IsAbsolutePath = true;
#if defined(_WIN32)
	if( sPath.size() > 2 && sPath[1] == ':' && sPath[2] == '/' )
		IsAbsolutePath = true;
#endif

	// strip off executable name
	size_t n = sPath.find_last_of("/");
	if( n != sPath.npos )
		sPath.erase(n);
	else
		sPath.erase();

	if( !IsAbsolutePath )
	{
		sPath = GetCwd() + "/" + sPath;
		sPath.Replace( "\\", "/" );
	}

	return sPath;
#endif
}
Пример #5
0
bool CIniFile::ReadString(const char* ini_str)
{
  CString   line;
  CString   keyname, valuename, value;
  CString::size_type pLeft, pRight;

  Clear();
  CString _str = ini_str;
  while( getline( _str, line)) {
    // To be compatible with Win32, check for existence of '\r'.
    // Win32 files have the '\r' and Unix files don't at the end of a line.
    // Note that the '\r' will be written to INI files from
    // Unix so that the created INI file can be read under Win32
    // without change.
    //printf("str=%s \n line=%s\n",_str.c_str(),line.c_str());
    if ( line[line.length() - 1] == '\r')
      line = line.substr( 0, line.length() - 1);

    if ( line.length()) {
      // Check that the user hasn't openned a binary file by checking the first
      // character of each line!
      if ( !isprint( line.at(0))) {
//       printf( "Failing on char %d\n", line[0]);
//       f.close();
//        return false;
      };
      if (( pLeft = line.find_first_of(";#[=:")) != CString::npos) {
       switch ( line[pLeft]) {
       case '[':
         if ((pRight = line.find_last_of("]")) != CString::npos &&
              pRight > pLeft) {
           keyname = line.substr( pLeft + 1, pRight - pLeft - 1);
           AddKeyName( keyname);
//           printf("Section: %s\n",keyname.c_str());
         }
       break;

       case '=':
//       case ':':
         valuename = line.substr( 0, pLeft);
         value = line.substr( pLeft + 1);
         AddValue( keyname, valuename, value);
//         printf("%s=%s\n",valuename.c_str(),value.c_str());
       break;

       case ';':
       case '#':
         if ( !names.size())
            HeaderComment( line.substr( pLeft + 1));
          else
            KeyComment( keyname, line.substr( pLeft + 1));
       break;
       };//switch()
      }//if(( pLeft = line.find_first_of(";#[=")) != CString::npos)
    };//if ( line.length())
  };//while( getline( ini_str, line))

  if(minSize <= 0)
    return true;

  if ( names.size())
    return true;

  return false;
};
Пример #6
0
bool CIniFile::ReadFile(const CString&  _path)
{
  // Normally you would use ifstream, but the SGI CC compiler has
  // a few bugs with ifstream. So ... fstream used.
  ifstream f;
  CString   line;
  CString   keyname, valuename, value;
  CString::size_type pLeft, pRight;

  //если файл испортили из-вне.
  //проверка испорченности файла: открытие
  f.open( _path.c_str());
  if ( f.fail()){
    printf("Warning: ini file:'%s' is NOT OPENED\n", _path.c_str());
    f.close();
    return false;
  };

  //проверка испорченности файла: проверяем размер
  if((minSize > 0) && (size_of_stream(f) < minSize)){
    printf("Warning: ini file:'%s' is suspiciously SMALL\n", _path.c_str());
    f.close();
    return false;
  };

  try{
  Clear();
  while( getline( f, line)) {
    // To be compatible with Win32, check for existence of '\r'.
    // Win32 files have the '\r' and Unix files don't at the end of a line.
    // Note that the '\r' will be written to INI files from
    // Unix so that the created INI file can be read under Win32
    // without change.
    //printf("str=%s \n line=%s\n",_str.c_str(),line.c_str());
    if ( line[line.length() - 1] == '\r')
      line = line.substr( 0, line.length() - 1);

    if ( line.length()) {
      // Check that the user hasn't openned a binary file by checking the first
      // character of each line!
//      if ( !isprint( line[0])) {
//       printf( "Failing on char %d\n", line[0]);
//       f.close();
//        return false;
//      };
      if (( pLeft = line.find_first_of(";#[=:")) != CString::npos) {
       switch ( line[pLeft]) {
       case '[':
         if ((pRight = line.find_last_of("]")) != CString::npos &&
              pRight > pLeft) {
           keyname = trim(line.substr( pLeft + 1, pRight - pLeft - 1));

           AddKeyName(keyname);
           //printf("Section: %s\n",keyname.c_str());
         }
       break;

       case '=':
         valuename = trim(line.substr( 0, pLeft));
         value = trim(line.substr( pLeft + 1));
         SetValue( keyname, valuename, value);
       break;
//
//       case ':':
//         valuename = line.substr( 0, pLeft);
//         value = line.substr( pLeft + 1);
//         AddValue( keyname, valuename, value);
//       break;

       case ';':
       case '#':
         if ( !names.size())
            HeaderComment( line.substr( pLeft + 1));
          else
            KeyComment( keyname, line.substr( pLeft + 1));
       break;
       };//switch()
      }//if(( pLeft = line.find_first_of(";#[=")) != CString::npos)
    };//if ( line.length())
  };//while( getline( ini_str, line))
  }catch(...){

  };
  f.close();

  //проверка испорченности файла: проверяем размер
  if(minSize<=0)
    return true;

  if(0 == names.size()){
    printf("Warning: ini file:'%s' is NOT contain any names\n", _path.c_str());
    return false;
  };

  return (CheckFile());
}