Example #1
0
static void SetNameCaption(const TCHAR* tFilter) {

  TCHAR namfilter[50];
  if ( _tcscmp(tFilter,_T("*")) == 0)
        _tcscpy(namfilter,_T("*"));
  else {
        if (_tcslen(tFilter) <GC_SUB_STRING_THRESHOLD)
                _stprintf(namfilter,_T("%s*"),tFilter);
        else
          {
                if (_tcslen(tFilter) <6)
                        _stprintf(namfilter,_T("*%s*"),tFilter);
                else {
                        _tcscpy(namfilter,_T("*"));
                        _tcsncat(namfilter,tFilter,5);
                        namfilter[5]='\0';
                        _tcscat(namfilter,_T("..*"));
                }
        }

  }
//  StartupStore(_T("SETCAPTION <%s>\n"),namfilter);
  wpnewName->SetCaption(namfilter);

}
Example #2
0
/*
Prepares the log file:
- calculates the absolute path (and store it in the db)
- creates the directory

*/
int InitFileOutput(void)
{
	TCHAR szfpath[MAX_PATH], szmpath[MAX_PATH];
	GetModuleFileName(NULL, szmpath, MAX_PATH);

	DBVARIANT dbv;
	if(!db_get_ts(NULL, S_MOD, "FileName", &dbv))
	{
		_tcsncpy(szfpath, dbv.ptszVal, MAX_PATH);
		db_free(&dbv);
	}
	else _tcsncpy(szfpath, DEFAULT_FILENAME, MAX_PATH);

	if (szfpath[0] == '\\')
		_tcsncpy(szfpath, szfpath+1, MAX_PATH);

	TCHAR *str = _tcsrchr(szmpath, '\\');
	if (str != NULL)
		*++str=0;

	_tcsncat(szmpath, szfpath, MAX_PATH);
	_tcsncpy(szfpath, szmpath, MAX_PATH);

	str = _tcsrchr(szmpath, '\\');
	if (str != NULL)
		*++str=0;

	db_set_ts(NULL, S_MOD, "PathToFile", szfpath);
	return 0;
}
Example #3
0
void dlgTeamCodeShowModal(void)
{
    WndProperty* wp = NULL;
    WndButton *buttonCode = NULL;
    wf = NULL;
    char filename[MAX_PATH];
    if (InfoBoxLayout::landscape)
    {
        LocalPathS(filename, TEXT("dlgTeamCode_L.xml"));
        wf = dlgLoadFromXML(CallBackTable,

                            filename,
                            hWndMainWindow,
                            TEXT("IDR_XML_TEAMCODE_L"));
        if (!wf) return;
    }
    else
    {
        LocalPathS(filename, TEXT("dlgTeamCode.xml"));
        wf = dlgLoadFromXML(CallBackTable,

                            filename,
                            hWndMainWindow,
                            TEXT("IDR_XML_TEAMCODE"));
        if (!wf) return;
    }

    TCHAR sTmp[32] = { 0 };
    if( WayPointList && ValidWayPoint(TeamCodeRefWaypoint)) {
        // LKTOKEN _@M1230_ "Team Ref.: "
        _tcsncpy(sTmp, gettext(TEXT("_@M1230_")), 20);
        _tcsncat(sTmp, WayPointList[TeamCodeRefWaypoint].Name,10);
    } else {
        // LKTOKEN _@M1231_ "Team code: SET REF!"
        _tcsncpy(sTmp, gettext(TEXT("_@M1231_")), 30);
    }
    wf->SetCaption(sTmp);

    // set event for button
    buttonCode = ((WndButton *)wf->FindByName(TEXT("cmdSetCode")));
    if (buttonCode) {
        buttonCode->SetOnClickNotify(OnCodeClicked);
    }

    // Set unit for range
    wp = (WndProperty*)wf->FindByName(TEXT("prpRange"));
    if (wp) {
        wp->GetDataField()->SetUnits(Units::GetDistanceName());
    }

    Update();

    wf->SetTimerNotify(OnTimerNotify);

    wf->ShowModal();

    delete wf;
    wf=NULL;

}
Example #4
0
char *fsdb_create_unique_nname (a_inode *base, const char *suggestion)
{
	TCHAR *c;
	TCHAR tmp[256] = UAEFSDB_BEGINS;
	int i;

	_tcsncat (tmp, suggestion, 240);

        /* replace the evil ones... */
        for (i = 0; i < NUM_EVILCHARS; i++)
                while ((c = _tcschr (tmp, evilchars[i])) != 0)
                        *c = '_';

        while ((c = _tcschr (tmp, '.')) != 0)
                *c = '_';
        while ((c = _tcschr (tmp, ' ')) != 0)
                *c = '_';

        for (;;) {
                TCHAR *p = build_nname (base->nname, tmp);
                if (!fsdb_exists (p)) {
                        write_log (_T("unique name: %s\n"), p);
                        return p;
                }
                xfree (p);
                /* tmpnam isn't reentrant and I don't really want to hack configure
                * right now to see whether tmpnam_r is available...  */
                for (i = 0; i < 8; i++) {
                        tmp[i+8] = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"[rand () % 63];
                }
        }
}
Example #5
0
void CFilteringTable::RemoveSpace(LPCTSTR textInput, LPTSTR textOutput, size_t size) const
{
	TCHAR buffer[MAX_PATH] = {0};	

	for(PUCHAR inputPointer = PUCHAR(textInput);
		0 < *inputPointer;
		inputPointer = _mbsinc((const PUCHAR)inputPointer))
	{
		LPCTSTR removedSpeicalCharacter = _T("\t\n\r ~`!@#$%^&*()-_=+\\|<,>.?/");

		if(_tcschr(removedSpeicalCharacter, *inputPointer))
		{
			continue;
		}

		_tcsncat(
			buffer,
			LPCTSTR(inputPointer),
			IsDBCSLeadByte(*inputPointer) ? 2 : 1);
	}

	SafeStrCpy(
		textOutput,
		buffer,
		size);
}
Example #6
0
HRESULT WriteConfig(char* pSN , DEV_CONFIG * pDevConfig)
{
	if (NULL == pDevConfig || NULL == pSN)
	{
		return E_FAIL;
	}
	const int MAXPATH = 260;
	TCHAR szFileName[ MAXPATH ] = {0};
	TCHAR szIniName[MAXPATH] = {0};
	TCHAR szBakName[MAXPATH] = {0};
	GetModuleFileName(NULL, szFileName, MAXPATH);	//取得包括程序名的全路径
	PathRemoveFileSpec(szFileName);				//去掉程序名
	_tcsncpy(szIniName, szFileName, MAXPATH);
	_tcsncpy(szBakName, szFileName, MAXPATH);
	_tcsncat(szIniName, _T("\\HvAutoLink.ini"), MAXPATH - 1);

	char szIndex[32];
	ZeroMemory(szIndex , sizeof(szIndex));
	sprintf(szIndex , "%d", pDevConfig->nIndex);

	WritePrivateProfileString(pSN , "Enable" ,pDevConfig->fEnableRecvHistory?"1":"0", szIniName);
	WritePrivateProfileString(pSN , "BeginTime" ,pDevConfig->szBeginTime, szIniName);
	WritePrivateProfileString(pSN , "Index" ,szIndex, szIniName);
	WritePrivateProfileString(pSN , "EndTime" ,pDevConfig->szEndTime, szIniName);
	WritePrivateProfileString(pSN , "OnlyViolation" ,pDevConfig->fOnlyViolation?"1":"0", szIniName);

	return S_OK;
}
Example #7
0
/** Function prepares a format string with error number and an error message
 *  for use with logerr() and logerrs() functions.
 * \param[in] pszStr - input format string (%err will be replaced with a 0x%lx (error message)
 * \param[in] iSysError - system error to parse
 * \param[out] pszOut - pointer to a buffer that will receive the data (must be 2048 bytes in size)
 * \return If the %err string was found and replaced within a given format string.
 */
