Example #1
0
    IAudioSource* cAudioManager::createFromMemory(const char* name, const char* data, size_t length, const char* extension)
    {
		if(!Initialized) return NULL;

		cAudioMutexBasicLock lock(Mutex);
		cAudioString audioName = fromUTF8(name);
		cAudioString ext = fromUTF8(extension);
		IAudioDecoderFactory* factory = getAudioDecoderFactory(toUTF8(ext));

		if(!factory) {
			getLogger()->logError("AudioManager", "Failed to create Audio Source (%s): Codec (.%s) is not supported.", toUTF8(audioName), toUTF8(ext));
			return NULL;
		}

		cMemorySource* source = CAUDIO_NEW cMemorySource(data, length, true);
		if(source && source->isValid())
		{
			IAudioDecoder* decoder = factory->CreateAudioDecoder(source);
			source->drop();

			IAudioSource* audio = createAudioSource(decoder, audioName, _CTEXT("cMemorySource"));
			if(audio != NULL)
				return audio;

			if(source)
				source->drop();
		}
		return NULL;
    }
Example #2
0
void AcceleratorDictionary::Map( const KeyAcceleratorCode& _acode, const char *searchfor )
{
	// Search override mapping at ini file
	KeyAcceleratorCode acode = _acode;
	wxString overrideStr;
	wxAcceleratorEntry codeParser;	//Provides string parsing capabilities
	wxFileConfig cfg(L"", L"", L"" , GetUiKeysFilename(), wxCONFIG_USE_GLOBAL_FILE );
	if( cfg.Read( wxString::FromUTF8(searchfor), &overrideStr) )
	{
		// needs a '\t' prefix (originally used for wxMenu accelerators parsing)...
		if (codeParser.FromString(wxString(L"\t") + overrideStr))
		{
			// ini file contains alternative parsable key combination for current 'searchfor'.
			acode = codeParser;
			if (_acode.ToString() != acode.ToString()) {
				Console.WriteLn(Color_StrongGreen, L"Overriding '%s': assigning %s (instead of %s)",
					WX_STR(fromUTF8(searchfor)), WX_STR(acode.ToString()), WX_STR(_acode.ToString()));
			}
		}
		else
		{
			Console.Error(L"Error overriding KB shortcut for '%s': can't understand '%s'",
						  WX_STR(fromUTF8(searchfor)), WX_STR(overrideStr));
		}
	}
	// End of overrides section

	const GlobalCommandDescriptor* result = NULL;

	std::unordered_map<int, const GlobalCommandDescriptor*>::const_iterator iter(find(acode.val32));
	if (iter != end())
		result = iter->second;

	if( result != NULL )
	{
		Console.Warning(
			L"Kbd Accelerator '%s' is mapped multiple times.\n"
			L"\t'Command %s' is being replaced by '%s'",
			WX_STR(acode.ToString()), WX_STR(fromUTF8( result->Id )), WX_STR(fromUTF8( searchfor ))
		);
	}

	std::unordered_map<std::string, const GlobalCommandDescriptor*>::const_iterator acceleratorIter(wxGetApp().GlobalCommands->find(searchfor));

	if (acceleratorIter != wxGetApp().GlobalCommands->end())
		result = acceleratorIter->second;

	if( result == NULL )
	{
		Console.Warning( L"Kbd Accelerator '%s' is mapped to unknown command '%s'",
			WX_STR(acode.ToString()), WX_STR(fromUTF8( searchfor ))
		);
	}
	else
	{
		operator[](acode.val32) = result;
	}
}
Example #3
0
void WFileUpload::setFormData(CgiEntry *entry)
{
  if (!entry->clientFilename().empty()) {
    spoolFileName_ = entry->value();
    clientFileName_ = fromUTF8(entry->clientFilename());
    contentDescription_ = fromUTF8(entry->contentType());
    entry->stealFile();
    isStolen_ = false;
  }

  resourceTriggerUpdate_ = true;
}
Example #4
0
T Parse( const wxString& src, const wxString& separators=L",")
{
	T retval;
	if( !TryParse( retval, src, separators ) )
		throw Exception::ParseError( "Parse failure on call to " + fromUTF8(__WXFUNCTION__) + ": " + src );
	return retval;
}
Example #5
0
	IAudioSource* cAudioManager::createFromRaw(const char* name, const char* data, size_t length, unsigned int frequency, AudioFormats format)
	{
		if(!Initialized) return NULL;

		cAudioMutexBasicLock lock(Mutex);
		cAudioString audioName = fromUTF8(name);
		IAudioDecoderFactory* factory = getAudioDecoderFactory("raw");

		if(!factory) {
			getLogger()->logError("AudioManager", "Failed to create Audio Source (%s): Codec (.raw) is not supported.", toUTF8(audioName));
			return NULL;
		}

		cMemorySource* source = CAUDIO_NEW cMemorySource(data, length, true);
		if(source && source->isValid())
		{
			IAudioDecoder* decoder = ((cRawAudioDecoderFactory*)factory)->CreateAudioDecoder(source, frequency, format);
			source->drop();

			IAudioSource* audio = createAudioSource(decoder, audioName, _CTEXT("cMemorySource"));
			if(audio != NULL)
				return audio;

			if(source)
				source->drop();
		}
		return NULL;
	}
