Beispiel #1
0
static bool
ReadTextFile(const TCHAR *path, tstring &buffer)
{
  /* auto-detect the character encoding, to be able to parse XCSoar
     6.0 task files */
  FileLineReader reader(path, ConvertLineReader::AUTO);
  if (reader.error())
    return false;

  long size = reader.size();
  if (size > 65536)
    return false;
  else if (size < 0)
    size = 4096;

  buffer.reserve(size);

  const TCHAR *line;
  while ((line = reader.read()) != NULL) {
    if (buffer.length() > 65536)
      /* too long */
      return false;

    buffer.append(line);
    buffer.append(_T("\n"));
  }

  return true;
}
Beispiel #2
0
static bool
ReadTextFile(Path path, tstring &buffer)
try {
  /* auto-detect the character encoding, to be able to parse XCSoar
     6.0 task files */
  FileLineReader reader(path, Charset::AUTO);

  long size = reader.GetSize();
  if (size > 65536)
    return false;
  else if (size < 0)
    size = 4096;

  buffer.reserve(size);

  const TCHAR *line;
  while ((line = reader.ReadLine()) != nullptr) {
    if (buffer.length() > 65536)
      /* too long */
      return false;

    buffer.append(line);
    buffer.append(_T("\n"));
  }

  return true;
} catch (const std::runtime_error &) {
  return false;
}
Beispiel #3
0
void Helium::SetCmdLine( int argc, const tchar_t** argv )
{
    for ( int i=0; i<argc; i++ )
    {
        bool quote = FindCharacter( argv[i], TXT( ' ' ) ) != NULL;
        if ( quote )
        {
            g_CmdLine.append( TXT( "\"" ) );
        }

        g_CmdLine.append( argv[ i ] );   

        if ( quote )
        {
            g_CmdLine.append( TXT( "\"" ) );
        }

        if ( i+1 < argc )
        {
            g_CmdLine.append( TXT( " " ) );
        }
    }

	ProcessCmdLine( g_CmdLine.c_str(), g_Argc, g_Argv );
}
int CDBCommandBuilderBase::GenerateSqlInsert(const IDBRecord& rec, tstring& buffer)
{
	buffer.append(TEXT("INSERT INTO "));
	WrapperIdentifier(TableSchema_->DBName.c_str(), buffer);

	buffer.append(TEXT(" ("));

	for (int i = 0; i < TableSchema_->Columns.size(); ++i)
	{
		WrapperIdentifier(TableSchema_->Columns[i].DBName.c_str(), buffer);
		buffer.append(TEXT(", "));
	}
	
	*(buffer.end() - 2) = ')';
	buffer.append(TEXT("VALUES ("));

	for (int i = 0; i < TableSchema_->Columns.size(); ++i)
	{
		WrapperValue(rec.GetField(i).c_str(), TableSchema_->Columns[i].DBType, buffer);
		buffer.append(TEXT(", "));
	}

	*(buffer.end() - 2) = ')';

	return 1;
}
Beispiel #5
0
void CProcessTool::GetFileDescription(tstring FileName,tstring &strDescription,tstring &strCompanyName)
{
	BOOL bSucceed = FALSE;
	DWORD dwInfoSize = 0;
	DWORD dwHandle = 0;
	dwInfoSize = sizeof(VS_FIXEDFILEINFO);
	strDescription = _T("");

	dwInfoSize = GetFileVersionInfoSize(FileName.c_str(),&dwHandle);

	if(dwInfoSize >0)
	{
		void *pvInfo = new TCHAR[dwInfoSize];
		if(GetFileVersionInfo(FileName.c_str(),0,dwInfoSize,pvInfo))
		{
			struct LANGANDCODEPAGE{
				WORD wLanguage;
				WORD wCodePage;
			}*lpTranslate;

			UINT cbTranslate = 0;

			if(VerQueryValue(pvInfo,_T("\\VarFileInfo\\Translation"),
				(void**)&lpTranslate,&cbTranslate))
			{
				if(cbTranslate/sizeof(struct LANGANDCODEPAGE)>0){
					const TCHAR *lpBuffer = 0;
					UINT cbSizeBuf = 0;
					TCHAR szSubBlock[50];

					_stprintf_s(szSubBlock,sizeof(szSubBlock),_T("\\StringFileInfo\\%04x%04x\\FileDescription"),
						lpTranslate[0].wLanguage,lpTranslate[0].wCodePage);
					if(VerQueryValue(pvInfo,szSubBlock,(void **)&lpBuffer,&cbSizeBuf))
					{
						strDescription.append(lpBuffer,cbSizeBuf);
					}

					memset(szSubBlock,0,sizeof(szSubBlock));
					_stprintf_s(szSubBlock,50,_T("\\StringFileInfo\\%04x%04x\\CompanyName"),
						lpTranslate[0].wLanguage,lpTranslate[0].wCodePage);
					if(VerQueryValue(pvInfo,szSubBlock,(void **)&lpBuffer,&cbSizeBuf))
					{
						strCompanyName.append(lpBuffer,cbSizeBuf);
					}


				}
			}
		}
	}

}
Beispiel #6
0
bool MudGameView::initialize(const tstring& profile)
{
    if (!initPluginsSystem())
    {
        msgBox(m_hWnd, IDS_ERROR_SCRIPTENGINE_FAILED, MB_OK | MB_ICONSTOP);
        return false;
    }

#ifdef _DEBUG
    InputCommandTemplateUnitTests::run();
    ParamsHelperUnitTests::run();
    CompareObjectUnitTests::run();
#endif

    if (!m_processor.init())
    {
        msgBox(m_hWnd, IDS_ERROR_SCRIPTENGINE_FAILED, MB_OK|MB_ICONSTOP);
        return false;
    }

    if (!m_manager.init())
    {
        msgBox(m_hWnd, IDS_ERROR_INITPROFILES_FAILED, MB_OK|MB_ICONSTOP);
        return false;
    }

    tstring error;
    if (!m_manager.loadProfile(profile, &error))
    {
        tstring msg;
        loadString(IDS_ERROR_LASTLOAD_FAILED, &msg);
        tstring profile(m_manager.getProfileGroup());
        profile.append(L" - ");
        profile.append(m_manager.getProfileName());
        tstring_replace(&msg, L"%s", profile);
        if (msgBox(m_hWnd, msg, error, MB_YESNO|MB_ICONSTOP) != IDYES) { return false; }

        Profile p(m_manager.getProfile());
        p.name = default_profile_name;
        if (!m_manager.loadProfile(p, &error))
        {
            if (!m_manager.createEmptyProfile(p))
            {
                msgBox(m_hWnd, IDS_ERROR_NEWPROFILE_FAILED, MB_OK|MB_ICONSTOP);
                return false;
            }
        }
    }
    return true;
}
void CDBCommandBuilderBase::GenerateFieldConditionStr(const DBColumnSchema& col,const tstring& val, tstring& buffer)
{
	buffer.append(col.DBName);

	if(col.DBType->IsNull(val.c_str()))
	{
		buffer.append(TEXT(" IS null"));
	}
	else
	{
		buffer.append(TEXT(" = "));
		WrapperValue(val.c_str(), col.DBType, buffer);		
	}
}
int CDBCommandBuilderBase::GenerateSqlSelect(tstring& buffer)
{
	buffer.append(TEXT("SELECT * FROM "));
	WrapperIdentifier(TableSchema_->DBName.c_str(), buffer);

	return 1;
}
void CDBCommandBuilderBase::GenerateConditionStr(const IDBRecord& rec, const CDBRecordComparison& cmp, tstring& buffer)
{
	if(cmp.KeyFields().size() > 0)
	{
		buffer.append(TEXT(" WHERE "));

		for (int i = 0; i < cmp.KeyFields().size(); ++i)
		{					
			int field = cmp.KeyFields()[i];
			GenerateFieldConditionStr((*TableSchema_)[field], rec.GetField(field), buffer);
			buffer.append(TEXT(" AND "));
		}

		*(buffer.end() - 4) = '\0';
	}
}
int CDBCommandBuilderBase::GenerateSqlDelete(const IDBRecord& rec, const CDBRecordComparison& cmp, tstring& buffer)
{
	buffer.append(TEXT("DELETE FROM "));
	WrapperIdentifier(TableSchema_->DBName.c_str(), buffer);
	GenerateConditionStr(rec, cmp, buffer);

	return 1;
}
Beispiel #11
0
void NumberFormatter::append0(tstring& str, int64_t value, int width)
{
    FIRTEX_ASSERT2 (width > 0 && width < 64);

    char buffer[64];
    std::sprintf(buffer, "%0*" I64_FMT"d", width, (I64_VAL)value);
    str.append(buffer);
}
Beispiel #12
0
void NumberFormatter::append0(tstring& str, uint32_t value, int width)
{
    FIRTEX_ASSERT2 (width > 0 && width < 64);

    char buffer[64];
    std::sprintf(buffer, "%0*u", width, value);
    str.append(buffer);
}
Beispiel #13
0
void NumberFormatter::append(tstring& str, double value, int width, int precision)
{
    FIRTEX_ASSERT2 (width > 0 && width < 64 && precision >= 0 && precision < width);

    char buffer[64];
    std::sprintf(buffer, "%*.*f", width, precision, value);
    str.append(buffer);
}
Beispiel #14
0
void NumberFormatter::append(tstring& str, double value, int precision)
{
    FIRTEX_ASSERT2 (precision >= 0 && precision < 32);

    char buffer[64];
    std::sprintf(buffer, "%.*f", precision, value);
    str.append(buffer);
}
int CDBCommandBuilderBase::GenerateSqlUpdate(const IDBRecord& ori, const IDBRecord& cur, const CDBRecordComparison& cmp, tstring& buffer)
{
	buffer.append(TEXT("UPDATE "));
	WrapperIdentifier(TableSchema_->DBName.c_str(), buffer);
	buffer.append(TEXT(" SET "));

	for (int i = 0; i < TableSchema_->Columns.size(); ++i)
	{
		GenerateFieldAssignmentStr(TableSchema_->Columns[i], cur.GetField(i), buffer);
		buffer.append(TEXT(", "));
	}

	*(buffer.end() - 2) = ' ';
	GenerateConditionStr(ori, cmp, buffer);

	return 1;
}
Beispiel #16
0
static void
FormatDecodedMETAR(const METAR &metar, const ParsedMETAR &parsed,
                   tstring &output)
{
  /*
  00 ## Hamburg-Fuhlsbuettel, Germany (EDDH) 53-38N 010-00E 15M ##
  01 ## Dec 14, 2011 - 06:20 PM EST / 2011.12.14 2320 UTC ##
  02 ## Wind: from the SW (220 degrees) at 18 MPH (16 KT):0 ##
  03 ## Visibility: greater than 7 mile(s):0 ##
  04 ## Sky conditions: mostly cloudy ##
  05 ## Temperature: 41 F (5 C) ##
  06 ## Dew Point: 35 F (2 C) ##
  07 ## Relative Humidity: 80% ##
  08 ## Pressure (altimeter): 29.47 in. Hg (0998 hPa) ##
  */

  LineSplitter lines(metar.decoded);
  for (unsigned i = 0; lines.HasNext(); ++i) {
    auto range = lines.Next();

    if (i == 0) {
      // Try to provide a new title line
      if (parsed.name_available) {
        StaticString<256> buffer;
        buffer.Format(_("METAR for %s:"), parsed.name.c_str());
        output += buffer;
        output += '\n';
      } else
        output.append(range.first, range.second);

      output += '\n';

    } else if (i == 1) {
      // ignore second line and continue without line break

    } else {
      if (!FormatDecodedMETARLine(range.first, range.second, parsed, output)) {
        output.append(range.first, range.second);
        output += '\n';
      }
    }
  }
}
int CDBCommandBuilderBase::WrapperValue(const tchar* val, IDBDataType const* type, tstring& buffer)
{
	_ASSERT(type && val);
	if(type->IsNull(val))
	{
		buffer.append(TEXT("null"));
	}
	else
	{
		switch(type->Category())
		{
		case EnumDBDataTypeCategory::DBString:
			{
				buffer.append(TEXT("'"));

				// convert '\'' to "''"
				const tchar* pTail = val + _tcslen(val);
				const tchar* pPosPre = val;
				const tchar* pPosCur = 0;
				while(pPosPre < pTail && (pPosCur = _tcschr(pPosPre, '\'')) != NULL)
				{
					if(pPosCur - pPosPre > 1)
					{
						buffer.append(pPosPre, pPosCur);
						buffer.append(TEXT("''"));
					}

					pPosPre = pPosCur + 1;
				}

				if(pPosPre < pTail)
				{
					buffer.append(pPosPre, pTail);
				}

				buffer.append(TEXT("'"));
			}
			break;
		case EnumDBDataTypeCategory::DBNumeric:
			{
				buffer.append(val);
			}
			break;
		case EnumDBDataTypeCategory::DBBlob:
			throw std::exception();
			break;
		}
	}

	return 1;
}
int CDBCommandBuilderBase::WrapperIdentifier(const tchar* val, tstring& buffer)
{
	const tchar* pTail;

	if(!val || val >= (pTail = val + _tcslen(val))) // Identifier should not be null
	{
		throw new std::exception();
	}

	//buffer.append(TEXT("["));
	buffer.append(val);
	//buffer.append(TEXT("]"));

	return 1;
}
Beispiel #19
0
void NumberFormatter::append(tstring& str, float value)
{
    char buffer[64];
    std::sprintf(buffer, "%.*g", 8, (double) value);
    str.append(buffer);
}
Beispiel #20
0
void NumberFormatter::append(tstring& str, uint64_t value)
{
    char buffer[64];
    std::sprintf(buffer, "%" I64_FMT"u", (UI64_VAL)value);
    str.append(buffer);
}
Beispiel #21
0
void NumberFormatter::append(tstring& str, uint32_t value)
{
    char buffer[64];
    std::sprintf(buffer, "%u", value);
    str.append(buffer);
}
Beispiel #22
0
void NumberFormatter::append(tstring& str, double value)
{
    char buffer[64];
    std::sprintf(buffer, "%.*g", 16, value);
    str.append(buffer);
}