bool log_file::prepare_fmt(const tchar_t* pszStr, int_t iSysErr, tchar_t* pszOut) const
{
	// find the %err in pszStr
	const tchar_t* pszFnd=_tcsstr(pszStr, _t("%err"));
	if (pszFnd)
	{
		// find an error description for the error
		tchar_t* pszErrDesc=NULL;
#ifdef _WIN32
		tchar_t szErrDesc[512];
		FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, (DWORD)iSysErr, 0, szErrDesc, 512, NULL);
		pszErrDesc=szErrDesc;
#else
		pszErrDesc=strerror(iSysErr);
#endif

		// format a string with err no and desc
		tchar_t szError[1024];
		_sntprintf(szError, 1023, _t("0x%lx (%s)"), iSysErr, pszErrDesc);
		szError[1023] = _T('\0');

		// replace %err with the new data
		pszOut[0]=_t('\0');
		_tcsncat(pszOut, pszStr, (size_t)(pszFnd-pszStr));
		_tcscat(pszOut, szError);
		_tcscat(pszOut, pszFnd+4);

		return true;
	}
	else
		return false;
}
Example #8
0
static void
LoadChecklist()
{
  nLists = 0;

  free(ChecklistText[0]);
  ChecklistText[0] = NULL;

  free(ChecklistTitle[0]);
  ChecklistTitle[0] = NULL;

  TLineReader *reader = OpenDataTextFile(_T(XCSCHKLIST));
  if (reader == NULL) {
    addChecklist(_("No checklist loaded"),_("Create xcsoar-checklist.txt\n"));
    return;
  }

  TCHAR Details[MAXDETAILS];
  TCHAR Name[100];
  bool inDetails = false;
  int i;

  Details[0] = 0;
  Name[0] = 0;

  TCHAR *TempString;
  while ((TempString = reader->read()) != NULL) {
    // Look for start
    if (TempString[0] == '[') {
      if (inDetails) {
        addChecklist(Name, Details);
        Details[0] = 0;
        Name[0] = 0;
      }

      // extract name
      for (i = 1; i < MAXTITLE; i++) {
        if (TempString[i] == ']')
          break;

        Name[i - 1] = TempString[i];
      }
      Name[i - 1] = 0;

      inDetails = true;
    } else {
      // append text to details string
      _tcsncat(Details, TempString, MAXDETAILS - 2);
      _tcscat(Details, _T("\n"));
      // TODO code: check the string is not too long
    }
  }

  delete reader;

  if (inDetails) {
    addChecklist(Name, Details);
  }
}
Example #9
0
BOOL goCommand::combineCommandLine(LPCTSTR go_cmd, LPTSTR pkg)
{
	PathQuoteSpaces(pkg);

	size_t size = _tcslen(go_cmd) + _tcslen(this->cmd) +_tcslen(pkg) + 2;
	LPTSTR args = (LPTSTR) calloc(size + 1, sizeof(TCHAR));
	if (args == NULL) return FALSE;

	_tcsncat(args, go_cmd, __min(_tcslen(go_cmd), size - _tcslen(args)));
	_tcsncat(args, _T(" "), __min(sizeof(args), size - _tcslen(args)));
	_tcsncat(args, cmd, __min( _tcslen(cmd), size -_tcslen(args)));
	_tcsncat(args, _T(" "), __min(sizeof(args), size - _tcslen(args)));
	_tcsncat(args, pkg, __min( _tcslen(pkg), size -_tcslen(args)));

	this->commandLine = args;
	return TRUE;
}
Example #10
0
/**
 * @brief Open text file to text editor.
 * @param [in] hwnd Parent window for the editor process (Frhed main window?).
 * @param [in] file Relative (to Frhed executable) path the the file to open.
 */