Example #6
0
	bool cAudioManager::isAudioDecoderRegistered(const char* extension)
	{
		cAudioMutexBasicLock lock(Mutex);
		cAudioString ext = fromUTF8(extension);
		decodermapIterator it = decodermap.find(ext);
		return (it != decodermap.end());
	}
Example #7
0
	bool cAudioManager::isDataSourceRegistered(const char* name)
	{
		cAudioMutexBasicLock lock(Mutex);
		cAudioString safeName = fromUTF8(name);
		datasourcemapIterator it = datasourcemap.find(safeName);
		return (it != datasourcemap.end());
	}
Example #8
0
	bool cAudioCapture::initialize(const char* deviceName, unsigned int frequency, AudioFormats format, unsigned int internalBufferSize)
	{
		cAudioMutexBasicLock lock(Mutex);
		DeviceName = fromUTF8(deviceName);
		Frequency = frequency;
		InternalBufferSize = internalBufferSize;

		Format = format;
		if(Format == EAF_8BIT_MONO)
			SampleSize = 1;
		else if(Format == EAF_8BIT_STEREO)
			SampleSize = 2;
		else if(Format == EAF_16BIT_MONO)
			SampleSize = 2;
		else
			SampleSize = 4;

		shutdownOpenALDevice();
		signalEvent(ON_INIT);
		bool isInit = initOpenALDevice();

#ifdef CAUDIO_USE_INTERNAL_THREAD
		if (!AudioThread)
		{
			AudioThread = new cAudioThread(this);
		}
		AudioThread->start();
#endif
		return isInit;
	}
