Пример #1
0
/**
 * Reads the selected LanguageFile into the cache
 */
void
ReadLanguageFile()
{
  CloseLanguageFile();

  LogStartUp(_T("Loading language file"));

  TCHAR buffer[MAX_PATH], second_buffer[MAX_PATH];
  const TCHAR *value = Profile::GetPath(ProfileKeys::LanguageFile, buffer)
    ? buffer : _T("");

  if (_tcscmp(value, _T("none")) == 0)
    return;

  if (StringIsEmpty(value) || _tcscmp(value, _T("auto")) == 0) {
    AutoDetectLanguage();
    return;
  }

  const TCHAR *base = BaseName(value);
  if (base == NULL)
    base = value;

  if (base == value) {
    LocalPath(second_buffer, value);
    value = second_buffer;
  }

  if (!LoadLanguageFile(value) && !ReadResourceLanguageFile(base))
    AutoDetectLanguage();
}
Пример #2
0
void
TrafficListWidget::UpdateList()
{
  assert(filter_widget != nullptr);

  items.clear();
  last_update.Clear();

  const TCHAR *callsign = filter_widget->GetValueString(CALLSIGN);
  if (!StringIsEmpty(callsign)) {
    FlarmId ids[30];
    unsigned count = FlarmDetails::FindIdsByCallSign(callsign, ids, 30);

    for (unsigned i = 0; i < count; ++i)
      AddItem(ids[i]);
  } else {
    /* if no filter was set, show a list of current traffic and known
       traffic */

    /* add live FLARM traffic */
    for (const auto &i : CommonInterface::Basic().flarm.traffic.list) {
      AddItem(i.id);
    }

    /* add FLARM peers that have a user-defined color */
    for (const auto &i : traffic_databases->flarm_colors) {
      Item &item = AddItem(i.first);
      item.color = i.second;
    }

    /* add FLARM peers that have a user-defined name */
    for (const auto &i : traffic_databases->flarm_names) {
      AddItem(i.id);
    }

#ifdef HAVE_SKYLINES_TRACKING_HANDLER
    /* show SkyLines traffic unless this is a FLARM traffic picker
       dialog (from dlgTeamCode) */
    if (action_listener == nullptr) {
      const auto &data = tracking->GetSkyLinesData();
      const ScopeLock protect(data.mutex);
      for (const auto &i : data.traffic) {
        items.emplace_back(i.first, i.second.location);
        Item &item = items.back();

        if (i.second.location.IsValid() &&
            CommonInterface::Basic().location_available)
          item.vector = GeoVector(CommonInterface::Basic().location,
                                  i.second.location);
      }
    }
#endif
  }

  GetList().SetLength(items.size());

  UpdateVolatile();
  UpdateButtons();
}
Пример #3
0
const TCHAR *
PrefixDataField::GetAsDisplayString() const
{
  const TCHAR *s = DataFieldString::GetAsDisplayString();
  if (StringIsEmpty(s))
    s = _T("*");
  return s;
}
Пример #4
0
/*********************************************************************
                Get the V3_KEY In order to save it
*********************************************************************/
bool GetV3key()
{
    memset(&v3key, 0, sizeof(v3key));
    if(Form_V3KEY->CheckBox_SaveV3->Checked)
    {
        if(!StringIsEmpty(Form_V3KEY->Edit1->Text, 2)
        || !StringIsEmpty(Form_V3KEY->Edit2->Text, 2)
        || !StringIsEmpty(Form_V3KEY->Edit3->Text, 32)
        || !StringIsEmpty(Form_V3KEY->Edit4->Text, 32)
        || !StringIsEmpty(Form_V3KEY->Edit5->Text, 32)
        || !StringIsEmpty(Form_V3KEY->Edit6->Text, 32)
        || !StringIsEmpty(Form_V3KEY->Edit7->Text, 32))
        {
            return false;
        }
        sprintf(v3key.itemname, "V3KEY");
        v3key.bSave[0] = '1';
        //if(Form_V3KEY->Edit_Manufactur->Text)
        strcpy(v3key.manufactur, Form_V3KEY->Edit1->Text.c_str());
        strcpy(v3key.version, Form_V3KEY->Edit2->Text.c_str());
        strcpy(v3key.key_value[0], Form_V3KEY->Edit3->Text.c_str());
        strcpy(v3key.key_value[1], Form_V3KEY->Edit4->Text.c_str());
        strcpy(v3key.key_value[2], Form_V3KEY->Edit5->Text.c_str());
        strcpy(v3key.key_value[3], Form_V3KEY->Edit6->Text.c_str());
        strcpy(v3key.key_value[4], Form_V3KEY->Edit7->Text.c_str());
        return true;
    }
    return false;
}
Пример #5
0
void
Profile::LoadFile(const TCHAR *szFile)
{
  if (StringIsEmpty(szFile))
    return;

  if (LoadFile(map, szFile))
    LogFormat(_T("Loaded profile from %s"), szFile);
}
Пример #6
0
void
Profile::SaveFile(const TCHAR *szFile)
{
  if (StringIsEmpty(szFile))
    return;

  LogFormat(_T("Saving profile to %s"), szFile);
  SaveFile(map, szFile);
}
Пример #7
0
void
NmeaReplay::SetFilename(const TCHAR *name)
{
  if (!name || StringIsEmpty(name))
    return;

  if (_tcscmp(file_name, name) != 0)
    _tcscpy(file_name, name);
}
Пример #8
0
bool
LiveTrack24::Client::GenerateSessionID(const TCHAR *_username, const TCHAR *_password,
                                       OperationEnvironment &env)
{
  // http://www.livetrack24.com/client.php?op=login&user=<username>&pass=<pass>

  assert(_username != NULL);
  assert(!StringIsEmpty(_username));
  assert(_password != NULL);
  assert(!StringIsEmpty(_password));

  const WideToUTF8Converter username2(_username);
  const WideToUTF8Converter password2(_password);
  if (!username2.IsValid() || !password2.IsValid())
    return false;

  NarrowString<1024> url;
  url.Format("http://%s/client.php?op=login&user=%s&pass=%s",
             (const char *)server, (const char *)username2, (const char *)_password);

  // Open download session
  Net::Session session;

  // Request the file
  char buffer[1024];
  size_t size = Net::DownloadToBuffer(session, url, buffer, sizeof(buffer) - 1,
                                      env);
  if (size == 0 || size == size_t(-1))
    return false;

  buffer[size] = 0;

  char *p_end;
  UserID user_id = strtoul(buffer, &p_end, 10);
  if (buffer == p_end) {
      return false;
  }

  username.SetASCII(_username);
  password.SetASCII(_password);
  session_id = RandomSessionID();
  session_id |= (user_id & 0x00ffffff);
  return true;
}
Пример #9
0
void
TaskEditPanel::OnPaintItem(Canvas &canvas, const PixelRect rc,
                           unsigned DrawListIndex)
{
  assert(DrawListIndex <= ordered_task->TaskSize());

  const unsigned padding = Layout::GetTextPadding();
  const unsigned line_height = rc.bottom - rc.top;

  TCHAR buffer[120];

  // Draw "Add turnpoint" label
  if (DrawListIndex == ordered_task->TaskSize()) {
    row_renderer.DrawFirstRow(canvas, rc, _("Add Turnpoint"));
    return;
  }

  const OrderedTaskPoint &tp = ordered_task->GetTaskPoint(DrawListIndex);
  GeoVector leg = tp.GetNominalLegVector();
  bool show_leg_info = leg.distance > fixed(0.01);

  PixelRect text_rc = rc;
  text_rc.left += line_height + padding;

  if (show_leg_info) {
    // Draw leg distance
    FormatUserDistanceSmart(leg.distance, buffer, true);
    const int x1 = row_renderer.DrawRightFirstRow(canvas, rc, buffer);

    // Draw leg bearing
    FormatBearing(buffer, ARRAY_SIZE(buffer), leg.bearing);
    const int x2 = row_renderer.DrawRightSecondRow(canvas, rc, buffer);

    text_rc.right = std::min(x1, x2);
  }

  // Draw details line
  OrderedTaskPointRadiusLabel(tp.GetObservationZone(), buffer);
  if (!StringIsEmpty(buffer))
    row_renderer.DrawSecondRow(canvas, text_rc, buffer);

  // Draw turnpoint name
  OrderedTaskPointLabel(tp.GetType(), tp.GetWaypoint().name.c_str(),
                        DrawListIndex, buffer);
  row_renderer.DrawFirstRow(canvas, text_rc, buffer);

  // Draw icon
  const RasterPoint pt(rc.left + line_height / 2,
                       rc.top + line_height / 2);

  const unsigned radius = line_height / 2 - padding;
  OZPreviewRenderer::Draw(canvas, tp.GetObservationZone(),
                          pt, radius, task_look,
                          CommonInterface::GetMapSettings().airspace,
                          airspace_look);
}
Пример #10
0
unsigned
FlarmDetails::FindIdsByCallSign(const TCHAR *cn, FlarmId array[],
                                unsigned size)
{
  assert(cn != NULL);
  assert(!StringIsEmpty(cn));
  assert(traffic_databases != nullptr);

  return traffic_databases->FindIdsByName(cn, array, size);
}
Пример #11
0
void
WPASupplicant::Close()
{
  if (!StringIsEmpty(local_path)) {
    File::Delete(local_path);
    local_path[0] = 0;
  }

  fd.Close();
}
Пример #12
0
void
SetPrimaryDataPath(const TCHAR *path)
{
  assert(path != NULL);
  assert(!StringIsEmpty(path));

  free(data_path);
  data_path = _tcsdup(path);
  data_path_length = _tcslen(data_path);
}
Пример #13
0
// TaskSave
// Saves the task to the specified filename
void
InputEvents::eventTaskSave(const TCHAR *misc)
{
  if (protected_task_manager == NULL)
    return;

  if (!StringIsEmpty(misc)) {
    protected_task_manager->TaskSave(LocalPath(misc));
  }
}
Пример #14
0
char * zuluCryptGetLoopDeviceAddress( const char * device )
{
	char * z = NULL ;
	const char * e ;

	string_t st = StringVoid ;
	string_t xt = StringVoid ;

	int i ;
	int r ;

	z = zuluCryptLoopDeviceAddress_1( device ) ;

	if( z == NULL ){
		return NULL ;
	}else{
		st = String( "" ) ;

		for( i = 0 ; i < 255 ; i++ ){

			StringReplace( st,"/sys/block/loop" ) ;
			StringAppendInt( st,i ) ;

			xt = StringGetFromVirtualFile( StringAppend( st,"/loop/backing_file" ) ) ;

			e = StringRemoveRight( xt,1 ) ;
			r = StringsAreEqual( e,z ) ;

			StringDelete( &xt ) ;

			if( r ){

				StringReplace( st,"/dev/loop" ) ;
				e = StringAppendInt( st,i ) ;

				if( StringsAreNotEqual( device,e ) ){

					break ;
				}
			}else{
				StringReset( st ) ;
			}
		}

		StringFree( z ) ;

		if( StringIsEmpty( st ) ){

			StringDelete( &st ) ;
			return NULL ;
		}else{
			return StringDeleteHandle( &st ) ;
		}
	}
}
Пример #15
0
// returns NULL if CommandPreffix is not command Command
// returns pointer to next token otherwise
LPTSTR IsCommand(LPTSTR Command, LPTSTR CommandPreffix)
{
	// avoid case of empty string
	if (StringIsEmpty(CommandPreffix))
		return NULL;

	while(*Command && *CommandPreffix && (*Command == *CommandPreffix)) {
		Command++;
		CommandPreffix++;
	}

	if(StringIsEmpty(CommandPreffix))
		return CommandPreffix;
	else if (*CommandPreffix == TEXT(' ')) {
		while(*CommandPreffix == TEXT(' '))
			CommandPreffix++;
		return CommandPreffix;
	} else
		return NULL;
}
Пример #16
0
/**
 * Looks up a string of text from the current language file
 *
 * Currently very simple. Looks up the current string and current language
 * to find the appropriate string response. On failure will return
 * the string itself.
 *
 * NOTES CACHING:
 * - Could load the whole file or part
 * - qsort/bsearch good idea
 * - cache misses in data structure for future use
 * @param text The text to search for
 * @return The translation if found, otherwise the text itself
 */