void paths_OpenFile(HWND hwnd, LPCTSTR file)
{
	TCHAR filepath[MAX_PATH] = {0};
	paths_GetModulePath(GetModuleHandle(NULL), filepath, MAX_PATH);
	const int len = _tcslen(filepath);
	_tcsncat(filepath, file, MAX_PATH - len);
	ShellExecute(hwnd, _T("open"), _T("notepad.exe"), filepath, NULL, SW_SHOWNORMAL);
}
Example #11
0
/**
 * @brief Get the full path for relative (to Frhed exe) path.
 * @param [in] path Relative path to Frhed executable.
 * @param [in, out] fullpath Buffer where the full path is copied.
 * @param [in] size Size of the buffer pointed by fullpath parameter.
 */
void paths_GetFullPath(LPCTSTR path, LPTSTR fullpath, int size)
{
	TCHAR modpath[MAX_PATH] = {0};
	paths_GetModulePath(GetModuleHandle(NULL), modpath, MAX_PATH);
	const int len = _tcslen(modpath);
	_tcsncpy(fullpath, modpath, size - 1);
	_tcsncat(fullpath, path, size - len - 1);
}
Example #12
0
int KConfig::_ReadProfile()
{
	int nRetCode = false;
	int nResult  = false;
	TCHAR szServerFile[MAX_PATH];
	TCHAR szSection[MAX_PATH];
    tstring strDownloadURL;

	_tcsncpy(szServerFile, m_szAppPath, sizeof(szServerFile) / sizeof(TCHAR));
	szServerFile[sizeof(szServerFile) / sizeof(TCHAR) - 1] = _T('\0');

	nRetCode = (int)(sizeof(szServerFile) / sizeof(TCHAR) - _tcslen(szServerFile));
	_tcsncat(szServerFile, CONFIG_FILE_NAME, nRetCode);
	szServerFile[sizeof(szServerFile) / sizeof(TCHAR) - 1] = _T('\0');

	_sntprintf(szSection, sizeof(szSection) / sizeof(TCHAR),
		_T("%s%d"), SECTION_SERVER_LIST_PREFIX, 1);
	szSection[sizeof(szSection) /  sizeof(TCHAR) - 1] = _T('\0');

	nRetCode = GetPrivateProfileString(
		szSection, 
		KEY_IP,
		_T(""), 
		m_UpdateServer.szIP, 
		sizeof(m_UpdateServer.szIP) / sizeof(TCHAR),
		szServerFile
		);
	KGLOG_PROCESS_ERROR(nRetCode > 0);

	KGLogPrintf(KGLOG_INFO, "Get UpdateSever Is (%s)\n", (m_UpdateServer.szIP));

	nRetCode = GetPrivateProfileString(
		szSection, 
		KEY_BULLETIN_URL,
		_T(""), 
		m_szBulletinURL, 
		sizeof(m_szBulletinURL) / sizeof(TCHAR),
		szServerFile
    );
    KGLOG_PROCESS_ERROR(nRetCode > 0);

    nRetCode = GetPrivateProfileString(
        szSection, _T("URL"), NULL,
        m_szDownloadURL, sizeof(m_szDownloadURL) / sizeof(m_szDownloadURL[0]),
        szServerFile
    );
    if (nRetCode <= 0)
    {
        strDownloadURL = tstring(m_UpdateServer.szIP) + m_szVersionLineName + _T('/');

        _tcsncpy(m_szDownloadURL, strDownloadURL.c_str(), sizeof(m_szDownloadURL) / sizeof(m_szDownloadURL[0]));
        m_szDownloadURL[sizeof(m_szDownloadURL) / sizeof(m_szDownloadURL[0]) - 1] = _T('\0');
    }

	nResult = true;
Exit0:
	return nResult;
}
Example #13
0
/**
 * Our very own SHGetFolderPath function for support of windows operating
 * systems that don't have this function (eg Win9x, etc.). We try using the
 * native function, and if that doesn't exist we will try a more crude approach
 * of environment variables and hope for the best
 */
