void
TDocument::Streamer::Write(opstream& os) const
{
  TDocument* o = GetObject();

  while (!o->CanClose())   // can't permit cancel here
    ;
  os << o->OpenMode;
  _USES_CONVERSION;
  os.fwriteString(_W2A(o->DocPath));
  os.fwriteString(_W2A(o->Title));
  os << o->Template;       // templates already streamed, must be so if static
  os << o->ParentDoc;
  os << o->ViewList;       // each view streams out the next
  os << TView::NextViewId; // insure that this static var gets set on reload
}
Beispiel #2
0
//
/// "ShellExecute" is called to open the URL, but if this fails, then the registry
/// is examined in order to find a likely candidate for .html files. If one is found
/// then this it is launched with the hope that it can handle the URL string
/// supplied.  
//
HINSTANCE
TUrlLink::GotoURL(LPCTSTR url, int showcmd)
{
  // First try ShellExecute()
  HINSTANCE result = TShell::ShellExecute(NULL, _T("open"), url, NULL,NULL, showcmd);

  // If it failed, get the .htm regkey and lookup the program
   if (result <= reinterpret_cast<HINSTANCE>(HINSTANCE_ERROR)){
    tstring tmp_str = _T(".htm");
    tstring key = TRegValue(TRegKey::GetClassesRoot(),tmp_str.c_str()).GetName();
    if(!key.empty()){
      tmp_str = key;
      tmp_str += _T("\\shell\\open\\command");
      key = TRegValue(TRegKey::GetClassesRoot(),tmp_str.c_str()).GetName();
      if(!key.empty()){
        size_t pos = key.find(tstring(_T("\"%1\"")));
        if (pos == key.npos)
        {
          pos = key.find(tstring(_T("%1")));
          if (pos != key.npos)
            key.erase(pos);
        }
        else
          key.erase(pos);
        key += _T(" ");
        key += url;
        _USES_CONVERSION;
        UINT r = WinExec(_W2A(key.c_str()), showcmd);
        result = reinterpret_cast<HINSTANCE>(static_cast<UINT_PTR>(r));
      }
    }
  }
  return result;
}
Beispiel #3
0
bool CScriptEngine::LoadScript( const wchar * path )
{
    IFileSystem* fs = CEngine::instance()->mFilesystem();

    CON(MSG_INFO, _W("ScriptEngine: Loading script file %s"), path);

    // load using FS
    BYTE* pData=NULL;
    unsigned long fSize=0;
    FSFILE* fp = fs->Load(path, pData, fSize, true);
    if (!fp)
    {
        CON(MSG_ERR, _W("Faile to open script file %s!"), path);
        return false;
    }

    if (!LoadScriptString( (const char*)pData, 0, _W2A(path) ))
    {
        CON(MSG_ERR, _W("Error loading %s script!"), path );
        fs->UnLoad(fp, pData);
        return false;
    }

    fs->UnLoad(fp, pData);
    return true;
}
	//マッチした結果を正規表現キャプチャしたものだけを取得する.
	std::map<std::string , std::string> GetRegexpCapture() const
	{
		_USE_WINDOWS_ENCODING;

		std::map<std::string , std::string> ret;
		for(auto it = this->Track.pickupRules.begin(); it != this->Track.pickupRules.end() ; ++it)
		{
			const SPPHRASERULE* rule = *it;
			const int captureNumber = _wtoi(rule->pszName);

			//キャプチャされた値が入っているところまでスキップ
			unsigned int count = 0;
			const SPPHRASEELEMENT * pElem = this->Phrase->pElements;
			for (; count < rule->ulFirstElement ; ++pElem , count ++) 
				;
			//そこから指定された数の文字列を結合したものがキャプチャした結果になる。
			std::string str;
			for (count = 0; count < rule->ulCountOfElements ; ++pElem , count ++) 
			{
				str = str + _W2A(pElem->pszLexicalForm);
			}

			ret[num2str(captureNumber)] = str;
		}
		return ret;
	}