const TCHAR*
gettext(const TCHAR* text)
{
  assert(language_allowed);
  assert(text != NULL);

  // If empty string or no language file is loaded -> skip the translation
  if (StringIsEmpty(text) || mo_file == NULL)
    return text;

#ifdef _UNICODE
  // Try to lookup the english string in the map of cached TCHAR translations
  const tstring text2(text);
  translation_map::const_iterator it = translations.find(text2);
  if (it != translations.end())
    // Return the looked up translation
    return it->second.c_str();

  // Convert the english TCHAR string to char
  size_t wide_length = _tcslen(text);
  char original[wide_length * 4 + 1];

  // If the conversion failed -> use the english original string
  if (::WideCharToMultiByte(CP_UTF8, 0, text, -1,
                            original, sizeof(original), NULL, NULL) <= 0)
    return text;

  // Lookup the converted english char string in the MO file
  const char *translation = mo_file->lookup(original);
  // If the lookup failed -> use the english original string
  if (translation == NULL || *translation == 0 ||
      strcmp(original, translation) == 0)
    return text;

  // Convert the translated char string to TCHAR
  TCHAR translation2[strlen(translation) + 1];
  if (::MultiByteToWideChar(CP_UTF8, 0, translation, -1, translation2,
                            ARRAY_SIZE(translation2)) <= 0)
    return text;

  // Add the translated TCHAR string to the cache map for the next time
  translations[text2] = translation2;

  // Return the translated TCHAR string
  return translations[text2].c_str();
#else
  // Search for the english original string in the MO file
  const char *translation = mo_file->lookup(text);
  // Return either the translated string if found or the original
  return translation != NULL && *translation != 0 && ValidateUTF8(translation)
    ? translation
    : text;
#endif
}
Пример #17
0
bool
PolarGlue::LoadFromProfile(PolarInfo &polar)
{
  const TCHAR *polar_string = Profile::Get(szProfilePolar);
  if (polar_string != NULL && !StringIsEmpty(polar_string) &&
      polar.ReadString(polar_string)) {
    return true;
  }

  return LoadFromOldProfile(polar);
}
Пример #18
0
Path::const_pointer
Path::GetExtension() const
{
  auto base = GetBase();
  if (base == nullptr)
    return nullptr;

  assert(!StringIsEmpty(base.c_str()));

  return StringFindLast(base.c_str() + 1, _T('.'));
}
Пример #19
0
bool
AirspaceParser::Parse(TLineReader &reader, OperationEnvironment &operation)
{
  bool ignore = false;

  // Create and init ProgressDialog
  operation.SetProgressRange(1024);

  const long file_size = reader.GetSize();

  TempAirspaceType temp_area;
  AirspaceFileType filetype = AFT_UNKNOWN;

  TCHAR *line;

  // Iterate through the lines
  for (unsigned line_num = 1; (line = reader.ReadLine()) != NULL; line_num++) {
    // Skip empty line
    if (StringIsEmpty(line))
      continue;

    if (filetype == AFT_UNKNOWN) {
      filetype = DetectFileType(line);
      if (filetype == AFT_UNKNOWN)
        continue;
    }

    // Parse the line
    if (filetype == AFT_OPENAIR)
      if (!ParseLine(airspaces, line, temp_area) &&
          !ShowParseWarning(line_num, line, operation))
        return false;

    if (filetype == AFT_TNP)
      if (!ParseLineTNP(airspaces, line, temp_area, ignore) &&
          !ShowParseWarning(line_num, line, operation))
        return false;

    // Update the ProgressDialog
    if ((line_num & 0xff) == 0)
      operation.SetProgressPosition(reader.Tell() * 1024 / file_size);
  }

  if (filetype == AFT_UNKNOWN) {
    operation.SetErrorMessage(_("Unknown airspace filetype"));
    return false;
  }

  // Process final area (if any)
  if (!temp_area.points.empty())
    temp_area.AddPolygon(airspaces);

  return true;
}
Пример #20
0
bool
PolarGlue::LoadFromProfile(PolarInfo &polar)
{
  const char *polar_string = Profile::Get(ProfileKeys::Polar);
  if (polar_string != nullptr && !StringIsEmpty(polar_string) &&
      ParsePolar(polar, polar_string)) {
    return true;
  }

  return LoadFromOldProfile(polar);
}
Пример #21
0
void
Profile::Save()
{
  if (!IsModified())
    return;

  LogFormat("Saving profiles");
  if (StringIsEmpty(startProfileFile))
    SetFiles(_T(""));
  SaveFile(startProfileFile);
}
Пример #22
0
/*********************************************************************
                           获得VOICEMAIL号码
*********************************************************************/
bool GetVoiceMail()
{
    memset(&voicemail, 0, sizeof(voicemail));
    sprintf(voicemail.itemname, "VOICEMAIL");
    if(!StringIsEmpty(PRI_Form->Edit_VoiceMail->Text, PRI_Form->Edit_VoiceMail->Text.Length()))
    {
        return false;
    }
    strcpy(voicemail.voiceNumber, PRI_Form->Edit_VoiceMail->Text.c_str());
    return true;
}
Пример #23
0
static void
ParseCommandLine(Args &args)
{
  path = args.ExpectNextPath();

#ifdef USE_GDI
  TCHAR *endptr;
  unsigned _id = ParseUnsigned(path.c_str(), &endptr);
  if (StringIsEmpty(endptr))
    id = ResourceId(_id);
#endif
}
Пример #24
0
static void *
GetCallBack(const CallBackTableEntry *lookup_table,
            const XMLNode &node, const TCHAR* attribute)
{
  const TCHAR *name = node.getAttribute(attribute);
  if (name == NULL)
    return NULL;

  assert(!StringIsEmpty(name));

  return CallBackLookup(lookup_table, name);
}
Пример #25
0
const TCHAR *
BaseName(const TCHAR *path)
{
    const TCHAR *p = LastSeparator(path);
    if (p != nullptr)
        path = p + 1;

    if (StringIsEmpty(path))
        return nullptr;

    return path;
}
Пример #26
0
// TaskSave
// Saves the task to the specified filename
void
InputEvents::eventTaskSave(const TCHAR *misc)
{
  if (protected_task_manager == NULL)
    return;

  if (!StringIsEmpty(misc)) {
    TCHAR buffer[MAX_PATH];
    LocalPath(buffer, misc);
    protected_task_manager->TaskSave(buffer);
  }
}
Пример #27
0
const TCHAR *
BaseName(const TCHAR *path)
{
  const TCHAR *p = LastSeparator(path);
  if (p != NULL)
    path = p + 1;

  if (StringIsEmpty(path))
    return NULL;

  return path;
}
Пример #28
0
/**
 * Checks whether the given string str equals "." or ".."
 * @param str The string to check
 * @return True if string equals "." or ".."
 */