HRESULT OTTDSHGetFolderPath(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPTSTR pszPath)
{
	static HRESULT (WINAPI *SHGetFolderPath)(HWND, int, HANDLE, DWORD, LPTSTR) = NULL;
	static bool first_time = true;

	/* We only try to load the library one time; if it fails, it fails */
	if (first_time) {
#if defined(UNICODE)
# define W(x) x "W"
#else
# define W(x) x "A"
#endif
		/* The function lives in shell32.dll for all current Windows versions, but it first started to appear in SHFolder.dll. */
		if (!LoadLibraryList((Function*)&SHGetFolderPath, "shell32.dll\0" W("SHGetFolderPath") "\0\0")) {
			if (!LoadLibraryList((Function*)&SHGetFolderPath, "SHFolder.dll\0" W("SHGetFolderPath") "\0\0")) {
				DEBUG(misc, 0, "Unable to load " W("SHGetFolderPath") "from either shell32.dll or SHFolder.dll");
			}
		}
#undef W
		first_time = false;
	}

	if (SHGetFolderPath != NULL) return SHGetFolderPath(hwnd, csidl, hToken, dwFlags, pszPath);

	/* SHGetFolderPath doesn't exist, try a more conservative approach,
	 * eg environment variables. This is only included for legacy modes
	 * MSDN says: that 'pszPath' is a "Pointer to a null-terminated string of
	 * length MAX_PATH which will receive the path" so let's assume that
	 * Windows 95 with Internet Explorer 5.0, Windows 98 with Internet Explorer 5.0,
	 * Windows 98 Second Edition (SE), Windows NT 4.0 with Internet Explorer 5.0,
	 * Windows NT 4.0 with Service Pack 4 (SP4) */
	{
		DWORD ret;
		switch (csidl) {
			case CSIDL_FONTS: // Get the system font path, eg %WINDIR%\Fonts
				ret = GetEnvironmentVariable(_T("WINDIR"), pszPath, MAX_PATH);
				if (ret == 0) break;
				_tcsncat(pszPath, _T("\\Fonts"), MAX_PATH);

				return (HRESULT)0;

			case CSIDL_PERSONAL:
			case CSIDL_COMMON_DOCUMENTS: {
				HKEY key;
				if (RegOpenKeyEx(csidl == CSIDL_PERSONAL ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE, REGSTR_PATH_SPECIAL_FOLDERS, 0, KEY_READ, &key) != ERROR_SUCCESS) break;
				DWORD len = MAX_PATH;
				ret = RegQueryValueEx(key, csidl == CSIDL_PERSONAL ? _T("Personal") : _T("Common Documents"), NULL, NULL, (LPBYTE)pszPath, &len);
				RegCloseKey(key);
				if (ret == ERROR_SUCCESS) return (HRESULT)0;
				break;
			}

			/* XXX - other types to go here when needed... */
		}
	}

	return E_INVALIDARG;
}
Example #14
0
static void FilterGetStrings(TCHAR *filter, int bytesLeft, BOOL xml, BOOL swf)
{
	TCHAR *pfilter;
	int wParam = bytesLeft;

	lstrcpyn(filter, TranslateT("All Files"), bytesLeft); bytesLeft-=lstrlen(filter);
	_tcsncat(filter, _T(" (*.bmp;*.jpg;*.gif;*.png"), bytesLeft);
	if (swf) _tcscat(filter, _T(";*.swf"));
	if (xml) _tcscat(filter, _T(";*.xml"));
	_tcscat(filter, _T(")"));
	pfilter=filter+lstrlen(filter)+1; bytesLeft=wParam-(pfilter-filter);
	lstrcpyn(pfilter, _T("*.BMP;*.RLE;*.JPG;*.JPEG;*.GIF;*.PNG"), bytesLeft);
	if (swf) _tcscat(pfilter, _T(";*.SWF"));
	if (xml) _tcscat(pfilter, _T(";*.XML"));
	pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter);

	lstrcpyn(pfilter, TranslateT("Windows Bitmaps"), bytesLeft); bytesLeft-=lstrlen(pfilter);
	_tcsncat(pfilter, _T(" (*.bmp;*.rle)"), bytesLeft);
	pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter);
	lstrcpyn(pfilter, _T("*.BMP;*.RLE"), bytesLeft);
	pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter);

	lstrcpyn(pfilter,TranslateT("JPEG Bitmaps"),bytesLeft); bytesLeft-=lstrlen(pfilter);
	_tcsncat(pfilter, _T(" (*.jpg;*.jpeg)"), bytesLeft);
	pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter);
	lstrcpyn(pfilter, _T("*.JPG;*.JPEG"), bytesLeft);
	pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter);

	lstrcpyn(pfilter,TranslateT("GIF Bitmaps"),bytesLeft); bytesLeft-=lstrlen(pfilter);
	_tcsncat(pfilter, _T(" (*.gif)"), bytesLeft);
	pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter);
	lstrcpyn(pfilter, _T("*.GIF"), bytesLeft);
	pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter);

	lstrcpyn(pfilter,TranslateT("PNG Bitmaps"), bytesLeft); bytesLeft-=lstrlen(pfilter);
	_tcsncat(pfilter, _T(" (*.png)"), bytesLeft);
	pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter);
	lstrcpyn(pfilter, _T("*.PNG"), bytesLeft);
	pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter);

	if (swf)
	{
		lstrcpyn(pfilter,TranslateT("Flash Animations"), bytesLeft); bytesLeft-=lstrlen(pfilter);
		_tcsncat(pfilter, _T(" (*.swf)"), bytesLeft);
		pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter);
		lstrcpyn(pfilter, _T("*.SWF"), bytesLeft);
		pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter);
	}

	if (xml)
	{
		lstrcpyn(pfilter, TranslateT("XML Files"), bytesLeft); bytesLeft-=lstrlen(pfilter);
		_tcsncat(pfilter, _T(" (*.xml)"), bytesLeft);
		pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter);
		lstrcpyn(pfilter, _T("*.XML"), bytesLeft);
		pfilter+=lstrlen(pfilter)+1; bytesLeft=wParam-(pfilter-filter);
	}

	if (bytesLeft) *pfilter='\0';
}
Example #15
0
BOOL GetInternetExplorerVersion(TCHAR *ieVersion, size_t ieSize)
{
	HKEY hKey;
	TCHAR ieVer[1024] = {0}, ieBuild[64] = {0}, iVer[64] = {0};
	
	if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Internet Explorer"), 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
	{
		DWORD size;
		size = SIZEOF(ieVer);
		if (RegQueryValueEx(hKey, TEXT("Version"), NULL, NULL, (LPBYTE) ieVer, &size) != ERROR_SUCCESS)
			ieVer[0] = 0;
		size = SIZEOF(ieBuild);
		if (RegQueryValueEx(hKey, TEXT("Build"), NULL, NULL, (LPBYTE) ieBuild, &size) != ERROR_SUCCESS)
			ieBuild[0] = 0;
		size = SIZEOF(iVer);
		if (RegQueryValueEx(hKey, TEXT("IVer"), NULL, NULL, (LPBYTE) iVer, &size) != ERROR_SUCCESS)
			iVer[0] = 0;

		RegCloseKey(hKey);
	}

	if (ieVer[0] == 0)
	{
		if (iVer[0] == 0)
			_tcsncpy(ieVersion, _T("<not installed>"), ieSize);
		else if (_tcscmp(iVer, _T("100")) == 0)
			_tcsncpy(ieVersion, _T("1.0"), ieSize);
		else if (_tcscmp(iVer, _T("101")) == 0)
			_tcsncpy(ieVersion, _T("NT"), ieSize);
		else if (_tcscmp(iVer, _T("102")) == 0)
			_tcsncpy(ieVersion, _T("2.0"), ieSize);
		else if (_tcscmp(iVer, TEXT("103")) == 0)
			_tcsncpy(ieVersion, _T("3.0"), ieSize);
	} else 
		_tcsncpy(ieVersion, ieVer, ieSize);

	if (ieBuild[0] != 0)
	{
		_tcsncat(ieVersion, _T(" (build "), ieSize);
		_tcsncat(ieVersion, ieBuild, ieSize);
		_tcsncat(ieVersion, _T(")"), ieSize);
	}
	
	return TRUE;
}
void UTBStr::tcsncat(TCHAR * dest, size_t size, const TCHAR * src, size_t count)
{
#if _MSC_VER >= 1400
	_tcsncat_s(dest, size, src, count);
#else
	UNREFERENCED_PARAMETER(size);
	_tcsncat(dest, src, count);
# endif
}
Example #17
0
// The function will create a temp file in the system temp directory,
// don't forget to remove the file when you don't need the temp file.
void GetTempFilePath(TCHAR* buf, DWORD buf_len, const TCHAR* prefix)
{
        TCHAR name[MAX_PATH]  = {};
        TCHAR path[MAX_PATH] = {};

        GetTempPath(_countof(path), path);
        GetTempFileName(path, prefix, 0, name);

        _tcsncat(buf, name, buf_len - 1);
}
void Printer_SetFilename(char* prtFilename)
{
	if(*prtFilename)
		strcpy(g_szPrintFilename, (const char *) prtFilename);
	else  //No registry entry is available
	{
		_tcsncpy(g_szPrintFilename, g_sProgramDir, MAX_PATH);
        _tcsncat(g_szPrintFilename, _T(DEFAULT_PRINT_FILENAME), MAX_PATH);		
		RegSaveString(TEXT("Configuration"),REGVALUE_PRINTER_FILENAME,1,g_szPrintFilename);
	}
}
//===========================================================================
static BOOL CheckPrint()
{
    inactivity = 0;
    if (file == NULL)
    {
        TCHAR filepath[MAX_PATH * 2];
        _tcsncpy(filepath, g_sProgramDir, MAX_PATH);
        _tcsncat(filepath, _T("Printer.txt"), MAX_PATH);
        file = fopen(filepath, "wb");
    }
    return (file != NULL);
}
Example #20
0
int KTgaBlockLoader::ReadTextFromIcon(LPCTSTR pcszText, HWND hWnd)
{
	int nResult = false;
	int nRetCode = false;
	std::vector<TXTFILEDATA> aTextCurrentVector;
	TCHAR szFile[MAX_PATH];
	TCHAR szCurrent[MAX_PATH];
	int i = 0;

	KG_PROCESS_ERROR(pcszText);

	nRetCode = KTgaManager::GetSelf().Clear();
	KG_PROCESS_ERROR(nRetCode);
	nRetCode = KIconManager::GetSelf().Clear();
	KG_PROCESS_ERROR(nRetCode);

	aTextCurrentVector.clear();
	for (i = 0; i < (int)m_aNewIconTxtVector.size(); ++i)
	{
		_tcsncpy(szFile, pcszText, sizeof(szCurrent)/sizeof(TCHAR));
		_tcsncat(szFile, "\\",sizeof(szFile)/sizeof(TCHAR));
		_tcsncpy(szCurrent, m_aNewIconTxtVector[i].szTxtFile, sizeof(szCurrent)/sizeof(TCHAR));
		_tcsncat(szFile, szCurrent,sizeof(szFile)/sizeof(TCHAR));
		_tcsncpy(m_aNewIconTxtVector[i].szTxtFile, szFile, sizeof(m_aNewIconTxtVector[i].szTxtFile)/sizeof(TCHAR));
		aTextCurrentVector.push_back(m_aNewIconTxtVector[i]);
	}

	for (i = 0; i < (int)m_aNewIconTxtVector.size(); ++i)
	{
		nRetCode = KTgaBlockLoader::LoadUITex(
			aTextCurrentVector[i].szTxtFile,LOAD_AS_REPLACE, READ_TEXT, FIND_ICON_FILE,
			aTextCurrentVector[i].nTextNum,aTextCurrentVector[i].nFrameNum, hWnd);
		KG_PROCESS_ERROR(nRetCode);
	}
	nRetCode = KIconManager::GetSelf().UpDataListView();
    KG_PROCESS_ERROR(nRetCode);
	nResult	= true;
Exit0:
	return nResult;
}
Example #21
0
void ReplaceVars(XSTATUSCHANGE *xsc , TCHAR *Template, TCHAR *delimiter, TCHAR *buff)
{
	buff[0] = 0;
	TCHAR *pch = _tcschr(Template, _T('%'));
	while (pch != NULL) {
		size_t len = _tcslen(buff);
		_tcsncat(buff, Template, pch - Template);
		buff[len + pch - Template] = 0;

		if (pch[1] == _T('N') || pch[1] == _T('T') || pch[1] == _T('I') || pch[1] == _T('D') || pch[1] == _T('B')) {
			switch (pch[1]) {
			case _T('N'):
				{
					TCHAR stzType[32];
					_tcscat(buff, GetStatusTypeAsString(xsc->type, stzType));
				}
				break;
			case _T('T'):
				if (xsc->stzTitle)
					_tcscat(buff, xsc->stzTitle);
				break;
			case _T('I'):
				if (xsc->stzText)
					_tcscat(buff, xsc->stzText);
				break;
			case _T('D'):
				if (xsc->stzText) {
					if (_tcscmp(delimiter, _T("%B")) == 0)
						_tcscat(buff, _T("\r\n"));
					else
						_tcscat(buff, delimiter);
				}
				break;
			case _T('B'):
				_tcscat(buff, _T("\r\n"));
				break;
			}

			Template = pch + 2;
		}
		else {
			_tcscat(buff, _T("%"));
			Template = pch + 1;
		}

		pch = _tcschr(Template, _T('%'));
	}

	// append rest of the text
	if (Template != NULL)
		_tcscat(buff, Template);
}
//*****************************************************************************
// You can use this function to create backups in the way that you copy all 
// files recursive into a folder under the installation folder. So the whole tree
// of the previous installation in lDir can be copied into lSubdir.
//*****************************************************************************
long WINAPI	RecursiveCopyIntoSubdir(long lDir,long lSubdir)
{
	TCHAR DirToCopy[MAX_PATH+1];
	TCHAR SubDir[MAX_PATH+1];
	TCHAR SupressSubDir[MAX_PATH+1];

	// Verzeichnis ist notwendig!
	if(lDir==0) return 1;

	memset(DirToCopy,0,sizeof(DirToCopy));
	memset(SubDir,0,sizeof(SubDir));
	memset(SupressSubDir,0,sizeof(SupressSubDir));

	_tcsncpy(DirToCopy,(TCHAR*)lDir,MAX_PATH);
	if(DirToCopy[_tcslen(DirToCopy)-1] != '\\')
		_tcsncat(DirToCopy,"\\",MAX_PATH);

	// Übertragen in Unterverzeichnis
	SubDir[0] = '\0';
	_tcsncat(SubDir,DirToCopy,MAX_PATH);
	if(lSubdir==0)
		_tcsncat(SubDir,"bak",MAX_PATH);
	else 
		_tcsncat(SubDir,(TCHAR*)lSubdir,MAX_PATH);

	if(SubDir[_tcslen(SubDir)-1] != '\\')
		_tcsncat(SubDir,"\\",MAX_PATH);

	// Erzeugen des Unterverzeichnisses
	CreateDirectory(SubDir,NULL);

	// Übertragen in Supress-Verzeichnis
	_tcscpy(SupressSubDir,SubDir);

	return CopyDirectory(DirToCopy,SubDir,SupressSubDir);
	
	return 0;
	
};
Example #23
0
BOOL FileNameTagger::MakeMewPath(LPTSTR outPath, LPCTSTR newName, LPCTSTR originalPath)
{
	ASSERT(outPath != NULL);
	ASSERT(newName != NULL);
	ASSERT(originalPath != NULL);
	const TCHAR* pos = _tcsrchr(originalPath, '\\');
	if (pos != NULL)
	{
		pos++;
		_tcsncpy(outPath, originalPath, pos - originalPath);
		outPath[pos - originalPath] = 0;

		_tcsncat(outPath, newName, MAX_PATH - _tcslen(outPath));
		pos = _tcsrchr(originalPath, '.');
		if (pos != NULL)
		{
			_tcsncat(outPath, pos, MAX_PATH - _tcslen(outPath));
			return TRUE;
		}
	}
	return FALSE;
}
Example #24
0
static void
InitGUI(const TCHAR * FontDescription)
{
  #define FONTEDIT_GUI_MAX_TITLE 128

  WndProperty* wp;

  TCHAR sTitle[FONTEDIT_GUI_MAX_TITLE];
  _tcsncpy(sTitle, _("Edit Font"), FONTEDIT_GUI_MAX_TITLE);
  _tcsncat(sTitle, _T(": "), FONTEDIT_GUI_MAX_TITLE);
  _tcsncat(sTitle, FontDescription, FONTEDIT_GUI_MAX_TITLE);
  wf->SetCaption(sTitle);

  wp = (WndProperty*)wf->FindByName(_T("prpFontName"));
  if (wp) {
    DataFieldEnum* dfe;
    dfe = (DataFieldEnum*)wp->GetDataField();
    dfe->addEnumText(_T("Tahoma"));
    dfe->addEnumText(_T("TahomaBD"));
    dfe->addEnumText(_T("DejaVu Sans Condensed"));
    // RLD ToDo code: add more font faces, and validate their availabiliy
  }
}
// cats string as much as possible
// returns true if pSrc safely fits into pDst, else false (pSrc would of overflowed pDst)
//===========================================================================
bool StringCat ( TCHAR * pDst, LPCSTR pSrc, const int nDstSize )
{
	int nLenDst = _tcslen( pDst );
	int nLenSrc = _tcslen( pSrc );
	int nSpcDst = nDstSize - nLenDst;
	int nChars  = MIN( nLenSrc, nSpcDst );

	_tcsncat( pDst, pSrc, nChars );

	bool bOverflow = (nSpcDst < nLenSrc);
	if (bOverflow)
		return false;
		
	return true;
}
Example #26
0
// load the weather update data form INI files
bool LoadWIData(bool dial)
{
	TCHAR szSearchPath[MAX_PATH], FileName[MAX_PATH];
	WIN32_FIND_DATA fd;
	WIDATA Data;

	// make sure that the current service data list is empty
	WITail = NULL;
	WIHead = WITail;

	// find all *.ini file in the plugin\weather directory
	GetModuleFileName(GetModuleHandle(NULL), szSearchPath, SIZEOF(szSearchPath));
	TCHAR *chop = _tcsrchr(szSearchPath, '\\');
	*chop = '\0';
	_tcsncat(szSearchPath, _T("\\Plugins\\Weather\\*.ini"),SIZEOF(szSearchPath));
	_tcsncpy(FileName, szSearchPath, SIZEOF(FileName));

	HANDLE hFind = FindFirstFile(szSearchPath, &fd);

	// load the content of the ini file into memory
	if (hFind != INVALID_HANDLE_VALUE) {
		do {
			chop = _tcsrchr(FileName, '\\');
			chop[1] = '\0';
			_tcscat(FileName, fd.cFileName);
			if ( _tcsicmp(fd.cFileName, _T("SAMPLE_INI.INI"))) {
				LoadStationData(FileName, fd.cFileName, &Data);
				if (Data.Enabled)
					WIListAdd(Data);
			}
			// look through the entire "plugins\weather" directory
		}
			while(FindNextFile(hFind, &fd));
		FindClose(hFind);
	}
	
	if (WIHead == NULL) {
		// no ini found, display an error message box.
		if (dial)
			hWndSetup = CreateDialog(hInst, MAKEINTRESOURCE(IDD_SETUP), NULL, DlgProcSetup);
		else
			MessageBox(NULL, 
				TranslateT("No update data file is found. Please check your Plugins\\Weather directory."), 
				TranslateT("Weather Protocol"), MB_OK | MB_ICONERROR);
		return false;
	}
	return true;
}
Example #27
0
HRESULT ReadConfig(char* pSN , DEV_CONFIG * pDevConfig)
{
	if (NULL == pDevConfig || NULL == pSN)
	{
		return E_FAIL;
	}
	const int MAXPATH = 260;
	TCHAR szFileName[ MAXPATH ] = {0};
	TCHAR szIniName[MAXPATH] = {0};
	TCHAR szBakName[MAXPATH] = {0};
	GetModuleFileName(NULL, szFileName, MAXPATH);	//取得包括程序名的全路径
	PathRemoveFileSpec(szFileName);				//去掉程序名
	_tcsncpy(szIniName, szFileName, MAXPATH);
	_tcsncpy(szBakName, szFileName, MAXPATH);
	_tcsncat(szIniName, _T("\\HvAutoLink.ini"), MAXPATH - 1);

	char szTemp[64];
	ZeroMemory(szTemp , sizeof(szTemp));

	SYSTEMTIME systemTime;
	GetSystemTime(& systemTime);
	char szDefaultTime[64];
	ZeroMemory(szDefaultTime , sizeof(szDefaultTime));
	sprintf(szDefaultTime , "%4d.%2d.%2d_%2d" , systemTime.wYear ,systemTime.wMonth , systemTime.wDay ,systemTime.wHour );
	CString strDefaultTime(szDefaultTime);
	strDefaultTime.Replace(' ','0');

	GetPrivateProfileString(pSN , "Enable" , "0", szTemp ,sizeof(szTemp),szIniName);
	pDevConfig->fEnableRecvHistory = atoi(szTemp);
	GetPrivateProfileString(pSN , "BeginTime" , strDefaultTime, szTemp ,sizeof(szTemp),szIniName);
	if (strlen(szTemp) < sizeof(pDevConfig->szBeginTime))
	{
		strcpy(pDevConfig->szBeginTime , szTemp);
	}
	GetPrivateProfileString(pSN , "Index" , "0", szTemp ,sizeof(szTemp),szIniName);
	pDevConfig->nIndex = atoi(szTemp);
	GetPrivateProfileString(pSN , "EndTime" , "0", szTemp ,sizeof(szTemp),szIniName);
	if (strlen(szTemp) < sizeof(pDevConfig->szEndTime))
	{
		strcpy(pDevConfig->szEndTime , szTemp);
	}

	GetPrivateProfileString(pSN , "OnlyViolation" , "0", szTemp ,sizeof(szTemp),szIniName);
	pDevConfig->fOnlyViolation = atoi(szTemp);

	return S_OK;
}
Example #28
0
BOOL StartExplorer(DWORD timeout, NS_UNUSED BOOL kill)
{
    STARTUPINFO si;
    PROCESS_INFORMATION pi;
    TCHAR shellpath[MAX_PATH];

    OutputDebugString(_T("nsRE::StartExplorer"));

    if (FindWindow(SHELLWND, NULL))
        NS_FAILED(NULL, _T("Explorer already running"));

    GetWindowsDirectory(shellpath, MAX_PATH - 1);
    shellpath[MAX_PATH - 1] = 0;
    _tcsncat(shellpath, SHELL, MAX_PATH - 1);
    shellpath[MAX_PATH - 1] = 0;

    FakeStartupIsDone();

    memset(&pi, 0, sizeof(PROCESS_INFORMATION));
    memset(&si, 0, sizeof(STARTUPINFO));

    si.cb = sizeof(STARTUPINFO);

    if(!CreateProcess(NULL,     /* No module name (use command line) */
        shellpath,              /* Command line */
        NULL,                   /* Process handle not inheritable */
        NULL,                   /* Thread handle not inheritable */
        FALSE,                  /* Set handle inheritance to FALSE */
        0,                      /* No creation flags */
        NULL,                   /* Use parent's environment block */
        NULL,                   /* Use parent's starting directory */
        &si,                    /* Pointer to STARTUPINFO structure */
        &pi))                   /* Pointer to PROCESS_INFORMATION structure */
        NS_FAILED(NULL, _T("Cannot spawn explorer process"));

    switch (WaitForInputIdle(pi.hProcess, timeout))
    {
        case 0            : break; /* OK */
        case WAIT_TIMEOUT :
            if (timeout == IGNORE) break; /* OK as requested */
            NS_FAILED(pi.hProcess, _T("Timeout while waiting for explorer process"));
        case WAIT_FAILED  : NS_FAILED(pi.hProcess, _T("Error while waiting for explorer process"));
        default           : NS_FAILED(pi.hProcess, _T("This should not be reached"));
    }

    return TRUE;
}
Example #29
0
static void
update_display( HWND hwndDlg, libspectrum_word base )
{
  size_t i, j;

  TCHAR buffer[ 8 + 64 + 20 ];
  TCHAR *text[] = { &buffer[0], &buffer[ 8 ], &buffer[ 8 + 64 ] };
  TCHAR buffer2[ 8 ];

  SendDlgItemMessage( hwndDlg, IDC_MEM_LV, LVM_DELETEALLITEMS, 0, 0 );

  LV_ITEM lvi;
  lvi.mask = LVIF_TEXT;

  for( i = 0; i < 20; i++ ) {
    _sntprintf( text[0], 8, TEXT( "%04X" ), base );

    text[1][0] = '\0';
    for( j = 0; j < 0x10; j++, base++ ) {

      libspectrum_byte b = readbyte_internal( base );

      _sntprintf( buffer2, 4, TEXT( "%02X " ), b );
      _tcsncat( text[1], buffer2, 4 );

      text[2][j] = ( b >= 32 && b < 127 ) ? b : '.';
    }
    text[2][ 0x10 ] = '\0';

    /* append the item */
    lvi.iItem = SendDlgItemMessage( hwndDlg, IDC_MEM_LV,
                                    LVM_GETITEMCOUNT, 0, 0 );
    lvi.iSubItem = 0;
    lvi.pszText = text[0];
    SendDlgItemMessage( hwndDlg, IDC_MEM_LV, LVM_INSERTITEM, 0,
                        ( LPARAM ) &lvi );
    lvi.iSubItem = 1;
    lvi.pszText = text[1];
    SendDlgItemMessage( hwndDlg, IDC_MEM_LV, LVM_SETITEM, 0,
                        ( LPARAM ) &lvi );
    lvi.iSubItem = 2;
    lvi.pszText = text[2];
    SendDlgItemMessage( hwndDlg, IDC_MEM_LV, LVM_SETITEM, 0,
                        ( LPARAM ) &lvi );
  }
}
Example #30
0
bool initialize(bool i_isYamy)
{
#ifndef NDEBUG
    _TCHAR path[GANA_MAX_PATH];
    GetModuleFileName(NULL, path, GANA_MAX_PATH);
    _tsplitpath_s(path, NULL, 0, NULL, 0, g.m_moduleName, GANA_MAX_PATH, NULL, 0);
    if (_tcsnicmp(g.m_moduleName, _T("Dbgview"), sizeof(_T("Dbgview"))/sizeof(_TCHAR)) != 0 &&
            _tcsnicmp(g.m_moduleName, _T("windbg"), sizeof(_T("windbg"))/sizeof(_TCHAR)) != 0) {
        g.m_isLogging = true;
    }
#endif // !NDEBUG
#ifdef HOOK_LOG_TO_FILE
    _TCHAR logFileName[GANA_MAX_PATH];
    GetEnvironmentVariable(_T("USERPROFILE"), logFileName, NUMBER_OF(logFileName));
    _tcsncat(logFileName, _T("\\AppData\\LocalLow\\yamydll.txt"), _tcslen(_T("\\AppData\\LocalLow\\yamydll.log")));
    g.m_logFile = CreateFile(logFileName, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
                             OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
#endif // HOOK_LOG_TO_FILE
    WriteToLog("try to open mailslot\r\n");
    g.m_hMailslot =
        CreateFile(NOTIFY_MAILSLOT_NAME, GENERIC_WRITE,
                   FILE_SHARE_READ | FILE_SHARE_WRITE,
                   (SECURITY_ATTRIBUTES *)NULL, OPEN_EXISTING,
                   FILE_ATTRIBUTE_NORMAL, (HANDLE)NULL);
    if (g.m_hMailslot == INVALID_HANDLE_VALUE) {
        HOOK_RPT2("MAYU: %S create mailslot failed(0x%08x)\r\n", g.m_moduleName, GetLastError());
        WriteToLog("open mailslot NG\r\n");
    } else {
        HOOK_RPT1("MAYU: %S create mailslot successed\r\n", g.m_moduleName);
        WriteToLog("open mailslot OK\r\n");
    }
    if (!mapHookData(i_isYamy))
        return false;
    _tsetlocale(LC_ALL, _T(""));
    g.m_WM_MAYU_MESSAGE =
        RegisterWindowMessage(addSessionId(WM_MAYU_MESSAGE_NAME).c_str());
    g.m_hwndTaskTray = g_hookData->m_hwndTaskTray;
    if (!i_isYamy) {
        NotifyThreadAttach ntd;
        ntd.m_type = Notify::Type_threadAttach;
        ntd.m_threadId = GetCurrentThreadId();
        notify(&ntd, sizeof(ntd));
    }
    g.m_isInitialized = true;
    return true;
}