Esempio n. 1
0
BOOL MsiSession::SetProperty(LPCTSTR szMsiPorpeorty, const wstring& sVal)
{
	return SetProperty(szMsiPorpeorty, sVal.c_str());
}
Esempio n. 2
0
wstring GetFileExtension(wstring& FileName)
{
	wstring tmp = FileName.substr(FileName.find_last_of(L".") + 1, FileName.length());
	return tmp;
}
Esempio n. 3
0
wstring CrabStringFindWholeWord(const wstring &t, size_t pos, const wstring &BreakupMark, const wstring &BreakupMarkOnceMore)
{
    wstring foundstr;
    if(0==pos) {
        wstring strR = t;
        size_t foundposL = 0;
        size_t foundposR = t.find(BreakupMark);
        if(BreakupMarkOnceMore.length()>0){ // <added><20150615><dzliu> use another BreakupMarkOnceMore
            if(wstring::npos==foundposR){foundposR = strR.find(BreakupMarkOnceMore);}else{
                if(strR.find(BreakupMarkOnceMore)<foundposR){foundposR=strR.find(BreakupMarkOnceMore);}
            }
        }
        if(wstring::npos==foundposR){foundposR=t.length()-1;}else{
            foundposR=foundposR-1;
        }
        foundstr = t.substr(foundposL,foundposR-foundposL+1);
    } else if(t.length()-1==pos) {
        wstring strL = t;
        size_t foundposL = t.rfind(BreakupMark);
        if(BreakupMarkOnceMore.length()>0){ // <added><20150615><dzliu> use another BreakupMarkOnceMore
            if(wstring::npos==foundposL){foundposL = strL.rfind(BreakupMarkOnceMore);}else{
                if(strL.rfind(BreakupMarkOnceMore)>foundposL){foundposL=strL.rfind(BreakupMarkOnceMore);}
            }
        }
        if(wstring::npos==foundposL){foundposL=0;}else{
            foundposL=foundposL+1;
        }
        size_t foundposR = t.length()-1;
        foundstr = t.substr(foundposL,foundposR-foundposL+1);
    } else if(0<pos && t.length()-1>pos) {
        wstring strL = t.substr(0,pos);
        wstring strR = t.substr(pos);
        size_t foundposL = strL.rfind(BreakupMark);
        if(BreakupMarkOnceMore.length()>0){ // <added><20150615><dzliu> use another BreakupMarkOnceMore
            if(wstring::npos==foundposL){foundposL = strL.rfind(BreakupMarkOnceMore);}else{
                if(strL.rfind(BreakupMarkOnceMore)>foundposL){foundposL=strL.rfind(BreakupMarkOnceMore);}
            }
        }
        if(wstring::npos==foundposL){foundposL=0;}else{
            foundposL=foundposL+1;
        }
        size_t foundposR = strR.find(BreakupMark);
        if(BreakupMarkOnceMore.length()>0){ // <added><20150615><dzliu> use another BreakupMarkOnceMore
            if(wstring::npos==foundposR){foundposR = strR.find(BreakupMarkOnceMore);}else{
                if(strR.find(BreakupMarkOnceMore)<foundposR){foundposR=strR.find(BreakupMarkOnceMore);}
            }
        }
        if(wstring::npos==foundposR){foundposR=t.length()-1;}else{
            foundposR=foundposR-1+pos;
        }
        foundstr = t.substr(foundposL,foundposR-foundposL+1);
    }
    return foundstr;
}
Esempio n. 4
0
wstring toLowerCase(wstring str)
{
	if (str.length())
		_wcslwr_s(&str[0], str.length() + 1);
	return str;
}
Esempio n. 5
0
string ws2s(wstring& inputws)
{ 
	USES_CONVERSION;
	return W2CA(inputws.c_str()); 
}
Esempio n. 6
0
 void encode_string(const wstring& d) {
   encode_string(d.c_str(), d.size());
 }