#ifndef HAVE_POSIX
static bool
IsDots(const TCHAR* str)
{
  return StringIsEqual(str, _T(".")) || StringIsEqual(str, _T(".."));
}
#endif

#ifndef HAVE_POSIX /* we use fnmatch() on POSIX */
static bool
checkFilter(const TCHAR *filename, const TCHAR *filter)
{
  // filter = e.g. "*.igc" or "config/*.prf"
  // todo: make filters like "config/*.prf" work

  // if invalid or short filter "*" -> return true
  // todo: check for asterisk
  if (!filter || StringIsEmpty(filter + 1))
    return true;

  return StringEndsWithIgnoreCase(filename, filter + 1);
}
Пример #29
0
/**
 * Delete eldest IGC file in the given path
 * @param gps_info Current NMEA_INFO
 * @param pathname Path where to search for the IGC files
 * @return True if a file was found and deleted, False otherwise
 */
static bool
DeleteOldestIGCFile(unsigned current_year, const TCHAR *pathname)
{
  OldIGCFileFinder visitor(current_year);
  Directory::VisitSpecificFiles(pathname, _T("*.igc"), visitor, true);

  if (StringIsEmpty(visitor.GetOldestIGCFile()))
    return false;

  // now, delete the file...
  File::Delete(visitor.GetOldestIGCFile());
  return true;
}
Пример #30
0
/*********************************************************************
                           获得SIM/IMSI数据
*********************************************************************/
bool GetSIM_IMSI()
{
    memset(&sim_imsi, 0, sizeof(sim_imsi));
    sprintf(sim_imsi.itemname, "SIM_IMSI");
    if(Security_Form->RadioButton_SIM_Disable->Checked == true)
    {
        sim_imsi.simpin[0] = '0';
    }
    else
    {
        sim_imsi.simpin[0] = '1';
    }
    if(Security_Form->ComboBox_AutoSIMState->Text == ""
    || !StringIsEmpty(Security_Form->Edit_SIM_PIN_Default->Text, Security_Form->Edit_SIM_PIN_Default->Text.Length())
    || !StringIsEmpty(Security_Form->Edit_SIM_PIN_Locked->Text, Security_Form->Edit_SIM_PIN_Locked->Text.Length()))
    {
        return false;
    }
    if(strcmp(Security_Form->ComboBox_AutoSIMState->Text.c_str(), "Deactive") == 0)
    {
        sim_imsi.autopinlock[0] = '0';
    }
    else
    {
        sim_imsi.autopinlock[0] = '1';
    }
    strcpy(sim_imsi.defaultpin , Security_Form->Edit_SIM_PIN_Default->Text.c_str());
    strcpy(sim_imsi.autopin, Security_Form->Edit_SIM_PIN_Locked->Text.c_str());
    if(Security_Form->RadioButton_IMSI_Disable->Checked == true)
    {
        sim_imsi.imsilock[0] = '0';
    }
    else
    {
        sim_imsi.imsilock[0] = '1';
    }
    return true;
    //strcpy(sim_imsi.imsiNumber, Security_Form->Edit_IMSINumber->Text.c_str());
}