Example #1
0
BOOL CUtils::RemoveDirectory( LPCTSTR lpszDirectoryPath )
{
    if(!::PathFileExists(lpszDirectoryPath))
        return TRUE;

    if(::PathIsRoot(lpszDirectoryPath))
    {
        ATLASSERT(FALSE);
        return FALSE;
    }

    CString strDirPathTemp = lpszDirectoryPath;

    strDirPathTemp.AppendChar(_T('\0'));

    SHFILEOPSTRUCT FileOp; 
    ZeroMemory((void*)&FileOp, sizeof(SHFILEOPSTRUCT));

    FileOp.wFunc = FO_DELETE; 
    FileOp.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_NOCONFIRMMKDIR;	
    FileOp.pFrom = strDirPathTemp; 
    FileOp.pTo = NULL; 

    return SHFileOperation(&FileOp) == 0;
}
void CSubmoduleUpdateDlg::OnBnClickedOk()
{
	CResizableStandAloneDialog::UpdateData(TRUE);
	m_PathList.clear();

	CString selected;
	for (int i = 0; i < m_PathListBox.GetCount(); ++i)
	{
		if (m_PathListBox.GetSel(i))
		{
			if (!selected.IsEmpty())
				selected.AppendChar(L'|');
			CString text;
			m_PathListBox.GetText(i, text);
			m_PathList.push_back(text);
			selected.Append(text);
		}
	}
	m_regPath = selected;

	m_regInit = m_bInit;
	m_regRecursive = m_bRecursive;
	m_regForce = m_bForce;
	m_regRemote = m_bRemote;
	m_regNoFetch = m_bNoFetch;
	m_regMerge = m_bMerge;
	m_regRebase = m_bRebase;

	CResizableStandAloneDialog::OnOK();
}
Example #3
0
BOOL CAddonUpdaterApp::InitInstance()
{
	// InitCommonControlsEx() is required on Windows XP if an application
	// manifest specifies use of ComCtl32.dll version 6 or later to enable
	// visual styles.  Otherwise, any window creation will fail.
	INITCOMMONCONTROLSEX InitCtrls;
	InitCtrls.dwSize = sizeof(InitCtrls);
	// Set this to include all the common control classes you want to use
	// in your application.
	InitCtrls.dwICC = ICC_WIN95_CLASSES;
	InitCommonControlsEx(&InitCtrls);

	CWinApp::InitInstance();


	AfxEnableControlContainer();

	// Create the shell manager, in case the dialog contains
	// any shell tree view or shell list view controls.
	CShellManager *pShellManager = new CShellManager;

	if (!GetWOWPath().IsEmpty())
	{
		CAddonUpdaterDlg dlg;
		m_pMainWnd = &dlg;
		INT_PTR nResponse = dlg.DoModal();
		if (nResponse == IDOK)
		{
			// TODO: Place code here to handle when the dialog is
			//  dismissed with OK
		}
		else if (nResponse == IDCANCEL)
		{
			// TODO: Place code here to handle when the dialog is
			//  dismissed with Cancel
		}
	}
	else
	{
		MessageBox(NULL, _T("δÕÒµ½Ä§ÊÞÊÀ½ç°²×°Â·¾¶¡£"), _T("´íÎó"), MB_ICONEXCLAMATION | MB_OK);
	}

	// Delete the shell manager created above.
	if (pShellManager != NULL)
	{
		delete pShellManager;
	}

	SHFILEOPSTRUCT op = {0};
	op.wFunc = FO_DELETE;
	CString strPath = theApp.GetTempPath();
	strPath.AppendChar(_T('\0'));
	op.pFrom = strPath.GetString();
	op.fFlags = FOF_NOCONFIRMATION;
	SHFileOperation(&op);

	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return FALSE;
}
static bool WincredExists()
{
	CString path = g_Git.ms_LastMsysGitDir;
	if (g_Git.ms_LastMsysGitDir.Right(1) != _T("\\"))
		path.AppendChar(_T('\\'));
	path.Append(_T("..\\libexec\\git-core\\git-credential-wincred.exe"));
	return !!PathFileExists(path);
}
Example #5
0
void CXMLElement::ToString(CString& strXML, BOOL bNewline) const
{
	// strXML += '<' + m_sName; Optimzed:
	strXML.AppendChar( _T('<') );
	strXML.Append( m_sName );

	POSITION pos = GetAttributeIterator();
	for ( ; pos ; )
	{
		strXML.AppendChar( _T(' ') );
		const CXMLAttribute* pAttribute = GetNextAttribute( pos );
		pAttribute->ToString( strXML );
	}

	pos = GetElementIterator();

	if ( pos == NULL && m_sValue.IsEmpty() )
	{
		strXML.Append( _PT("/>") );
		if ( bNewline )
			strXML.Append( _PT("\r\n") );
		return;
	}

	strXML.AppendChar( _T('>') );
	if ( bNewline && pos )
		strXML.Append( _PT("\r\n") );

	while ( pos )
	{
		const CXMLElement* pElement = GetNextElement( pos );
		pElement->ToString( strXML, bNewline );
	}

	strXML += Escape( m_sValue );

	strXML.Append( _PT("</") );
	strXML.Append( m_sName );
	strXML.AppendChar( _T('>') );
	if ( bNewline )
		strXML.Append( _PT("\r\n") );
}
CString CompatibleFile::ReadLine()
{
	CString result = "";
	for(char c = fgetc(fp); c != '\n' && c != -1; c = fgetc(fp))
	{	
		if(c == '\r')
			continue;
		result.AppendChar(c);
	}
	return result;
}
bool Application::Upgrade(LPCTSTR updateFilePath, LPCTSTR version) {
  HINSTANCE hInstance = AfxGetResourceHandle();
  HRSRC hResInfo = FindResource(hInstance, MAKEINTRESOURCE(IDR_APP_UPDATE), _T("EXE"));
  if (hResInfo == NULL) {
    return false;
  }  
  HGLOBAL hResData = LoadResource(hInstance, hResInfo);
  if (hResData == NULL) {
    return false;
  }
  int size = SizeofResource(hInstance, hResInfo);  
  const void *data = LockResource(hResData);
  if (data == NULL) {
    return false;
  }
  TCHAR tempFilePath[MAX_PATH];
  GetTempPath(_countof(tempFilePath), tempFilePath);
  GetTempFileName(tempFilePath, _T("~"), 0, tempFilePath);
  PathRemoveExtension(tempFilePath);
  _tcscat(tempFilePath, _T(".exe"));
  TCHAR appDir[MAX_PATH];
  GetModuleFileName(NULL, appDir, _countof(appDir));
  PathRemoveFileSpec(appDir);
  try {
    CFile file(tempFilePath, CFile::modeCreate | CFile::typeBinary | CFile::modeWrite);
    file.Write(data, size);
    file.Close();
  } catch (CException *e) {
    e->Delete();
    return false;
  }
  CString parameters;
  parameters.AppendChar(_T('\"'));
  parameters.Append(updateFilePath);
  parameters.AppendChar(_T('\"'));
  parameters.AppendChar(_T(' '));
  parameters.AppendChar(_T('\"'));
  parameters.Append(appDir);
  parameters.AppendChar(_T('\"'));
  parameters.AppendChar(_T(' '));
  parameters.AppendChar(_T('\"'));
  parameters.Append(version);
  parameters.AppendChar(_T('\"'));

  HINSTANCE instance = ShellExecute(NULL, NULL, tempFilePath, parameters, NULL, SW_SHOW); 
  if ((DWORD)instance <= 32) {
    return false;
  }
  return true;
}
Example #8
0
CString CAddonUpdaterApp::GetWOWPath()
{
	TCHAR cPath[256] = {0};
	DWORD dwSize = 256 * sizeof(TCHAR);
	HKEY hKey = NULL;
	LONG lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Blizzard Entertainment\\World of Warcraft"), 0, KEY_QUERY_VALUE, &hKey);
	if (lResult == ERROR_SUCCESS)
	{
		RegQueryValueEx(hKey, _T("InstallPath"), NULL, NULL, (LPBYTE)cPath, &dwSize);
		RegCloseKey(hKey);
	} 
	else
	{
		return _T("");
	}

	CString strPath = cPath;
	if (!strPath.ReverseFind(_T('\\')) == strPath.GetLength() - 1)
		strPath.AppendChar(_T('\\'));

	return strPath;
}
CString JavaScriptEscape::javaEscape(CString s) 
{
	CString sbuf;
	int len = s.GetLength();

	for (int i = 0; i < len; i++) 
	{
		int ch = s.GetAt(i);
		if (ch == ' ')
		{
			sbuf+="%20";
		}
		else if ('A' <= ch && ch <= 'Z')
		{
			sbuf.AppendChar((char)ch);
		}
		else if ('a' <= ch && ch <= 'z')
		{
			sbuf.AppendChar((char)ch);
		}
		else if ('0' <= ch && ch <= '9')
		{
			sbuf.AppendChar((char)ch);
		}
		else if (ch == '-' || ch == '_'
			|| ch == '.' || ch == '!'
			|| ch == '~' || ch == '*'
			|| ch == '\'' || ch == '('
			|| ch == ')'){
				sbuf.AppendChar((char)ch);
		}
		else if (ch <= 0x007F)
		{
			sbuf.AppendChar('%');
			sbuf+=strHex[ch];
		}
		else
		{
			sbuf.AppendChar('%');
			sbuf.AppendChar('u');
			sbuf+=strHex[(ch >> 8)];
			sbuf+=strHex[(0x00FF & ch)];
		}
	}
	return sbuf;
}
Example #10
0
/*
================
SpinFloatString
================
*/
void SpinFloatString( CString &str, bool up ) {
	int i, dotIndex = -1, digitIndex = -1;

	for ( i = 0; str[i]; i++ ) {
		if ( str[i] == '.' ) {
			if ( dotIndex == -1 ) {
				dotIndex = i;
			}
		}
		else if ( str[i] != '0' ) {
			if ( digitIndex == -1 ) {
				digitIndex = i;
			}
		}
	}
	if ( digitIndex == -1 ) {
		str.SetString( "1" );
		return;
	}

	if ( dotIndex != -1 ) {
		str.Delete( dotIndex, 1 );
		if ( digitIndex > dotIndex ) {
			digitIndex--;
		}
	}
	else {
		dotIndex = i;
	}

	if ( up ) {
		if ( str[digitIndex] == '9' ) {
			str.SetAt( digitIndex, '0' );
			if ( digitIndex == 0 ) {
				str.Insert( 0, '1' );
				dotIndex++;
			}
			else {
				str.SetAt( digitIndex-1, '1' );
			}
		}
		else {
			str.SetAt( digitIndex, str[digitIndex] + 1 );
		}
	}
	else {
		if ( str[digitIndex] == '1' ) {
			if ( str[digitIndex+1] == '\0' ) {
				str.SetAt( digitIndex, '0' );
				str.AppendChar( '9' );
			}
			else if ( str[digitIndex+1] == '0' ) {
				str.SetAt( digitIndex, '0' );
				str.SetAt( digitIndex+1, '9' );
			}
			else {
				str.SetAt( digitIndex+1, str[digitIndex+1] - 1 );
			}
		}
		else {
			str.SetAt( digitIndex, str[digitIndex] - 1 );
		}
	}
	if ( dotIndex < str.GetLength() ) {
		str.Insert( dotIndex, '.' );
		// remove trailing zeros
		for ( i = str.GetLength()-1; i >= 0; i-- ) {
			if ( str[i] != '0' && str[i] != '.' ) {
				break;
			}
		}
		if ( i < str.GetLength() - 1 ) {
			str.Delete( i+1, str.GetLength() - i );
		}
	}
	for ( i = 0; str[i]; i++ ) {
		if ( str[i] == '.' ) {
			if ( i > 1 ) {
				str.Delete( 0, i-1 );
			}
			break;
		}
		if ( str[i] != '0' ) {
			if ( i > 0 ) {
				str.Delete( 0, i );
			}
			break;
		}
	}
}
Example #11
0
//----------------------------------------------------------------------------
//  ResolveModuleID
HRESULT CMagpieApplication::ResolveModuleID(
  CMagpieModule * pSrcModule,
  LPCOLESTR       lpszModuleID,
  CString       & sAbsoluteModuleID)
{
  if (!lpszModuleID || !_tcslen(lpszModuleID))
  {
    // empty id? no way!
    return E_FAIL;
  }

  // if ID is already absolute...
  if (lpszModuleID[0] != _T('.'))
  {
    // ...return it as it is...
    sAbsoluteModuleID = lpszModuleID;
    return S_OK;
  }

  HRESULT hr = E_FAIL;
  CString sSrcModuleID;
  // if no source module is given id will be
  // relative to root (means sSrcModuleID will be empty)
  if (pSrcModule)
  {
    pSrcModule->GetID(sSrcModuleID);
  }

  CAtlList<CString> srcIdList, idList;

  SplitString(lpszModuleID, _T("/"), idList);
  SplitString(sSrcModuleID, _T("/"), srcIdList);
  if (!srcIdList.IsEmpty())
  {
    // Remove last part, it is the "filename" part of the srcID.
    // dstID should be relative to the "folder" of srcID
    srcIdList.RemoveTailNoReturn();
  }

  // Adjust the srcIdList according to the parts in idList.
  // Any './' will change nothing.
  // Any '../' will pop off the tail of srcIdList.
  // Anything else will be appended to srcIdList.
  POSITION pos = idList.GetHeadPosition();
  while(pos)
  {
    const CString & cur = idList.GetNext(pos);
    if (cur == _T("."))
    {
      // current folder, do nothing
      continue;
    }
    if (cur == _T(".."))
    {
      // one up, remove tail from srcIdList
      if (srcIdList.IsEmpty())
      {
        // Oops, already top level.
        // Return an error.
        return E_FAIL;
      }
      srcIdList.RemoveTailNoReturn();
    }
    else
    {
      // append
      srcIdList.AddTail(cur);
    }
  }

  // Now compose final id.
  // sAbsoluteModuleID does NOT get emptied before, allowing to pass in
  // a parent path.
  pos = srcIdList.GetHeadPosition();
  while(pos)
  {
    sAbsoluteModuleID.Append(idList.GetNext(pos));
    if (pos)
    {
      sAbsoluteModuleID.AppendChar(_T('/'));
    }
  }
  return S_OK;
}
BOOL AboutGameDialog::OnInitDialog()
{
  BaseDialog::OnInitDialog();

  CWaitCursor wc;
  const FrotzApp::GameInfo& gameInfo = theApp.GetGameInfo();

  // Initialize the rich edit text control
  if (m_info.SubclassDlgItem(IDC_INFO,this) == FALSE)
    return FALSE;
  m_info.SetText(SF_TEXT,gameInfo.description);

  // Add the title, author, etc.
  CString heading;
  heading.Append(gameInfo.title);
  heading.AppendChar('\r');
  if (gameInfo.seriesNumber.IsEmpty() == FALSE)
  {
    heading.Append(gameInfo.series);
    heading.Append(" #");
    heading.Append(gameInfo.seriesNumber);
    heading.AppendChar('\r');
  }
  if (gameInfo.headline.IsEmpty() == FALSE)
  {
    heading.Append(gameInfo.headline);
    heading.AppendChar('\r');
  }
  heading.Append(gameInfo.author);
  if (gameInfo.year.IsEmpty() == FALSE)
  {
    heading.Append(" (");
    heading.Append(gameInfo.year);
    heading.AppendChar(')');
  }
  heading.Append("\r\r");
  
  m_info.SetSel(0,0);
  CHARFORMAT format;
  format.cbSize = sizeof format;
  format.dwMask = CFM_BOLD;
  format.dwEffects = CFE_BOLD;
  m_info.SetSelectionCharFormat(format);
  m_info.ReplaceSel(heading);

  // Set the dialog title
  SetWindowText(gameInfo.title);

  // Get the initial position of the rich edit, used for spacing
  CRect initRect;
  m_info.GetWindowRect(initRect);
  ScreenToClient(initRect);

  // Get the cover art
  FrotzGfx* coverGfx = NULL;
  if (gameInfo.cover != -1)
    coverGfx = FrotzGfx::Get(gameInfo.cover,theApp.GetBlorbMap(),gameInfo.coverFormatWrong);

  CRect screen = theApp.GetScreenSize(true);
  if (coverGfx != NULL)
  {
    // Choose a size for the cover art
    CSize size = coverGfx->GetSize(1.0);

    double r = (double) screen.Width() / ((double) size.cx * 3.0);

    size = coverGfx->GetSize(r);

    // Resize the cover art
    CWindowDC dc(this);
    if (!m_coverBitmap.CreateBitmap(dc,size.cx,size.cy))
      return FALSE;
    coverGfx->Paint(m_coverBitmap,CPoint(0,0),r);

    m_coverRect = CRect(initRect.TopLeft(),size);
  }
  else
    m_coverRect = CRect(initRect.TopLeft(),CSize(screen.Width()/3,screen.Width()/3));

  // Resize the rich edit control
  CRect infoRect = m_coverRect;
  if (coverGfx != NULL)
    infoRect.OffsetRect(m_coverRect.right,0);
  m_info.MoveWindow(infoRect);

  // Get the size of the OK button
  CRect okRect;
  m_ok.GetClientRect(okRect);

  // Resize the OK button
  okRect.MoveToXY(
    initRect.left+((infoRect.right+initRect.left)/2)-(okRect.Width()/2),
    m_coverRect.bottom+infoRect.top);
  m_ok.MoveWindow(okRect,FALSE);

  // Get the initial dialog size
  CRect dlgCRect, dlgWRect;
  GetClientRect(dlgCRect);
  GetWindowRect(dlgWRect);
  int dlgX = dlgWRect.Width()-dlgCRect.Width();
  int dlgY = dlgWRect.Height()-dlgCRect.Height();

  // Resize the dialog
  MoveWindow(0,0,
    infoRect.right+initRect.left+dlgX,
    okRect.bottom+initRect.top+dlgY,FALSE);
  CenterWindow();
  return TRUE;
}
Example #13
0
// This method is assumed to be called with m_SharedMutex locked.
int CGitHeadFileList::GetPackRef(const CString &gitdir)
{
    CString PackRef = g_AdminDirMap.GetAdminDir(gitdir) + _T("packed-refs");

    __int64 mtime;
    if (g_Git.GetFileModifyTime(PackRef, &mtime))
    {
        //packed refs is not existed
        this->m_PackRefFile.Empty();
        this->m_PackRefMap.clear();
        return 0;
    }
    else if(mtime == m_LastModifyTimePackRef)
    {
        return 0;
    }
    else
    {
        this->m_PackRefFile = PackRef;
        this->m_LastModifyTimePackRef = mtime;
    }

    int ret = 0;
    {
        this->m_PackRefMap.clear();

        CAutoFile hfile = CreateFile(PackRef,
                                     GENERIC_READ,
                                     FILE_SHARE_READ|FILE_SHARE_DELETE|FILE_SHARE_WRITE,
                                     NULL,
                                     OPEN_EXISTING,
                                     FILE_ATTRIBUTE_NORMAL,
                                     NULL);
        do
        {
            if (!hfile)
            {
                ret = -1;
                break;
            }

            DWORD filesize = GetFileSize(hfile, NULL);
            if (filesize == 0)
            {
                ret = -1;
                break;
            }
            DWORD size =0;
            char *buff;
            buff = new char[filesize];

            ReadFile(hfile, buff, filesize, &size, NULL);

            if (size != filesize)
            {
                delete[] buff;
                ret = -1;
                break;
            }

            CString hash;
            CString ref;

            for(DWORD i=0; i<filesize;)
            {
                hash.Empty();
                ref.Empty();
                if (buff[i] == '#' || buff[i] == '^')
                {
                    while (buff[i] != '\n')
                    {
                        ++i;
                        if (i == filesize)
                            break;
                    }
                    ++i;
                }

                if (i >= filesize)
                    break;

                while (buff[i] != ' ')
                {
                    hash.AppendChar(buff[i]);
                    ++i;
                    if (i == filesize)
                        break;
                }

                ++i;
                if (i >= filesize)
                    break;

                while (buff[i] != '\n')
                {
                    ref.AppendChar(buff[i]);
                    ++i;
                    if (i == filesize)
                        break;
                }

                if (!ref.IsEmpty() )
                {
                    this->m_PackRefMap[ref] = hash;
                }

                while (buff[i] == '\n')
                {
                    ++i;
                    if (i == filesize)
                        break;
                }
            }

            delete[] buff;

        } while(0);
    }
    return ret;

}
Example #14
0
CString CSZCommandLineEx::FormatParamUsage(
    LPCTSTR         lpszParamName,
    CParamUsage&    usage, 
    int             nParamNameWidth,
    int             nValueNameWidth)
{
    assert(0 <= nParamNameWidth && nParamNameWidth <= 80);
    assert(0 <= nValueNameWidth && nValueNameWidth <= 80);


    CString strParamUsage;

    if (nValueNameWidth)
        nValueNameWidth += 3;   // for :<>

    // indent
    int nTruncateLength = 4;
    strParamUsage.AppendChar(_T(' '));
    strParamUsage.AppendChar(_T(' '));
    strParamUsage.AppendChar(_T(' '));
    strParamUsage.AppendChar(_T('-'));

    // param name
    nTruncateLength += nParamNameWidth;
    strParamUsage.Append(lpszParamName);
    for (int i = strParamUsage.GetLength(); i <= nTruncateLength; ++i)
    {
        strParamUsage.AppendChar(_T(' '));
    }
    strParamUsage.Truncate(nTruncateLength);


    // space
    nTruncateLength += 2;
    strParamUsage.AppendChar(_T(' '));
    strParamUsage.AppendChar(_T(' '));


    // param value
    nTruncateLength += nValueNameWidth;
    if (!usage.m_strParamValueName.IsEmpty())
        strParamUsage.AppendFormat(_T(":<%s>"), usage.m_strParamValueName);
    for (int i = strParamUsage.GetLength(); i <= nTruncateLength; ++i)
    {
        strParamUsage.AppendChar(_T(' '));
    }
    strParamUsage.Truncate(nTruncateLength);


    // space
    nTruncateLength += 4;
    strParamUsage.AppendChar(_T(' '));
    strParamUsage.AppendChar(_T(' '));
    strParamUsage.AppendChar(_T(' '));
    strParamUsage.AppendChar(_T(' '));


    // param usage
    strParamUsage.Append(usage.m_strUsage);
    return strParamUsage;
}
Example #15
0
void FormatHeader(CString& Result, UINT& Align, const char* Format, const char* Title, const char* Author, const char* Description, int CurPage, int TotalPages)
{
	char Buffer[128];
	const char* Ptr = Format;

	Result.Empty();
	Align = DT_CENTER;

	while (*Ptr)
	{
		if (*Ptr != '&')
		{
			Result.AppendChar(*Ptr);
			Ptr++;
			continue;
		}

		if (Ptr[1] == '&')
		{
			Result.AppendChar(*Ptr);
			Ptr++;
			Ptr++;
			continue;
		}

		switch (Ptr[1])
		{
		case 'L':
			Align = DT_LEFT;
			Ptr++;
			break;

		case 'C':
			Align = DT_CENTER;
			Ptr++;
			break;

		case 'R':
			Align = DT_RIGHT;
			Ptr++;
			break;

		case 'F':
			Result.Append(Title);
			Ptr++;
			break;

		case 'A':
			Result.Append(Author);
			Ptr++;
			break;

		case 'N':
			Result.Append(Description);
			Ptr++;
			break;

		case 'D':
			_strdate(Buffer);
			Result.Append(Buffer);
			Ptr++;
			break;

		case 'T':
			_strtime(Buffer);
			Result.Append(Buffer);
			Ptr++;
			break;

		case 'P':
			sprintf(Buffer, "%d", CurPage);
			Result.Append(Buffer);
			Ptr++;
			break;

		case 'O':
			sprintf(Buffer, "%d", TotalPages);
			Result.Append(Buffer);
			Ptr++;
			break;

		case 0:
		default:
			Result.AppendChar(*Ptr);
			break;
		}

		Ptr++;
	}
}