Esempio n. 7
0
bool UserCmd_Process(uint client, const wstring &cmd)
{
	returncode = DEFAULT_RETURNCODE;
	
	if (!cmd.compare(L"/conn"))
	{
		// Prohibit jump if in a restricted system or in the target system
		uint system = 0;
		pub::Player::GetSystem(client, system);
		if (system == set_iRestrictedSystemID
			|| system == set_iTargetSystemID
			|| GetCustomBaseForClient(client))
		{
			PrintUserCmdText(client, L"ERR Cannot use command in this system or base");
			return true;
		}

		if (!IsDockedClient(client))
		{
			PrintUserCmdText(client, STR_INFO1);
			return true;
		}

		if (!ValidateCargo(client))
		{
			PrintUserCmdText(client, STR_INFO2);
			return true;
		}

		StoreReturnPointForClient(client);
		PrintUserCmdText(client, L"Redirecting undock to Connecticut.");
		transferFlags[client] = CLIENT_STATE_TRANSFER;

		return true;
	}
	else if (!cmd.compare(L"/return"))
	{
		if (!ReadReturnPointForClient(client))
		{
			PrintUserCmdText(client, L"No return possible");
			return true;
		}

		if (!IsDockedClient(client))
		{
			PrintUserCmdText(client, STR_INFO1);
			return true;
		}

		if (!CheckReturnDock(client, set_iTargetBaseID))
		{
			PrintUserCmdText(client, L"Not in correct base");
			return true;
		}

		if (!ValidateCargo(client))
		{
			PrintUserCmdText(client, STR_INFO2);
			return true;
		}

		PrintUserCmdText(client, L"Redirecting undock to previous base");
		transferFlags[client] = CLIENT_STATE_RETURN;

		return true;
	}

	return false;
}
Esempio n. 8
0
__int64 extract(int fd,__int64 startOffset,__int64 endOffset ,const wstring &toDir,const wstring& prefix,bool printProgress)
{
	
	LOG_DEBUG(L"Extracting block... %s", prefix.c_str());
	
	wstring normailizedToDir= NormalizeDirPath(toDir);
	struct archive *inArch;
	struct archive *outArch;
	struct archive_entry *entry;
	int flags;
	int r;

	flags = ARCHIVE_EXTRACT_TIME;
	flags |= ARCHIVE_EXTRACT_PERM;
	flags |= ARCHIVE_EXTRACT_ACL;
	flags |= ARCHIVE_EXTRACT_FFLAGS;

	inArch = archive_read_new();
	archive_read_support_format_all(inArch);
	archive_read_support_compression_all(inArch);
	uint64_t totalSize=0;
	uint64_t totalWritten=0;
	if (r = duck_read_open_fd(inArch, fd, 10240,startOffset,endOffset))
	{
		LOG_ERROR(L"Could not open fd");
		return false;
	}
	while (true) 
	{
		r = archive_read_next_header(inArch, &entry);
		if (r == ARCHIVE_EOF)
		{
			break;
		}
		if (r < ARCHIVE_WARN)
		{
			Logger::logger.logCstr(true,L"archive_read_next_header-computing size returned error ",archive_error_string(inArch));
			return false;	
		}
		wstring path(archive_entry_pathname_w(entry));
		if(!strIsPrefixed(path, prefix))
		{
			continue;
		}
		totalSize+=archive_entry_size(entry);
	}
	LOG_DEBUG(L"Computed size: %I64u" ,totalSize);
	if(printProgress)
	{
		wprintf(L"Total size: %I64u bytes\n",totalSize);
	}
	
	outArch = archive_write_disk_new();
	archive_write_disk_set_options(outArch, flags);

	archive_read_close(inArch);
	archive_read_free(inArch);
	inArch = archive_read_new();
	archive_read_support_format_all(inArch);
	archive_read_support_compression_all(inArch);
	if (r = duck_read_open_fd(inArch, fd, 10240,startOffset,endOffset))
	{
		
		LOG_ERROR(L"Could not open fd");
		Logger::logger.logCstr(true,L"archive_read_next_header returned error ",archive_error_string(inArch));
		return false;
	}

	//archive_read_extract_set_progress_callback(inArch,extractProgress,NULL);
	while (true) 
	{
		r = archive_read_next_header(inArch, &entry);
		if (r == ARCHIVE_EOF)
		{
			LOG_DEBUG(L"EOF reached");
			break;
		}
		if (r < ARCHIVE_WARN)
		{
			Logger::logger.logCstr(true,L"archive_read_next_header returned error ",archive_error_string(inArch));
			return false;	
		}
		if (r < ARCHIVE_OK)
		{
			Logger::logger.logCstr(true,L"archive_read_next_header returned ",archive_error_string(inArch));
			//return false;	
		}

		wstring path(archive_entry_pathname_w(entry));
		if(!strIsPrefixed(path, prefix))
		{
			continue;
		}
		//remove prefix and dir seperator:
		if (prefix != L"")
		{
			path = path.substr(prefix.length() + 1);
		}
		wstring s=normailizedToDir;
		s+=path;
		LOG_DEBUG(L"Setting old name %s to %s",path.c_str(),s.c_str());
		if (printProgress)
		{
			wprintf(L"Writing file: %s\n", s.c_str());
		}
		archive_entry_copy_pathname_w ( entry, s.c_str() );
		bool isDir=archive_entry_filetype(entry)&AE_IFDIR==0;

		bool retry = true;
		while (retry)
		{
			retry = false;
			r = archive_write_header(outArch, entry);
			if (r < ARCHIVE_OK)
			{

				if (printProgress)
				{
					wchar_t answer = L'i';
					string err(archive_error_string(outArch));
					wstring errWide(err.begin(), err.end());
					wprintf(L"Write error: %s\n", errWide.c_str());
					wprintf(L"Would you like to (R)etry, (I)gnore or (A)bort?\n");
					std::cout.flush();
					wscanf_s(L" %c", &answer,1);
					if (answer == L'r' || answer == L'R')
					{
						retry = true;
						continue;
					}
					else if (answer == L'a' || answer == L'A')
					{
						return false;
					}
					wprintf(L"ignoring...\n");
				}
				Logger::logger.logCstr(true, L"archive_write_header returned ", archive_error_string(outArch));
				//return false;	
			}
			else if (!isDir)
			{
				r = copy_data(inArch, outArch);
				if (r == false)
				{
					return false;
				}

			}
		}
		r = archive_write_finish_entry(outArch);
		if (printProgress)
		{
			wprintf(L"Written %s %s\n", isDir ? L"dir" : L"file", path.c_str());
			totalWritten += archive_entry_size(entry);
			wprintf(L"Progress %I64u/%I64u\n", totalWritten, totalSize);
		}
		if (r < ARCHIVE_WARN)
		{

			if (printProgress)
			{
				wprintf(L"Write finish fatal error: %s\n", archive_error_string(outArch));
			}
			Logger::logger.logCstr(true, L"archive_write_finish_entry returned error ", archive_error_string(outArch));
			return false;
		}
		if (r < ARCHIVE_OK)
		{
			if (printProgress)
			{
				wprintf(L"Write finish error: %s\n", archive_error_string(outArch));
			}
			Logger::logger.logCstr(true, L"archive_write_finish_entry returned ", archive_error_string(outArch));
			//return false;	
		}
		
		
	}
	archive_read_close(inArch);
	archive_read_free(inArch);

	archive_write_close(outArch);
	archive_write_free(outArch);
	
	return true;
}
Esempio n. 9
0
int wmain(int argc, wchar_t**argv){
	wstring pCmdLine;
	for (int i = 0; i < argc; i++)
	{
		pCmdLine += L' ';
		pCmdLine += argv[i];
	}
	wchar_t path[MAX_PATH]= moduleDbg;
#else
	int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) {
	wchar_t path[MAX_PATH];
	GetModuleFileNameW(NULL, path, MAX_PATH) ;
#endif
	
	//let windows parse arguments find the arg after the log path token and use it
	LPWSTR *arglist;
	int nArgs;
	arglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);

	LOG_DEBUG(L"Module path: %s",path);
	
	
	
	wstring pathStr(path);

	const wstring verbose(L"--verbose");
	const wstring shouldLog(L"--log");
	const wstring block2(L"--block2");
	const wstring block2Path(L"--block2Path");
	const wstring block2Target(L"--block2Target");
	const wstring logpath(L"--logpath");

	wstring cmd(pCmdLine);
	Logger::logger.setVerbose(cmd.find(verbose)!=cmd.npos);
	bool LoggerOn=cmd.find(shouldLog)!=cmd.npos;
	Logger::logger.setOn(LoggerOn);
	
	if(LoggerOn)
	{
		if(cmd.find(logpath)!=cmd.npos)
		{
			
			for(int i=0;i<nArgs-1;i++)
			{
				//check if the argument i equals logpath ("--logpath") which means the next argument is the log path
				if(logpath.compare(arglist[i])==0)
				{
					if(!Logger::logger.openStream(wstring(arglist[i+1])))
					{
						//msg box?
						//LOG_ERROR(L"Could not open log file stream : %s",arglist[i+1]);
					}
				}
			}

		}
		else
		{
			
			wstring logPath(pathStr.substr(0,pathStr.find_last_of(L"/\\")) +L"/duckinstaller.log");
			if(!Logger::logger.openStream(logPath))
			{
				//msg box?
				//LOG_ERROR(L"Could not open log file stream : %s",logPath.c_str);
			}
		}
	}
	
	int  selfFileHandle;
	errno_t err = _wsopen_s( &selfFileHandle,  path, _O_RDONLY, _SH_DENYWR, _S_IREAD );

	if (err != 0)
	{
		LOG_DEBUG(L"Could not open self (err=%d): %s", (int)err,path);
		return -1;
	}
	DuckFileDescriptor desc={0};

	_lseek(selfFileHandle,-(long)(sizeof(desc)),SEEK_END);
	size_t endOfDesc=_tell(selfFileHandle);
	_read (selfFileHandle, (char*)&desc, sizeof(desc) );

	LOG_DEBUG(L"Descriptor read %d %d %d %d %d %d",desc.crc32, desc.magicNum,desc.block1Offset, desc.block2Offset,  desc.varDescOffset, desc.version);

	if(desc.magicNum== ND_MAGIC_NUM&&desc.version==ND_VER)
	{
		if(cmd.find(block2)!=cmd.npos)
		{
			wstring extractFromPath;
			wstring targetPath(pathStr.substr(0,pathStr.find_last_of(L"/\\")));
			for(int i=0;i<nArgs-1;i++)
			{
				if(block2Path.compare(arglist[i])==0)
				{
					extractFromPath=arglist[i+1];
				}
				else if( block2Target.compare(arglist[i])==0)
				{
					targetPath=arglist[i+1];
				}

			}
			if(extractFromBlock2(selfFileHandle,desc.block2Offset,desc.varDescOffset,targetPath,extractFromPath))
			{
				//LOG_ERROR(L"Could not extract block2");
			}
		}
		else
		{
			if(SetEnvironmentVariable(L"ND_SFX_EXE",path)==0)
			{
				LOG_ERROR(L"Could not set exe var %s",GetLastErrorStdStrW().c_str());
				return -1;
			}
			string exeCmd;

			char buf[2048] = { 0 };
			_lseek(selfFileHandle, desc.varDescOffset, SEEK_SET);
			_read(selfFileHandle, (char*)&buf, endOfDesc - desc.varDescOffset);
			std::string json(buf, endOfDesc - desc.varDescOffset);
			std::istringstream is(json);

			//string s(buf);
			//exeCmd = wstring(s.begin(), s.end());
			boost::property_tree::ptree pt;
			try
			{
				boost::property_tree::read_json(is, pt);
				exeCmd = pt.get<std::string>("run");
			}
			catch (boost::exception & e)
			{
				
				LOG_ERROR(L"read_json error:", boost::diagnostic_information(e));
				return -1;
			}
			
			
			if(extractAndRunBlock1(selfFileHandle,desc.block1Offset,desc.block2Offset, exeCmd))
			{
				LOG_ERROR(L"Could not extract block1");
				return -1;
			}
		}
	}
	else
	{
		LOG_ERROR(L"Installer file corrupted");
		return -1;
	}
}
Esempio n. 10
0
void NCurses_Editor::LineDraw(	const wstring&	sViewWStr,
						int nY, 
						int nN, 
						int nTextNum,
						int nNum)
{
	setcol(_tColorEdit, _pWin);
	wmove(_pWin, nY, nN);

	int 	nBoxLine = 0;

	if ( _bFullScreen )
		nBoxLine = 0;
	else
		nBoxLine = 1;
	
	whline(_pWin, ' ', width-(nBoxLine*2));
	
	if (_bLineNumView == true)
	{
		setcol(_tColorEditInfo, _pWin);
		mvwprintw(_pWin, nY, nN+1, "%*d", _nLineWidth, nTextNum+1);
		setcol(_tColorEditInfo, _pWin);
		mvwhline(_pWin, nY, nN+_nLineWidth+1, VLINE, 1);
		nN = 3+_nLineWidth+nN;
	}
	
	string	sTab;
	sTab.append(1, (char)TABCONVCHAR);

	if (_EditMode == EDIT)
	{
		string sViewStr = wstrtostr(sViewWStr);
		string sViewStr2 = MLSUTIL::Replace(sViewStr, sTab.c_str(), " "); // Tab -> Space
		setcol(_tColorEdit, _pWin);
		mvwprintw(_pWin, nY, nN, "%s", sViewStr2.c_str());
	}
	else if (_EditMode == SELECT || _EditMode == SHIFT_SELECT)
	{
		EditSelect	tEditSelect = _EditSelect;
		SelectSort(&tEditSelect);

		int x1 = tEditSelect.x1;
		int x2 = tEditSelect.x2;

		wstring 		sLineWStr = _vText[nTextNum];
		wstring			sWStr;
		StrLineToken	tStrLineToken;
		tStrLineToken.SetWString(sLineWStr, _nCulumn);
		
		int				nCurSize = 0;
		for (int n = 0; n<tStrLineToken.LineSize(); n++)
		{
			sWStr = tStrLineToken.GetLineStr(n);
			if (n == nNum) break;
			nCurSize=nCurSize+sWStr.size();
		}

		int	nCurEndSize = nCurSize+sViewWStr.size();
		
		if (tEditSelect.x1 > nCurSize)	x1 = tEditSelect.x1 - nCurSize;
		if (tEditSelect.x2 > nCurSize)	x2 = tEditSelect.x2 - nCurSize;
		
		if (tEditSelect.y1 == nTextNum && tEditSelect.y2 == nTextNum)
		{
			if (tEditSelect.x1 >= nCurSize && tEditSelect.x2 <= nCurEndSize)
			{
				SelectionDraw(sViewWStr, nY, nN, x1, x2);
			}
			else if (tEditSelect.x1 >= nCurSize && tEditSelect.x2 > nCurEndSize)
			{
				SelectionDraw(sViewWStr, nY, nN, x1, sViewWStr.size());
			}
			else if (tEditSelect.x1 < nCurSize && tEditSelect.x2 > nCurSize)
			{
				SelectionDraw(sViewWStr, nY, nN, 0, x2);
			}
			else if (tEditSelect.x1 < nCurSize && tEditSelect.x2 > nCurEndSize)
			{
				string sViewStr = wstrtostr(sViewWStr);
				string sViewStr2 = MLSUTIL::Replace(sViewStr, sTab.c_str(), " "); // Tab -> Space
				setrcol(_tColorEdit, _pWin); // 반전
				mvwprintw(_pWin, nY, nN, "%s", sViewStr2.c_str());
			}
			else
			{
				string sViewStr = wstrtostr(sViewWStr);
				string sViewStr2 = MLSUTIL::Replace(sViewStr, sTab.c_str(), " "); // Tab -> Space
				setcol(_tColorEdit, _pWin);
				mvwprintw(_pWin, nY, nN, "%s", sViewStr2.c_str());
			}
		}
		else if (tEditSelect.y1 == nTextNum)
		{
			if (tEditSelect.x1 >= nCurSize)
			{
				SelectionDraw(sViewWStr, nY, nN, x1, sViewWStr.size());
				
				string sViewStr = wstrtostr(sViewWStr);
				string sViewStr2 = MLSUTIL::Replace(sViewStr, sTab.c_str(), " "); // Tab -> Space
				wmove(_pWin, nY, nN+scrstrlen(sViewStr2));
				whline(_pWin, ' ', width-nN-scrstrlen(sViewStr2)-nBoxLine);
			}
			else if (tEditSelect.x1 < nCurSize)
			{
				string sViewStr = wstrtostr(sViewWStr);
				string sViewStr2 = MLSUTIL::Replace(sViewStr, sTab.c_str(), " "); // Tab -> Space
				setrcol(_tColorEdit, _pWin); // 반전
				mvwprintw(_pWin, nY, nN, "%s", sViewStr2.c_str());
			}
			else
			{
				string sViewStr = wstrtostr(sViewWStr);
				string sViewStr2 = MLSUTIL::Replace(sViewStr, sTab.c_str(), " "); // Tab -> Space
				
				mvwprintw(_pWin, nY, nN, "%s", sViewStr2.c_str());
			}
		}
		else if (tEditSelect.y2 == nTextNum)
		{
			if (tEditSelect.x2 > nCurSize)
			{
				SelectionDraw(sViewWStr, nY, nN, 0, x2);
			}
			else if (tEditSelect.x2 > nCurEndSize)
			{
				string sViewStr = wstrtostr(sViewWStr);
				string sViewStr2 = MLSUTIL::Replace(sViewStr, sTab.c_str(), " "); // Tab -> Space
				setrcol(_tColorEdit, _pWin); // 반전
				mvwprintw(_pWin, nY, nN, "%s", sViewStr2.c_str());
			}
			else
			{
				string sViewStr = wstrtostr(sViewWStr);
				string sViewStr2 = MLSUTIL::Replace(sViewStr, sTab.c_str(), " "); // Tab -> Space
				setcol(_tColorEdit, _pWin);
				mvwprintw(_pWin, nY, nN, "%s", sViewStr2.c_str());
			}
		}
		else if (tEditSelect.y1 < nTextNum && tEditSelect.y2 > nTextNum)
		{
			string sViewStr = wstrtostr(sViewWStr);
			string sViewStr2 = MLSUTIL::Replace(sViewStr, sTab.c_str(), " "); // Tab -> Space
			setrcol(_tColorEdit, _pWin); // 반전
			wmove(_pWin, nY, nN);
			whline(_pWin, ' ', width-nBoxLine);
			mvwprintw(_pWin, nY, nN, "%s", sViewStr2.c_str());
		}
		else
		{
			string sViewStr = wstrtostr(sViewWStr);
			string sViewStr2 = MLSUTIL::Replace(sViewStr, sTab.c_str(), " "); // Tab -> Space
			setcol(_tColorEdit, _pWin);
			mvwprintw(_pWin, nY, nN, "%s", sViewStr2.c_str());
		}
	}
}
Esempio n. 11
0
void Logger::logCstr(bool error,const wstring & prefix,const char * str)
{
	string s(str);
	wstring wideS(convertToWideString(s));
	log(!error,L"%s : %s",prefix.c_str(),wideS.c_str());
}
Esempio n. 12
0
wstring upcase(const wstring& str) {
  Buffer<wchar_t> up_str(str.size());
  wmemcpy(up_str.data(), str.data(), str.size());
  CharUpperBuffW(up_str.data(), static_cast<DWORD>(up_str.size()));
  return wstring(up_str.data(), up_str.size());
}
Esempio n. 13
0
bool Key::set_str_nt(const wchar_t* name, const wstring& value) {
  LONG res = RegSetValueExW(h_key, name, 0, REG_SZ, reinterpret_cast<LPBYTE>(const_cast<wchar_t*>(value.c_str())), (static_cast<DWORD>(value.size()) + 1) * sizeof(wchar_t));
  if (res != ERROR_SUCCESS) {
    SetLastError(res);
    return false;
  }
  return true;
}
Esempio n. 14
0
	void StringParser::Parse( const string& key, const wstring& text, StringParser::StringItem* item )
	{
		item->m_Key = key;
		item->m_Text = text;
		int i = 0;
		int j = 0;
		int k = 0;
		bool hasError = false;
		while( true )
		{
			for( int x=i; x<text.length(); ++x )
			{
				if( text[x] == L'{' && x < text.length()-1 && text[x+1] == L'%' )
				{
					i = x;
					break;
				}
			}
			//i = text.find_first_of( L"{%", i );
			if( i < 0 )
				break;
			/// 0123{%s1}
			/// 012345678
			if( text.length() < i+5 )
				break;
			wchar_t typeChar = text.at( i+2 );
			/// 0123{%{%s1}
			if( typeChar != L's' 
				&& typeChar != L'S'
				&& typeChar != L'd'
				&& typeChar != L'D'
				&& typeChar != L'i'
				&& typeChar != L'I'
				&& typeChar != L'f'
				&& typeChar != L'F' )
			{
				i += 2;
				continue;
			}
			j = text.find_first_of( L"}", i+4 );
			if( j < 0 )
				break;
			int indexLen = j - i - 3;
			/// 0123{%s}8
			if( indexLen < 1 )
			{
				i = j + 1;
				continue;
			}
			/// Ö»Ö§³Ö1-99µÄÐòºÅ
			/// 0123{%s100}
			if( indexLen > 2 )
			{
				i = j + 1;
				continue;
			}
			wstring indexStr = text.substr( i+3, indexLen );
			/// ÅжÏÊÇ·ñÊÇÊý×Ö
			if( indexStr < L"0" || indexStr > L"99" )
			{
				break;
			}
			int index = We::Type::ToInt( indexStr );
			if( index <= 0 )
			{
				_LogError( string("StringParser::Parse Error : ") + key );
				hasError = true;
				break;
			}
			item->m_Indexes.push_back( index );
			item->m_Texts.push_back( text.substr( k, i-k ) );
			k = j + 1;
			i = j + 1;
		}
		item->m_Texts.push_back( text.substr( k, text.length()-k ) );
		/// ¼ì²éÐòºÅÊÇ·ñÓÐÎó
		for( int i=0; i<item->m_Indexes.size(); ++i )
		{
			/// ÐòºÅ³¬³ö·¶Î§
			if( item->m_Indexes[i] > item->m_Indexes.size() )
			{
				_LogError( string("StringParser::Parse Error : ") + key );
				hasError = true;
				break;
			}
			/// ÐòºÅÖظ´
			for( int j=i+1; j<item->m_Indexes.size(); ++j )
			{
				if( item->m_Indexes[i] == item->m_Indexes[j] )
				{
					_LogError( string("StringParser::Parse Error : ") + key );
					hasError = true;
					break;
				}
			}
		}
		if( hasError )
		{
			item->m_Texts.clear();
			item->m_Indexes.clear();
		}
	}
