bool StringToULongLong(const wxString &str, wxULongLong &_result) 
{
	wxULongLong_t result = 0;
	wxLongLong_t test;
	bool bResult, bResultTest;

#if wxCHECK_VERSION(2,7,2)
	bResultTest = str.ToLongLong(&test);
	if(test < 0 && bResultTest) {
		return false;
	}
	// supported first with 2.7.2
	bResult = str.ToULongLong(&result);
#else
	bResult = false;
	(void)test;
	(void)bResultTest;
#endif

	if(!bResult) {
		// this is ONLY the case, if the number is a) too big
		// or b) we are using mingw
		result = StrToULongLong(str, bResult);
	}

	if(bResult) {
		_result = result;
	}

	return bResult;
}
Esempio n. 2
0
bool CRegTable::TryParseFPR(wxString str, FormatSpecifier format, unsigned long long* value)
{
  if (format == FormatSpecifier::Hex16)
  {
    return str.ToULongLong(value, 16);
  }
  if (format == FormatSpecifier::Double)
  {
    double double_val;
    if (str.ToCDouble(&double_val))
    {
      std::memcpy(value, &double_val, sizeof(u64));
      return true;
    }
    return false;
  }
  return false;
}
Esempio n. 3
0
uint64_t cbDebuggerStringToAddress(const wxString &address)
{
    if (address.empty())
        return 0;
#if defined(__WXMSW__)
    // Workaround for the 'ToULongLong' bug in wxWidgets 2.8.12
#if wxCHECK_VERSION(2, 8, 12)
    return strtoull(address.mb_str(), nullptr, 16);
#else
    uint64_t result;
    if (address.ToULongLong(&result))
        return result;
    else
        return 0;
#endif // wxCHECK_VERSION
#else
    uint64_t result;
    if (address.ToULong(&result, 16))
        return result;
    else
        return 0;
#endif
}
Esempio n. 4
0
static u64 StrToU64(const wxString& str, int base = 10)
{
    wxULongLong_t l;
    str.ToULongLong(&l, base);
    return l;
}
Esempio n. 5
0
void CUpdater::ParseData()
{
	const wxLongLong ownVersionNumber = CBuildInfo::ConvertToVersionNumber(CBuildInfo::GetVersion().c_str());
	version_information_ = version_information();

	wxString raw_version_information = raw_version_information_;

	log_ += wxString::Format(_("Parsing %d bytes of version information.\n"), static_cast<int>(raw_version_information.size()));

	while( !raw_version_information.empty() ) {
		wxString line;
		int pos = raw_version_information.Find('\n');
		if (pos != -1) {
			line = raw_version_information.Left(pos);
			raw_version_information = raw_version_information.Mid(pos + 1);
		}
		else {
			line = raw_version_information;
			raw_version_information.clear();
		}

		wxStringTokenizer tokens(line, _T(" \t\n"),  wxTOKEN_STRTOK);
		if( !tokens.CountTokens() ) {
			// After empty line, changelog follows
			version_information_.changelog = raw_version_information;
			version_information_.changelog.Trim(true);
			version_information_.changelog.Trim(false);

			if( COptions::Get()->GetOptionVal(OPTION_LOGGING_DEBUGLEVEL) == 4 ) {
				log_ += wxString::Format(_T("Changelog: %s\n"), version_information_.changelog);
			}
			break;
		}

		if( tokens.CountTokens() != 2 && tokens.CountTokens() != 6 ) {
			if( COptions::Get()->GetOptionVal(OPTION_LOGGING_DEBUGLEVEL) == 4 ) {
				log_ += wxString::Format(_T("Skipping line with %d tokens\n"), static_cast<int>(tokens.CountTokens()));
			}
			continue;
		}

		wxString type = tokens.GetNextToken();
		wxString versionOrDate = tokens.GetNextToken();

		if (type == _T("nightly")) {
			wxDateTime nightlyDate;
			if( !nightlyDate.ParseFormat(versionOrDate, _T("%Y-%m-%d")) ) {
				if( COptions::Get()->GetOptionVal(OPTION_LOGGING_DEBUGLEVEL) == 4 ) {
					log_ += _T("Could not parse nightly date\n");
				}
				continue;
			}

			wxDateTime buildDate = CBuildInfo::GetBuildDate();
			if (!buildDate.IsValid() || !nightlyDate.IsValid() || nightlyDate <= buildDate) {
				if( COptions::Get()->GetOptionVal(OPTION_LOGGING_DEBUGLEVEL) == 4 ) {
					log_ += _T("Nightly isn't newer\n");
				}
				continue;
			}
		}
		else {
			wxLongLong v = CBuildInfo::ConvertToVersionNumber(versionOrDate.c_str());
			if (v <= ownVersionNumber)
				continue;
		}

		build* b = 0;
		if( type == _T("nightly") && UpdatableBuild() ) {
			b = &version_information_.nightly_;
		}
		else if( type == _T("release") ) {
			b = &version_information_.stable_;
		}
		else if( type == _T("beta") ) {
			b = &version_information_.beta_;
		}

		if( b ) {
			b->version_ = versionOrDate;

			if( UpdatableBuild() && tokens.CountTokens() == 4 ) {
				wxString const url = tokens.GetNextToken();
				wxString const sizestr = tokens.GetNextToken();
				wxString const hash_algo = tokens.GetNextToken();
				wxString const hash = tokens.GetNextToken();

				if( GetFilename(url).empty() ) {
					if( COptions::Get()->GetOptionVal(OPTION_LOGGING_DEBUGLEVEL) == 4 ) {
						log_ += wxString::Format(_T("Could not extract filename from URL: %s\n"), url);
					}
					continue;
				}

				if( hash_algo.CmpNoCase(_T("sha512")) ) {
					continue;
				}

				unsigned long long l = 0;
				if( !sizestr.ToULongLong(&l) ) {
					if( COptions::Get()->GetOptionVal(OPTION_LOGGING_DEBUGLEVEL) == 4 ) {
						log_ += wxString::Format(_T("Could not parse size: %s"), sizestr);
					}
					continue;
				}

				b->url_ = url;
				b->size_ = l;
				b->hash_ = hash;

				// @translator: Two examples: Found new nightly 2014-04-03\n, Found new release 3.9.0.1\n
				log_ += wxString::Format(_("Found new %s %s\n"), type, b->version_);
			}
		}
	}

	version_information_.update_available();

	COptions::Get()->SetOption( OPTION_UPDATECHECK_NEWVERSION, raw_version_information_ );
}