Example #9
0
void FSAdapter::scan(const wstring& path)
{
    wstring localPath = fromUTF8(m_dirPath) + path;
    WIN32_FIND_DATAW fd;
    HANDLE fh = FindFirstFileW((LPCWSTR)(localPath + L"*").c_str(), &fd);

    if (fh == INVALID_HANDLE_VALUE)
    {
        Log::error() << "Cannot open directory " << toUTF8(localPath) << ": " << strerror(errno);
        return;
    }
    do
    {
        if (!wcscmp(fd.cFileName, L".") || !wcscmp(fd.cFileName, L".."))
        {
            continue;
        }
        if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
            scan(path + fd.cFileName + L'\\');
        else
        {
            wstring fileName = path + fd.cFileName;
            std::replace(fileName.begin(), fileName.end(), L'\\', L'/');
            std::wstring lcPath = fileName;
            std::transform(fileName.begin(), fileName.end(), lcPath.begin(), ::towlower);
            m_files[toUTF8(lcPath)] = toUTF8(fileName);
        }
    }
    while (FindNextFileW(fh, &fd));
}
String String::fromUTF8WithLatin1Fallback(const LChar* string, size_t size)
{
    String utf8 = fromUTF8(string, size);
    if (!utf8)
        return String(string, size);
    return utf8;
}
Example #11
0
void GSFrame::OnUpdateTitle( wxTimerEvent& evt )
{
#ifdef __linux__
	// Important Linux note: When the title is set in fullscreen the window is redrawn. Unfortunately
	// an intermediate white screen appears too which leads to a very annoying flickering.
	if (IsFullScreen()) return;
#endif
	AppConfig::UiTemplateOptions& templates = g_Conf->Templates;

	double fps = wxGetApp().FpsManager.GetFramerate();
	// The "not PAL" case covers both Region_NTSC and Region_NTSC_PROGRESSIVE
	float per = gsRegionMode == Region_PAL ? (fps * 100) / EmuConfig.GS.FrameratePAL.ToFloat() : (fps * 100) / EmuConfig.GS.FramerateNTSC.ToFloat();

	char gsDest[128];
	gsDest[0] = 0; // No need to set whole array to NULL.
	GSgetTitleInfo2( gsDest, sizeof(gsDest) );

	wxString limiterStr = templates.LimiterUnlimited;

	if( g_Conf->EmuOptions.GS.FrameLimitEnable )
	{
		switch( g_LimiterMode )
		{
			case Limit_Nominal:	limiterStr = templates.LimiterNormal; break;
			case Limit_Turbo:	limiterStr = templates.LimiterTurbo; break;
			case Limit_Slomo:	limiterStr = templates.LimiterSlowmo; break;
		}
	}

	FastFormatUnicode cpuUsage;
	if (m_CpuUsage.IsImplemented()) {
		m_CpuUsage.UpdateStats();

		cpuUsage.Write(L"EE: %3d%%", m_CpuUsage.GetEEcorePct());
		cpuUsage.Write(L" | GS: %3d%%", m_CpuUsage.GetGsPct());

		if (THREAD_VU1)
			cpuUsage.Write(L" | VU: %3d%%", m_CpuUsage.GetVUPct());

		pxNonReleaseCode(cpuUsage.Write(L" | UI: %3d%%", m_CpuUsage.GetGuiPct()));
	}

	const u64& smode2 = *(u64*)PS2GS_BASE(GS_SMODE2);
	wxString omodef = (smode2 & 2) ? templates.OutputFrame : templates.OutputField;
	wxString omodei = (smode2 & 1) ? templates.OutputInterlaced : templates.OutputProgressive;

	wxString title = templates.TitleTemplate;
	title.Replace(L"${slot}",		pxsFmt(L"%d", States_GetCurrentSlot()));
	title.Replace(L"${limiter}",	limiterStr);
	title.Replace(L"${speed}",		pxsFmt(L"%3d%%", lround(per)));
	title.Replace(L"${vfps}",		pxsFmt(L"%.02f", fps));
	title.Replace(L"${cpuusage}",	cpuUsage);
	title.Replace(L"${omodef}",		omodef);
	title.Replace(L"${omodei}",		omodei);
	title.Replace(L"${gsdx}",		fromUTF8(gsDest));
	if (CoreThread.IsPaused())
		title = templates.Paused + title;

	SetTitle(title);
}
String String::fromUTF8WithLatin1Fallback(const char* string, size_t size)
{
    String result = fromUTF8(string, size);
    if (!result)
        result = String(string, size);
    
    return result;
}
Example #13
0
	bool cAudioCapture::setDevice(const char* deviceName)
	{
		cAudioMutexBasicLock lock(Mutex);
		DeviceName = fromUTF8(deviceName);

		shutdownOpenALDevice();
		return initOpenALDevice();
	}
Example #14
0
    bool cAudioManager::registerAudioDecoder(IAudioDecoderFactory* factory, const char* extension)
    {
		cAudioMutexBasicLock lock(Mutex);
		cAudioString ext = fromUTF8(extension);
        decodermap[ext] = factory;
		getLogger()->logInfo("AudioManager", "Audio Decoder for extension .%s registered.", toUTF8(ext));
		return true;
    }