Beispiel #5
0
//
// writes the TEditFile to the passed opstream
//
void
TEditFile::Streamer::Write(opstream& os) const
{
  TEditFile* o = GetObject();
  WriteBaseObject((TEditSearch*)o, os);
  _USES_CONVERSION;
  os.fwriteString(o->FileName ? _W2A(o->FileName) : "");
}
Beispiel #6
0
	//------------------------------------------
	bool CEngine::SendScriptCommands(tArray<Str> &commands)
	{
		bool allOk=true;
		for(unsigned int i=0; i<commands.Size(); i++)
		{
			if( !cScriptEngine()->LoadScriptString( _W2A(commands[i].Get()) ) )
				allOk = false;
		}
		return allOk;
	}
	std::string GetAllString() const
	{
		_USE_WINDOWS_ENCODING;

		std::string str;
		const SPPHRASEELEMENT * pElem = this->Phrase->pElements;
		const int allcount = this->Phrase->Rule.ulCountOfElements;
		for(int count = 0;count < allcount;++pElem,++count)
		{
			str = str + _W2A(pElem->pszLexicalForm);
		}
		return str;
	}
Beispiel #8
0
	bool CShaderHLSL::Create(P3D::sShaderDesc &desc)
	{
		const char *pData;
		ULONG fsize;
		IFileSystem* pFS = CRenderer::mEngine()->mFilesystem();
		wchar path[P3DMAX_PATH];
		wsprintf(path, P3DMAX_PATH-1, _W("shaders/%s.rshader"), desc.ShaderFile.Get());
		FSFILE *fp = pFS->Load(path, (BYTE *&)pData, fsize, true);
		if (!fp)
		{
			CON(MSG_ERR, _W("Can't open %s.hlsl shader file from data/shaders directory!"), desc.ShaderFile.Get());
			return false;
		}

		ID3D10Blob *pShaderBlob = NULL;
		ID3D10Blob *pErrors = NULL;
		UINT flags = D3D10_SHADER_DEBUG;  //D3D10_SHADER_OPTIMIZATION_LEVEL3

		char profile[128];
		switch(desc.ShaderType)
		{
		case SHADERTYPE_VERTEX_SHADER:
			strcpy(profile, D3D10GetVertexShaderProfile(g_pD3ddev));
			break;
		case SHADERTYPE_GEOMETRY_SHADER:
			strcpy(profile, D3D10GetGeometryShaderProfile(g_pD3ddev));
			break;
		case SHADERTYPE_PIXEL_SHADER:
			strcpy(profile, D3D10GetPixelShaderProfile(g_pD3ddev));
			break;
		default:
			CON(MSG_ERR, _W("Chader creation failed. No apropriate ShaderType given."));
			return false;
		}

		CIncludeHandler includeHandler;
		
		D3D10_SHADER_MACRO Shader_Macros[] = 
		{
			{ "DX10", NULL },
			{ "SM4", NULL },
			NULL
		};

		if(!CheckHRResult(D3DX10CompileFromMemory(
			pData, 
			fsize, 
			NULL, 
			Shader_Macros, 
			&includeHandler, 
			_W2A(desc.EntryFunction.Get()), 
			profile, 
			flags,
			0,
			NULL,
			&pShaderBlob, 
			&pErrors,
			NULL
			)))
		{
			if(pErrors) CON(MSG_ERR, _W("%s"), _A2W((char*)pErrors->GetBufferPointer()));
			else CON(MSG_ERR, _W("Error description not given"));
			CON(MSG_ERR, _W("Shader %s could not be compiled"), desc.ShaderFile.Get());
			SAFE_RELEASE(pErrors);
			return false;
		}

		pFS->UnLoad(fp, (BYTE *)pData);

		//save to cache
		fp = pFS->Open(_W("cache/shaders/hlsl"), _W("wb"));
		const char* cs = (const char*)pShaderBlob->GetBufferPointer();
		pFS->Write(cs, 1, pShaderBlob->GetBufferSize(), fp);
		pFS->Close(fp);

		bool shaderCreated = false;
		switch(desc.ShaderType)
		{
		case SHADERTYPE_VERTEX_SHADER:
			shaderCreated = CheckHRResult(g_pD3ddev->CreateVertexShader(pShaderBlob->GetBufferPointer(), pShaderBlob->GetBufferSize(), &m_pVS));
			break;
		case SHADERTYPE_GEOMETRY_SHADER:
			shaderCreated = CheckHRResult(g_pD3ddev->CreateGeometryShader(pShaderBlob->GetBufferPointer(), pShaderBlob->GetBufferSize(), &m_pGS));
			break;
		case SHADERTYPE_PIXEL_SHADER:
			shaderCreated = CheckHRResult(g_pD3ddev->CreatePixelShader(pShaderBlob->GetBufferPointer(), pShaderBlob->GetBufferSize(), &m_pPS));
			break;
		}
		
		if(!shaderCreated)
		{
			CON(MSG_ERR, _W("Shader creation error"));
			return false;
		}

		//if(!CheckHRResult(D3DReflect((DWORD*)pShaderBlob->GetBufferPointer(), pShaderBlob->GetBufferSize(), __uuidof(ID3D10ShaderReflection), &m_pReflection)))
		if(!CheckHRResult(D3D10ReflectShader(pShaderBlob->GetBufferPointer(), pShaderBlob->GetBufferSize(), &m_pReflection)))
		{
			CON(MSG_ERR, _W("Could not create a Shader reflection"));
			return false;
		}
		//HRESULT D3DReflect(LPCVOID pSrcData, SIZE_T SrcDataSize, REFIID pInterface,	void **ppReflector);
		D3D10_SHADER_DESC shDesc;
		m_pReflection->GetDesc(&shDesc);
		m_numResources = shDesc.BoundResources; //not sure about this

		if(desc.ShaderType == SHADERTYPE_VERTEX_SHADER)
			m_pVertDecl = new CVertexDeclaration(CRenderer::cGraphicsManager()->GetVertexDescByID(desc.VertexDescID), pShaderBlob);
		
		SAFE_RELEASE(pShaderBlob);

		m_desc = desc;

		CON(MSG_INFO, _W("Shader '%s' created"), desc.ShaderFile);
		
		return true;
	}
