/**
 * Parses the data provided by the airfield details file handle
 */
static void
ParseAirfieldDetails(Waypoints &way_points, TLineReader &reader,
                     OperationEnvironment &operation)
{
  tstring details;
  std::vector<tstring> files_external, files_embed;
  TCHAR name[201];
  const TCHAR *filename;

  name[0] = 0;

  bool in_details = false;
  int i;

  const long filesize = std::max(reader.GetSize(), 1l);
  operation.SetProgressRange(100);

  TCHAR *line;
  while ((line = reader.ReadLine()) != NULL) {
    if (line[0] == _T('[')) { // Look for start
      if (in_details)
        SetAirfieldDetails(way_points, name, details, files_external,
                           files_embed);

      details.clear();
      files_external.clear();
      files_embed.clear();

      // extract name
      for (i = 1; i < 201; i++) {
        if (line[i] == _T(']'))
          break;

        name[i - 1] = line[i];
      }
      name[i - 1] = 0;

      in_details = true;

      operation.SetProgressPosition(reader.Tell() * 100 / filesize);
    } else if ((filename =
                StringAfterPrefixCI(line, _T("image="))) != NULL) {
      files_embed.emplace_back(filename);
    } else if ((filename =
                StringAfterPrefixCI(line, _T("file="))) != NULL) {
#ifdef ANDROID
      files_external.emplace_back(filename);
#endif
    } else {
      // append text to details string
      if (!StringIsEmpty(line)) {
        details += line;
        details += _T('\n');
      }
    }
  }

  if (in_details)
    SetAirfieldDetails(way_points, name, details, files_external, files_embed);
}
Beispiel #2
0
/**
 * Parses the data provided by the airfield details file handle
 */
static void
ParseAirfieldDetails(Waypoints &way_points, TLineReader &reader)
{
  tstring Details;
  TCHAR Name[201];

  Name[0] = 0;

  bool inDetails = false;
  int i;

  long filesize = std::max(reader.size(), 1l);
  ProgressGlue::SetRange(100);

  TCHAR *TempString;
  while ((TempString = reader.read()) != NULL) {
    if (TempString[0] == '[') { // Look for start
      if (inDetails)
        SetAirfieldDetails(way_points, Name, Details);

      Details.clear();

      // extract name
      for (i = 1; i < 201; i++) {
        if (TempString[i] == ']')
          break;

        Name[i - 1] = TempString[i];
      }
      Name[i - 1] = 0;

      inDetails = true;

      ProgressGlue::SetValue(reader.tell() * 100 / filesize);
    } else {
      // append text to details string
      if (!string_is_empty(TempString)) {
        Details += TempString;
        Details += _T('\n');
      }
    }
  }

  if (inDetails) {
    SetAirfieldDetails(way_points, Name, Details);
    Details.clear();
  }
}