Example #15
0
static void convert_out_cp1256(char* out, int out_len, char* in)
{
  BufferCharSource utf8Source(in);
  InternalEncodingConverter fromUTF8(utf8Source, ExternalEncoding::Unicode20UTF8(), InternalEncoding::Unicode20());
  BufferCharSink outSink(out, out_len);
  InternalEncodingConverterSink sinkToCP1256(InternalEncoding::Unicode20(), ExternalEncoding::CP1256(), outSink);
  sinkToCP1256.Put(fromUTF8);
}
Example #16
0
static void convert_out_iso_8859_15(char* out, int out_len, char* in)
{
  BufferCharSource utf8Source(in);
  InternalEncodingConverter fromUTF8(utf8Source, ExternalEncoding::Unicode20UTF8(), InternalEncoding::Unicode20());
  BufferCharSink outSink(out, out_len);
  InternalEncodingConverterSink sinkToISO_8859_15(InternalEncoding::Unicode20(), ExternalEncoding::ISO_8859_15(), outSink);
  sinkToISO_8859_15.Put(fromUTF8);
}
Example #17
0
void GSFrame::OnUpdateTitle( wxTimerEvent& evt )
{
#ifdef __linux__
    // Important Linux note: When the title is set in fullscreen the window is redrawn. Unfortunately
    // an intermediate white screen appears too which leads to a very annoying flickering.
    if (IsFullScreen()) return;
#endif

    double fps = wxGetApp().FpsManager.GetFramerate();

    char gsDest[128];
    GSgetTitleInfo2( gsDest, sizeof(gsDest) );

    const wxChar* limiterStr = L"None";

    if( g_Conf->EmuOptions.GS.FrameLimitEnable )
    {
        switch( g_LimiterMode )
        {
        case Limit_Nominal:
            limiterStr = L"Normal";
            break;
        case Limit_Turbo:
            limiterStr = L"Turbo";
            break;
        case Limit_Slomo:
            limiterStr = L"Slomo";
            break;
        }
    }

    FastFormatUnicode cpuUsage;
    if (m_CpuUsage.IsImplemented()) {
        m_CpuUsage.UpdateStats();
        if (THREAD_VU1) { // Display VU thread's usage
            cpuUsage.Write(L" | EE: %3d%% | GS: %3d%% | VU: %3d%% | UI: %3d%%",
                           m_CpuUsage.GetEEcorePct(),	m_CpuUsage.GetGsPct(),
                           m_CpuUsage.GetVUPct(),		m_CpuUsage.GetGuiPct());
        }
        else {
            cpuUsage.Write(L" | EE: %3d%% | GS: %3d%% | UI: %3d%%",
                           m_CpuUsage.GetEEcorePct(),	m_CpuUsage.GetGsPct(),
                           m_CpuUsage.GetGuiPct());
        }
    }

    const u64& smode2 = *(u64*)PS2GS_BASE(GS_SMODE2);

    SetTitle( pxsFmt( L"%s | %ls (%ls) | Limiter: %ls | fps: %6.02f%ls | State %d",
                      WX_STR(fromUTF8(gsDest)),
                      (smode2 & 1) ? L"Interlaced" : L"Progressive",
                      (smode2 & 2) ? L"frame" : L"field",
                      limiterStr, fps, cpuUsage.c_str(), States_GetCurrentSlot() )
            );

    //States_GetCurrentSlot()
}
Example #18
0
PokemonString& PokemonString::operator=(Base::PokemonString const& other) {
    if (!other.isGBA()) {
        _japanese = other.usesJapaneseCharset();

        fromUTF8(other.toUTF8());
        return *this;
    }
    else return operator=((PokemonString const&)other);
}
Example #19
0
bool checkDirWritable(const std::string& path)
{
//FIXME: more correct file name.
#ifdef WIN32
    FILE *fp = _wfopen(fromUTF8(path + L"\\98hj8u.tmp").c_str(), L"w");
#else
    FILE *fp = fopen((path + "/98hj8u.tmp").c_str(), "w");
#endif
    if (fp == NULL)
        return false;
    fclose(fp);
#ifdef WIN32
    _wremove(fromUTF8(path + L"\\98hj8u.tmp").c_str());
#else
    remove((path + "/98hj8u.tmp").c_str());
#endif
    return true;
}
Example #20
0
Exception::RuntimeError::RuntimeError( const std::exception& ex, const wxString& prefix )
{
	IsSilent = false;

	SetDiagMsg( pxsFmt( L"STL Exception%s: %s",
		(prefix.IsEmpty() ? L"" : pxsFmt(L" (%s)", WX_STR(prefix)).c_str()),
		WX_STR(fromUTF8( ex.what() ))
	) );
}
Example #21
0
void Label::processMain()
{
    RANGERS_D(Label);
    if (!d->font)
        return;
    lock();

    if (!d->wordWrap)
        d->region = TextureRegion(d->font->renderText(fromUTF8(d->text.c_str())));
    else
        d->region = TextureRegion(d->font->renderText(fromUTF8(d->text.c_str()), d->width));

    if (!d->fixedWidth)
        d->width = d->region.texture->width();
    if (!d->fixedHeight)
        d->height = d->region.texture->height();

    unlock();
    Sprite::processMain();
}
Example #22
0
	void cAudioManager::unRegisterAudioDecoder(const char* extension)
	{
		cAudioMutexBasicLock lock(Mutex);
		cAudioString ext = fromUTF8(extension);
		decodermapIterator it = decodermap.find(ext);
		if(it != decodermap.end())
		{
			decodermap.erase(it);
			getLogger()->logInfo("AudioManager", "Audio Decoder for extension .%s unregistered.", toUTF8(ext));
		}
	}