Beispiel #9
0
bool CEditLog::OnAddText(
		bool bForce
		)
{
	bool		 bAdded = false;
	std::wstring wsText;
	int			 cchText;

	HWND hEdit = GetHandle();

	// Retrieve the text from our buffer
	// We store it in a local variable to prevent long time locking
	::EnterCriticalSection( &m_csLock );
	wsText = m_wsStore;
	m_bMessagePending = false; 
	::LeaveCriticalSection( &m_csLock );

	cchText = wsText.length();


	// Get Edit contents dimensions and cursor position
	int nStartChar, nEndChar, nSize;
	::SendMessage( hEdit, EM_GETSEL, (WPARAM) &nStartChar, (LPARAM) &nEndChar );
	nSize = (int) ::SendMessage( hEdit, WM_GETTEXTLENGTH, 0, 0 );


	if( nStartChar == nSize && nSize == nEndChar  ) {
		// The cursor resides at the end of text
	
		SCROLLINFO si;
		si.cbSize	= sizeof si;
		si.fMask	= SIF_ALL;
		::GetScrollInfo( GetHandle(), SB_VERT, &si );
		if( si.nPos >= si.nMax - si.nPage + 1  ) {
			// Not scrolled away
			::SendMessage( hEdit, EM_SETSEL, (WPARAM) nSize, (LPARAM) nSize );
			if( g_bIsWinNT )
				::SendMessageW( hEdit, EM_REPLACESEL, 0, (LPARAM) wsText.c_str() );
			else 
				::SendMessage( hEdit, EM_REPLACESEL, 0, (LPARAM) _W2A( wsText.c_str() ) );
			bAdded = true;
		}
		else if( bForce ) {
			int nFirstLine, nFirstLineNow;

			// Reduce flicker by ignoring WM_PAINT
			m_bNoPaint = true;

			// Remember where we are
			nFirstLine = (int)::SendMessage( hEdit, EM_GETFIRSTVISIBLELINE, 0, 0 );
		
			// Select at the end of text and replace the selection
			// This is a very fast way to add text to an edit control
			::SendMessage( hEdit, EM_SETSEL, (WPARAM) nSize, (LPARAM) nSize );
			if( g_bIsWinNT )
				::SendMessageW( hEdit, EM_REPLACESEL, 0, (LPARAM) wsText.c_str() );
			else 
				::SendMessage( hEdit, EM_REPLACESEL, 0, (LPARAM) _W2A( wsText.c_str() ) );

			// Restore our previous selection
			::SendMessage( hEdit, EM_SETSEL, (WPARAM) nStartChar, (LPARAM) nEndChar );
			nFirstLineNow = (int)::SendMessage( hEdit, EM_GETFIRSTVISIBLELINE, 0, 0 );
			::SendMessage( hEdit, EM_LINESCROLL, 0, (LPARAM) nFirstLine - nFirstLineNow);

			m_bNoPaint = false;
			bAdded = true;
		}
	}
	else if( bForce ) {
		// We should add the text anyway...

		POINT pt;
		int nFirstLine, nFirstLineNow, nCaretPos;

		// Reduce flicker by ignoring WM_PAINT
		m_bNoPaint = true;

		// Remember where we are
		nFirstLine = (int)::SendMessage( hEdit, EM_GETFIRSTVISIBLELINE, 0, 0 );
	
		if( nStartChar != nEndChar ) {
			// If we are currently selecting some text, we have to find out
			// if the caret is near the beginning of this block or near the end.
			// Note that this does not always work. Because of the EM_CHARFROMPOS
			// message returning only 16 bits this will fail if the user has selected 
			// a block with a length dividable by 64k.
			
			::GetCaretPos( &pt );
			nCaretPos = (int) LOWORD(::SendMessage( hEdit, EM_CHARFROMPOS, 0, MAKELPARAM(pt.x, pt.y) ) );
			if( abs( (nStartChar % 0xffff - nCaretPos) ) < abs( (nEndChar % 0xffff - nCaretPos) ) ) {
				nCaretPos	= nStartChar;
				nStartChar	= nEndChar;
				nEndChar	= nCaretPos;
			}
		}

		// Note: This will flicker, if someone has a good idea how to prevent this - let me know
		
		// Select at the end of text and replace the selection
		// This is a very fast way to add text to an edit control
		::SendMessage( hEdit, EM_SETSEL, (WPARAM) nSize, (LPARAM) nSize );
		if( g_bIsWinNT )
			::SendMessageW( hEdit, EM_REPLACESEL, 0, (LPARAM) wsText.c_str() );
		else 
			::SendMessage( hEdit, EM_REPLACESEL, 0, (LPARAM) _W2A( wsText.c_str() ) );

		// Restore our previous selection
		::SendMessage( hEdit, EM_SETSEL, (WPARAM) nStartChar, (LPARAM) nEndChar );
		nFirstLineNow = (int)::SendMessage( hEdit, EM_GETFIRSTVISIBLELINE, 0, 0 );
		::SendMessage( hEdit, EM_LINESCROLL, 0, (LPARAM) nFirstLine - nFirstLineNow);

		m_bNoPaint = false;
		bAdded = true;
	}
	//позиционируемся на самой последней строке
	int nLineCount = (int)::SendMessage( hEdit, EM_GETLINECOUNT, 0, 0 );
	::SendMessage( hEdit, EM_LINESCROLL, 0, (LPARAM) nLineCount);


	if( bAdded ) {
		// Delete the processed text from our buffer
		::EnterCriticalSection( &m_csLock );
		m_wsStore.erase( 0, cchText );
		::LeaveCriticalSection( &m_csLock );
	}
	return bAdded;
}
Beispiel #10
0
	bool CShaderHLSL::Create(P3D::sShaderDesc &desc)
	{
		const char *pData;
		ULONG fsize;
		IFileSystem* pFS = CRenderer::mEngine()->mFilesystem();
		wchar path[P3DMAX_PATH];
		wsprintf(path, P3DMAX_PATH-1, _W("shaders/%s.rshader"), desc.ShaderFile.Get());
		FSFILE *fp = pFS->Load(path, (BYTE *&)pData, fsize, true);
		if (!fp)
		{
			CON(MSG_ERR, _W("Can't open %s.hlsl shader file from data/shaders directory!"), desc.ShaderFile.Get());
			return false;
		}

		ID3DXBuffer *pShaderBlob = NULL;
		ID3DXBuffer *pErrors = NULL;
		DWORD flags = D3DXSHADER_DEBUG;  //D3DXSHADER_OPTIMIZATION_LEVEL3

		char profile[128];
		switch(desc.ShaderType)
		{
		case SHADERTYPE_VERTEX_SHADER:
			strcpy(profile, D3DXGetVertexShaderProfile(g_pD3ddev));
			break;
		case SHADERTYPE_PIXEL_SHADER:
			strcpy(profile, D3DXGetPixelShaderProfile(g_pD3ddev));
			break;
		case SHADERTYPE_GEOMETRY_SHADER:
			CON(MSG_ERR, _W("DX9 does not support geometry shaders."));
			return false;
		default:
			CON(MSG_ERR, _W("Chader creation failed. No apropriate ShaderType given."));
			return false;
		}

		CIncludeHandler includeHandler;
		
		D3DXMACRO Shader_Macros[] = 
		{
			{ "DX9", NULL },
			{ "SM3", NULL },
			NULL
		};

		if(FAILED(D3DXCompileShader(
			pData, 
			fsize, 
			Shader_Macros, 
			&includeHandler, 
			_W2A(desc.EntryFunction.Get()), 
			profile, 
			flags,
			&pShaderBlob, 
			&pErrors,
			&m_pConstTable
			)))
		{
			if(pErrors) CON(MSG_ERR, _W("%s"), _A2W((char*)pErrors->GetBufferPointer()));
			else CON(MSG_ERR, _W("Error description not given"));
			CON(MSG_ERR, _W("Shader %s could not be compiled"), desc.ShaderFile.Get());
			SAFE_RELEASE(pErrors);
			return false;
		}

		pFS->UnLoad(fp, (BYTE *)pData);

		//save to cache
		fp = pFS->Open(_W("cache/shaders/hlsl"), _W("wb"));
		const char* cs = (const char*)pShaderBlob->GetBufferPointer();
		pFS->Write(cs, 1, pShaderBlob->GetBufferSize(), fp);
		pFS->Close(fp);

		bool shaderCreated = false;
		switch(desc.ShaderType)
		{
		case SHADERTYPE_VERTEX_SHADER:
			shaderCreated = SUCCEEDED(g_pD3ddev->CreateVertexShader((const DWORD*)pShaderBlob->GetBufferPointer(), &m_pVS));
			break;
		case SHADERTYPE_PIXEL_SHADER:
			shaderCreated = SUCCEEDED(g_pD3ddev->CreatePixelShader((const DWORD*)pShaderBlob->GetBufferPointer(), &m_pPS));
			break;
		}

		if(!shaderCreated)
		{
			CON(MSG_ERR, _W("Shader creation error"));
			return false;
		}

		//set constant to their default values 
		m_pConstTable->SetDefaults(g_pD3ddev);

		//create vertex declaration
		if(desc.ShaderType == SHADERTYPE_VERTEX_SHADER)
			m_pVertDecl = new CVertexDeclaration(CRenderer::cGraphicsManager()->GetVertexDescByID(desc.VertexDescID), pShaderBlob);

		SAFE_RELEASE(pShaderBlob);

		m_desc = desc;

		CON(MSG_INFO, _W("Shader '%s' created"), desc.ShaderFile);

		return true;
	}
