bool MainDialog::IsAppRunning(wxString app)
{
    FILE *fp;
    char path[PATH_MAX];
    char cmd[PATH_MAX];
    bool running = false;

    sprintf(cmd, "ps -C %s | grep %s", (const char*)app.ToUTF8(), (const char*)app.ToUTF8());

    fp = popen(cmd, "r");

    if (fgets(path, PATH_MAX, fp) == NULL)
    {
	running = false;
    }
    else
    {
	wxString result = wxString::FromUTF8(path);

	if (result.Find(app) == wxNOT_FOUND)
	{
	    running = false;
	}
	else
	{
	    running = true;
	}
    }

    pclose(fp);

    return running;
}
Example #2
0
void ShowMessageBoxSwitchable(const wxString &szTitle, const wxString &szMessage, const wxString &szConfigKey)
{
    CStr S;
    S = gpApp->GetConfig(SZ_SECT_DO_NOT_SHOW_THESE, szConfigKey.ToUTF8());
    if (atol(S.GetData()) > 0)
        return;

    CMessageBoxSwitchableDlg dlg(NULL, szTitle.ToUTF8(), szMessage.ToUTF8());
    dlg.ShowModal();
    if (dlg.m_chbSwitchOff->IsChecked())
        gpApp->SetConfig(SZ_SECT_DO_NOT_SHOW_THESE, szConfigKey.ToUTF8(), "1");
}
Example #3
0
// -------------------------------------------------------------------------------- //
wxString guFileDnDEncode( const wxString &file )
{
  wxString RetVal;
  wxString HexCode;
  size_t index;
  wxCharBuffer CharBuffer = file.ToUTF8();
  size_t StrLen = strlen( CharBuffer );

  for( index = 0; index < StrLen; index++ )
  {
    wxChar C = CharBuffer[ index ];
    {
      static const wxChar marks[] = wxT( " -_.\"/+!~*()'[]%" ); //~!@#$&*()=:/,;?+'

      if( ( C >= 'a' && C <= 'z' ) ||
          ( C >= 'A' && C <= 'Z' ) ||
          ( C >= '0' && C <= '9' ) ||
          wxStrchr( marks, C ) )
      {
        RetVal += C;
      }
      else
      {
        HexCode.Printf( wxT( "%%%02X" ), C & 0xFF );
        RetVal += HexCode;
      }
    }
  }
  return RetVal;
}
Example #4
0
wxString CompressedCachePath(wxString path)
{
#if defined(__WXMSW__)
    int colon = path.find(':', 0);
    path.Remove(colon, 1);
#endif
    
    /* replace path separators with ! */
    wxChar separator = wxFileName::GetPathSeparator();
    for(unsigned int pos = 0; pos < path.size(); pos = path.find(separator, pos))
        path.replace(pos, 1, _T("!"));

    //  Obfuscate the compressed chart file name, to (slightly) protect some encrypted raster chart data.
    wxCharBuffer buf = path.ToUTF8();
    unsigned char sha1_out[20];
    sha1( (unsigned char *) buf.data(), strlen(buf.data()), sha1_out );

    wxString sha1;
    for (unsigned int i=0 ; i < 20 ; i++){
        wxString s;
        s.Printf(_T("%02X"), sha1_out[i]);
        sha1 += s;
    }
    
    return g_Platform->GetPrivateDataDir() + separator + _T("raster_texture_cache") + separator + sha1;
    
}
Example #5
0
wxString FontMgr::GetFontConfigKey( const wxString &description )
{
    // Create the configstring by combining the locale with
    // a hash of the font description. Hash is used because the i18n
    // description can contain characters that mess up the config file.

    wxString configkey;
    configkey = s_locale;
    configkey.Append( _T("-") );

    using namespace std;
    locale loc;
    const collate<char>& coll = use_facet<collate<char> >( loc );
//    char cFontDesc[101];
//    wcstombs( cFontDesc, description.c_str(), 100 );
//    cFontDesc[100] = 0;

    wxCharBuffer abuf = description.ToUTF8();
    
    int fdLen = strlen( abuf );

    configkey.Append(
            wxString::Format( _T("%08lx"),
                              coll.hash( abuf.data(), abuf.data() + fdLen ) ) );
    return configkey;
}
Example #6
0
WebSocketMessage::WebSocketMessage(const wxString &text)
{
	_type = WebSocketMessage::Text;

	wxScopedCharBuffer buffer = text.ToUTF8();
	_content.AppendData(buffer.data(), buffer.length());
}
Example #7
0
// -------------------------------------------------------------------------------- //
wxString guURLEncode( const wxString &url )
{
    static const wxChar marks[] = wxT( "-_.\"!~*()'" );

	wxString RetVal;
    wxChar CurChar;

    wxCharBuffer CharBuffer = url.ToUTF8();
	int Index;
	int Count = strlen( CharBuffer );

	for( Index = 0; Index < Count; ++Index )
	{
		CurChar = CharBuffer[ Index ];

        if( ( CurChar >= 'a' && CurChar <= 'z' ) || ( CurChar >= 'A' && CurChar <= 'Z' ) ||
            ( CurChar >= '0' && CurChar <= '9' ) || wxStrchr( marks, CurChar ) )
		{
	        RetVal += CurChar;
	    }
	    else if( CurChar == wxT( ' ' ) )
	    {
		    RetVal += wxT( "+" );
		}
		else
		{
            RetVal += wxString::Format( wxT( "%%%02X" ), CurChar & 0xFF );
		}
	}

    //guLogMessage( wxT( "URLEncode: '%s' => '%s'" ), url.c_str(), RetVal.c_str() );

	return RetVal;
}
Example #8
0
// This function *will* reset the emulator in order to allow the specified elf file to
// take effect.  This is because it really doesn't make sense to change the elf file outside
// the context of a reset/restart.
void SysCoreThread::SetElfOverride( const wxString& elf )
{
	//pxAssertDev( !m_hasValidMachine, "Thread synchronization error while assigning ELF override." );
	m_elf_override = elf;


	Hle_SetElfPath(elf.ToUTF8());
}
Example #9
0
bool LV2EffectsModule::IsPluginValid(const wxString & path)
{
   LilvNode *uri = lilv_new_uri(gWorld, path.ToUTF8());
   const LilvPlugin *plugin = lilv_plugins_get_by_uri(lilv_world_get_all_plugins(gWorld), uri);
   lilv_node_free(uri);

   return plugin != NULL;
}
Example #10
0
static void __concall ConsoleToFile_DoWrite( const wxString& fmt )
{
#ifdef __linux__
	if ((g_Conf) && (g_Conf->EmuOptions.ConsoleToStdio)) ConsoleWriter_Stdout.WriteRaw(fmt);
#endif

	px_fputs( emuLog, fmt.ToUTF8() );
}
bool DXF2BRD_CONVERTER::ImportDxfFile( const wxString& aFile )
{
    dxfRW* dxf = new dxfRW( aFile.ToUTF8() );
    bool success = dxf->read( this, true );

    delete dxf;

    return success;
}
Example #12
0
bool CPhone::parseAndFormat(const wxString& val, wxString& formattedNr)
{
  initClass();

  bool rc;
  if (isInternalNumber(val))
  {
    formattedNr = val;
    rc = val.IsNumber();
  }
  else
  {
    PhoneNumber phoneNr;
    std::string strCC        = m_Prefs->getPrefs().getCC();
    std::string strAC        = m_Prefs->getPrefs().getAC();
    bool        bAddAC       = m_Prefs->getPrefs().addACIfShortLen();
    int         nLocalMaxLen = m_Prefs->getPrefs().getLocalNrMaxLen();
    PhoneNumberUtil::ErrorType err = m_PhoneUtil->ParseAndKeepRawInput(
        val.ToUTF8().data(), strCC, &phoneNr);
    if (err == PhoneNumberUtil::NO_PARSING_ERROR)
    {
      std::string number;
      if (bAddAC && !strAC.empty() && (val.Length() < nLocalMaxLen))
      {
        // When we have an AreaCode set in the preferences and the number
        // entered is too short to contain an area code then add it and
        // parse/format again.
        // NOTE: Because Area Codes are ambiguous this can produce unexpected
        //       results or simply not work at all.
        std::string nsn;
        m_PhoneUtil->GetNationalSignificantNumber(phoneNr, &nsn);
        number  = strAC;
        number += nsn;
        err = m_PhoneUtil->Parse(number, strCC, &phoneNr);
        if (err == PhoneNumberUtil::NO_PARSING_ERROR) {
          m_PhoneUtil->Format(phoneNr, PhoneNumberUtil::INTERNATIONAL, &number);
          formattedNr = wxString::FromUTF8(number.c_str());
          rc = true;
        } else {
          formattedNr = val;
          rc = false;
        }
      }
      else {
        m_PhoneUtil->Format(phoneNr, PhoneNumberUtil::INTERNATIONAL, &number);
        formattedNr = wxString::FromUTF8(number.c_str());
        rc = true;
      }
    }
    else {
      formattedNr = val;
      rc = false;
    }
  }
  return rc;
}
Example #13
0
void VirtualList::SetItems(const wxString sourcePath, const int sourceEnc, const wxString transPath, const int transEnc) {
    if (transPath.empty())
        GetStrings(sourcePath.ToUTF8().data(), sourceEnc, internalData);
    else {
        boost::unordered_map<uint32_t, std::string> sourceMap;
        boost::unordered_map<uint32_t, std::string> transMap;
        GetStrings(sourcePath.ToUTF8().data(), sourceEnc, sourceMap);
        GetStrings(transPath.ToUTF8().data(), transEnc, transMap);
        BuildStringData(sourceMap, transMap, internalData);
    }

    sort(internalData.begin(), internalData.end(), compare_old_new);
    size_t listSize = internalData.size();
    SetItemCount(listSize);
    RefreshItems(0, listSize - 1);
    //Reset everything.
    filter.clear();
    currentSelectionIndex = -1;
}
Example #14
0
bool KICADPCB::WriteIGES( const wxString& aFileName, bool aOverwrite )
{
    if( m_pcb )
    {
        std::string filename( aFileName.ToUTF8() );
        return m_pcb->WriteIGES( filename, aOverwrite );
    }

    return false;
}
Example #15
0
GpxLinkElement::GpxLinkElement(const wxString &uri, const wxString &description, const wxString &mime_type) : TiXmlElement("link")
{
      SetAttribute("href", uri.ToUTF8()); //TODO: some checks?
      if(!description.IsEmpty()) {
            GpxSimpleElement * g = new GpxSimpleElement(wxString(_T("text")), description);
            LinkEndChild(g);
      }
      if(!mime_type.IsEmpty())
            LinkEndChild(new GpxSimpleElement(wxString(_T("type")), mime_type));
}
Example #16
0
void VirtualList::SetItems(const wxString xmlPath) {
    ImportAsXML(xmlPath.ToUTF8().data(), internalData);

    sort(internalData.begin(), internalData.end(), compare_old_new);
    size_t listSize = internalData.size();
    SetItemCount(listSize);
    RefreshItems(0, listSize - 1);
    //Reset everything.
    filter.clear();
    currentSelectionIndex = -1;
}
Example #17
0
void EnviroFrame::OnDrop(const wxString &str)
{
	vtString utf8 = (const char *) str.ToUTF8();

	if (!str.Right(4).CmpNoCase(_T(".kml")))
	{
		g_App.ImportModelFromKML(utf8);
	}
	else
		LoadLayer(utf8);
}
Example #18
0
void GpxTrkElement::SetSimpleExtension(const wxString &name, const wxString &value)
{
      //FIXME: if the extensions don't exist, we should create them
      TiXmlElement * exts = FirstChildElement("extensions");
      if (exts) {
            TiXmlElement * ext = exts->FirstChildElement(name.ToUTF8());
            if (ext)
                  exts->ReplaceChild(ext, GpxSimpleElement(name, value));
            else
                  exts->LinkEndChild(new GpxSimpleElement(name, value));
      }
}
Example #19
0
void VirtualList::UpdateSelectedItem(const wxString str) {
    if (currentSelectionIndex != -1) {

        string newStr = str.ToUTF8().data();

        if (internalData[currentSelectionIndex].newString != newStr) {
            internalData[currentSelectionIndex].newString = newStr;
            internalData[currentSelectionIndex].edited = true;
            internalData[currentSelectionIndex].fuzzy = false;
            RefreshItem(currentSelectionIndex);
        }
    }
}
bool wx_TextDropTarget::OnDropText(wxCoord x, wxCoord y, const wxString& data)
{
	const Function *pFunc = Gura_LookupWxMethod(_pObj, OnDropText);
	if (pFunc == nullptr) return false;
	Environment &env = *_pObj;
	ValueList valList;
	valList.push_back(Value(x));
	valList.push_back(Value(y));
	valList.push_back(Value(data.ToUTF8()));
	Value rtn = _pObj->EvalMethod(*_pObj, pFunc, valList);
	if (!CheckMethodResult(_pObj->GetSignal(), rtn, VTYPE_boolean)) return false;
	return rtn.GetBoolean();
}
Example #21
0
void ApiHandler::OnInputLineChanged(unsigned int nid, const wxString& text) {
	// Look up notifier id
	map<unsigned int, IConnection*>::const_iterator p = m_notifiers.find(nid);
	if (p == m_notifiers.end()) return;
	IConnection& conn = *p->second;

	// Send notifier
	hessian_ipc::Writer& writer = conn.get_reply_writer();
	const wxCharBuffer str = text.ToUTF8();
	writer.write_notifier(nid, str.data());

	conn.notifier_done();
}
bool OCP_DataStreamInput_Thread::SetOutMsg(const wxString &msg)
{
    if(out_que.size() < OUT_QUEUE_LENGTH){
        wxCharBuffer buf = msg.ToUTF8();
        if(buf.data()){
            char *qmsg = (char *)malloc(strlen(buf.data()) +1);
            strcpy(qmsg, buf.data());
            out_que.push(qmsg);
            return true;
        }
    }
    
    return false;
}
Example #23
0
bool CPhone::numberFromText(const wxString& strText, wxString& result)
{
  initClass();

  bool rc = false;
  std::string number;
  PhoneNumberMatch match;
  PhoneNumberMatcher matcher(strText.ToUTF8().data(),  m_Prefs->getPrefs().getCC());
  if (matcher.HasNext()) {
    matcher.Next(&match);
    m_PhoneUtil->Format(match.number(), PhoneNumberUtil::E164, &number);
    result = wxString::FromUTF8(number.c_str());
    rc = true;
  }
  return rc;
}
bool OCP_DataStreamInput_Thread::SetOutMsg(const wxString &msg)
{
    //  Assume that the caller already owns the mutex
    wxCriticalSectionLocker locker( m_outCritical );
    
    if(out_que.size() < OUT_QUEUE_LENGTH){
        wxCharBuffer buf = msg.ToUTF8();
        if(buf.data()){
            char *qmsg = (char *)malloc(strlen(buf.data()) +1);
            strcpy(qmsg, buf.data());
            out_que.push(qmsg);
            return true;
        }
    }
    
    return false;
    
#if 0
    if((m_takIndex==0 && m_putIndex==OUT_QUEUE_LENGTH-1) || (m_takIndex==(m_putIndex+1)))
    {
        return false;
    }
    else
    {
        if(m_takIndex==(-1) && m_putIndex==(-1))
        {
            m_putIndex=0;
            m_takIndex=0;
        }
        else if(m_takIndex!=0 && m_putIndex==OUT_QUEUE_LENGTH-1)
            m_putIndex=0;
        else
            m_putIndex=m_putIndex+1;

        //      Error backstop....
        if(m_putIndex <= OUT_QUEUE_LENGTH)
            strncpy(m_poutQueue[m_putIndex], msg.mb_str(), MAX_OUT_QUEUE_MESSAGE_LENGTH-1);
        else {
            m_takIndex = -1;
            m_putIndex = -1;
        }

        return true;
    }
#endif    
}
Example #25
0
void VirtualList::ApplyFilter(const wxString str) {
    filter.clear();
    size_t itemCount = 0;
    if (!str.empty()) {
        string filterStr = boost::locale::fold_case(str.ToUTF8().data());
        for (size_t i=0, max=internalData.size(); i < max; ++i) {
            if (boost::contains(boost::locale::fold_case(internalData[i].oldString), filterStr))
                filter.push_back(i);
        }
        itemCount = filter.size();
    } else {
        itemCount = internalData.size();
    }

    SetItemCount(itemCount);
    RefreshItems(0, itemCount - 1);
}
Example #26
0
void ApiHandler::IpcEditorPrompt(EditorCtrl& editor, IConnection& conn) {
	const hessian_ipc::Call& call = *conn.get_call();

	// Get the title
	const hessian_ipc::Value& v2 = call.GetParameter(1);
	const string& t = v2.GetString();
	const wxString title(t.c_str(), wxConvUTF8, t.size());

	// Show Prompt
	WindowEnabler we; // otherwise dlg wont be able to return focus
	const wxString text = wxGetTextFromUser(title, _("Input text"), wxEmptyString, &editor);
	
	const wxCharBuffer str = text.ToUTF8();

	hessian_ipc::Writer& writer = conn.get_reply_writer();
	writer.write_reply(str.data());
}
Example #27
0
GpxRootElement::GpxRootElement(const wxString &creator, GpxMetadataElement *metadata, ListOfGpxWpts *waypoints, ListOfGpxRoutes *routes, ListOfGpxTracks *tracks, GpxExtensionsElement *extensions) : TiXmlElement("gpx")
{
      my_extensions = NULL;
      my_metadata = NULL;
      first_waypoint = NULL;
      last_waypoint = NULL;
      first_route = NULL;
      last_route = NULL;
      first_track = NULL;
      last_track = NULL;

      SetAttribute ( "version", "1.1" );
      SetAttribute ( "creator", creator.ToUTF8() );
      SetAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" );
      SetAttribute( "xmlns", "http://www.topografix.com/GPX/1/1" );
      SetAttribute( "xmlns:gpxx", "http://www.garmin.com/xmlschemas/GpxExtensions/v3" );
      SetAttribute( "xsi:schemaLocation", "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd" );
      SetMetadata(metadata);
      if (waypoints) {
            wxListOfGpxWptsNode *waypoint = waypoints->GetFirst();
            while (waypoint)
            {
                  AddWaypoint(waypoint->GetData());
                  waypoint = waypoint->GetNext();
            }
      }
      if (routes) {
            wxListOfGpxRoutesNode *route = routes->GetFirst();
            while (route)
            {
                  AddRoute(route->GetData());
                  route = route->GetNext();
            }
      }
      if (tracks) {
            wxListOfGpxTracksNode *track = tracks->GetFirst();
            while (track)
            {
                  AddTrack(track->GetData());
                  track = track->GetNext();
            }
      }
      SetExtensions(extensions);
}
Example #28
0
/*!
 The function writes the wxString object \c str to the output object.
 The string is written as is; you cannot use it to write JSON strings
 to the output text.
 The function converts the string \c str to UTF-8 and writes the buffer..
*/
int
wxJSONWriter::WriteString( wxOutputStream& os, const wxString& str )
{
    wxLogTrace( writerTraceMask, _T("(%s) string to write=%s"),
                  __PRETTY_FUNCTION__, str.c_str() );
    int lastChar = 0;
    char* writeBuff = 0;

    // the buffer that has to be written is either UTF-8 or ANSI c_str() depending
    // on the 'm_noUtf8' flag
    wxCharBuffer utf8CB = str.ToUTF8();        // the UTF-8 buffer
#if !defined( wxJSON_USE_UNICODE )
    wxCharBuffer ansiCB( str.c_str());        // the ANSI buffer

    if ( m_noUtf8 )    {
        writeBuff = ansiCB.data();
    }
    else    {
        writeBuff = utf8CB.data();
    }
#else
    writeBuff = utf8CB.data();
#endif

    // NOTE: in ANSI builds UTF-8 conversion may fail (see samples/test5.cpp,
    // test 7.3) although I do not know why
    if ( writeBuff == 0 )    {
        const char* err = "<wxJSONWriter::WriteComment(): error converting the string to UTF-8>";
        os.Write( err, strlen( err ));
        return 0;
    }
    size_t len = strlen( writeBuff );

    os.Write( writeBuff, len );
    if ( os.GetLastError() != wxSTREAM_NO_ERROR )    {
        return -1;
    }

    wxLogTrace( writerTraceMask, _T("(%s) result=%d"),
                  __PRETTY_FUNCTION__, lastChar );
    return lastChar;
}
Example #29
0
	int unElement::CompileChunk()
	{
		// Skip if no script
		if( Name == GNameNone() )
			return LUA_NOREF;

		// Setup expression
		const wxString luaText = wxString(wxT("return ")).Append(Name->wx_str());

		// Compile expression
		if( luaL_loadstring(GLuaState(), luaText.ToUTF8()) != 0 )
			throw unException( wxT("Expression did not compile: %s"), GLua().PopString(-1).c_str() );

		// Pop compiled result off the stack and store in registry
		int expression = luaL_ref(GLuaState(), LUA_REGISTRYINDEX);
		if( expression == LUA_REFNIL )
			throw unException( wxT("Expression compiled to nil result: %s"), luaText.c_str() );

		return expression;
	}
void S3D_PLUGIN_MANAGER::checkPluginPath( const wxString& aPath,
    std::list< wxString >& aSearchList )
{
    // check the existence of a path and add it to the path search list
    if( aPath.empty() )
        return;

    #ifdef DEBUG
    wxLogTrace( MASK_3D_PLUGINMGR, " * [INFO] checking for 3D plugins in '%s'\n",
        aPath.ToUTF8() );
    #endif

    wxFileName path;

    if( aPath.StartsWith( "${" ) || aPath.StartsWith( "$(" ) )
        path.Assign( ExpandEnvVarSubstitutions( aPath ), "" );
    else
        path.Assign( aPath, "" );

    path.Normalize();

    if( !wxFileName::DirExists( path.GetFullPath() ) )
        return;

    // determine if the directory is already in the list
    wxString wxpath = path.GetFullPath();
    std::list< wxString >::iterator bl = aSearchList.begin();
    std::list< wxString >::iterator el = aSearchList.end();

    while( bl != el )
    {
        if( 0 == (*bl).Cmp( wxpath ) )
            return;

        ++bl;
    }

    aSearchList.push_back( wxpath );

    return;
}