BOOL CExtInstaller::CreateDeepDirectory(LPCTSTR lpPathName,
						 LPSECURITY_ATTRIBUTES lpSecurityAttributes   )
{
	if(PathFileExists(lpPathName))
	{
		return TRUE;
	}

	tstring strPath = _T("");
	TCHAR pszSrc[MAX_PATH] = {0};
	wcscpy(pszSrc, lpPathName);
	TCHAR *ptoken = wcstok(pszSrc, _T("\\"));
	while(ptoken)
	{
		strPath += ptoken;
		strPath += _T("\\");
		if(!PathFileExists(strPath.c_str()))  
		{
			if(!CreateDirectory(strPath.c_str(), lpSecurityAttributes))
			{
				SHOW_LOG( _T("CExtInstaller::CreateDeepDirectory CreateDirectory [ERROR CODE]%d\n"), GetLastError());
				return FALSE;
			}
		}
		ptoken = wcstok(NULL, _T("\\"));
	}
	return TRUE;
Beispiel #2
0
BOOL ParseProxyList()
{
	WCHAR * tmpProxyString = _wcsdup(szProxyString);
	ExpandEnvironmentStrings(tmpProxyString, szProxyString, sizeof(szProxyString)/sizeof(szProxyString[0]));
	free(tmpProxyString);
	WCHAR *sep = L"\n";
	WCHAR *pos = wcstok(szProxyString, sep);
	INT i = 0;
	lpProxyList[i++] = L"";
	while (pos && i < sizeof(lpProxyList)/sizeof(lpProxyList[0]))
	{
		lpProxyList[i++] = pos;
		pos = wcstok(NULL, sep);
	}
	lpProxyList[i] = 0;

	
	for (LPSTR ptr = szRasPbk; *ptr; ptr++)
	{
		if (*ptr == '\n')
		{
			*ptr++ = 0;
		}
	}
	return TRUE;
}
bool Blockporter::IsNewModelVersion(const TCHAR* file, const TCHAR* nodeName)
{
	mStream = _tfopen(file, _T("r"));
	if(!mStream)
		return true; //the file doesn't exist, so the current modelversion is greater

	//Version is in the third line of the file, so let's get it
	TCHAR line[128];
	TCHAR model[64];
	wcscpy(model, nodeName);
	fgetws(line, _countof(line), mStream);
	//first check if this is´the proper file
	if(wcscmp(line, L"<Header>\n")) //The first line isn't <Header> so it's not the right file
	{
		fclose(mStream);
		return true;
	}

	fgetws(line, _countof(line), mStream);
	fgetws(line, _countof(line), mStream);

	TCHAR* oVer = wcstok(line, L"=");
	oVer = wcstok(nullptr, L"=");
	TCHAR* nVer = wcstok(model, L"=");
	nVer = wcstok(nullptr, L"=");

	if(_wtoi(oVer) <= _wtoi(nVer))
	{
		fclose(mStream);
		return true; //The old version is below the new one
	}

	fclose(mStream);
	return false; //The old version is above the new one. Better ask if we really want to export.
}
void getFolder(WCHAR * folder, WCHAR * wfile)
{
	// now we need to get the containing folder of the obj file
	// this only works if the mtl and jpg files are in the same folder
	// but it shouldn't matter where that folder is

	std::vector <WCHAR *> result;

	WCHAR * res = wcstok(wfile, L"\\");
	while (res)
	{
		result.push_back(res);
		res = wcstok(NULL, L"\\");
	}

	// the last element of the result vector should be the filename, and everything else can be concatenated to make the containing folder

	USHORT resSize = result.size();

	// make the folder string empty
	wcscpy(folder, L"");

	WCHAR *slash = L"\\";

	for (int i = 0; i < resSize - 1; i++) // -1 to exclude last element
	{
		wcscat(folder, result[i]);
		wcscat(folder, slash);
	}
}
Beispiel #5
0
//load words into an avl tree
TREE_NODE * index_file(char *file_name){
  FILE *file;
  file = fopen(file_name,"r");
  if(!file){
    printf("arquivo de entrada invalido\n");
    return NULL;
  }

  wchar_t line [ 10000 ];
  wchar_t *token;
  wchar_t *state;
  const wchar_t delimiters[] = L" \n,.;'\"?-|:*&!@$%{}()[]<>\\";//only consider letters
  int current_line = 1;
  TREE_NODE *tree = NULL;
  W_TOKEN *w_token = NULL;

  while ( fgetws ( line, sizeof(line), file ) ){//read line by line
    for (token = wcstok(line, delimiters, &state);
           token != NULL;
           token = wcstok(NULL, delimiters, &state)) {
      if(token) w_token = create_word(token);
      insert_avl(&tree, (void *)w_token, lex_order, current_line);
      }
    current_line++;
  }

  fclose ( file );
  return tree;
}
Beispiel #6
0
BOOL SetEenvironment() {
    WCHAR *sep = L"\n";
    WCHAR *pos = NULL;
    WCHAR *token = wcstok(szEnvironment, sep);
    while(token != NULL) {
        if (pos = wcschr(token, L'=')) {
            *pos = 0;
            SetEnvironmentVariableW(token, pos+1);
        }
        token = wcstok(NULL, sep);
    }
    GetEnvironmentVariableW(L"ENV_VISIBLE", szVisible, sizeof(szVisible)/sizeof(szVisible[0])-1);
    GetEnvironmentVariableW(L"ENV_TITLE", szTitle, sizeof(szTitle)/sizeof(szTitle[0])-1);
    GetEnvironmentVariableW(L"ENV_TOOLTIP", szTooltip, sizeof(szTooltip)/sizeof(szTooltip[0])-1);
    GetEnvironmentVariableW(L"ENV_BALLOON", szBalloon, sizeof(szBalloon)/sizeof(szBalloon[0])-1);

    ParseSubMenuTitleList();
    ParseSubMenuCmdList();
    ParseSubMenuPathList();

    GetModuleFileName(NULL, szPath, sizeof(szPath)/sizeof(szPath[0])-1);
    *wcsrchr(szPath, L'\\') = 0;
    SetEnvironmentVariableW(L"ENV_BOOT_PWD", szPath);
    
    return TRUE;
}
Beispiel #7
0
static void _loadCustomDictionary(void){
	char			szFileName[MAX_PATH];
	char			szTemp[64];
	HANDLE			hFile;
	int				size = 0;

	_itoa(m_CodePage, szTemp, 10);
	strcat(szTemp, ".cust");
	strcpy(szFileName, m_CustPath);
	strcat(szFileName, szTemp);
	hFile = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
	if(hFile != INVALID_HANDLE_VALUE){
		size = GetFileSize(hFile, NULL);
		if(size > 0){
			wchar_t	*pWords = calloc(size, sizeof(wchar_t));
			if(pWords){
				wchar_t	*pTemp = pWords;
				DWORD		dwBytesRead = 0;
				ReadFile(hFile, pTemp, size, &dwBytesRead, NULL);
				if(dwBytesRead == size){
					wchar_t		*ptr;
					wchar_t *word = wcstok(pTemp, L"^", &ptr);
					while(word){
						if(wcslen(word) > 0){
							AddWordToDictionary(word, FALSE);
						}
						word = wcstok(NULL, L"^", &ptr);
					}
				}
				free(pWords);
			}
		}
		CloseHandle(hFile);
	}
}
Beispiel #8
0
int CSVPToolBox::Explode(std::wstring szIn,
                         std::wstring szTok,
                         std::vector<std::wstring>* szaOut)
{
  szaOut->clear();

  std::wstring resToken;

  int size=sizeof(wchar_t);
  wchar_t* str = new wchar_t[szIn.length() + 1];
  wcscpy(str, szIn.c_str());
  wchar_t* sep = new wchar_t[szTok.length() + 1];
  wcscpy(sep, szTok.c_str());
  wchar_t* token = NULL;
  wchar_t* next_token = NULL;
  token = wcstok(str, sep, &next_token);

  while (token != NULL)
  {
    szaOut->push_back((std::wstring)token);
    token = wcstok( NULL, sep, &next_token);
  }

  delete[] str;
  delete[] sep;

  return 0;
}
void
TableMakerAdvProperties::InitTableTypeValues()
{
    HWND        hwndcombo;
    wyInt32     index;
    wyString    strengine;
    wyWChar     *enginebuff, *tokpointer;

    GetTableEngineString(m_tunnel, m_mysql, strengine);

    enginebuff = AllocateBuffWChar(strengine.GetLength()+1);
    wcscpy(enginebuff, strengine.GetAsWideChar());
    VERIFY(hwndcombo = GetDlgItem(m_hwnd, IDC_TYPE));

    tokpointer = wcstok(enginebuff, L";");

    while(tokpointer != NULL)
    {
        VERIFY((SendMessage(hwndcombo, CB_ADDSTRING, 0, (LPARAM)tokpointer)) >= 0);

        tokpointer = wcstok(NULL, L";");
    }
    free(enginebuff);

    if((index = SendMessage(hwndcombo , CB_ADDSTRING, 0,(LPARAM)TEXT(STR_DEFAULT))) != CB_ERR)
        SendMessage(hwndcombo, CB_SELECTSTRING, index, (LPARAM)TEXT(STR_DEFAULT));

    return;
}
Beispiel #10
0
void Runtime::Debugger::ProcessArgs(Load* load) {
  // clear
  arguments.clear();
  arguments.push_back(L"obr");
  arguments.push_back(program_file);
  // parse arguments
  const wstring temp = load->GetFileName();
  wchar_t* buffer = (wchar_t*)calloc(sizeof(wchar_t), temp.size() + 1);
  wcsncpy(buffer, temp.c_str(), temp.size());
#ifdef WIN32
  wchar_t* token = wcstok(buffer, L" ");
#else
  wchar_t *state;
  wchar_t* token = wcstok(buffer, L" ", &state);
#endif
  while(token) {
    arguments.push_back(token);
#ifdef WIN32
    token = wcstok(NULL, L" ");
#else
    token = wcstok(NULL, L" ", &state);
#endif
  }
  wcout << L"program arguments sets." << endl;

  // clean up
  free(buffer);
  buffer = NULL;
}
Beispiel #11
0
BOOL SetEenvironment()
{
	LoadString(hInst, IDS_CMDLINE, szCommandLine, sizeof(szCommandLine)/sizeof(szCommandLine[0])-1);
	LoadString(hInst, IDS_ENVIRONMENT, szEnvironment, sizeof(szEnvironment)/sizeof(szEnvironment[0])-1);
	//LoadString(hInst, IDS_PROXYLIST, szProxyString, sizeof(szProxyString)/sizeof(szEnvironment[0])-1);

	WCHAR *sep = L"\n";
	WCHAR *pos = NULL;
    WCHAR *token = wcstok(szEnvironment, sep);
	while(token != NULL)
	{
		if (pos = wcschr(token, L'='))
		{
			*pos = 0;
			SetEnvironmentVariableW(token, pos+1);
			//wprintf(L"[%s] = [%s]\n", token, pos+1);
		}
		token = wcstok(NULL, sep);
	}

	GetEnvironmentVariableW(L"TASKBAR_TITLE", szTitle, sizeof(szTitle)/sizeof(szTitle[0])-1);
	GetEnvironmentVariableW(L"TASKBAR_TOOLTIP", szTooltip, sizeof(szTooltip)/sizeof(szTooltip[0])-1);
	GetEnvironmentVariableW(L"TASKBAR_BALLOON", szBalloon, sizeof(szBalloon)/sizeof(szBalloon[0])-1);

	return TRUE;
}
Beispiel #12
0
wchar_t *os_wcstok(wchar_t *_pwstData, const wchar_t *_pwstDelim, wchar_t** _pswtState)
{
#ifndef _MSC_VER
    return wcstok(_pwstData, _pwstDelim, _pswtState);
#else
    return wcstok(_pwstData, _pwstDelim);
#endif
}
wchar_t * Melder_wcstok (wchar_t *string, const wchar_t *delimiter, wchar_t **last) {
	#if defined (__MINGW32__)
		(void) last;
		return wcstok (string, delimiter);
	#else
		return wcstok (string, delimiter, last);
	#endif
}
Beispiel #14
0
int find_sound(const char *word)
{
	wchar_t *word_wc;
	wchar_t *lang_wc_ptr;
	wchar_t *word_wc_ptr;
	wchar_t *word_token_wc;
	wchar_t *word_token_wc_state;
	char *play_command;
	size_t word_wc_len;
	size_t play_command_len;


	if ( (word_wc_len = strlen(word)) < 1 )
		return 0;
	word_wc_len = (word_wc_len + 16) * sizeof(wchar_t);


	if ( (word_wc = (wchar_t *) malloc(word_wc_len)) == NULL ) {
		fprintf(stderr, "Cannot allocate memory (%s:%d): %s\n", __FILE__, __LINE__, strerror(errno));
		return -1;
	}

	strncpy_lower_wc(word_wc, word, word_wc_len);

	if ( (word_wc_ptr = wcschr(word_wc, ':')) == NULL ) { // lang:word
		fprintf(stderr, "A word must be given in the format \"language:word\"\n");
		free(word_wc);
		return -1;
	}

	lang_wc_ptr = word_wc;
	*word_wc_ptr = L'\0';
	++word_wc_ptr;

	for (word_token_wc = wcstok(word_wc_ptr, L" -./\\()", &word_token_wc_state); word_token_wc;
		word_token_wc = wcstok(NULL, L" -./\\()", &word_token_wc_state)) {

		play_command_len = ( (strlen(AUDIO_PLAYER_BIN) + strlen(ALL_SOUNDS_DIR) + strlen(AUDIO_POSTFIX)) * sizeof(char) +
			(wcslen(lang_wc_ptr) + wcslen(word_token_wc)) * sizeof(wchar_t) + 32 );

		if ( (play_command = (char *) malloc(play_command_len)) == NULL ) {
			fprintf(stderr, "Cannot allocate memory (%s:%d): %s\n", __FILE__, __LINE__, strerror(errno));
			continue;
		}

		sprintf(play_command, "%s %s/%ls/%lc/%ls%s", AUDIO_PLAYER_BIN, ALL_SOUNDS_DIR, lang_wc_ptr,
			word_token_wc[0], word_token_wc, AUDIO_POSTFIX);

		system(play_command);

		free(play_command);
	}

	free(word_wc);

	return 0;
}
Beispiel #15
0
static int find_word_combinations(const char *word, const char *dict_name, FILE *dict_fp)
{
	wchar_t word_wc[MAX_WORD_SIZE];
	wchar_t str_wc[MAX_WORD_SIZE];

	wchar_t *str_token_wc;
	wchar_t *str_token_wc_state;

	char *str = NULL;
	size_t str_len = 0;

	int translate_count = 0;


	if ( strlen(word) < 1 )
		return 0;

	if ( strncpy_lower_wc(word_wc, word, MAX_WORD_SIZE - 1) == NULL ) {
		fprintf(stderr, "Cannot convert \"%s\" to (wchar_t *): %s\n", word, strerror(errno));
		return -1;
	}

	while ( getline(&str, &str_len, dict_fp) != -1 ) {
		if ( str[0] == '#' || str[0] == '\n' )
			continue;

		if ( strncpy_lower_filter_wc(str_wc, str, MAX_WORD_SIZE - 1) == NULL )
			continue;

		for (str_token_wc = wcstok(str_wc, L" -./\\", &str_token_wc_state); str_token_wc;
			str_token_wc = wcstok(NULL, L" -./\\", &str_token_wc_state)) {
			if ( word_wc[0] != str_token_wc[0] )
				continue;

			if ( !strcmp_full_wc(str_token_wc, word_wc) ) {
				++translate_count;

				//if ( translate_count == 1 )
				//	print_header(dict_name, word_wc);
				print_translate(str, translate_count);
				//print_separator();

				if ( translate_count >= settings.max_translate_count )
					goto external_loop_break_label;

				break;
			}
		}
	}

	external_loop_break_label :

	free(str);

	return translate_count;
}
Beispiel #16
0
int
mkfulldir_internal (wchar_t *path)
{
	wchar_t *token;
	struct _stat st;
	static wchar_t tokpath[_MAX_PATH];
	static wchar_t trail[_MAX_PATH];

	StringCbCopyW (tokpath, _MAX_PATH, path);
	trail[0] = L'\0';

	token = wcstok (tokpath, L"\\/");

	if (tokpath[0] == L'\\' && tokpath[1] == L'\\')
	{			/* unc */
		trail[0] = tokpath[0];
		trail[1] = tokpath[1];
		trail[2] = L'\0';
		if (token)
		{
			StringCbCatW (trail, _MAX_PATH, token);
			StringCbCatW (trail, _MAX_PATH, L"\\");
			token = wcstok (NULL, L"\\/");
			if (token)
			{		/* get share name */
				StringCbCatW (trail, _MAX_PATH, token);
				StringCbCatW (trail, _MAX_PATH, L"\\");
			}
			token = wcstok (NULL, L"\\/");
		}
	}

	if (tokpath[1] == L':')
	{			/* drive letter */
		StringCbCatW (trail, _MAX_PATH, tokpath);
		StringCbCatW (trail, _MAX_PATH, L"\\");
		token = wcstok (NULL, L"\\/");
	}

	while (token != NULL)
	{
		int x;
		StringCbCatW (trail, _MAX_PATH, token);
		x = _wmkdir (trail);
		StringCbCatW (trail, _MAX_PATH, L"\\");
		token = wcstok (NULL, L"\\/");
	}

	return _wstat (path, &st);
}
Beispiel #17
0
HRESULT LoadVoices(void){
	HRESULT 					hr;
    ISpObjectToken 				*pToken;
	IEnumSpObjectTokens			*cpEnum;
	wchar_t						*pDescription, *p, *ptr, szBuffer[64];

	hr = _EnumTokens(SPCAT_VOICES, NULL, NULL, &cpEnum);
	if(hr == S_OK){
		g_VoicesCount = 0;
		pDescription = (wchar_t *)CoTaskMemAlloc(128 * sizeof(wchar_t));
		while(IEnumSpObjectTokens_Next(cpEnum, 1, &pToken, NULL) == S_OK){
			hr = _GetDescription(pToken, &pDescription);
			if(SUCCEEDED(hr)){
				g_VoicesCount++;
				wcscpy(g_PVoices[g_VoicesCount - 1].name, pDescription);
				g_PVoices[g_VoicesCount - 1].token = pToken;
				GetPrivateProfileStringW(S_VOICES, pDescription, NULL, szBuffer, 64, g_NotePaths.INIFile);
				if(*szBuffer){
					p = wcstok(szBuffer, L"|", &ptr);
					g_PVoices[g_VoicesCount - 1].rate = _wtol(p);
					p = wcstok(NULL, L"|", &ptr);
					g_PVoices[g_VoicesCount - 1].volume = (unsigned short)_wtoi(p);
					g_PVoices[g_VoicesCount - 1].pitch = (short)_wtoi(ptr);
				}
				else{
					ISpVoice		*pVoice = CreateVoice();
					ISpVoice_SetVoice(pVoice, (ISpObjectToken *)g_PVoices[g_VoicesCount - 1].token);
					ISpVoice_GetVolume(pVoice, &g_PVoices[g_VoicesCount - 1].volume);
					ISpVoice_GetRate(pVoice, &g_PVoices[g_VoicesCount - 1].rate);
					g_PVoices[g_VoicesCount - 1].pitch = 0;
					ReleaseVoice(pVoice);
				}
				if(g_VoicesCount == NELEMS(g_PVoices))
					break;
			}
			if (FAILED(hr))
            {
                ISpObjectToken_Release(pToken);
				break;
            }
		}
		CoTaskMemFree(pDescription);
	}
	else
    {
        hr = SPERR_NO_MORE_ITEMS;
    }
    return hr;
}
Beispiel #18
0
static TACommandVerdict wcstok_cmd(TAThread thread,TAInputStream stream)
{
    wchar_t* stringp, *buff, *delim, *res;

/*
    freopen(NULL, "a+", stdout);
    orient=fwide(stdout, 0);
    wprintf(L"Before wcstok(wprintf): mode==%ls\n", orient>0?L"Wide": orient<0?L"Byte":L"Non oriented");
    wprintf(L"Test==%ls\n", test);
    ta_debug_printf("Before wcstok(printf): mode==%s\n", orient>0?"Wide": orient<0?"Byte":"Non oriented");
*/    

    // Prepare       
    stringp=(wchar_t*)readPointer(&stream);
    delim=(wchar_t*)readPointer(&stream);
    buff=(wchar_t*)readPointer(&stream);    

    // Execute    
    START_TARGET_OPERATION(thread);
    res = wcstok(stringp, delim, &buff);
    END_TARGET_OPERATION(thread);

    // Response    
    writePointer(thread, res);
    writePointer(thread, buff);

    sendResponse(thread);

    return taDefaultVerdict;
}
Beispiel #19
0
BOOL ParseSubMenuPathList() {
    WCHAR * tmpSubString = _wcsdup(szSubMenuPath);
    ExpandEnvironmentStrings(tmpSubString, szSubMenuPath, sizeof(szSubMenuPath)/sizeof(szSubMenuPath[0]));
    free(tmpSubString);
    WCHAR *sep = L"\n";
    WCHAR *pos = wcstok(szSubMenuPath, sep);
    INT i = 0;
    lpSubMenuPathList[i++] = szPath;
    while (pos && i < sizeof(lpSubMenuPathList)/sizeof(lpSubMenuPathList[0])) {
        lpSubMenuPathList[i++] = pos;
        pos = wcstok(NULL, sep);
    }
    lpSubMenuPathList[i] = 0;

    return TRUE;
}
void FixAutoplay( LPCWSTR wszApplicationName, LPCWSTR wszCommandLine, LPCWSTR wszCurrentDirectory )
{
	LPCWSTR uppApplicationName = _wcsupr( _wcsdup( wszApplicationName ) );

	// only UT2004
	if( wcsstr(uppApplicationName,L"UT2004.EXE") == NULL )
		return;

	// read mod name from commandline, must be specified
	LPCWSTR uppCommandLine = _wcsupr( _wcsdup( wszCommandLine ) );
	LPWSTR pb = wcsstr(uppCommandLine,L"-MOD=");
	if( pb == NULL )
		return;
	
	// mod name must be valid
	LPWSTR ps = pb + wcslen(L"-MOD=");
	LPWSTR token = wcstok( ps, L" " );
	if( token == NULL )
		return;

	// mod directory must be valid
	if( !SetCurrentDirectoryW(wszCurrentDirectory)
	||	!SetCurrentDirectoryW(L"..")
	||	!SetCurrentDirectoryW(token) )
		return;

	// copy Autoplay.ut2
	if( !CopyFileW( L"..\\Maps\\Autoplay.ut2", L"Maps\\Autoplay.ut2", FALSE ) )
		return;

	//MessageBox( NULL, TEXT("Copy OK"), TEXT("SwAutoplayFix"), MB_OK );
}
Beispiel #21
0
void DumpStreamInfo(char *szFilename, WIN32_STREAM_ID *psStreamInfo)
{
    wchar_t arSeparators[] = L":";
    wchar_t *szStreamShortName = L"<noname>";
    const char *szStreamType;
    DWORD dwStreamSize = psStreamInfo->Size.QuadPart / (1024 * 1024);

    if (psStreamInfo->dwStreamNameSize > 0)
    {
        szStreamShortName = wcstok(psStreamInfo->cStreamName, arSeparators);
    }

    switch (psStreamInfo->dwStreamId)
    {
        case BACKUP_DATA: { szStreamType = "data"; break; }
        case BACKUP_EA_DATA: { szStreamType = "extended attributes"; break; }
        case BACKUP_SECURITY_DATA: { szStreamType = "security"; break; }
        case BACKUP_ALTERNATE_DATA: { szStreamType = "other"; break; }
        case BACKUP_LINK: { szStreamType = "link"; break; }
        default: { szStreamType = "unknown"; break; }
    }

    printf("[%s] %s:%S", szStreamType, szFilename, szStreamShortName);
    if (dwStreamSize > 0)
    {
        printf(" = %d mb\n", dwStreamSize);
    }
    else
    {
        printf("\n");
    }
}
void CShowActiveDirUsers::GetUserAndDomainNameFromUPN(LPTSTR szUser, 
								LPTSTR szUserName, LPTSTR szDomainName)
{
	ULONG size = 8192;
	TCHAR buffer[8192];

	if ( TranslateName( szUser, NameUserPrincipal, NameSamCompatible, 
										buffer, &size ) )
	{
		// we UPN name
		TCHAR  szSeparators[] = L"\\";
		TCHAR* szToken  = L"";

		szToken = _tcstok( buffer, szSeparators );

		// domain
		_tcsupr(szToken);
		_tcscpy(szDomainName, szToken);

		// user name
		szToken = wcstok( NULL, szSeparators );
		_tcslwr(szToken);
		_tcscpy(szUserName, szToken);

	}
}
Beispiel #23
0
static int
find_env_config_value(FILE * env_file, const wchar_t * key, wchar_t * value)
{
    int result = 0; /* meaning not found */
    char buffer[MAXPATHLEN*2+1];  /* allow extra for key, '=', etc. */

    fseek(env_file, 0, SEEK_SET);
    while (!feof(env_file)) {
        char * p = fgets(buffer, MAXPATHLEN*2, env_file);
        wchar_t tmpbuffer[MAXPATHLEN*2+1];
        PyObject * decoded;
        int n;

        if (p == NULL)
            break;
        n = strlen(p);
        if (p[n - 1] != '\n') {
            /* line has overflowed - bail */
            break;
        }
        if (p[0] == '#')    /* Comment - skip */
            continue;
        decoded = PyUnicode_DecodeUTF8(buffer, n, "surrogateescape");
        if (decoded != NULL) {
            Py_ssize_t k;
            wchar_t * state;
            k = PyUnicode_AsWideChar(decoded,
                                     tmpbuffer, MAXPATHLEN * 2);
            Py_DECREF(decoded);
            if (k >= 0) {
                wchar_t * tok = wcstok(tmpbuffer, L" \t\r\n", &state);
                if ((tok != NULL) && !wcscmp(tok, key)) {
                    tok = wcstok(NULL, L" \t", &state);
                    if ((tok != NULL) && !wcscmp(tok, L"=")) {
                        tok = wcstok(NULL, L"\r\n", &state);
                        if (tok != NULL) {
                            wcsncpy(value, tok, MAXPATHLEN);
                            result = 1;
                            break;
                        }
                    }
                }
            }
        }
    }
    return result;
}
Beispiel #24
0
/* Search for a prefix value in an environment file (pyvenv.cfg).
   If found, copy it into the provided buffer. */
int
_Py_FindEnvConfigValue(FILE *env_file, const wchar_t *key,
                       wchar_t *value, size_t value_size)
{
    int result = 0; /* meaning not found */
    char buffer[MAXPATHLEN*2+1];  /* allow extra for key, '=', etc. */

    fseek(env_file, 0, SEEK_SET);
    while (!feof(env_file)) {
        char * p = fgets(buffer, MAXPATHLEN*2, env_file);

        if (p == NULL) {
            break;
        }

        size_t n = strlen(p);
        if (p[n - 1] != '\n') {
            /* line has overflowed - bail */
            break;
        }
        if (p[0] == '#') {
            /* Comment - skip */
            continue;
        }

        wchar_t *tmpbuffer = _Py_DecodeUTF8_surrogateescape(buffer, n);
        if (tmpbuffer) {
            wchar_t * state;
            wchar_t * tok = wcstok(tmpbuffer, L" \t\r\n", &state);
            if ((tok != NULL) && !wcscmp(tok, key)) {
                tok = wcstok(NULL, L" \t", &state);
                if ((tok != NULL) && !wcscmp(tok, L"=")) {
                    tok = wcstok(NULL, L"\r\n", &state);
                    if (tok != NULL) {
                        wcsncpy(value, tok, MAXPATHLEN);
                        result = 1;
                        PyMem_RawFree(tmpbuffer);
                        break;
                    }
                }
            }
            PyMem_RawFree(tmpbuffer);
        }
    }
    return result;
}
Beispiel #25
0
void GrantAllPrivs(HANDLE h)
{
	Log(L"DEBUG: GrantAllPrivs", false);
	CString privs = L"SeCreateTokenPrivilege,SeAssignPrimaryTokenPrivilege,SeLockMemoryPrivilege,SeIncreaseQuotaPrivilege,SeMachineAccountPrivilege,"
					L"SeTcbPrivilege,SeSecurityPrivilege,SeTakeOwnershipPrivilege,SeLoadDriverPrivilege,SeSystemProfilePrivilege,SeSystemtimePrivilege,SeProfileSingleProcessPrivilege,"
					L"SeIncreaseBasePriorityPrivilege,SeCreatePagefilePrivilege,SeCreatePermanentPrivilege,SeBackupPrivilege,SeRestorePrivilege,SeShutdownPrivilege,SeDebugPrivilege,"
					L"SeAuditPrivilege,SeSystemEnvironmentPrivilege,SeChangeNotifyPrivilege,SeRemoteShutdownPrivilege,SeUndockPrivilege,SeSyncAgentPrivilege,SeEnableDelegationPrivilege,"
					L"SeManageVolumePrivilege,SeImpersonatePrivilege,SeCreateGlobalPrivilege,SeTrustedCredManAccessPrivilege,SeRelabelPrivilege,SeIncreaseWorkingSetPrivilege,"
					L"SeTimeZonePrivilege,SeCreateSymbolicLinkPrivilege";

	wchar_t* pC = wcstok(privs.LockBuffer(), L",");
	while(NULL != pC)
	{
		EnablePrivilege(pC, h); //needed to call CreateProcessAsUser
		pC = wcstok(NULL, L",");
	}
}
Beispiel #26
0
BOOL SetEenvironment()
{
	TCHAR *sep = L"\n";
	TCHAR *token = wcstok(szEnvironment, sep);
	while(token!=NULL)
	{
		TCHAR *pos = wcschr(token, L'=');
		if (pos)
		{
			*pos = 0;
			TCHAR* key = token;
			TCHAR* value = pos + 1;
			SetEnvironmentVariableW(key, value);
		}
		token = wcstok(NULL, sep);
	}
	return TRUE;
}
Beispiel #27
0
BOOL wbSetTabControlText(PWBOBJ pwboTab, LPCTSTR pszText)
{
	TCHAR *szTitle = _wcsdup(pszText);
	TCHAR *ptr;

	if(!pwboTab || !pwboTab->hwnd || !IsWindow(pwboTab->hwnd))
		return FALSE;

	if(!pszText || !*pszText)
		return FALSE;

	SendMessage(pwboTab->hwnd, TCM_DELETEALLITEMS, 0, 0);
	ptr = wcstok(szTitle, TEXT("\r\n,"));
	while(ptr) {
		wbCreateTabItem(pwboTab, ptr);
		ptr = wcstok(NULL, TEXT("\r\n,"));
	}
	return TRUE;
}
Beispiel #28
0
void scorelist_load() {
  int i, j;
  wchar_t chunk[1024];
  wchar_t delim[2] = L" ";
  wchar_t *ptr;
  wchar_t *token;

  FILE *fp = fopen(scorelist_file, "r, ccs=UTF-8");
  if (fp != NULL) {
    i = 0;
    while (fgetws(chunk, 1024, fp) != NULL) {
      chunk[wcslen(chunk) - 1] = L'\0';
      if (wcslen(chunk) > 0) {
        j = 0;
        token = wcstok(chunk, delim, &ptr);
        while (token != NULL) {
          switch (j) {
            case 0:
              wcsncpy(scorelist[i].name, token, 255);
              break;
            case 1:
              scorelist[i].points = (unsigned int)wcstoul(token, NULL, 0);
              break;
            case 2:
              scorelist[i].chars = (unsigned int)wcstoul(token, NULL, 0);
              break;
            case 3:
              scorelist[i].seconds = (unsigned int)wcstoul(token, NULL, 0);
              break;
          }
          token = wcstok(ptr, delim, &ptr);
          j++;
        }
        i++;
      }
    }
    fclose(fp);
    scorelist_length = i;
  }

  free(ptr);
  free(token);
}
Beispiel #29
0
void CAddDevice::GetONVIFStreamPort(const CString& str, WORD& nPort)
{
	CString cs_rtsp = str;
	wchar_t *wstr = NULL;
	wchar_t str_rtsp[128];
	wcscpy(str_rtsp, cs_rtsp.GetBuffer());
	wstr = wcstok(str_rtsp,_T(":"));
	wstr = wcstok(NULL,_T(":"));
	if(wstr)
	{
		wstr = wcstok(NULL,_T("/"));
	}

	if (wstr)
		nPort = _ttoi(wstr);
	else
		nPort = 554;
	cs_rtsp.ReleaseBuffer();
}
Beispiel #30
0
bool fsEnsureDirectoryExists(const wchar_t* dir) {
	if (dir == NULL) return false;
	wchar_t* targetDir = fsAbsolutePath(dir);
	wchar_t* currentDir = _wgetcwd(NULL, CBUF_TRY_SIZE);

	/// If the directory already exists, do nothing.
	if (_wchdir(targetDir) == 0) {
		_wchdir(currentDir);
		free(currentDir);
		return true;
	}

	/**
	 * Create all directories along the specified path.
	 */
	wchar_t* workPath = newWCString(wcslen(dir));
	wcscpy(workPath, dir);

	/**
	 * The first component of the path is the drive specifier.
	 * We should go to its root first.
	 */
	wchar_t* pathComponent = wcstok(workPath, L"\\");
	wchar_t* initialPath = wcsAppend(pathComponent, L"\\");
	_wchdir(initialPath);
	free(initialPath);
	pathComponent = wcstok(NULL, L"\\");

	bool status = 0;
	while (pathComponent) {
		_wmkdir(pathComponent);
		status = _wchdir(pathComponent);
		if (status != 0) break;
		pathComponent = wcstok(NULL, L"\\");
	}

	_wchdir(currentDir);
	free(currentDir);
	free(workPath);

	return status == 0;
}