Esempio n. 1
0
void CSearch::OnBnClickedOk()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(TRUE);
	
	//搜索用户
	if (m_bIsUid)
	{
		if (m_strid == m_client->m_szUID)
		{
			MessageBox(L"不能搜索自己");
			return;
		}

		CStringA str = CW2A(m_strid.GetBuffer(), CP_THREAD_ACP);
		m_client->Send(SEARCHUSER, str.GetBuffer(), 1);
	}
	else
	{
		CStringA str = CW2A(m_strid.GetBuffer(), CP_THREAD_ACP);
		m_client->Send(SEARCHGROUP, str.GetBuffer(), 1);
	}

	//CDialogEx::OnOK();
}
Esempio n. 2
0
void CCaHtmlParse::__GetPriceAndRamainTicket(UINT *pPrice, UINT *pRemainTicket, const TidyDoc & tdoc, const TidyNode & tdNode)
{
	CStringA straRet;
	*pPrice = 0;
	*pRemainTicket = 0;

	TidyBuffer text = {0};
	tidyBufInit(&text);
	TidyNodeType type = tidyNodeGetType(tdNode);
	tidyNodeGetText(tdoc, tdNode, &text);
	straRet.Format("%s",text.bp);
	straRet.TrimLeft();

	CStringA straKey("</font>");
	int iPos = straRet.Find(straKey);
	int iEndPos = straRet.Find("</strong>");
	int iStartPos = iPos+straKey.GetLength();
	CStringA straPrice = straRet.Mid(iStartPos, iEndPos-iStartPos);
	straPrice.Remove(0x0d);//去掉回车
	straPrice.Remove(0x0a);//去掉换行
	*pPrice = atoi(straPrice.GetBuffer(0));
	straPrice.ReleaseBuffer();

	//剩余座位
	straKey = ":";
	iPos = straRet.Find(straKey);
	iEndPos = straRet.Find("</td>");
	iStartPos = iPos+straKey.GetLength();
	CStringA straRemainSeat = straRet.Mid(iStartPos, iEndPos-iStartPos);
	*pRemainTicket = atoi(straRemainSeat.GetBuffer(0));
	straRemainSeat.ReleaseBuffer();

	tidyBufFree(&text);
}
Esempio n. 3
0
int CPatch::Parse(CString &pathfile)
{
	CString str;

	m_PathFile = pathfile;

	CFile PatchFile;

	if (!PatchFile.Open(m_PathFile, CFile::modeRead))
		return -1;

	PatchFile.Read(m_Body.GetBuffer((UINT)PatchFile.GetLength()), (UINT)PatchFile.GetLength());
	m_Body.ReleaseBuffer();
	PatchFile.Close();

	try
	{
		int start=0;
		CStringA one;
		one=m_Body.Tokenize("\n",start);

		if (start == -1)
			return -1;
		one=m_Body.Tokenize("\n",start);
		if(one.GetLength()>6)
			g_Git.StringAppend(&m_Author, (BYTE*)one.GetBuffer() + 6, CP_UTF8, one.GetLength() - 6);

		if (start == -1)
			return -1;
		one=m_Body.Tokenize("\n",start);
		if(one.GetLength()>6)
			g_Git.StringAppend(&m_Date, (BYTE*)one.GetBuffer() + 6, CP_UTF8, one.GetLength() - 6);

		if (start == -1)
			return -1;
		one=m_Body.Tokenize("\n",start);
		if(one.GetLength()>9)
		{
			g_Git.StringAppend(&m_Subject, (BYTE*)one.GetBuffer() + 9, CP_UTF8, one.GetLength() - 9);
			while (m_Body.GetLength() > start && m_Body.GetAt(start) == _T(' '))
			{
				one = m_Body.Tokenize("\n", start);
				g_Git.StringAppend(&m_Subject, (BYTE*)one.GetBuffer(), CP_UTF8, one.GetLength());
			}
		}

		if (start + 1 < m_Body.GetLength())
			g_Git.StringAppend(&m_strBody, (BYTE*)m_Body.GetBuffer() + start + 1, CP_UTF8, m_Body.GetLength() - start - 1);
	}
	catch (CException *)
	{
		return -1;
	}

	return 0;
}
Esempio n. 4
0
CString Utf8DecodeUni(CStringA str)
{
#ifdef _UNICODE
	LPTSTR msg;
	Utf8DecodeCP(str.GetBuffer(), CP_ACP, &msg);
	return msg;
#else
	return Utf8DecodeCP(str.GetBuffer(), CP_ACP, NULL);
#endif
}
Esempio n. 5
0
CGitHash CGit::GetHash(TCHAR* friendname)
{
	// no need to parse a ref if it's already a 40-byte hash
	if (CGitHash::IsValidSHA1(friendname))
	{
		CString sHash(friendname);
		return CGitHash(sHash);
	}

	if (m_IsUseLibGit2)
	{
		git_repository *repo = NULL;
		CStringA gitdirA = CUnicodeUtils::GetMulti(CTGitPath(m_CurrentDir).GetGitPathString(), CP_UTF8);
		if (git_repository_open(&repo, gitdirA.GetBuffer()))
		{
			gitdirA.ReleaseBuffer();
			return CGitHash();
		}
		gitdirA.ReleaseBuffer();

		CStringA refnameA = CUnicodeUtils::GetMulti(friendname, CP_UTF8);

		git_object * gitObject = NULL;
		if (git_revparse_single(&gitObject, repo, refnameA.GetBuffer()))
		{
			refnameA.ReleaseBuffer();
			git_repository_free(repo);
			return CGitHash();
		}
		refnameA.ReleaseBuffer();

		const git_oid * oid = git_object_id(gitObject);
		if (oid == NULL)
		{
			git_object_free(gitObject);
			git_repository_free(repo);
			return CGitHash();
		}

		CGitHash hash((char *)oid->id);

		git_object_free(gitObject); // also frees oid
		git_repository_free(repo);

		return hash;
	}
	else
	{
		CString cmd;
		CString out;
		cmd.Format(_T("git.exe rev-parse %s" ),FixBranchName(friendname));
		Run(cmd, &out, NULL, CP_UTF8);
		return CGitHash(out.Trim());
	}
}
Esempio n. 6
0
int CPatch::Parser(CString &pathfile)
{
	CString str;

	CFile PatchFile;

	m_PathFile=pathfile;
	if( ! PatchFile.Open(pathfile,CFile::modeRead) )
		return -1;

#if 0
	int i=0;
	while(i<4)
	{
		PatchFile.ReadString(str);
		if(i==1)
			this->m_Author=str.Right( str.GetLength() - 6 );
		if(i==2)
			this->m_Date = str.Right( str.GetLength() - 6 );
		if(i==3)
			this->m_Subject = str.Right( str.GetLength() - 8 );

		++i;
	}

	LONGLONG offset=PatchFile.GetPosition();
#endif
	PatchFile.Read(m_Body.GetBuffer((UINT)PatchFile.GetLength()), (UINT)PatchFile.GetLength());
	m_Body.ReleaseBuffer();
	PatchFile.Close();

	int start=0;
	CStringA one;
	one=m_Body.Tokenize("\n",start);

	one=m_Body.Tokenize("\n",start);
	if(one.GetLength()>6)
		g_Git.StringAppend(&m_Author, (BYTE*)one.GetBuffer() + 6, CP_UTF8, one.GetLength() - 6);

	one=m_Body.Tokenize("\n",start);
	if(one.GetLength()>6)
		g_Git.StringAppend(&m_Date, (BYTE*)one.GetBuffer() + 6, CP_UTF8, one.GetLength() - 6);

	one=m_Body.Tokenize("\n",start);
	if(one.GetLength()>9)
		g_Git.StringAppend(&m_Subject, (BYTE*)one.GetBuffer() + 9, CP_UTF8, one.GetLength() - 9);

	//one=m_Body.Tokenize("\n",start);

	g_Git.StringAppend(&m_strBody, (BYTE*)m_Body.GetBuffer() + start + 1, CP_UTF8, m_Body.GetLength() - start - 1);

	return 0;
}
Esempio n. 7
0
BOOL CStdioFileEx::ReadAnsiString(CStringA& rString)
{
   _ASSERTE(m_pStream);
   rString = "";      // empty string without deallocating
   
   if(!m_bIsUnicodeText)
   {
      const int nMaxSize = 128;
      LPSTR lpsz = rString.GetBuffer(nMaxSize);
      LPSTR lpszResult;
      int nLen = 0;
      for (;;)
      {
         lpszResult = fgets(lpsz, nMaxSize+1, m_pStream);
         rString.ReleaseBuffer();
         
         // handle error/eof case
         if (lpszResult == NULL && !feof(m_pStream))
         {
            Afx_clearerr_s(m_pStream);
            AfxThrowFileException(CFileException::genericException, _doserrno,
               m_strFileName);
         }
         
         // if string is read completely or EOF
         if (lpszResult == NULL ||
            (nLen = (int)lstrlenA(lpsz)) < nMaxSize ||
            lpsz[nLen-1] == '\n')
            break;
         
         nLen = rString.GetLength();
         lpsz = rString.GetBuffer(nMaxSize + nLen) + nLen;
      }
      //remove crlf if exist.
      nLen = rString.GetLength();
      if (nLen > 1 && rString.Mid(nLen-2) == "\r\n")
      {
         rString.GetBufferSetLength(nLen-2);
      }
      return rString.GetLength() > 0;
   }
   else
   {
      CStringW wideString;
      BOOL bRetval = ReadWideString(wideString);
      //setlocale(LC_ALL, "chs_chn.936");//no need
      rString = wideString;
      return bRetval;
   }
}
Esempio n. 8
0
int GitRev::GetCommit(CString refname)
{
	CAutoLocker lock(g_Git.m_critGitDllSec);

	g_Git.CheckAndInitDll();

	if(refname.GetLength() >= 8)
		if(refname.Find(_T("00000000")) == 0)
		{
			this->m_CommitHash.Empty();
			this->m_Subject=_T("Working Copy");
			return 0;
		}
	CStringA rev;
	rev= CUnicodeUtils::GetUTF8(g_Git.FixBranchName(refname));
	GIT_HASH sha;

	try
	{
		if (git_get_sha1(rev.GetBuffer(), sha))
			return -1;
	}
	catch (char * msg)
	{
		MessageBox(NULL, _T("Could not get SHA-1 of ref \"") + g_Git.FixBranchName(refname) + _T("\".\nlibgit reports:\n") + CString(msg), _T("TortoiseGit"), MB_ICONERROR);
		return -1;
	}

	CGitHash hash((char*)sha);
	GetCommitFromHash_withoutLock(hash);
	return 0;
}
extern "C" void __declspec(dllexport) open_file_dialog(
  HWND hwndParent, 
  int string_size, 
	char *variables, 
  stack_t **stacktop)
{
	EXDLL_INIT();
		
	char szBuffer[1024]="";
	popstring(szBuffer);
	HWND hWndParent = (HWND)atoi(szBuffer);

	CFileDialog dlg(TRUE, _T("lic"), NULL, OFN_FILEMUSTEXIST, 
		_T("CrashFix License Files (*.lic)\0*.lic\0All Files (*.*)\0*.*\0\0"), hWndParent);
	INT_PTR nResult = dlg.DoModal(hWndParent);
	if(nResult==IDOK)
	{
		CStringA sFileName = dlg.m_szFileName;		
		pushstring(sFileName.GetBuffer());
	}
	else
	{
		pushstring("");
	}	
}
Esempio n. 10
0
extern "C" void __declspec(dllexport) detect_httpd(
  HWND hwndParent, 
  int string_size, 
	char *variables, 
  stack_t **stacktop)
{
	EXDLL_INIT();

	TCHAR str[1024];
	ULONG len = 1024;
	char szPath[1024]="";
	bool bDetected = false;

	CRegKey regKey;
	if(ERROR_SUCCESS==regKey.Open(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\services\\Apache2.2")))
	{
		if(ERROR_SUCCESS==regKey.QueryStringValue(_T("ImagePath"), str, &len))
		{
			bDetected = true;
		}
	}

	CStringA sPath = str;
	int nPos = sPath.Find("\\bin\\httpd.exe");
	if(nPos<0)
		bDetected = false;
	sPath = sPath.Mid(0, nPos);
	sPath.Replace("\"", "");
		
	if(bDetected)
		pushstring(sPath.GetBuffer());	
	else
		pushstring("");	
}
Esempio n. 11
0
BOOL CDLsyn::sendData(CStringA strFormData)
{
	//strFormData.Replace("&","\\&");
	string td=strFormData.GetBuffer();

	string rtd=ansiToUtf8(td);//unicodeToUtf8(strFormData.GetBuffer());
	BOOL result = m_pFile->SendRequest(m_strHeaders,(LPVOID)rtd.c_str(),rtd.length());
	if(result == FALSE) return false;
	//pFile->SendRequestEx(strFormData.GetLength()); 
	//pFile->WriteString(strFormData);
	//pFile->EndRequest();
	//free(tmpdata);
	DWORD dwRet;
	m_pFile->QueryInfoStatusCode(dwRet);

	CString m_strHtml=_T("");
	char szBuff[1024];
	UINT nRead;
	//pFile->Read(szBuff,1023);
	while ((nRead = m_pFile->Read(szBuff,1023))>0)
	{
		m_strHtml+=CString(szBuff,nRead);
	}
	if (dwRet == HTTP_STATUS_OK)
	{
		return true;
	}
	return true;
}
Esempio n. 12
0
CStringA ConvertMBCS(CStringA str, DWORD SrcCharSet, DWORD DstCharSet)
{
    WCHAR* utf16 = new WCHAR[str.GetLength() + 1];
    memset(utf16, 0, (str.GetLength() + 1)*sizeof(WCHAR));

    CHAR* mbcs = new CHAR[str.GetLength() * 6 + 1];
    memset(mbcs, 0, str.GetLength() * 6 + 1);

    int len = MultiByteToWideChar(
                  CharSetToCodePage(SrcCharSet), 0,
                  str.GetBuffer(str.GetLength()), str.GetLength(),
                  utf16, (str.GetLength() + 1) * sizeof(WCHAR));

    len = WideCharToMultiByte(
              CharSetToCodePage(DstCharSet), 0,
              utf16, len,
              mbcs, str.GetLength() * 6,
              NULL, NULL);

    str = mbcs;

    delete [] utf16;
    delete [] mbcs;

    return str;
}
BOOL CRichEditSpellCheck::GetWord(const CHARRANGE& cr, CStringA& sWord) const
{
	if (cr.cpMax > cr.cpMin)
	{
		static CStringA sWord;

		TEXTRANGE tr;
		tr.chrg = cr;

#if defined(UNICODE) || defined(_UNICODE)
		CString strTemp;
		tr.lpstrText = strTemp.GetBuffer(cr.cpMax - cr.cpMin);
		m_re.SendMessage(EM_GETTEXTRANGE, 0, (LPARAM)&tr);
		strTemp.ReleaseBuffer();
		sWord = ATL::CT2A(strTemp);
#else
		tr.lpstrText = sWord.GetBuffer(cr.cpMax - cr.cpMin);
		m_re.SendMessage(EM_GETTEXTRANGE, 0, (LPARAM)&tr);
		sWord.ReleaseBuffer();
#endif   // UNICODE || _UNICODE
	}
	else
	{
		sWord.Empty();
	}

	// else
	return !sWord.IsEmpty();
}
Esempio n. 14
0
UINT CWnd::GetDlgItemText(int nIDDlgItem,CStringA& str) const
{
	HWND hCtrl=::GetDlgItem(m_hWnd,nIDDlgItem);
	UINT len=(UINT)::SendMessage(hCtrl,WM_GETTEXTLENGTH,0,0);
	::SendMessage(hCtrl,WM_GETTEXT,len+1,(LPARAM)str.GetBuffer(len));
	return len;
}
Esempio n. 15
0
BSTR CBoxEncoding::Base64Encode(VARIANT& var)
{
	CBoxBinPtr varPtr(var);
	CStringA str;
	LPSTR pstr;
	int strSize;
	int nPos, i;

	strSize = ((varPtr.m_nSize + 2) / 3) * 4;
	strSize += (strSize / 64) * 2;
	pstr = str.GetBuffer(strSize);

	for(i = 0, nPos = 0; i < varPtr.m_nSize; i += 48)
		if(varPtr.m_nSize - i > 48)
		{
			EVP_EncodeBlock((unsigned char*)pstr + nPos, (unsigned char*)varPtr + i, 48);
			nPos += 64;
			pstr[nPos ++] = '\r';
			pstr[nPos ++] = '\n';
		}else
			EVP_EncodeBlock((unsigned char*)pstr + nPos, (unsigned char*)varPtr + i, varPtr.m_nSize - i);

	str.ReleaseBuffer(strSize);
	return str.AllocSysString();
}
Esempio n. 16
0
CStringW DecodeDoubleEncodedUtf8(LPCWSTR pszFileName)
{
    size_t nChars = wcslen(pszFileName);

    // Check if all characters are valid for UTF-8 value range
    //
    for (UINT i = 0; i < nChars; i++) {
        if ((_TUCHAR)pszFileName[i] > 0xFFU)
            return pszFileName; // string is already using Unicode character value range; return original
    }

    // Transform Unicode string to UTF-8 byte sequence
    //
    CStringA strA;
#pragma warning(disable : 4267)
    LPSTR pszA = strA.GetBuffer(nChars);

    for (UINT i = 0; i < nChars; i++)
        pszA[i] = (CHAR)pszFileName[i];
    strA.ReleaseBuffer(nChars);

    // Decode the string with UTF-8
    //
    CStringW strW;
    LPWSTR pszW = strW.GetBuffer(nChars);
    int iNewChars = utf8towc(strA, nChars, pszW, nChars);
#pragma warning(disable : 4267)
    if (iNewChars < 0) {
        strW.ReleaseBuffer(0);
        return pszFileName;		// conversion error (not a valid UTF-8 string); return original
    }
    strW.ReleaseBuffer(iNewChars);

    return strW;
}
Esempio n. 17
0
void FindString(string str){
	int i;
	int l=str.length();
	int z1=str.find(course.GetBuffer(0));
	if (z1==-1) return;
	//for(i=0;i<=30;i++) s1[i]=str[z1+i]; s1[i+1]='\0';
    int z2=str.find("style1",z1);
	z2=str.find("style1",z2+10);
	z2=str.find("style1",z2+10);
	z2+=9;
	//for(i=0;i<=5;i++) s1[i]=str[z2+9+i]; s1[i+1]='\0';
	i=0;
	while(str[z2]>='0'&&str[z2]<='9') 
		{
			n1=n1*10+str[z2]-'0';
			z2++;
			//s1[i++]=str[z2++];
	}
	//s1[i]='\0';
	int z3=str.find("style1",z2);
	z3+=9;
	i=0;
	while(str[z3]>='0'&&str[z3]<='9') 
		{
			n2=n2*10+str[z3]-'0';
			z3++;
			//s2[i++]=str[z3++];
	}
	//s2[i]='\0';

}
Esempio n. 18
0
bool CStringUtils::ReadStringFromTextFile(const CString& path, CString& text)
{
	if (!PathFileExists(path))
		return false;
	try
	{
		CStdioFile file;
		// w/o typeBinary for some files \r gets dropped
		if (!file.Open(path, CFile::typeBinary | CFile::modeRead | CFile::shareDenyWrite))
			return false;

		CStringA filecontent;
		UINT filelength = (UINT)file.GetLength();
		int bytesread = (int)file.Read(filecontent.GetBuffer(filelength), filelength);
		filecontent.ReleaseBuffer(bytesread);
		text = CUnicodeUtils::GetUnicode(filecontent);
		file.Close();
	}
	catch (CFileException* pE)
	{
		text.Empty();
		pE->Delete();
	}
	return true;
}
Esempio n. 19
0
CStringA ConvertUnicodeToString(LPCWSTR pSrc)
{
	CStringA strResult;
	UINT nCodePage = CP_GB18030;
	if (!IsValidCodePage(CP_GB18030))
	{
		nCodePage = _AtlGetConversionACP();
	}
	int iBytes = ::WideCharToMultiByte(nCodePage, 0, pSrc, -1, NULL, 0, NULL, NULL);
	if (iBytes)
	{
		iBytes = ::WideCharToMultiByte(nCodePage, 0, pSrc, -1, strResult.GetBuffer(iBytes), iBytes, NULL, NULL);
		strResult.GetBuffer()[iBytes] = 0;
		strResult.ReleaseBufferSetLength(iBytes);
	}
	return strResult;
}
Esempio n. 20
0
BOOL CSNMP::Init(LPCWSTR pAddress, LPCWSTR pCommunity, INT nTimeoutMilliSec, INT nRetry)
{
	if (!pAddress)
		return FALSE;

	if (!pCommunity)
		return FALSE;

	CStringA strAddress = XLibS::StringCode::ConvertWideStrToAnsiStr(pAddress);
	CStringA strCommunity = XLibS::StringCode::ConvertWideStrToAnsiStr(pCommunity);

	m_SnmpSession = 
		::SnmpMgrOpen(strAddress.GetBuffer(), strCommunity.GetBuffer(), nTimeoutMilliSec, nRetry);
	strAddress.ReleaseBuffer();
	strCommunity.ReleaseBuffer();

	return m_SnmpSession != NULL;
}
Esempio n. 21
0
CString PjToStr(const pj_str_t* str, BOOL utf)
{
	CStringA rab;
	rab.Format("%.*s", str->slen, str->ptr);
	if (utf)
	{
#ifdef _UNICODE
		WCHAR* msg;
		Utf8DecodeCP(rab.GetBuffer(), CP_ACP, &msg);
		return msg;
#else
		return Utf8DecodeCP(rab.GetBuffer(), CP_ACP, NULL);
#endif
	} else 
	{
		return CString(rab);
	}
}
Esempio n. 22
0
BOOL CStdioFileT::ReadString(CStringA& rString)
{
	ASSERT_VALID(this);

#ifndef afxChNil
	static TCHAR afxChNil = '\0';
#endif

	rString = &afxChNil;    // empty string without deallocating
	const int nMaxSize = 128;
	LPSTR lpsz = rString.GetBuffer(nMaxSize);
	LPSTR lpszResult;
	int nLen = 0;
	for (;;)
	{
		lpszResult = fgets(lpsz, nMaxSize+1, m_pStream);
		rString.ReleaseBuffer();

		// handle error/eof case
		if (lpszResult == NULL && !feof(m_pStream))
		{
			clearerr(m_pStream);
			AfxThrowFileException(CFileException::genericException, _doserrno,
				m_strFileName);
		}

		// if string is read completely or EOF
		if (lpszResult == NULL ||
			(nLen = (int)strlen(lpsz)) < nMaxSize ||
			lpsz[nLen-1] == '\n')
			break;

		nLen = rString.GetLength();
		lpsz = rString.GetBuffer(nMaxSize + nLen) + nLen;
	}

	// remove '\n' from end of string if present
	lpsz = rString.GetBuffer(0);
	nLen = rString.GetLength();
	if (nLen != 0 && lpsz[nLen-1] == '\n')
		rString.GetBufferSetLength(nLen-1);

	return lpszResult != NULL;
}
Esempio n. 23
0
int CGit::UnsetConfigValue(CString key, CONFIG_TYPE type, int encoding, CString *GitPath)
{
	if(this->m_IsUseGitDLL)
	{
		CAutoLocker lock(g_Git.m_critGitDllSec);

		try
		{
			CheckAndInitDll();
		}catch(...)
		{
		}
		CStringA keya;
		keya = CUnicodeUtils::GetMulti(key, CP_UTF8);
		CStringA p;
		if(GitPath)
			p=CUnicodeUtils::GetMulti(*GitPath,CP_ACP);

		return get_set_config(keya.GetBuffer(), NULL, type, p.GetBuffer());
	}
	else
	{
		CString cmd;
		CString option;
		switch(type)
		{
		case CONFIG_GLOBAL:
			option = _T("--global");
			break;
		case CONFIG_SYSTEM:
			option = _T("--system");
			break;
		default:
			break;
		}
		cmd.Format(_T("git.exe config %s --unset %s"), option, key);
		CString out;
		if (Run(cmd, &out, NULL, encoding))
		{
			return -1;
		}
	}
	return 0;
}
CString CSettingGitCredential::Load(CString key)
{
	CString cmd;

	if (m_strUrl.IsEmpty())
		cmd.Format(_T("credential.%s"), key);
	else
		cmd.Format(_T("credential.%s.%s"), m_strUrl, key);

	git_config * config;
	git_config_new(&config);
	int sel = m_ctrlConfigType.GetCurSel();
	if (sel == ConfigType::Local)
	{
		CStringA projectConfigA = CUnicodeUtils::GetUTF8(g_Git.GetGitLocalConfig());
		git_config_add_file_ondisk(config, projectConfigA.GetBuffer(), GIT_CONFIG_LEVEL_LOCAL, FALSE);
		projectConfigA.ReleaseBuffer();
	}
	else if (sel == ConfigType::Global)
	{
		CStringA globalConfigA = CUnicodeUtils::GetUTF8(g_Git.GetGitGlobalConfig());
		git_config_add_file_ondisk(config, globalConfigA.GetBuffer(), GIT_CONFIG_LEVEL_GLOBAL, FALSE);
		globalConfigA.ReleaseBuffer();
		CStringA globalXDGConfigA = CUnicodeUtils::GetUTF8(g_Git.GetGitGlobalXDGConfig());
		git_config_add_file_ondisk(config, globalXDGConfigA.GetBuffer(), GIT_CONFIG_LEVEL_XDG, FALSE);
		globalXDGConfigA.ReleaseBuffer();
	}
	else if (sel == ConfigType::System)
	{
		CStringA systemConfigA = CUnicodeUtils::GetUTF8(g_Git.GetGitSystemConfig());
		git_config_add_file_ondisk(config, systemConfigA.GetBuffer(), GIT_CONFIG_LEVEL_SYSTEM, FALSE);
		systemConfigA.ReleaseBuffer();
	}
	
	CStringA cmdA = CUnicodeUtils::GetUTF8(cmd);
	CStringA valueA;
	const git_config_entry *entry;
	if (!git_config_get_entry(&entry, config, cmdA))
		valueA = CStringA(entry->value);
	cmdA.ReleaseBuffer();
	git_config_free(config);

	return CUnicodeUtils::GetUnicode(valueA);
}
Esempio n. 25
0
int CGit::GetRemoteList(STRING_VECTOR &list)
{
	if (this->m_IsUseLibGit2)
	{
		git_repository *repo = NULL;

		CStringA gitdir = CUnicodeUtils::GetMulti(CTGitPath(m_CurrentDir).GetGitPathString(), CP_UTF8);
		if (git_repository_open(&repo, gitdir.GetBuffer()))
		{
			gitdir.ReleaseBuffer();
			return -1;
		}
		gitdir.ReleaseBuffer();

		git_strarray remotes;

		if (git_remote_list(&remotes, repo))
		{
			git_repository_free(repo);
			return -1;
		}

		for (size_t i = 0; i < remotes.count; i++)
		{
			CStringA remote(remotes.strings[i]);
			list.push_back(CUnicodeUtils::GetUnicode(remote));
		}

		git_strarray_free(&remotes);

		git_repository_free(repo);

		std::sort(list.begin(), list.end());

		return 0;
	}
	else
	{
		int ret;
		CString cmd, output;
		cmd=_T("git.exe remote");
		ret = Run(cmd, &output, NULL, CP_UTF8);
		if(!ret)
		{
			int pos=0;
			CString one;
			while( pos>=0 )
			{
				one=output.Tokenize(_T("\n"),pos);
				if (!one.IsEmpty())
					list.push_back(one);
			}
		}
		return ret;
	}
}
Esempio n. 26
0
static CStringW Unzip_GetCurentFilePath(unzFile uf, FILETIME& ftLocal)
{
    unz_file_info file_info;
    CStringA pathA;
    const int pathLen = 256;
    if (UNZ_OK != unzGetCurrentFileInfo(uf, &file_info, pathA.GetBuffer(pathLen), pathLen, NULL, 0, NULL, 0))
        throw runtime_error("failed to unzGetCurrentFileInfo");
    pathA.ReleaseBuffer(-1);
    DosDateTimeToFileTime((WORD)(file_info.dosDate>>16), (WORD)file_info.dosDate, &ftLocal);
    return CStringW(pathA);
}
Esempio n. 27
0
int GitRev::GetCommit(const CString& refname)
{
	if (g_Git.UsingLibGit2(CGit::GIT_CMD_GET_COMMIT))
	{
		CAutoRepository repo(g_Git.GetGitRepository());
		if (!repo)
		{
			m_sErr = g_Git.GetLibGit2LastErr();
			return -1;
		}
		return GetCommit(repo, refname);
	}

	CAutoLocker lock(g_Git.m_critGitDllSec);

	try
	{
		g_Git.CheckAndInitDll();
	}
	catch (char* msg)
	{
		m_sErr = L"Could not initiate libgit.\nlibgit reports:\n" + CString(msg);
		return -1;
	}

	if(refname.GetLength() >= 8)
		if (refname.GetLength() >= 8 && wcsncmp(refname, GitRev::GetWorkingCopy(), refname.GetLength()) == 0)
		{
			this->m_CommitHash.Empty();
			this->m_Subject = L"Working Tree";
			m_sErr.Empty();
			return 0;
		}
	CStringA rev;
	rev= CUnicodeUtils::GetUTF8(g_Git.FixBranchName(refname));
	GIT_HASH sha;

	try
	{
		if (git_get_sha1(rev.GetBuffer(), sha))
		{
			m_sErr = L"Could not get SHA-1 of ref \"" + g_Git.FixBranchName(refname);
			return -1;
		}
	}
	catch (char * msg)
	{
		m_sErr = L"Could not get SHA-1 of ref \"" + g_Git.FixBranchName(refname) + L"\".\nlibgit reports:\n" + CString(msg);
		return -1;
	}

	CGitHash hash(sha);
	return GetCommitFromHash_withoutLock(hash);
}
Esempio n. 28
0
CStringA netbios_name::GetANSIName() const
{
	CStringA sName;
	LPSTR szName = sName.GetBuffer( NCBNAMSZ );
	CopyMemory( szName, (LPCSTR)netbiosed.name, NCBNAMSZ - 1 );
	szName[ NCBNAMSZ - 1 ] = 0;
	sName.ReleaseBuffer();
	sName.Trim();
	sName.OemToAnsi();
	return sName;
}
Esempio n. 29
0
CStringA Util::String::UnicodeToGBK( CStringW unicode )
{
	CStringA strGBK = "";
	DWORD dwMinSize = 0;
	dwMinSize = WideCharToMultiByte(936, NULL, unicode, unicode.GetLength(),NULL, 0, NULL, FALSE);
	strGBK.GetBufferSetLength(dwMinSize);
	LPSTR lpszStr =  strGBK.GetBuffer();
	INT ok = WideCharToMultiByte(936, NULL, unicode, unicode.GetLength(), lpszStr, dwMinSize, NULL, FALSE);
	strGBK.ReleaseBuffer();
	return strGBK;
}
Esempio n. 30
0
CStringA CTime::FormatGmt(LPCSTR pFormat) const
{
	CStringA str;
	struct tm Time;
	if (gmtime_s(&Time,&m_time))
		return szEmpty;

	strftime(str.GetBuffer(1000),1000,pFormat,&Time);
	str.FreeExtra();
	return str;
}