예제 #1
0
DWORD request_custom_command(Remote *remote, Packet *packet)
{
	Packet * response = packet_create_response(packet);
	Tlv argTlv             = {0};
	DWORD index            = 0;
	vector<wstring> args;

	LPCSTR func = packet_get_tlv_value_string(packet, TLV_TYPE_MIMIKATZ_FUNCTION);
	dprintf("Function: %s", packet_get_tlv_value_string(packet, TLV_TYPE_MIMIKATZ_FUNCTION));
	wstring function = s2ws(func);

	while( packet_enum_tlv( packet, index++, TLV_TYPE_MIMIKATZ_ARGUMENT, &argTlv ) == ERROR_SUCCESS )
	{
		dprintf("Arg: %s", (PCHAR)argTlv.buffer);
		args.push_back(s2ws((PCHAR)argTlv.buffer));
	}

	clear_buffer();

	initialize_mimikatz();
	myMimiKatz->doCommandeLocale(&function, &args);

	wchar_t* output = convert_wstring_to_wchar_t(oss.str());
	
	clear_buffer();

	packet_add_tlv_raw(response, TLV_TYPE_MIMIKATZ_RESULT, output, (DWORD)(wcslen(output)*sizeof(wchar_t)));
	packet_transmit_response(ERROR_SUCCESS, remote, response);

	return ERROR_SUCCESS;	
}
예제 #2
0
static bool comp(string a, string b)
{
	bool ret;

	std::wstring stemp1 = s2ws(a);
	LPCWSTR lpa1 = stemp1.c_str();

	std::wstring stemp2 = s2ws(b);
	LPCWSTR lpa2 = stemp2.c_str();

	if (StrCmpLogicalW(lpa1, lpa2) >= 0)
	{
		ret = false;
	}
	else
	{
		ret = true;
	}

	if (reverseflag)
	{
		ret = !ret;
	}

	return ret;
}
예제 #3
0
bool CDlgModelPlayer::OnInitDialog()
{
	m_ComboBoxSkeleton.AddItem(L"");
	m_ComboBoxHead.AddItem(L"");
	m_ComboBoxSet.AddItem(L"");
	for (size_t i=0;i<ET_MAX;++i)
	{
		m_ComboBoxEquips[i].AddItem(L"");
	}
	m_ComboBoxLeftHand.AddItem(L"");
	m_ComboBoxRightHand.AddItem(L"");
	m_ComboBoxBack.AddItem(L"");
	std::set<std::wstring>	setString;

	std::string strDirMU = IniGetStr("WorldEditor.cfg","ResDir","mu");
	std::wstring wstrFindPath = s2ws(strDirMU)+L"Player\\";//|{"+wstrFileType+L"}";
	CDir dir;
	dir.ReadDir(wstrFindPath);
	for (size_t i=0; i<dir.m_FileInfo.size(); i++)
	{
		if (!dir.m_FileInfo[i].IsDirectory())
		{
			std::wstring wstrFilename = dir.m_FileInfo[i].wstrFilename;
			std::transform(wstrFilename.begin(),wstrFilename.end(),wstrFilename.begin(),std::toupper);
			//if (wstrFileType.find(GetExtension(dir.m_FileInfo[i].wstrFilename))!=std::wstring::npos)
			if (GetExtension(wstrFilename)==L".bmd")
			{
				if (wstrFilename.find(L"HELMCLASS")!=std::wstring::npos)
				{
					m_ComboBoxHead.AddItem(wstrFilename.c_str());
				}
				else if (wstrFilename.find(L"PLAYER")!=std::wstring::npos)
				{
					m_ComboBoxSkeleton.AddItem(wstrFilename.c_str());
				}
				else
				{
					for (size_t i=0;i<ET_MAX;++i)
					{
						if (wstrFilename.find(s2ws(g_EquipNames[i]))!=std::wstring::npos)
						{
							m_ComboBoxEquips[i].AddItem(wstrFilename.c_str());
							int index=wstrFilename.find(s2ws(g_EquipNames[i]));
							wstrFilename.replace(index, strlen(g_EquipNames[i]), L"*");
							setString.insert(wstrFilename);
							break;
						}
					}
				}
			}
		}
	}
	for (std::set<std::wstring>::iterator it=setString.begin();it!=setString.end();it++)
	{
		m_ComboBoxSet.AddItem(it->c_str());
	}
	return true;
}
예제 #4
0
//--------------------------------------------------------------------------------------//
//		Load Guild info
//--------------------------------------------------------------------------------------//
void CClientSession::SendLoadGuildInfo(CNtlPacket * pPacket, CChatServer * app)
{

	app->db->prepare("CALL GuildInfo (?, @guild_id,@guild_name,@guild_master,@guild_notice,@guild_rep,@second_guild_master)");
	app->db->setInt(1, this->GetCharacterId());
	app->db->execute();

	app->db->execute("SELECT @guild_id,@guild_name,@guild_master,@guild_notice,@guild_rep,@second_guild_master");
	app->db->fetch();

//Check if user inside guild
	if(app->db->getInt("@guild_id") != 0)
	{
	//SET GUILD INFO
		CNtlPacket packet(sizeof(sTU_GUILD_INFO));
		sTU_GUILD_INFO * res = (sTU_GUILD_INFO *)packet.GetPacketData();

		int guildID = app->db->getInt("@guild_id");
		this->guildName = app->db->getString("@guild_name");

		res->wOpCode = TU_GUILD_INFO;
		res->guildInfo.dwGuildReputation = app->db->getInt("@guild_rep");
		res->guildInfo.guildId = guildID;
		res->guildInfo.guildMaster = app->db->getInt("@guild_master");
		res->guildInfo.guildSecondMaster[0] = app->db->getInt("@second_guild_master");
		wcscpy_s(res->guildInfo.wszName, NTL_MAX_SIZE_GUILD_NAME_IN_UNICODE, s2ws(app->db->getString("@guild_name")).c_str());
		wcscpy_s(res->guildInfo.awchName, NTL_MAX_SIZE_CHAR_NAME_UNICODE, s2ws(this->GetCharName()).c_str());
		wcscpy_s(res->guildInfo.awchNotice, NTL_MAX_LENGTH_OF_GUILD_NOTICE_UNICODE, s2ws(app->db->getString("@guild_notice")).c_str());
		packet.SetPacketLen( sizeof(sTU_GUILD_INFO));
		int rc = g_pApp->Send( this->GetHandle(), &packet);
		printf("Guild ID: %i \n",guildID);

	//SET GUILD MEMBERS
		CNtlPacket packet2(sizeof(sTU_GUILD_MEMBER_INFO));
		sTU_GUILD_MEMBER_INFO * res2 = (sTU_GUILD_MEMBER_INFO *)packet2.GetPacketData();

		app->db->prepare("SELECT CharID,CharName,Level,Race,Class FROM characters WHERE GuildID = ?");
		app->db->setInt(1, guildID);
		app->db->execute();

		while(app->db->fetch())
		{
			res2->wOpCode = TU_GUILD_MEMBER_INFO;
			res2->guildMemberInfo.bIsOnline = true;
			res2->guildMemberInfo.byClass = app->db->getInt("Class");
			res2->guildMemberInfo.byLevel = app->db->getInt("Level");
			res2->guildMemberInfo.byRace = app->db->getInt("Race");
			res2->guildMemberInfo.charId = app->db->getInt("CharID");
			res2->guildMemberInfo.dwReputation = 0;
			wcscpy_s(res2->guildMemberInfo.wszMemberName, NTL_MAX_SIZE_CHAR_NAME_UNICODE, s2ws(app->db->getString("CharName")).c_str());

			packet2.SetPacketLen( sizeof(sTU_GUILD_MEMBER_INFO));
			rc = g_pApp->Send( this->GetHandle(), &packet2);
		}
	}

}
예제 #5
0
파일: msgbox.cpp 프로젝트: cstrahan/argss
///////////////////////////////////////////////////////////
/// Warning Message Box
///////////////////////////////////////////////////////////
void MsgBox::Warning(std::string msg, std::string title) {
	if (msg.length() == 0) return;
	if (msg.length() == 1 && (msg[0] == '\n' || msg[0] == '\r')) return;
#ifdef UNICODE
	MessageBox(0, s2ws(msg).c_str(), s2ws(title).c_str(), MB_OK | MB_ICONEXCLAMATION);
#else
	MessageBox(0, msg.c_str(), title.c_str(), MB_OK | MB_ICONEXCLAMATION);
#endif
}
예제 #6
0
void TransfersDialog::populateList()
{
    vector<Transfer*> &transfers = Transfer::getTransfers();
    ListBox1->Clear();
    for (auto it : transfers) {
        wxString var = s2ws(it->getVarName());
        wxString descr = s2ws(it->getDescription());
        wxString src = s2ws(it->getSourceNameAlt());
        wxString dest = s2ws(it->getDestNameAlt());
        ListBox1->Append(descr + _(" (") + var + _(") : ") + src + _(" to ") + dest);
    }
}
예제 #7
0
bool ZipResourceDepot::RegisterPackages(std::wstring basePackagePath)
{
	HANDLE fileHandle;
	WIN32_FIND_DATA findData;

	//Get first file
	std::wstring pathSpec = basePackagePath + L"*";
	fileHandle = FindFirstFile(pathSpec.c_str(), &findData);
	if (fileHandle != INVALID_HANDLE_VALUE)
	{
		//Loop on all remaining entries
		while (FindNextFile(fileHandle, &findData))
		{
			//Skip if file is hidden
			if (findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
			{
				continue;
			}

			//Do not currently support packages within directories, so throw Warning
			if (findData.dwFileAttributes &FILE_ATTRIBUTE_DIRECTORY)
			{
				//Do not warn for directory symbol
				if (findData.cFileName != s2ws(".."))
				{
					BE_WARNING("Packages within Directories are ignored");
				}
			}
			else
			{
				std::wstring filename = findData.cFileName;
				std::wstring lowerPackageName = filename;

				std::transform(lowerPackageName.begin(), lowerPackageName.end(), lowerPackageName.begin(), (int(*)(int))std::tolower);
				lowerPackageName = lowerPackageName.substr(0, lowerPackageName.find_last_of('.'));

				pathSpec = pathSpec.substr(0, pathSpec.find_last_of('/'));
				pathSpec = pathSpec + s2ws("/") + filename;

				//Add Package to mapping
				m_packageMap[ws2s(lowerPackageName)] = PackageMappingDetails(m_numPackages, ws2s(pathSpec));
				m_numPackages++;
			}
		}
	}

	FindClose(fileHandle);


	return true;
}
예제 #8
0
//Parse our array of values to get the initial mappings
void initSoundManifest()
{
	//ofstream oHash("hash3.txt");
	for(u32 i = 0; i < NUM_MAPPINGS; i++)
	{
		g_mSoundIDToString[g_soundMap[i].id] = s2ws(g_soundMap[i].name);
		g_mStringToSoundID[s2ws(g_soundMap[i].name)] = g_soundMap[i].id;
		//oHash << "id: " << g_soundMap[i].id << ", filename: " << g_soundMap[i].name << ", filename hashed: " << hash(g_soundMap[i].name) << endl;
		//if(g_soundMap[i].id != hash(g_soundMap[i].name))
		//	oHash << "Hash failed." << endl;
		//else
		//	oHash << "Hash worked!" << endl;
	}
}
예제 #9
0
BOOL CCBitmapConvert::TranstToBMP(string srcPath,string destPath)
{
	remove(destPath.c_str());
	WCHAR wCH[255] = {0};
	WCHAR wCH1[255] = {0};
	wstring wstrPath = s2ws(srcPath);
	wcscpy(wCH,wstrPath.c_str());
	Image img(wCH);//这里的图片可以是其它格式	
	CLSID pngClsid;
	GetImageCLSID(L"image/bmp", &pngClsid);//这里的图片可以是其它格式,此处转化为BMP格式
	wstrPath = s2ws(destPath);
	wcscpy(wCH1, wstrPath.c_str());
	img.Save(wCH1, &pngClsid, NULL);
	return TRUE;
}
예제 #10
0
int CellmlModelDefinition::loadModelFromString(const std::string &ms)
{
    std::cout << "Creating CellML Model Definition from the given model string"
              << std::endl;
    mUrl = "";
    std::wstring msW = s2ws(ms);
    ObjRef<iface::cellml_api::CellMLBootstrap> cb = CreateCellMLBootstrap();
    ObjRef<iface::cellml_api::DOMModelLoader> ml = cb->modelLoader();
    int code;
    try
    {
        ObjRef<iface::cellml_api::Model> model = ml->createFromText(msW);
        model->fullyInstantiateImports();
        // we have a model, so we can start grabbing hold of the CellML API objects
        mCapi = new CellmlApiObjects();
        mCapi->model = model;
        code = instantiateCellmlApiObjects();
    }
    catch (...)
    {
      std::wcerr << L"Error loading model from string." << std::endl;
      return -1;
    }
    return code;
}
예제 #11
0
 std::wstring FileIo::wpath() const
 {
     if (p_->wpMode_ == Impl::wpStandard) {
         return s2ws(p_->path_);
     }
     return p_->wpath_;
 }
예제 #12
0
void OIBReader::ReadSequenceOib()
{
   for (int i=0; i<(int)m_oib_info.size(); i++)
   {
      wstring path_name = m_oib_info[i].filename;

      if (path_name == m_path_name)
         m_cur_time = i;
	  
	   //storage
	   POLE::Storage pStg("temp_storage.txt"); 
	   //open
	   if (pStg.open()) {
		  //enumerate
		  std::list<std::string> entries = 
			  pStg.entries();
		  for(std::list<std::string>::iterator it = entries.begin();
			  it != entries.end(); ++it) {
                  m_oib_t = i;
			  if (!pStg.isDirectory(*it)) {
				  std::wstring st = s2ws(*it);
				  ReadStream(pStg,st);
			  }
		  }
	   }
	   //release
	   pStg.close();
   }
}
예제 #13
0
std::vector<std::string>* DataInDirectoryInvestigator::SearchFiles(std::string fileType){
	this->fileType = fileType;

	std::string searchQuery = dirPath;
	searchQuery.append(fileType);
	
	std::wstring stemp = s2ws(searchQuery);
	LPCWSTR DIRPATH = stemp.c_str();
	
	std::cout << "Searching Files in " << dirPath << std::endl;
	std::vector<std::string> * acquiredFilePaths = new std::vector<std::string>();

	HANDLE hFind;
	WIN32_FIND_DATA w32fd;
	hFind = FindFirstFile(DIRPATH, &w32fd);
	if( hFind != INVALID_HANDLE_VALUE){
		do {
			//std::cout << "cAlternateFileName : " << ws2s(w32fd.cAlternateFileName) << std::endl;
			//printf("ファイル名:%S\n", w32fd.cFileName);
			std::cout << "ファイル名: " << ws2s(w32fd.cFileName) << std::endl;
			acquiredFilePaths->push_back(ws2s(w32fd.cFileName));
		} while (FindNextFile (hFind, &w32fd));
		FindClose(hFind);
	}
	return acquiredFilePaths;
}
예제 #14
0
int CellmlModelDefinition::loadModel(const std::string &url)
{
    std::cout << "Creating CellML Model Definition from the URL: "
              << url << std::endl;
    mUrl = url;
    if (mUrl.empty()) return -1;
    std::wstring urlW = s2ws(url);
    ObjRef<iface::cellml_api::CellMLBootstrap> cb = CreateCellMLBootstrap();
    ObjRef<iface::cellml_api::DOMModelLoader> ml = cb->modelLoader();
    int code;
    try
    {
        ObjRef<iface::cellml_api::Model> model = ml->loadFromURL(urlW);
        model->fullyInstantiateImports();
        // we have a model, so we can start grabbing hold of the CellML API objects
        mCapi = new CellmlApiObjects();
        mCapi->model = model;
        code = instantiateCellmlApiObjects();
    }
    catch (...)
    {
      std::wcerr << L"Error loading model: " << urlW << std::endl;
      return -1;
    }
    return code;
}
예제 #15
0
bool CFile::SetTimestamp(long timestamp)
{
#ifdef WIN32
	FILETIME ftime;
	HANDLE h;
	bool close = false;
	if (handle==NULL) {
		h = CreateFile(s2ws(filename).c_str() , GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
		close = true;
	} else {
		h = (HANDLE)_get_osfhandle(fileno(handle));
	}
	if (h == NULL) {
		return false;
	}
	fileSystem->TimestampToFiletime(timestamp, ftime);
	bool ret = SetFileTime(h, NULL, NULL, &ftime);
	if (close) { //close opened file
		CloseHandle(h);
	}
	return ret;
#else
	struct timeval tv = {0, 0};
	tv.tv_sec = timestamp;
	if (handle==NULL) {
		return lutimes(filename.c_str(), &tv) == 0;
	} else {
		return futimes(fileno(handle), &tv) == 0;
	}
#endif
}
예제 #16
0
    void BasicError<char>::setMsg()
    {
        std::string msg = _(errMsg(code_));
        std::string::size_type pos;
        pos = msg.find("%0");
        if (pos != std::string::npos) {
            msg.replace(pos, 2, toString(code_));
        }
        if (count_ > 0) {
            pos = msg.find("%1");
            if (pos != std::string::npos) {
                msg.replace(pos, 2, arg1_);
            }
        }
        if (count_ > 1) {
            pos = msg.find("%2");
            if (pos != std::string::npos) {
                msg.replace(pos, 2, arg2_);
            }
        }
        if (count_ > 2) {
            pos = msg.find("%3");
            if (pos != std::string::npos) {
                msg.replace(pos, 2, arg3_);
            }
        }
        msg_ = msg;
#ifdef EXV_UNICODE_PATH
        wmsg_ = s2ws(msg);
#endif
    }
예제 #17
0
//-----------------------------------------------------------------------------
bool CPUTShaderDX11::ShaderRequiresPerModelPayload( CPUTConfigBlock &properties )
{
    ID3D11ShaderReflection *pReflector = NULL;

    D3DReflect( mpBlob->GetBufferPointer(), mpBlob->GetBufferSize(), IID_ID3D11ShaderReflection, (void**)&pReflector);
    // Walk through the shader input bind descriptors.
    // If any of them begin with '@', then we need a unique material per model (i.e., we need to clone the material).
    int ii=0;
    D3D11_SHADER_INPUT_BIND_DESC desc;
    HRESULT hr = pReflector->GetResourceBindingDesc( ii++, &desc );
    while( SUCCEEDED(hr) )
    {
        cString tagName = s2ws(desc.Name);
        CPUTConfigEntry *pValue = properties.GetValueByName(tagName);
        if( !pValue->IsValid() )
        {
            // We didn't find our property in the file.  Is it in the global config block?
            pValue = CPUTMaterial::mGlobalProperties.GetValueByName(tagName);
        }
        cString boundName = pValue->ValueAsString();
        if( (boundName.length() > 0) && ((boundName[0] == '@') || (boundName[0] == '#')) )
        {
            return true;
        }
        hr = pReflector->GetResourceBindingDesc( ii++, &desc );
    }
    return false;
}
예제 #18
0
void *LibLoader::loadFromPath(const std::string & p)
{
	
	std::cout << "loading lib: " << p << std::endl;
#ifdef __unix
	void *lib;
	lib = dlopen(p.c_str(), RTLD_LAZY);
#elif _WIN32
	#ifdef UNICODE
	std::wstring stemp = s2ws(p);
	HINSTANCE lib = LoadLibrary(stemp.c_str());
	#else
	HINSTANCE lib = LoadLibrary(p.c_str());
	#endif
#endif
	if (!lib)
	{
		char *error;
		#ifdef __unix
		if ((error = dlerror()))
		#else
		if (!lib)
			error = "Cannot open the lib";
		#endif
			throw(MyException(error));
	}
	_libs[lib] = p;
	return lib;
}
예제 #19
0
//--------------------------------------------------------------------------------------//
//		Change guild notice
//--------------------------------------------------------------------------------------//
void CClientSession::SendGuildChangeNotice(CNtlPacket * pPacket, CChatServer * app)
{
	sUT_GUILD_CHANGE_NOTICE_REQ * req = (sUT_GUILD_CHANGE_NOTICE_REQ *)pPacket->GetPacketData();

	app->db->prepare("CALL UpdateGuildNotice (?,?, @wResultCode)");
	app->db->setInt(1, this->GetCharacterId());
	app->db->setString(2, Ntl_WC2MB(req->awchNotice));
	app->db->execute();

	app->db->execute("SELECT @wResultCode");
	app->db->fetch();

	CNtlPacket packet(sizeof(sTU_GUILD_CHANGE_NOTICE_RES));
	sTU_GUILD_CHANGE_NOTICE_RES * res = (sTU_GUILD_CHANGE_NOTICE_RES *)packet.GetPacketData();
	res->wOpCode = TU_GUILD_CHANGE_NOTICE_RES;
	res->wResultCode = app->db->getInt("@wResultCode");
	packet.SetPacketLen( sizeof(sTU_GUILD_CHANGE_NOTICE_RES));
	int rc = g_pApp->Send( this->GetHandle(), &packet);

	if(app->db->getInt("@wResultCode") == 300)
	{
		CNtlPacket packet2(sizeof(sTU_GUILD_CHANGE_NOTICE_NFY));
		sTU_GUILD_CHANGE_NOTICE_NFY * res2 = (sTU_GUILD_CHANGE_NOTICE_NFY *)packet2.GetPacketData();
		res2->wOpCode = TU_GUILD_CHANGE_NOTICE_NFY;
		wcscpy_s(res2->awchCharName, NTL_MAX_SIZE_CHAR_NAME_UNICODE, s2ws(this->GetCharName()).c_str());
		memcpy(res2->awchNotice, req->awchNotice, sizeof(wchar_t)* NTL_MAX_LENGTH_OF_GUILD_NOTICE_UNICODE);
		res2->wNoticeLengthInUnicode = req->wNoticeLengthInUnicode;
		//app->UserBroadcastothers(&packet2, this); // CHANGE THAT IT ONLY BROADCAST TO OTHER GUILD MEMBERS
		packet2.SetPacketLen( sizeof(sTU_GUILD_CHANGE_NOTICE_NFY));
		rc = g_pApp->Send( this->GetHandle(), &packet2);
	}
	
}
bool
MMTT_SharedMem::createSharedMem()
{
    if (myMapping)
		return true;

#ifdef WIN32 
    myMapping = CreateFileMapping(INVALID_HANDLE_VALUE, 
		    						  NULL,
		    						  PAGE_READWRITE,
								  0,
								  mySize,
								  s2ws(myName).c_str());

    if (GetLastError() == ERROR_ALREADY_EXISTS)
    {
		detach();
		return false;
    }
#else
    assert(false);
#endif 

    if (myMapping)
		return true;
    else
		return false;
}
예제 #21
0
bool SpeechRecognizerModule::handleAsyncRecognitionCmd(const Bottle& cmd, Bottle& reply)
{
    HRESULT hr;
    string firstVocab = cmd.get(0).asString().c_str();
	if (firstVocab == "getGrammar")
    {
		reply.addString("NOT_IMPLEMENTED");
		return true;
	}

    if (firstVocab == "clear")
    {
        bool everythingIsFine=true;
        SPSTATEHANDLE rootRule;
        everythingIsFine &= SUCCEEDED(m_cpGrammarFromFile->SetGrammarState(SPGS_DISABLED));
        everythingIsFine &= SUCCEEDED(m_cpGrammarFromFile->GetRule(L"rootRule", NULL, SPRAF_TopLevel | SPRAF_Active, TRUE, &rootRule));
        everythingIsFine &= SUCCEEDED(m_cpGrammarFromFile->ClearRule(rootRule));
        everythingIsFine &= SUCCEEDED(hr = m_cpGrammarFromFile->Commit(NULL));
        everythingIsFine &= SUCCEEDED(m_cpGrammarFromFile->SetGrammarState(SPGS_ENABLED));        
        everythingIsFine &= SUCCEEDED(m_cpGrammarFromFile->SetRuleState(NULL, NULL, SPRS_ACTIVE));
        everythingIsFine &= SUCCEEDED(m_cpRecoCtxt->Resume(0));
        reply.addString("Cleared");
        return true;
    }

    if (firstVocab == "addGrammar")
    {    
        string grammar = cmd.get(1).asString().c_str();
        bool everythingIsFine = setGrammarCustom(m_cpGrammarFromFile,grammar,true);
        reply.addString("Added");
        return true;
    }

    if (firstVocab == "loadXML")
    { 
        string xml = cmd.get(1).asString().c_str();
        ofstream fileTmp("grammarTmp.grxml");
        fileTmp<<xml;
        fileTmp.close();

        std::wstring tmp = s2ws("grammarTmp.grxml");
        LPCWSTR cwgrammarfile = tmp.c_str();

        bool everythingIsFine =true;
        //everythingIsFine &= SUCCEEDED( m_cpRecoCtxt->CreateGrammar( 1, &m_cpGrammarFromFile ));
        everythingIsFine &= SUCCEEDED( m_cpGrammarFromFile->SetGrammarState(SPGS_DISABLED));
        everythingIsFine &= SUCCEEDED( m_cpGrammarFromFile->LoadCmdFromFile(cwgrammarfile, SPLO_DYNAMIC));

        everythingIsFine &= SUCCEEDED( m_cpGrammarFromFile->SetGrammarState(SPGS_ENABLED));
        everythingIsFine &= SUCCEEDED(m_cpGrammarFromFile->SetRuleState(NULL, NULL, SPRS_ACTIVE));
        everythingIsFine &= SUCCEEDED(m_cpRecoCtxt->Resume(0));

        refreshFromVocabulories(m_cpGrammarFromFile);
        reply.addString("Loaded");
        return true;
    }

    return false;
}
예제 #22
0
파일: main.cpp 프로젝트: jypuigbo/speech
int main(int argc, char* argv[])
{
    //Parse de parameters. Similar way to acapelaCmd
    std::string voice = "iCub_eng";
    if (argc>1)
        voice = argv[1];
    std::cout << "Voice is: " << voice << std::endl;
    std::cout << "TODO : select the right token from this option." << voice << std::endl;

    std::string textInput;
    std::getline(std::cin, textInput);
    std::cout << "Text is: " << textInput << std::endl;

    if (::CoInitializeEx(NULL, COINIT_MULTITHREADED) == S_OK)
    {
        HRESULT hr = S_OK;
        CComPtr<IEnumSpObjectTokens> cpIEnum;
        CComPtr<ISpObjectToken> cpToken;
        CComPtr<ISpVoice> cpVoice;

        // Enumerate voice tokens that speak US English in a female voice.
        hr = SpEnumTokens(SPCAT_VOICES, L"Language=409", L"Gender=Female;", &cpIEnum);

        // Get the best matching token.
        if (SUCCEEDED(hr))
        {
            hr = cpIEnum->Next(1, &cpToken , NULL);
        }

        // Create a voice and set its token to the one we just found.
        if (SUCCEEDED(hr))
        {
            hr = cpVoice.CoCreateInstance(CLSID_SpVoice);
        }

        // Set the voice.
        if (SUCCEEDED(hr))
        {
            hr = cpVoice->SetVoice(cpToken);
        }

        // Set the output to the default audio device.
        if (SUCCEEDED(hr))
        {
            hr = cpVoice->SetOutput(NULL, TRUE);
        }

        // Speak a string directly.
        if (SUCCEEDED(hr))
        {
            hr = cpVoice->Speak(s2ws(textInput).c_str(), NULL, NULL);
        }
    }
    ::CoUninitialize();

    return 0;
}
MMTT_Mutex::MMTT_Mutex(const char *name)
{
#ifdef WIN32
	myMutex = CreateMutex(NULL, FALSE, s2ws(name).c_str());
#else
	assert(false);
#endif

}
예제 #24
0
파일: window.cpp 프로젝트: maseek/HP
	Maybe<Window> open_IO( Engine& engine, const WindowConfig& windowConfig )
	{
		std::wstring windowNameW = s2ws( "HP_FP::" + engine.name );
		Window window{ nullptr, windowNameW.c_str( ) };
		if ( isOnlyInstance_IO( window.name ) )
		{
			// window class details
			WNDCLASSEX windowClass = { 0 };
			windowClass.cbSize = sizeof( WNDCLASSEX );
			windowClass.style = CS_VREDRAW | CS_HREDRAW;
			windowClass.lpfnWndProc = &windowProc_IO;
			windowClass.cbClsExtra = 0;
			windowClass.cbWndExtra = 0;
			windowClass.hInstance = GetModuleHandle( nullptr );
			windowClass.hIcon = 0;
			windowClass.hIconSm = 0;
			windowClass.hCursor = 0;
			windowClass.hbrBackground = 0;
			windowClass.lpszMenuName = 0;
			windowClass.lpszClassName = window.name;
			// register the window
			if ( RegisterClassEx( &windowClass ) )
			{
				// find position and size
				HDC screenDC = GetDC( nullptr );
				unsigned left = ( GetDeviceCaps( screenDC, HORZRES ) - windowConfig.width ) / 2;
				unsigned top = ( GetDeviceCaps( screenDC, VERTRES ) - windowConfig.height ) / 2;
				unsigned width = windowConfig.width;
				unsigned height = windowConfig.height;
				ReleaseDC( nullptr, screenDC );
				// set the style of the window
				DWORD style = WS_VISIBLE;
				if ( windowConfig.windowStyle == WindowStyle::Window )
				{
					style |= WS_CAPTION | WS_MINIMIZEBOX | WS_THICKFRAME | WS_MAXIMIZEBOX | WS_SYSMENU;
					// adjust the window size with the borders etc.
					RECT rectangle = { 0, 0, windowConfig.width, windowConfig.height };
					AdjustWindowRect( &rectangle, style, false );
					width = rectangle.right - rectangle.left;
					height = rectangle.bottom - rectangle.top;
				}
				// create the window
				window.handle = CreateWindowEx( 0, window.name, window.name, style, left, top, width, height, GetDesktopWindow( ), nullptr, GetModuleHandle( nullptr ), &engine );
				if ( window.handle == nullptr )
				{
					ERR( GetLastError( ) );
					return nothing<Window>( );
				}
				if ( windowConfig.windowStyle == WindowStyle::Fullscreen )
				{
					switchToFullscreen_IO( window.handle, windowConfig );
				}
			}
		}
		return just( std::move( window ) );
	}
예제 #25
0
파일: ods.cpp 프로젝트: a3587556/trochilus
void WriteDebugLog(DWORD dwLastError, LPCSTR file, int codeLine, LOG_LEVEL level, LPCTSTR content, ...)
{
	//格式化日志
	TCHAR logContent[ODS_LOG_MAXLENGTH + 1] = {0};

	DWORD dwThreadID = ::GetCurrentThreadId();
	std::string ansiCodefile = file;
	std::string::size_type pos = ansiCodefile.find_last_of('\\');
	if (pos != std::string::npos && pos + 1 < ansiCodefile.size()) ansiCodefile = ansiCodefile.substr(pos + 1);
	tstring codeFile = s2ws(ansiCodefile);

	tstring strLevel;
	switch (level)
	{
	case ODSLEVEL_DEBUG:
		strLevel = _T("debug");
		break;
	case ODSLEVEL_INFO:
		strLevel = _T("info");
		break;
	case ODSLEVEL_ERROR:
		strLevel = _T("error");
		break;
	default:
		strLevel = _T("unknown");
		break;
	}

	int iWritten = _stprintf_s(logContent, _T("%s [%s:%d] %u "), strLevel.c_str(), codeFile.c_str(), codeLine, dwThreadID);

	va_list ap;
	va_start(ap, content);
	_vsntprintf_s(logContent + iWritten, ODS_LOG_MAXLENGTH - iWritten, _TRUNCATE, content, ap);
	va_end(ap);

	if (dwLastError != 0)
	{
		TCHAR lastError[16] = {0};
		_stprintf_s(lastError, 15, _T(" E%u"), dwLastError);
		
		size_t len = _tcslen(logContent);
		if (len + _tcslen(lastError) < ODS_LOG_MAXLENGTH)
		{
			_tcscat_s(logContent, lastError);
		}
	}

// 	//写入日志
// #ifdef ODS_OUTPUT_STD
	printf("%s\n", t2a(logContent));
// #endif
#ifdef ODS_OUTPUT_FILE
 	OutputFile(logContent);
#endif
	OutputDebugString(logContent);
}
예제 #26
0
shap* InitShap(string smodpath)
{
	shap *pShap=new shap;
	

	LPD3DXBUFFER pD3DXMtrlBuffer;
	wstring s=s2ws(smodpath);
    // 装载.x文件,初始化shap的mesh和dwNumMaterials
	if( FAILED( D3DXLoadMeshFromX( s.c_str(), D3DXMESH_SYSTEMMEM,
                                   g_pd3dDevice, NULL,
								   &pD3DXMtrlBuffer, NULL, &pShap->dwNumMaterials,
								   &pShap->mesh ) ) )
    {        
            return NULL;
     
    }



    // 取出materials和textures
    D3DXMATERIAL* d3dxMaterials = ( D3DXMATERIAL* )pD3DXMtrlBuffer->GetBufferPointer();
	pShap->pMeshMaterials = new D3DMATERIAL9[pShap->dwNumMaterials];
    if( pShap->pMeshMaterials == NULL )
        return NULL;
	pShap->pMeshTextures = new LPDIRECT3DTEXTURE9[pShap->dwNumMaterials];
    if( pShap->pMeshTextures == NULL )
        return NULL;

    for( DWORD i = 0; i < pShap->dwNumMaterials; i++ )
    {
        // Copy the material
        pShap->pMeshMaterials[i] = d3dxMaterials[i].MatD3D;

        // Set the ambient color for the material (D3DX does not do this)
        pShap->pMeshMaterials[i].Ambient = pShap->pMeshMaterials[i].Diffuse;
		///////////////////////////////////////////////////////////////////////////////////
        pShap->pMeshTextures[i] = NULL;
        if( d3dxMaterials[i].pTextureFilename != NULL &&
            lstrlenA( d3dxMaterials[i].pTextureFilename ) > 0 )
        {
            // Create the texture
            if( FAILED( D3DXCreateTextureFromFileA( g_pd3dDevice,
                                                    d3dxMaterials[i].pTextureFilename,
                                                    &pShap->pMeshTextures[i] ) ) )
            {
                ;
            }
        }
    }

    // Done with the material buffer
    pD3DXMtrlBuffer->Release();

    return pShap;
	
}
예제 #27
0
파일: Logger.cpp 프로젝트: RozKen/SATest
Logger::Logger(std::string directoryPath, std::string fileName)
	:count(0), logFilePath(directoryPath.append("/").append(fileName))
	, logDirectoryPath(directoryPath), logFileName(fileName){
		if(!PathIsDirectory(s2ws(logDirectoryPath).c_str())){
			_mkdir(directoryPath.c_str());
		}else{
			std::cout << logDirectoryPath << " already exists." << std::endl;
		}
		Initialize();
}
예제 #28
0
    int FileIo::Impl::switchMode(OpMode opMode)
    {
        assert(fp_ != 0);
        if (opMode_ == opMode) return 0;
        OpMode oldOpMode = opMode_;
        opMode_ = opMode;

        bool reopen = true;
        switch(opMode) {
        case opRead:
            // Flush if current mode allows reading, else reopen (in mode "r+b"
            // as in this case we know that we can write to the file)
            if (openMode_[0] == 'r' || openMode_[1] == '+') reopen = false;
            break;
        case opWrite:
            // Flush if current mode allows writing, else reopen
            if (openMode_[0] != 'r' || openMode_[1] == '+') reopen = false;
            break;
        case opSeek:
            reopen = false;
            break;
        }

        if (!reopen) {
            // Don't do anything when switching _from_ opSeek mode; we
            // flush when switching _to_ opSeek.
            if (oldOpMode == opSeek) return 0;

            // Flush. On msvcrt fflush does not do the job
            std::fseek(fp_, 0, SEEK_CUR);
            return 0;
        }

        // Reopen the file
        long offset = std::ftell(fp_);
        if (offset == -1) return -1;
        // 'Manual' open("r+b") to avoid munmap()
        if (fp_ != 0) {
            std::fclose(fp_);
            fp_= 0;
        }
        openMode_ = "r+b";
        opMode_ = opSeek;
#ifdef EXV_UNICODE_PATH
        if (wpMode_ == wpUnicode) {
            fp_ = ::_wfopen(wpath_.c_str(), s2ws(openMode_).c_str());
        }
        else
#endif
        {
            fp_ = std::fopen(path_.c_str(), openMode_.c_str());
        }
        if (!fp_) return 1;
        return std::fseek(fp_, offset, SEEK_SET);
    } // FileIo::Impl::switchMode
예제 #29
0
yarp::sig::Sound SpeechRecognizerModule::toSound(CComPtr<ISpRecoResult> cpRecoResult)
{
    HRESULT hr = S_OK;
    CComPtr<ISpStreamFormat>      cpStreamFormat = NULL;
    SPPHRASE* pPhrase;
    bool successGetPhrase = SUCCEEDED(cpRecoResult->GetPhrase(&pPhrase));
    hr = cpRecoResult->GetAudio(0, pPhrase->Rule.ulCountOfElements, &cpStreamFormat);

    CComPtr<ISpStream> cpStream;
    ULONG cbWritten = 0; 
   
    string sPath = m_tmpFileFolder + "//tmp.wav";
    //static const WCHAR path[] = L"C://tmpSnd.wav";

    // create file on hard-disk for storing recognized audio, and specify audio format as the retained audio format
    hr = SPBindToFile(s2ws(sPath).c_str(), SPFM_CREATE_ALWAYS, &cpStream, &m_cAudioFmt.FormatId(), m_cAudioFmt.WaveFormatExPtr(), SPFEI_ALL_EVENTS);

    //Continuously transfer data between the two streams until no more data is found (i.e. end of stream)
    //Note only transfer 1000 bytes at a time to creating large chunks of data at one time
    while (TRUE)
    {
        // for logging purposes, the app can retrieve the recognized audio stream length in bytes
        STATSTG stats;
        hr = cpStreamFormat->Stat(&stats, NULL);
        // Check hr

        // create a 1000-byte buffer for transferring
        BYTE bBuffer[1000];
        ULONG cbRead;

        // request 1000 bytes of data from the input stream
        hr = cpStreamFormat->Read(bBuffer, 1000, &cbRead);
        // if data was returned…
        if (SUCCEEDED(hr) && cbRead > 0)
        {
            //then transfer/write the audio to the file-based stream
                hr = cpStream->Write(bBuffer, cbRead, &cbWritten);
            // Check hr
        }

        // since there is no more data being added to the input stream, if the read request returned less than expected, the end of stream was reached, so break data transfer loop
        if (cbRead < 1000)
        {
            break;
        }
    }
    cpStream->Close();
    cpStream.Release();

    yarp::sig::Sound s;
    yarp::sig::file::read(s, sPath.c_str());
    return s;
    return true;
}
예제 #30
0
void CDlgController::OpenFile(const std::wstring& wstrFilename)
{
	if (IOReadBase::Exists(ws2s(wstrFilename)))
	{
		OpenPath(GetParentPath(wstrFilename),s2ws(CRenderNodeMgr::getInstance().getDataPlugsMgr().getAllExtensions()));
		//m_ListBoxFolder.SetSelec()
		//GetFilename(wstrFilename)
		CMainRoot::getInstance().getMainDialog().getModelDisplay().LoadModel(ws2s(wstrFilename));
		CMainRoot::getInstance().getMainDialog().getDlgModelController().OnUpdate();
	}
}