//音声認識ルールを構築します。 正規表現にも対応しています。
xreturn::r<bool> Recognition_SAPI::AddRegexp(unsigned int id,const std::string & str ,SPSTATEHANDLE stateHandle ) 
{
	_USE_WINDOWS_ENCODING;

	//ルールに変更が加わるのでアップデートするフラグを立てる。
	this->IsNeedUpdateRule = true;

	//一番最初だけ正規表現の構文変換をかける.
    // .+ --> (:?.*)
    // (まる|さんかく)? --> (まる|さんかく|)   正しい正規表現としてはエラーだが、このエンジンの場合容認する.
    // なのは? --> なの(は|)
	std::wstring optstr = L"";

	for( const wchar_t * p = _A2W( str.c_str() ) ; *p ; ++p )
	{
        if ( *p == L'.' && *(p+1) == L'+')
        { // .+ --> (:?.*)
            optstr += L"(?:.+)";
			++p;
        }
        else if (*p == L'(' && *(p+1) == L'?' && *(p+2) == L':' )
		{
            optstr += L"(?:";
			p+=2;
		}
        else if (*(p+1) == L'?')
        {
            if (*p == L')')
            {// (まる|さんかく)? --> (まる|さんかく|)
                    optstr += L"|)";
            }
            else 
            {// なのは? --> なの(は|)
                    optstr += std::wstring(L"") + L"(?:" + *p + L"|)";
            }
			++p;
        }
        else if ( *p == L'[' && *(p+1) == L':' )
        {
			const wchar_t * end = wcsstr(p+2 , L":]");
			if (end == NULL)
			{
				return xreturn::error("[: があるのに :] がありませんでした");
			}
			optstr += std::wstring(p , (end - p) + 2);
			p = end + 1;
        }
        else if (*p == L'*' || *p == L'+' || *p == L'.' || *p == L'[' || *p == L']')
        {
			return xreturn::error(std::string("") + "現在は、メタ文字 " + _W2A(p) + " は利用できません。利用可能なメタ文字 () | .+ ?)");
        }
        else
        {
            optstr += *p;
        }
    }

	this->LocalCaptureRuleNodeCount = 1;
	if (id == UINT_MAX)
	{
		return AddRegexpImpl(NULL,optstr, stateHandle);
	}
	else
	{
		SPPROPERTYINFO prop;
		prop.pszName = L"Id";
		prop.pszValue = L"Property";
		prop.vValue.vt = VT_UINT;
		prop.vValue.ulVal = id;
		return AddRegexpImpl(&prop,optstr, stateHandle);
	}
}
//ルールベースで認識した結果の音声部分をもう一度 ディクテーションにかけます。
//これで過剰なマッチを排除します。
xreturn::r<std::string> Recognition_SAPI::convertDictation(ISpRecoResult* result,const std::string& ruleName)
{
	HRESULT hr;
	_USE_WINDOWS_ENCODING;

	CComPtr<ISpStreamFormat>	resultStream;
	{
		hr = result->GetAudio( 0, 1, &resultStream );
		if(FAILED(hr))	 return xreturn::windowsError(hr);

		//オーディオから読み込んでね
		hr = this->DictationEngine->SetInput( resultStream, TRUE);  
		if(FAILED(hr))	 return xreturn::windowsError(hr);

		hr = this->DictationGrammar->SetRuleState(ruleName.empty() ? NULL : _A2W(ruleName.c_str()), NULL, SPRS_ACTIVE );
		if(FAILED(hr))	 return xreturn::windowsError(hr);

		hr = this->DictationRecoCtxt->WaitForNotifyEvent(2000); //2秒タイムアウト
		if(FAILED(hr))	 return xreturn::windowsError(hr);

		hr = this->DictationGrammar->SetRuleState(NULL, NULL, SPRS_INACTIVE );
		if(FAILED(hr))	 return xreturn::windowsError(hr);

		{
			CSpEvent tempevent;
			hr = tempevent.GetFrom( this->DictationRecoCtxt );
			if(FAILED(hr))	 return xreturn::windowsError(hr);

			if (tempevent.eEventId == SPEI_RECOGNITION)
			{//認識した結果
				ISpRecoResult* tempresult;
				{
					tempresult = tempevent.RecoResult();

					//認識した文字列の取得
					CSpDynamicString tempdstrText;
					hr = tempresult->GetText(SP_GETWHOLEPHRASE, SP_GETWHOLEPHRASE, TRUE, &tempdstrText, NULL);
					if(FAILED(hr))	 return xreturn::windowsError(hr);

					SPPHRASE *pPhrase;
					hr = tempresult->GetPhrase(&pPhrase);
					if ( FAILED(hr) )	return xreturn::windowsError(hr);

					double confidence = pPhrase->pElements->SREngineConfidence;

					std::string ret = _W2A(tempdstrText);
					this->PoolMainWindow->SyncInvokeLog(std::string() + "ディクテーションフィルター :" + ret + + " " + num2str(confidence),LOG_LEVEL_DEBUG);

					if (confidence <= 0.60)
					{
						this->PoolMainWindow->SyncInvokeLog(std::string() + "ディクテーションフィルター棄却",LOG_LEVEL_DEBUG);
						return "";
					}

					return ret;
				}
			}
		}
	}

	//不明
	return "";
}