Esempio n. 15
0
 operator LPCTSTR() const {
   return name.empty() ? MAKEINTRESOURCE(id) : name.c_str();
 }
Esempio n. 16
0
void EnumerateBoots(wstring dir, int& count)
{
    // check for skip-path
    if (wcsicmp(dir.c_str(),_bootserv_config._random_skip.c_str())==0)
    {
        LOG1S(L"skipping {%s}: boots from this folder can ONLY BE ASSIGNED MANUALLY (using map.txt)", dir.c_str());
        return;
    }

	WIN32_FIND_DATA fData;
    wstring pattern(dir);
    pattern += L"*";

	HANDLE hff = FindFirstFile(pattern.c_str(), &fData);
	if (hff == INVALID_HANDLE_VALUE) 
	{
		// none found.
		return;
	}
	while(true)
	{
        // bounds check
        if (count >= MAX_BOOTS)
        {
            LOG1N(L"ERROR in bootserver: Too many boots (MAX supported = %d). Random boot enumeration stopped.", MAX_BOOTS);
            break;
        }

        // check if this is a directory
        if (fData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY
                && wcscmp(fData.cFileName,L".")!=0 
                && wcscmp(fData.cFileName,L"..")!=0)
        {
            wstring nestedDir(dir);
            nestedDir += fData.cFileName;
            nestedDir += L"\\";
            EnumerateBoots(nestedDir, count);
        }
        else if ((fData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
        {
            // check for ".bin" extension. This way we have
            // a little bit of protection against other types
            // of files in boots folder.
            int flen = wcslen(fData.cFileName);
            if (wcsicmp(fData.cFileName+flen-4, L".bin")==0)
            {
                int idx = FIRST_RANDOM_BOOT_SLOT + count;

                wstring bootFile(dir);
                bootFile += L"\\";
                bootFile += fData.cFileName;
                if (k_bootserv.debug)
                    LOG1N1S(L"random boot: %d <-- {%s}", idx, bootFile.c_str());

                _fast_bin_table[idx - FIRST_EXTRA_BOOT_SLOT] =
                    new wstring(bootFile);
                count++;
            }
		}

		// proceed to next file
		if (!FindNextFile(hff, &fData)) break;
	}
	FindClose(hff);
}
Esempio n. 17
0
 bool is_int() const {
   return name.empty();
 }
Esempio n. 18
0
int
Dictionary::operator[](const wstring & word)
{
    return word.size() == 1 || isDate(word) || isEnglish(word) 
            || isNumeric(word) || _dict[word];
}
Esempio n. 19
0
void d2d::ShowText(wstring strText, D2D1_RECT_F position)
{
    m_pRenderTarget->DrawText(strText.c_str(), strText.size(),
            m_pTextFormat, position, m_pBlackBrush, D2D1_DRAW_TEXT_OPTIONS_CLIP);
}
Esempio n. 20
0
string StringTools::ToString(const wstring& str)
{
	std::string temp(str.begin(), str.end());
	return temp;
}
Esempio n. 21
0
wstring toUpperCase(wstring str)
{
	if (str.length())
		_wcsupr_s(&str[0], str.length() + 1);
	return str;
}
Esempio n. 22
0
void fix_slashes(wstring& path) {
  for (size_t i = 0; i < path.size(); i++) {
    if (path[i] == L'/') path[i] = L'\\';
  }
}
Esempio n. 23
0
// See https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_string_as_a_parameter
// Some tricky test cases:
// "abcdefghijklmn".replace(/(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)(m)(n)/, "$001"): "$001"
// "abcdefghijklmn".replace(/(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)(m)(n)/, "$01"): "a"
// "abcdefghijklmn".replace(/(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)(m)(n)/, "$10"): "j"
// "abcdefghijklmn".replace(/(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)(m)(n)/, "$15"): "a5"
// "abcdefghijklmn".replace(/(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)(m)(n)/, "$20"): "b0"
void insertReplacedString(wstring& builder, const wstring& base, const wstring& str, const RegExpMatch& match)
{
	const vector<wstring>& substrings = match.substrings;
	const wstring& mstr = substrings[0];
	for (size_t i = 0; i < str.length(); i++)
	{
		if (str[i] == L'$' && str.length() > i + 1)
		{
			wchar_t ch = str[++i];
			switch (ch)
			{
			case L'$': // insert a '$'
				builder.push_back(ch);
				break;
			case L'&': // insert the matched string
				builder.append(mstr);
				break;
			case L'`': // insert the portion preceding the matched string
				builder.append(base.begin(), base.begin() + match.index);
				break;
			case L'\'': // insert the portion following the matched string
				builder.append(base.begin() + match.index + mstr.length(), base.end());
				break;
			default:
				if (ch >= L'0' && ch <= L'9')
				{
					int expidx = 0;
					wchar_t ch2 = str.length() > i + 1 ? str[i + 1] : L'\0';
					if (ch2 >= L'0' && ch2 <= L'9')
					{
						expidx = ch2 - L'0' + 10 * (ch - L'0');
						// if expidx overflows, fall back to single-digit
						if (expidx == 0 || expidx >= (int)substrings.size())
						{
							expidx = ch - L'0';
							ch2 = 0;
						}
					}
					else
					{
						ch2 = 0;
						expidx = ch - L'0';
					}
					// substrings.size() is 1 bigger than actual sub matches
					if (expidx < (int)substrings.size() && expidx > 0)
					{
						const wstring& submstr = substrings[expidx];
						builder.append(submstr);
						if (ch2) ++i;
						break;
					}
				}
				// $ escape fails, output as is
				builder.push_back(L'$');
				builder.push_back(ch);
			}
		}
		else builder.push_back(str[i]);
	}
}
/**
 * Lifecycle: load
 */
void FrameServer::load(HWND toolbar, HWND target, 
                       const wstring& uuid, const wstring& title, const wstring& icon, 
                       DWORDX processId, INT_PTRX proxy)
{
    logger->debug(L"FrameServer::load"
                  L" -> " + boost::lexical_cast<wstring>(toolbar) +
                  L" -> " + boost::lexical_cast<wstring>(target) +
                  L" -> " + uuid +
                  L" -> " + title +
                  L" -> " + icon +
                  L" -> " + boost::lexical_cast<wstring>(processId) +
                  L" -> " + boost::lexical_cast<wstring>(proxy));

    ATL::CComCritSecLock<CComAutoCriticalSection> lock(m_clientLock, true);

    if (processId != ::GetCurrentProcessId() && 
        m_clientListeners.find(processId) == m_clientListeners.end()) {
        // add IPC channel for proxy if it is in a different process 
        m_clientListeners[processId] = ClientListener(new Channel(L"IeBarMsgPoint", processId), 1);
        if (m_clientListeners.size() == 1) {
            m_activeProcessId = processId;
            m_activeProxy = proxy;
        }
    }

    // only initialize the first time
    if (++m_tabCount != 1) {
        logger->debug(L"FrameServer::load already initialized");
        lock.Unlock();
        return;
    }

    m_toolbar = toolbar;
    m_target  = target;
    
    // subclass windows
    m_oldWndProcToolbar = (WndProcPtr)::GetWindowLongPtr(m_toolbar, GWLP_WNDPROC);
    ::SetWindowLongPtr(m_toolbar, GWLP_WNDPROC, (LONG_PTR)WndProcToolbarS);
    m_oldWndProcTarget = (WndProcPtr)::GetWindowLongPtr(m_target, GWLP_WNDPROC);
    ::SetWindowLongPtr(m_target, GWLP_WNDPROC, (LONG_PTR)WndProcTargetS);

    lock.Unlock();
    
    // add button
    HRESULT hr;
    Button  button;
    hr = button_addCommand(uuid.c_str(), title.c_str(), icon.c_str()).exec(toolbar, target, &button);
    if (FAILED(hr)) {
        logger->error(L"FrameServer::load failed to create button"
                      L" -> " + logger->parse(hr));
        ::MessageBox(NULL,
                     wstring(L"Forge could not create button. Please check that "
                             L"your icon file is a 16x16 bitmap in .ico format: "
                             L"'" + icon + L"'").c_str(),
                     VENDOR_COMPANY_NAME,
                     MB_TASKMODAL | MB_ICONEXCLAMATION);
        return;
    }

    lock.Lock();
    m_buttons[uuid] = button;
    lock.Unlock();
    
}
Esempio n. 25
0
string ToString(const wstring& wstr)
{
	return ToString((WCHAR*)wstr.c_str());
}
Esempio n. 26
0
 RsrcModule(const wstring& file_path) {
   h_module = LoadLibraryEx(file_path.c_str(), nullptr, LOAD_LIBRARY_AS_DATAFILE);
   CHECK_SYS(h_module);
 }
Esempio n. 27
0
void TransparentWnd::RunAppIn(CefString appName, CefString param, CefString baseUrl){
	wstring appNameW=appName.ToWString();
	if(appNameW.find(L":")==-1){
		wstring path;
		if(!baseUrl.length()){
			path=modulePath;//szPath;
		}
		else{
			path=baseUrl.ToWString();
			replace_allW(path, L"\\", L"/");
			path=path.substr(0,path.find_last_of('/')+1);
		}
		appNameW=path.append(appNameW);
	}
	replace_allW(appNameW, L"\\", L"/");
	int w,h,_x,_y;
	int enableDrag=0,disableTransparent=0,exStyle=0,hasBorder=false,_max=false,_enableResize=false,disableRefresh=0,disableDevelop=0;
	TCHAR url[1000],name[100],iconPath[1000];
	wstring _folder=appNameW.substr(0,appNameW.find_last_of('/')+1);
	folder=_folder;
	GetPrivateProfileString(L"BASE",L"url",NULL,url,1000,appNameW.data());
	GetPrivateProfileString(L"BASE",L"name",NULL,name,100,appNameW.data());
	GetPrivateProfileString(L"BASE",L"icon",NULL,iconPath,1000,appNameW.data());
	w=GetPrivateProfileInt(L"BASE",L"width",0,appNameW.data());
	h=GetPrivateProfileInt(L"BASE",L"height",0,appNameW.data());
	_x=GetPrivateProfileInt(L"BASE",L"x",0,appNameW.data());
	_y=GetPrivateProfileInt(L"BASE",L"y",0,appNameW.data());
	enableDrag=GetPrivateProfileInt(L"BASE",L"enableDrag",0,appNameW.data());
	disableRefresh=GetPrivateProfileInt(L"BASE",L"disableRefresh",0,appNameW.data());
	disableDevelop=GetPrivateProfileInt(L"BASE",L"disableDevelop",0,appNameW.data());
	_enableResize=GetPrivateProfileInt(L"BASE",L"enableResize",0,appNameW.data());
	disableTransparent=GetPrivateProfileInt(L"BASE",L"disableTransparent",0,appNameW.data());
	hasBorder=GetPrivateProfileInt(L"BASE",L"hasBorder",0,appNameW.data());
	_max=GetPrivateProfileInt(L"BASE",L"max",0,appNameW.data());
	exStyle=GetPrivateProfileInt(L"BASE",L"exStyle",0,appNameW.data());
	int l=wcslen(iconPath);
	if(l>0){
		hIcon=GetIcon(iconPath);
	}
	if(_enableResize>0){
		enableResize=true;
	}
	enableRefresh=disableRefresh==0;
	enableDevelop=disableDevelop==0;
	CefString cefFile(url);
	wstring file=cefFile.ToWString();
	if(file.find(L":")==-1){
		file=_folder.append(file);
	}
	bool isTransparent=disableTransparent==0;
	if(hasBorder){
		char t[10];
		_itoa(isTransparent,t,10);
		CefString ct(t);
		wstring _name(name);
		file=modulePath.append(L"window\\index.html?name=").append(_name).append(L"&url=").append(file).append(L"&transparent=").append(ct.ToWString().data()).append(L"&x=");
		_itoa(_x,t,10);
		ct=t;
		file.append(ct.ToWString().data());
		file.append(L"&y=");
		_itoa(_y,t,10);
		ct=t;
		file.append(ct.ToWString().data());
		file.append(L"&width=");
		_itoa(w,t,10);
		ct=t;
		file.append(ct.ToWString().data());
		file.append(L"&height=");
		_itoa(h,t,10);
		ct=t;
		file.append(ct.ToWString().data());
		file.append(L"&max=");
		_itoa(_max,t,10);
		ct=t;
		file.append(ct.ToWString().data());
		isTransparent=true;
		if(param.length()){
			file.append(L"&param="+param.ToWString());
		}
	}
	else {
		if(param.length()){
			file.append(L"?param="+param.ToWString());
		}
	}
	CreateBrowserWindow(file, exStyle, isTransparent);
	if(_max){
		this->Max();
	}
	else{
		SetSize(w,h);
		Move(_x,_y);
	}
	this->SetTitle(name);
	if(enableDrag>0){
		EnableDrag();
	}

}
Esempio n. 28
0
 ResourceUpdate(const wstring& file_path) {
   handle = BeginUpdateResource(file_path.c_str(), FALSE);
   CHECK_SYS(handle);
 }
Esempio n. 29
0
long CrabStringFindWholeWord(const wstring &t, const wstring &strsearch, const wstring &BreakupMark, const wstring &BreakupMarkOnceMore)
{
    size_t foundpos = 0;
    int debug = 0;
    while(wstring::npos!=foundpos) {
        foundpos = t.find(strsearch,foundpos);
        if(debug) { std::wcout << "CrabStringFindWholeWord: searching " << strsearch << " got foundpos = " << foundpos << std::endl; }
        if(wstring::npos!=foundpos) {
            if(foundpos>=BreakupMark.length() && foundpos+strsearch.length()<t.length()-BreakupMark.length()) {
                if(BreakupMark==t.substr(foundpos-1,BreakupMark.length()) &&
                   BreakupMark==t.substr(foundpos+strsearch.length(),BreakupMark.length())) {break;}
                if(BreakupMarkOnceMore.length()>0){
                    if(BreakupMarkOnceMore==t.substr(foundpos-1,BreakupMarkOnceMore.length()) &&
                       BreakupMarkOnceMore==t.substr(foundpos+strsearch.length(),BreakupMarkOnceMore.length())) {break;}
                }
            }
            if(foundpos==0 && foundpos+strsearch.length()<t.length()-BreakupMark.length()) {
                if(BreakupMark==t.substr(foundpos+strsearch.length(),BreakupMark.length())) {break;}
                if(BreakupMarkOnceMore.length()>0){
                    if(BreakupMarkOnceMore==t.substr(foundpos+strsearch.length(),BreakupMarkOnceMore.length())) {break;}
                }
            }
            if(foundpos>=BreakupMark.length() && foundpos+strsearch.length()==t.length()-BreakupMark.length()-1) {
                if(BreakupMark==t.substr(foundpos-1,BreakupMark.length())) {break;}
                if(BreakupMarkOnceMore.length()>0){
                    if(BreakupMarkOnceMore==t.substr(foundpos-1,BreakupMarkOnceMore.length())) {break;}
                }
            }
            // <Corrected><20150316><dzliu> when the header is at the end of the line
            if(foundpos+strsearch.length()-1==t.length()-1) {
                break;
            }
        } else {
            break;
        }
        foundpos++;
    }
    return foundpos;
}
Esempio n. 30
0
wstring MsiSession::GetProperty(wstring& sMsiProperty)
{
	return GetProperty(sMsiProperty.c_str());
}