Exemplo n.º 1
0
const CFileName CFileName::NoSpaceName() const// sans spaces
{
  CStringArray ar1,ar2;
  const CString str2(ShortName());
  
  LPCTSTR pc,pcStart;
  
  pcStart=*this;
  for(pc=*this;*pc;pc++){
    if(_TCHAR('\\')==*pc){
      ar1.Add(CString(pcStart,pc-pcStart));
      pcStart=pc;
    }
  }
  ar1.Add(CString(pcStart,pc-pcStart));
  
  pcStart=str2;
  for(pc=str2;*pc;pc++){
    if(_TCHAR('\\')==*pc){
      ar2.Add(CString(pcStart,pc-pcStart));
      pcStart=pc;
    }
  }
  ar2.Add(CString(pcStart,pc-pcStart));
  
  ASSERT(ar1.GetSize()==ar2.GetSize());
  
  CString rc;
  for(int i=0;i<ar1.GetSize();i++){
    rc+=(-1==ar1[i].Find(_TCHAR(' ')))?ar1[i]:ar2[i];
  }
  return rc;
}
Exemplo n.º 2
0
void CDiskObject::QualifyPath( CString& str )
/* ============================================================
	Function :		CDiskObject::QualifyPath
	Description :	Creates a fully qualified path from "str". 
	Access :		Private
					
	Return :		void
	Parameters :	CString& str	-	the path to qualify

	Usage :			Call to create a fully qualified path.

   ============================================================*/
{

	str.Replace( _TCHAR( '/' ), _TCHAR( '\\' ) );

	// Append a trailing backslash to directory name
	if( str.GetLength( ) )
		if( str[ str.GetLength( ) - 1 ] != _TCHAR( '\\' ) )
			str += _TCHAR( '\\' );

	if( str.GetLength( ) < 2 || str.Left( 2) != "\\\\" )
		QualifyFile( str );

}
Exemplo n.º 3
0
// Create all keys down to the one specified
bool CProperties::CreateKey(LPCTSTR pszKey,HKEY hKey/*=HKEY_CURRENT_USER*/)
{
  bool rc=true;
  LPCTSTR pcStart=pszKey;
  LPCTSTR pcEnd;
  do {
    HKEY hKey2;
    pcEnd=_tcschr(pcStart,_TCHAR('\\'));
    if(NULL==pcEnd){
      pcEnd=pcStart+_tcslen(pcStart);
    }
    String strKey(pcStart,pcEnd-pcStart);
    if(ERROR_SUCCESS!=RegCreateKeyEx(hKey,                // handle to an open key
      strKey,         // address of subkey name
      0,           // reserved
      0,           // address of class string
      REG_OPTION_NON_VOLATILE,          // special options flag
      KEY_ALL_ACCESS,        // desired security access
      NULL,
      // address of key security structure
      &hKey2,          // address of buffer for opened handle
      NULL// address of disposition value buffer);
      )){
      rc=false;
      break;
    }
    RegCloseKey(hKey);
    hKey=hKey2;
    pcStart=pcEnd+1;
  } while (_TCHAR('\0')!=*pcEnd);
  RegCloseKey(hKey);
  return rc;
}
Exemplo n.º 4
0
bool CProperties::SaveToFile(LPCTSTR pszFileName) const
{
  CreatePathToFile(pszFileName);
  FILE *f=_tfopen(pszFileName,_T("w") MODE_TEXT);
  if(f){
    for(int i=ar.size()-1;i>=0;--i){
      const CProperty &p=ar[i];
      String str(p.strName);
      str+=_TCHAR('=');
      switch(p.Type){
        case CProperties::CProperty::Integer:
        case CProperties::CProperty::Bool:
        case CProperties::CProperty::Char:
        case CProperties::CProperty::Short:
          str+=String::SFormat(_T("%u"),p.GetValue());
          break;
        case CProperties::CProperty::Float:
        case CProperties::CProperty::Double:
        case CProperties::CProperty::szString:
        case CProperties::CProperty::Void:
          str+=p.GetStringValue();
          break;
      }
      str+=_TCHAR('\n');
      _fputts(str,f);
    }
    fclose(f);
  }
  return (0!=f);
}
Exemplo n.º 5
0
void CSummaryPage::AddResult(CeCosTest *pTest)
{
  const CString strResult((LPCTSTR)pTest->ResultString(false));
  int nLength=strResult.GetLength();
  CString arstr[8];
  CString strTime,strDate;
  TRACE(_T("%s\n"),strResult);
  // 1999-05-28 10:29:28 nan:0 TX39-jmr3904-sim tx39-jmr3904sim-libc10-signal2.exe Fail 0k/1108k D=0.0/0.0 Total=9.3 E=0.6/300.0 
  _stscanf(strResult,_T("%s %s %s %s %s %s %s %s %s %s"),strDate.GetBuffer(1+nLength),strTime.GetBuffer(1+nLength),arstr[0].GetBuffer(1+nLength),arstr[1].GetBuffer(1+nLength),arstr[2].GetBuffer(1+nLength),arstr[3].GetBuffer(1+nLength),arstr[4].GetBuffer(1+nLength),arstr[5].GetBuffer(1+nLength),arstr[6].GetBuffer(1+nLength),arstr[7].GetBuffer(1+nLength));
  // Remove before '=' in time fields
  for(int i=5;i<8;i++){
      TCHAR *pch=_tcschr(arstr[i],_TCHAR('='));
      if(pch){
          arstr[i]=pch+1;
      }
  }
  
  strDate.ReleaseBuffer();
  strTime.ReleaseBuffer();
  strDate+=_TCHAR(' ');
  strDate+=strTime;
  int nItem=m_List.GetItemCount();
  m_List.InsertItem(nItem,strDate);
  m_List.SetItemData(nItem,nItem);// to support sorting
  for(i=0;i<8;i++){
      m_List.SetItemText(nItem,1+i,arstr[i]);
      arstr[i].ReleaseBuffer();
  }
}
Exemplo n.º 6
0
ecFileName ecUtils::WPath(const std::string &str)
{
  // Convert a path as read from cdl into host format
  // Change / to \ throughout
  ecFileName
    strPath(str.c_str());
  strPath.Replace (_TCHAR('/'), _TCHAR('\\'));
  return strPath;
}
Exemplo n.º 7
0
int CUtils::Chop(LPCTSTR psz,CStringArray &ar,TCHAR cSep,bool bObserveStrings/*=false*/,bool bBackslashQuotes/*=false*/)
{
  if(_TCHAR(' ')==cSep){
    return Chop(psz,ar,_T("\t\n\v\f\r "),bObserveStrings,bBackslashQuotes);
  } else {
    ASSERT(_TCHAR('\0')!=cSep);
    TCHAR c[2]={cSep,_TCHAR('\0')};
    return Chop(psz,ar,c,bObserveStrings,bBackslashQuotes);
  }
}
Exemplo n.º 8
0
BOOL CUtils::StrToItemIntegerType(const CString & str,__int64 &d)
{
	extern int errno;
	PTCHAR pEnd;
	BOOL rc;
	errno=0;
	BOOL bHex=(str.GetLength()>2 && str[0]==_TCHAR('0') && (str[1]==_TCHAR('x')||str[1]==_TCHAR('X')));
	d=_tcstol(str,&pEnd,bHex?16:10);
	rc=(0==errno && (*pEnd==_TCHAR('\0')));
	return rc;
}
//-------------------------------------------------------------------------
bool ResetPermissionDialog::GetFolderText(
    stringT &Folder,
    bool bWarnRoot,
    bool bAddWildCard,
    bool bQuoteIfNeeded)
{
    TCHAR Path[MAX_PATH * 4];
    UINT len = GetDlgItemText(
        hDlg,
        IDTXT_FOLDER,
        Path,
        _countof(Path));

    if (len == 0)
        return false;

    if (bWarnRoot)
    {
        // Warn if resetting root permissions
        if (_tcslen(Path) == 3 && Path[1] == _TCHAR(':') && Path[2] == _TCHAR('\\'))
        {
            if (MessageBox(hDlg, STR_ROOT_WARNING, STR_WARNING, MB_YESNO | MB_ICONWARNING) == IDNO)
                return false;
        }

        // Warn if tool is used on unsupported file system
        if (!IsSupportedFileSystem(Path))
        {
            if (MessageBox(hDlg, STR_FS_NOT_SUPPORTED_WARNING, STR_WARNING, MB_YESNO | MB_ICONWARNING) == IDNO)
                return false;
        }
    }

    Folder = Path;

    // Add the wildcard mask
    if (bAddWildCard)
    {
        if (*Folder.rbegin() != TCHAR('\\'))
            Folder += _TEXT("\\");

        Folder += _TEXT("*");
    }

    // Quote the folder if needed
    if (bQuoteIfNeeded)
        QuotePath(Folder);

    return true;
}
Exemplo n.º 10
0
void CSummaryPage::OnEditSave() 
{
	CFileDialog dlg( FALSE, _T("log"), _T("Output"), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, 		
		_T("Log Files (*.log)|*.log|All Files (*.*)|*.*||"));
	if(IDOK==dlg.DoModal()){
	    TRY
	    {    
		    CStdioFile f( dlg.GetPathName(), CFile::modeCreate | CFile::modeWrite );
            CString str;
            int arColWidth[nCols];
            for(int nCol=0;nCol<nCols;nCol++){
    		    int &w=arColWidth[nCol];
                w=_tcslen(arpszCols[nCol]);
                for(int nItem=0;nItem<m_List.GetItemCount();nItem++){
                    w=max(w,m_List.GetItemText(nItem,nCol).GetLength());
                }
                TRACE(_T("max[%d]=%d\n"),nCol,w);
            }

            for(nCol=0;nCol<nCols;nCol++){
                const CString &strItem=arpszCols[nCol];
                str+=strItem;
                if(nCol<nCols-1){
                    CString strTab(_TCHAR(' '),1+arColWidth[nCol]-strItem.GetLength());
                    str+=strTab;
                }
            }
            str+=_TCHAR('\n');
            f.WriteString(str);
            for(int nItem=0;nItem<m_List.GetItemCount();nItem++){
		        CString str;
                for(int nCol=0;nCol<nCols;nCol++){
                    const CString strItem=m_List.GetItemText(nItem,nCol);
                    str+=strItem;
                    if(nCol<nCols-1){
                        CString strTab(_TCHAR(' '),1+arColWidth[nCol]-strItem.GetLength());
                        str+=strTab;
                    }
                }
                str+=_TCHAR('\n');
		        f.WriteString(str);
            }
		    f.Close();
	    }
	    CATCH( CFileException, e )
	    {
		    MessageBox(_T("Failed to write file"));
	    }
Exemplo n.º 11
0
BOOL CFindDialog::Create(LPCTSTR lpszFindWhat, DWORD dwFlags, WhereType where, CWnd* pParentWnd)
{
    m_nFindPos=where;
	m_nIDHelp = AFX_IDD_FIND;
	m_fr.Flags |= dwFlags;

	ASSERT_VALID(pParentWnd);
	m_fr.hwndOwner = pParentWnd->m_hWnd;
	ASSERT(m_fr.hwndOwner != NULL); // must have a parent for modeless dialog

	m_fr.wFindWhatLen = sizeof(m_szFindWhat);

    int n=min(sizeof(m_szFindWhat)-1,_tcslen(lpszFindWhat));
	_tcsncpy(m_szFindWhat, lpszFindWhat, n);
    m_szFindWhat[n]=_TCHAR('\0');

	AfxHookWindowCreate(this);
    HWND hWnd = ::FindText(&m_fr);
    if (!AfxUnhookWindowCreate()){
		PostNcDestroy();
    }

	ASSERT(hWnd == NULL || hWnd == m_hWnd);
	return hWnd != NULL;
}
Exemplo n.º 12
0
const wxString wxProcessKiller::Name(int pid)
{
    wxString str;
    str.Printf(_T("id=%d"),pid);
#ifdef _DEBUG
#ifdef _WIN32
    if(VER_PLATFORM_WIN32_NT==GetPlatform() && hInstLib1){
        static BOOL (WINAPI *lpfEnumProcessModules)( HANDLE, HMODULE *, DWORD, LPDWORD ) =
            (BOOL(WINAPI *)(HANDLE, HMODULE *, DWORD, LPDWORD)) GetProcAddress( (HINSTANCE) hInstLib1,"EnumProcessModules" ) ;
        static DWORD (WINAPI *lpfGetModuleFileNameEx)( HANDLE, HMODULE, LPTSTR, DWORD )=
            (DWORD (WINAPI *)(HANDLE, HMODULE,LPTSTR, DWORD )) GetProcAddress( (HINSTANCE) hInstLib1,"GetModuleFileNameExA" ) ;
        if( lpfEnumProcessModules &&  lpfGetModuleFileNameEx ) {
            HANDLE hProcess=::OpenProcess(PROCESS_ALL_ACCESS,false,pid);
            if(hProcess) {
                HMODULE hMod;
                DWORD dwSize;
                if(lpfEnumProcessModules( hProcess, &hMod, sizeof(HMODULE), &dwSize ) ){
                    // Get Full pathname:
                    TCHAR buf[1+MAX_PATH];
                    lpfGetModuleFileNameEx( hProcess, hMod, buf, MAX_PATH);
                    str+=_TCHAR(' ');
                    str+=buf;
                }
                CloseHandle(hProcess);
            }
        }
    }
#endif
#endif
    return str;
}
Exemplo n.º 13
0
bool CProperties::CreatePathToFile(LPCTSTR pszDir) 
{
  // Create intermediate directories
#ifdef _WIN32
  const TCHAR cSep='\\';
#else // UNIX
  const TCHAR cSep='/';
#endif
  for(LPCTSTR c=_tcschr(pszDir,cSep);c;c=_tcschr(c+1,cSep)){
#ifdef _WIN32
    if(c==pszDir+2 && _istalpha(pszDir[0]) && _TCHAR(':')==pszDir[1]){
      continue; // don't attempt to create "C:"
    }
#endif
    String strDir(pszDir,c-pszDir);
    struct _stat buf;
    if(!(0==_tstat(strDir,&buf) && (S_IFDIR&buf.st_mode))){
      // Need to create directory
      bool b=(0==_tmkdir(strDir));
      TRACE(_T("Create directory %s rc=%d\n"),(LPCTSTR)strDir,b);
      if(!b){
        return false;
      }
    }
  }
  return true;
}
LPVOID* Environment::CreateEnvironmentFromMap()
{
	size_t size = 0;
	for (auto varsIterator = _vars.begin(); varsIterator != _vars.end(); ++varsIterator)
	{		
		size += varsIterator->first.size() + varsIterator->second.size() + 2;
	}

	size++;

	auto environment = new _TCHAR[size];
	memset(environment, 0, sizeof(_TCHAR) * size);

	size_t pointer = 0;
	for (auto varsIterator = _vars.begin(); varsIterator != _vars.end(); ++varsIterator)
	{
		auto curSize = varsIterator->first.size();		
		memcpy(environment + pointer, varsIterator->first.c_str(), curSize * sizeof(_TCHAR));
		pointer += curSize;

		environment[pointer] = _TCHAR('=');
		pointer ++;

		curSize = varsIterator->second.size();
		memcpy(environment + pointer, varsIterator->second.c_str(), curSize * sizeof(_TCHAR));
		pointer += curSize;		

		pointer ++;
	}	

	return reinterpret_cast<LPVOID*>(environment);
}
Exemplo n.º 15
0
void COutputPage::AddText(LPCTSTR psz)
{
    const CString str(psz);
	CString strText;
	// Change \n into \r\n
	int nStart=0;
	for(int nIndex=0;nIndex<str.GetLength();nIndex++){
		if(str[nIndex]==_TCHAR('\n')){
			if(nIndex==0||str[nIndex-1]!=_TCHAR('\r')){
				strText+=str.Mid(nStart,nIndex-nStart);
				strText+=_TCHAR('\r');
				nStart=nIndex;
			}
		}
	}

	strText+=str.Mid(nStart,nIndex-nStart);

    /*
    CString strWText;
    m_Edit.GetWindowText(strWText);
    strWText+=strText;
    m_Edit.SetWindowText(strWText);
    */
    
	{
		int nStart,nEnd;
		int nLength=m_Edit.GetWindowTextLength();
		m_Edit.GetSel(nStart,nEnd);
		// Replace selection
		m_Edit.SetSel(nLength,nLength,TRUE);
		m_Edit.ReplaceSel(strText);
		if(m_Edit.GetWindowTextLength()!=nLength+strText.GetLength()){
			// Try again by removing equivalent length from start of buffer.
			// For neatness, remove whole lines
			int nLine=m_Edit.LineFromChar(strText.GetLength()-1);
			int nIndex=m_Edit.LineIndex(nLine+1);
			m_Edit.SetSel(0,nIndex-1,TRUE);
			m_Edit.ReplaceSel(_T(""));
			nLength=m_Edit.GetWindowTextLength();
			m_Edit.SetSel(nLength,nLength,TRUE);
			m_Edit.ReplaceSel(strText);
		} else if(nStart!=nEnd) {
			m_Edit.SetSel(nStart,nEnd,TRUE);
		}
	}
}
Exemplo n.º 16
0
BOOL CUtils::StrToDouble (const CString & strValue, double &dValue)
{
	extern int errno;
	PTCHAR pEnd;
	errno = 0;
	dValue = _tcstod (strValue, &pEnd);
	return (0 == errno) && (*pEnd == _TCHAR('\0'));
}
Exemplo n.º 17
0
bool CFileName::CreateDirectory(bool bParentsToo,bool bFailIfAlreadyExists) const
{
  LPCTSTR pszDir=m_pchData;
  if(bParentsToo){
    // Create intermediate directories
    for(LPCTSTR c=_tcschr(pszDir,_TCHAR('\\'));c;c=_tcschr(c+1,_TCHAR('\\'))){
      if(c==pszDir+2 && _istalpha(pszDir[0]) && _TCHAR(':')==pszDir[1]){
        continue; // don't attempt to create "C:"
      }
      const CFileName strDir(pszDir,c-pszDir);
      if(!(strDir.IsDir()? (!bFailIfAlreadyExists) : ::CreateDirectory(strDir,NULL))){
        return false;
      }
    }
  }
  return IsDir()? (!bFailIfAlreadyExists) : (TRUE==::CreateDirectory(pszDir,NULL));
}
Exemplo n.º 18
0
void CFileName::ReplaceExtension(LPCTSTR pszNewExt)
{
  ASSERT(pszNewExt);
  if(_TCHAR('.')==*pszNewExt){
    // Be tolerant of whether '.' is included in what we are passed:
    pszNewExt++;
  }
  LPTSTR pch=GetBuffer(2+GetLength()+_tcslen(pszNewExt));
  LPTSTR pcExt=_tcsrchr(pch,_TCHAR('.'));
  if(NULL==pcExt || _tcschr(pcExt,cSep)){
    // No existing extension
    pcExt=pch+GetLength();
    *pcExt++=_TCHAR('.');
  }
  _tcscpy(pcExt+1,pszNewExt);
  ReleaseBuffer();
}
Exemplo n.º 19
0
void String::ReleaseBuffer()
{
  assert(m_pszBuf);
  m_pszBuf[m_nBufferLength]=_TCHAR('\0'); // just in case the terminating null has been forgotten
  string::operator=(m_pszBuf);
  delete [] m_pszBuf;
  m_pszBuf=0;
}
Exemplo n.º 20
0
const CString CFileName::Root() const
{
  LPCTSTR ch=_tcsrchr(m_pchData,_TCHAR('.'));
  if(ch && !_tcschr(ch,cSep)){
    return CString(m_pchData,ch-m_pchData);
  } else {
    return m_pchData;
  }
}
Exemplo n.º 21
0
const CString CFileName::Extension() const
{
  LPCTSTR ch=_tcsrchr(m_pchData,_TCHAR('.'));
  if(ch && !_tcschr(ch,cSep)){
    return CString(ch+1);
  } else {
    return _T("");
  }
}
Exemplo n.º 22
0
void CFileName::Normalize()
{
  // Remove any trailing slash
  int &n=GetData()->nDataLength;
  if(n>1 && (cSep==m_pchData[n-1])){
    n--;
    m_pchData[n] = _TCHAR('\0');
  }
}
Exemplo n.º 23
0
int InitHeader(CListCtrl& list, const CString& header, int first)
{
   int beg, end, nbCol, fmt, field, len;
   HDITEM hi;

   if (first == 0) {
      // Delete the old columns
      int nbCol = list.GetHeaderCtrl()->GetItemCount();
      while (--nbCol >= 0) list.DeleteColumn(0);
   }

   len = header.GetLength();
   hi.mask = HDI_LPARAM|HDI_IMAGE;
   hi.iImage = 0;

   // Loop for all columns (a field in the string for each)
   for (beg = nbCol = 0; beg < len; nbCol++, beg = end + 1) {
      // It's not '\n' at the last field
      if ( (end = header.Find(_TCHAR('\n'), beg)) < 0 ) end = len;

      if (end > beg) {
         // Read the data type
         switch ( header.GetAt(beg) ) {
         case _TCHAR('T'): hi.lParam =             STI_TEXT,   beg++; break;
         case _TCHAR('N'): hi.lParam = STI_REVERSE|STI_NUMBER, beg++; break;
         case _TCHAR('H'): hi.lParam = STI_REVERSE|STI_HEXADEC,beg++; break;
         case _TCHAR('A'): hi.lParam = STI_REVERSE|STI_ABSOLU ,beg++; break;
         default : hi.lParam = 0;   // sort disable
         }
      } else hi.lParam = 0;         // sort disable

      if (end > beg) {
         // Read the alignment of the column and skip this char
         switch ( header.GetAt(beg) ) {
         case _TCHAR('L'): fmt = LVCFMT_LEFT,   beg++; break;
         case _TCHAR('C'): fmt = LVCFMT_CENTER, beg++; break;
         case _TCHAR('R'): fmt = LVCFMT_RIGHT,  beg++; break;
         default : fmt = LVCFMT_LEFT;
         }
      } else fmt = LVCFMT_LEFT;

      if ( (field = end - beg) >= 0 ) {
         // Inserts a new column in the list view
         list.InsertColumn(first + nbCol, header.Mid(beg, field), fmt);
         list.GetHeaderCtrl()->SetItem(first + nbCol, &hi);
      }
   }

   // Set reasonable widths for our columns
   for (int i = 0; i < nbCol; i++)
      list.SetColumnWidth(first + i, LVSCW_AUTOSIZE_USEHEADER);

   return first + nbCol;
}
Exemplo n.º 24
0
int String::Chop(StringArray &ar,TCHAR cSep,bool bObserveStrings/*=TRUE*/) const
{
  assert('\0'!=cSep);
#define IsSep(c) (cSep==_TCHAR(' ')?_istspace(c):c==cSep)
  LPCTSTR c=c_str();
  ar.clear();
  while(*c){
    // Spaces are slightly different from other separators - we treat multiple instances as
    // just one (a la sscanf)
    if(_istspace(cSep)){
      while(IsSep(*c))c++;
    } else if (ar.size()>0) {
      c++;
    }
    if(*c){
      String strTok;
      if(bObserveStrings){
        bool bInString=false;
        do{
          if(*c==_TCHAR('\\') && c[1]){
            strTok+=c[1];
            c++;
          } else if(*c==_TCHAR('"')){
            bInString ^= 1;
          } else if (!bInString && IsSep(*c)) {
            break;
          } else {
            strTok+=*c;
          }
        } while (*++c);
      } else {
        do {
          if(IsSep(*c)) {
            break;
          } else {
            strTok+=*c;
          }
        } while (*++c);
      }
      ar.push_back(strTok);
    }
  }
  return ar.size();
}
Exemplo n.º 25
0
bool CFileName::IsAbsolute() const
{
  int nLength=GetLength();
  LPCTSTR psz=*this;
  return 
    (nLength>0 && (cSep==psz[0]))|| // starts with '\'
    (nLength>1 && (
    (_istalpha(psz[0]) && _TCHAR(':')==psz[1]) ||  // starts with [e.g.] "c:\"
    (cSep==psz[0] && cSep==psz[1])));              // UNC
}
Exemplo n.º 26
0
//-------------------------------------------------------------------------
LPCTSTR ResetPermissionDialog::GenerateWorkBatchFileName()
{
    // Make temp file name
    static TCHAR CmdFileName[MAX_PATH2] = { 0 };

    // Compute if it was not already computed
    if (CmdFileName[0] == _TCHAR('\0'))
    {
        // Attempt to use local user AppData folder
        if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, CmdFileName)))
        {
            _tcsncat_s(CmdFileName, STR_FOLDER_LALLOUSLAB, _countof(CmdFileName));

            // Work directory note found? Create it!
            if ((GetFileAttributes(CmdFileName) == INVALID_FILE_ATTRIBUTES)
                && !CreateDirectory(CmdFileName, nullptr))
            {
                // Failed to create the folder. Discard the local app folder and use temp folder
                CmdFileName[0] = _T('\0');
            }
        }

        // Revert to temp folder if this fails
        if (CmdFileName[0] == _TCHAR('\0'))
        {
            // Get temp path via the API
            if (GetTempPath(_countof(CmdFileName), CmdFileName) == 0)
            {
                // Attempt to get it again via the environment variable
                if (GetEnvironmentVariable(_TEXT("TEMP"), CmdFileName, _countof(CmdFileName)) == 0)
                    return nullptr;
            }
        }

        if (CmdFileName[_tcslen(CmdFileName) - 1] != TCHAR('\\'))
            _tcsncat_s(CmdFileName, _TEXT("\\"), _countof(CmdFileName));

        _tcsncat_s(CmdFileName, STR_RESET_FN, _countof(CmdFileName));
    }

    return CmdFileName;
}
Exemplo n.º 27
0
bool CProperties::CProperty::SetValue(LPCTSTR psz)
{
  bool rc=false;
  TCHAR *pEnd;
  double d=0.0;
  long l=0;
  switch(Type){
    case szString:
      *(String *)pData=psz;
      rc=true;
      break;
    case Float:
      d=_tcstod(psz,&pEnd);
      rc=(_TCHAR('\0')==*pEnd);
      if(rc){
        SetValue((float)d);
      }
      break;
    case Double:
      d=_tcstod(psz,&pEnd);
      rc=(_TCHAR('\0')==*pEnd);
      if(rc){
        SetValue(d);
      }
      break;
    case Integer:
    case Bool:
    case Char:
    case Short:
      l=_tcstol(psz,&pEnd,10);
      rc=(_TCHAR('\0')==*pEnd);
      if(rc){
        SetValue((int)l);
      }
      break;
    default:
      TRACE(_T("Failed to set '%s' to string value '%s'\n"),(LPCTSTR)strName,psz);
      break;
  }
  return rc;
}
Exemplo n.º 28
0
String CProperties::MakeCommandString() const
{
  String strResult;
  bool bFirst=true;
  for(int i=ar.size()-1;i>=0;--i){
    String str;    
    const CProperty &p=ar[i];
    switch(p.Type){
      case CProperties::CProperty::Integer:
      case CProperties::CProperty::Bool:
      case CProperties::CProperty::Char:
      case CProperties::CProperty::Short:
        str.Format(_T("-%s=%u"),(LPCTSTR)p.strName,p.GetValue());
        break;
      case CProperties::CProperty::szString:
        {
          // Quote the string, escaping existing quotes as necessary
          str.Format(_T("-%s=\""),(LPCTSTR)p.strName);
          for(LPCTSTR c=p.GetStringValue();*c;c++){
            if(_TCHAR('"')==*c){
              str+=_TCHAR('\\');
            }
            str+=*c;
          }
          str+=_TCHAR('"');
        }
        break;
      case CProperties::CProperty::Float:
      case CProperties::CProperty::Double:
      case CProperties::CProperty::Void:
        str.Format(_T("-%s=%s"),(LPCTSTR)p.GetStringValue());
        break;
    }
    if(!bFirst){
      strResult+=_TCHAR(' ');
    }
    bFirst=false;
    strResult+=str;
  }
  return strResult;
}       
Exemplo n.º 29
0
const CFileName CFileName::CygPath () const 
{
  TCHAR buf[2+MAX_PATH];
  LPCTSTR rc=buf+1;
  if(!GetShortPathName(m_pchData,1+buf,MAX_PATH)){
    _tcscpy(1+buf,m_pchData);
  }
  if(_istalpha(*rc)&&_TCHAR(':')==rc[1]){
    // Convert c:\ to //c/ [this is the bit that requires the first char of buf]
    buf[0]=_TCHAR('/');
    buf[2]=buf[1];
    buf[1]=_TCHAR('/');
    rc=buf;
  }
  for(TCHAR *c=buf+1;*c;c++){
    if(_TCHAR('\\')==*c){
      *c=_TCHAR('/');
    }
  }
  
  return rc;
}
Exemplo n.º 30
0
int CUtils::Chop(LPCTSTR psz,CStringArray &ar,LPCTSTR pszSep,bool bObserveStrings/*=false*/,bool bBackslashQuotes/*=false*/)
{
	ar.RemoveAll();
	int i=0;
	for(;;){
		// Skip multiple separators
    while(*psz&&_tcschr(pszSep,*psz)){
      psz++;
    }
		if(!*psz){
			return i;
		}
		CString strTok;
		if(bObserveStrings){
			BOOL bInString=FALSE;
			do{
				if(*psz==_TCHAR('\\') && bBackslashQuotes && psz[1]){
					strTok+=psz[1];
					psz++;
				} else if(*psz==_TCHAR('"')){
					bInString ^= 1;
				} else if (!bInString && *psz && NULL!=_tcschr(pszSep,*psz)) {
					break;
				} else {
					strTok+=*psz;
				}
			} while (*++psz);
		} else {
      LPCTSTR pszStart=psz;
			do {
        psz++;
			} while (*psz && !_tcschr(pszSep,*psz));
      strTok=CString(pszStart,psz-pszStart);
		}
		ar.SetAtGrow(i++,strTok);
	}
    return ar.GetSize();
}