Example #23
0
	bool cAudioManager::registerDataSource(IDataSourceFactory* factory, const char* name, int priority)
	{
		cAudioMutexBasicLock lock(Mutex);
		cAudioString safeName = fromUTF8(name);
        datasourcemap[safeName] = factory;
		dataSourcePriorityList.push_back(std::pair<int, cAudioString>(priority, safeName));
		std::sort(dataSourcePriorityList.begin(), dataSourcePriorityList.end(), compareDataSourcePriorities);

		getLogger()->logInfo("AudioManager", "Data Source named %s registered (Priority %i).", toUTF8(safeName), priority);
		return true;
	}
Example #24
0
	IAudioDecoderFactory* cAudioManager::getAudioDecoderFactory(const char* extension)
	{
		cAudioMutexBasicLock lock(Mutex);
		cAudioString ext = fromUTF8(extension);
		decodermapIterator it = decodermap.find(ext);
		if(it != decodermap.end())
		{
			return it->second;
		}
		return NULL;
	}
Example #25
0
	IDataSourceFactory* cAudioManager::getDataSourceFactory(const char* name)
	{
		cAudioMutexBasicLock lock(Mutex);
		cAudioString safeName = fromUTF8(name);
		datasourcemapIterator it = datasourcemap.find(safeName);
		if(it != datasourcemap.end())
		{
			return it->second;
		}
		return NULL;
	}
Example #26
0
    IAudioSource* cAudioManager::getSoundByName(const char* name)
    {
		cAudioMutexBasicLock lock(Mutex);
		cAudioString audioName = fromUTF8(name);
        audioIndexIterator i = audioIndex.find(audioName);
        if (i == audioIndex.end())
		{
			return NULL;
		}
        return i->second;
    }
int CIEC_DT_WSTRING::fromString(const char *pa_pacValue) {
	int nRetVal = 0;
	if (0 == strncmp(pa_pacValue, "WSTRING#", 8)) {
		pa_pacValue += 8;
		nRetVal = 8;
	}

	int nUTF8Result = fromUTF8(pa_pacValue, -1, (*pa_pacValue == '"'));

	return (-1 == nUTF8Result) ? -1 : (nRetVal + nUTF8Result);
}
Example #28
0
Exception::RuntimeError::RuntimeError( const std::exception& ex, const wxString& prefix )
{
	IsSilent = false;

	const wxString msg( wxsFormat( L"STL Exception%s: %s",
		(prefix.IsEmpty() ? prefix.c_str() : wxsFormat(L" (%s)", prefix.c_str()).c_str()),
		fromUTF8( ex.what() ).c_str()
	) );

	SetDiagMsg( msg );
}
Example #29
0
CString ArbI18N::toFullWidth(char const * s)
{   
  /* we want to ensure the use of full-width numbers and latin text. */
  BufferCharSource utf8Source(s);
  InternalEncodingConverter fromUTF8(utf8Source, ExternalEncoding::Unicode20UTF8(), InternalEncoding::Unicode20());
  ToFullwidthTransform fullWidth(fromUTF8);
  StringCharSink backToUTF8;
  InternalEncodingConverterSink sinkToUTF8(InternalEncoding::Unicode20(), ExternalEncoding::Unicode20UTF8(), backToUTF8);
  sinkToUTF8.Put(fullWidth);
  CString r = backToUTF8.c_str();
  return r;
}
Example #30
0
FastFormatUnicode &FastFormatUnicode::WriteV(const char *fmt, va_list argptr)
{
    wxString converted(fromUTF8(FastFormatAscii().WriteV(fmt, argptr)));

    const uint inspos = m_Length;
    const uint convLen = converted.Length();
    m_dest.MakeRoomFor((inspos + convLen + 64) * sizeof(wxChar));
    memcpy(&((wxChar *)m_dest.GetPtr())[inspos], converted.wc_str(), (convLen + 1) * sizeof(wxChar));
    m_Length += convLen;

    return *this;
}