예제 #1
1
void CCheckForUpdatesDlg::FillChangelog(CAutoConfig& versioncheck, bool official)
{
	ProjectProperties pp;
	pp.lProjectLanguage = -1;
	if (versioncheck.GetString(_T("tortoisegit.issuesurl"), pp.sUrl))
		pp.sUrl = _T("https://tortoisegit.org/issue/%BUGID%");
	if (!pp.sUrl.IsEmpty())
	{
		pp.SetCheckRe(_T("[Ii]ssues?:?(\\s*(,|and)?\\s*#?\\d+)+"));
		pp.SetBugIDRe(_T("(\\d+)"));
	}
	m_cLogMessage.Init(pp);

	CString sChangelogURL;
	versioncheck.GetString(_T("TortoiseGit.changelogurl"), sChangelogURL);
	if (sChangelogURL.IsEmpty())
		sChangelogURL = _T("https://versioncheck.tortoisegit.org/changelog.txt");
	else
	{
		CString tmp(sChangelogURL);
		sChangelogURL.FormatMessage(tmp, TGIT_VERMAJOR, TGIT_VERMINOR, TGIT_VERMICRO, m_updateDownloader->m_sWindowsPlatform, m_updateDownloader->m_sWindowsVersion, m_updateDownloader->m_sWindowsServicePack);
	}

	CString tempchangelogfile = CTempFiles::Instance().GetTempFilePath(true).GetWinPathString();
	DWORD err;
	if ((err = m_updateDownloader->DownloadFile(sChangelogURL, tempchangelogfile, false)) != ERROR_SUCCESS)
	{
		CString msg = _T("Could not load changelog.\r\nError: ") + GetWinINetError(err) + _T(" (on ") + sChangelogURL + _T(")");
		::SendMessage(m_hWnd, WM_USER_FILLCHANGELOG, 0, reinterpret_cast<LPARAM>((LPCTSTR)msg));
		return;
	}
	if (official)
	{
		CString signatureTempfile = CTempFiles::Instance().GetTempFilePath(true).GetWinPathString();
		if ((err = m_updateDownloader->DownloadFile(sChangelogURL + SIGNATURE_FILE_ENDING, signatureTempfile, false)) != ERROR_SUCCESS || VerifyIntegrity(tempchangelogfile, signatureTempfile, m_updateDownloader))
		{
			CString error = _T("Could not verify digital signature.");
			if (err)
				error += _T("\r\nError: ") + GetWinINetError(err) + _T(" (on ") + sChangelogURL + SIGNATURE_FILE_ENDING + _T(")");
			::SendMessage(m_hWnd, WM_USER_FILLCHANGELOG, 0, reinterpret_cast<LPARAM>((LPCTSTR)error));
			DeleteUrlCacheEntry(sChangelogURL);
			DeleteUrlCacheEntry(sChangelogURL + SIGNATURE_FILE_ENDING);
			return;
		}
	}

	CString temp;
	CStdioFile file;
	if (file.Open(tempchangelogfile, CFile::modeRead | CFile::typeBinary))
	{
		auto buf = std::make_unique<BYTE[]>((UINT)file.GetLength());
		UINT read = file.Read(buf.get(), (UINT)file.GetLength());
		bool skipBom = read >= 3 && buf[0] == 0xEF && buf[1] == 0xBB && buf[2] == 0xBF;
		CGit::StringAppend(&temp, buf.get() + (skipBom ? 3 : 0), CP_UTF8, read - (skipBom ? 3 : 0));
	}
	else
		temp = _T("Could not open downloaded changelog file.");
	::SendMessage(m_hWnd, WM_USER_FILLCHANGELOG, 0, reinterpret_cast<LPARAM>((LPCTSTR)temp));
}
예제 #2
0
void CSettingGitConfig::LoadDataImpl(CAutoConfig& config)
{
	m_bInheritSigningKey = (config.GetString(_T("user.signingkey"), m_UserSigningKey) == GIT_ENOTFOUND);

	// special handling for UserName and UserEmail, because these can also be defined as environment variables for effective settings
	if (m_iConfigSource == CFG_SRC_EFFECTIVE)
	{
		m_UserName = g_Git.GetUserName();
		m_UserEmail = g_Git.GetUserEmail();
		m_bInheritUserName = FALSE;
		m_bInheritEmail = FALSE;
		m_bInheritSigningKey = FALSE;
	}
	else
	{
		m_bInheritUserName = (config.GetString(_T("user.name"), m_UserName) == GIT_ENOTFOUND);
		m_bInheritEmail = (config.GetString(_T("user.email"), m_UserEmail) == GIT_ENOTFOUND);
	}

	if (git_config_get_bool(&m_bAutoCrlf, config, "core.autocrlf") == GIT_ENOTFOUND)
		m_bAutoCrlf = BST_INDETERMINATE;

	if (git_config_get_bool(&m_bQuotePath, config, "core.quotepath") == GIT_ENOTFOUND)
	{
		if (m_iConfigSource == CFG_SRC_EFFECTIVE)
			m_bQuotePath = BST_CHECKED;
		else
			m_bQuotePath = BST_INDETERMINATE;
	}

	BOOL bSafeCrLf = FALSE;
	if (git_config_get_bool(&bSafeCrLf, config, "core.safecrlf") == GIT_ENOTFOUND)
		m_cSafeCrLf.SetCurSel(0);
	else if (bSafeCrLf)
		m_cSafeCrLf.SetCurSel(2);
	else
	{
		CString sSafeCrLf;
		config.GetString(_T("core.safecrlf"), sSafeCrLf);
		sSafeCrLf = sSafeCrLf.MakeLower().Trim();
		if (sSafeCrLf == _T("warn"))
			m_cSafeCrLf.SetCurSel(3);
		else
			m_cSafeCrLf.SetCurSel(1);
	}

	m_bNeedSave = false;
	SetModified(FALSE);
	UpdateData(FALSE);
}
예제 #3
0
static void StorePuttyKey(const CString& repoRoot, const CString& remote, const CString& keyFile)
{
	CAutoRepository repo(repoRoot);
	CAutoConfig config;
	CString configName;
	if (!repo)
		goto error;

	if (git_repository_config(config.GetPointer(), repo))
		goto error;

	configName.Format(_T("remote.%s.puttykeyfile"), (LPCTSTR)remote);

	if (git_config_set_string(config, CUnicodeUtils::GetUTF8(configName), CUnicodeUtils::GetUTF8(keyFile)))
		goto error;

	return;

error:
	MessageBox(hWndExplorer, CGit::GetLibGit2LastErr(L"Could not open repository"), _T("TortoiseGit"), MB_ICONERROR);
}
예제 #4
0
TEST(libgit2, TGitPatches)
{
	CAutoTempDir tempdir;

	git_repository_init_options options = GIT_REPOSITORY_INIT_OPTIONS_INIT;
	options.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE;
	CAutoRepository repo;
	ASSERT_EQ(0, git_repository_init_ext(repo.GetPointer(), CUnicodeUtils::GetUTF8(tempdir.GetTempDir()), &options));

	CAutoConfig config;
	ASSERT_EQ(0, git_repository_config(config.GetPointer(), repo));
	EXPECT_EQ(0, git_config_set_string(config, "core.autocrlf", "true"));
	EXPECT_EQ(0, git_config_set_string(config, "core.safecrlf", "true"));

	CAutoRepository repo2(tempdir.GetTempDir());
	ASSERT_TRUE(repo2.IsValid());
	CAutoIndex index;
	ASSERT_EQ(0, git_repository_index(index.GetPointer(), repo2));

	CString testFile = tempdir.GetTempDir() + L"\\safecrlf-failure.txt";
	EXPECT_TRUE(CStringUtils::WriteStringToTextFile(testFile, L"crlf\r\ncrlf\r\n"));
	EXPECT_EQ(0, git_index_add_bypath(index, "safecrlf-failure.txt"));

	EXPECT_TRUE(CStringUtils::WriteStringToTextFile(testFile, L"lf\nlf\n"));
	EXPECT_EQ(-1, git_index_add_bypath(index, "safecrlf-failure.txt"));

	EXPECT_TRUE(CStringUtils::WriteStringToTextFile(testFile, L"crlf\r\ncr\rcrlf\r\n"));
	EXPECT_EQ(0, git_index_add_bypath(index, "safecrlf-failure.txt"));

	EXPECT_EQ(0, git_config_set_string(config, "core.autocrlf", "input"));
	CAutoRepository repo3(tempdir.GetTempDir());
	ASSERT_TRUE(repo3.IsValid());
	ASSERT_EQ(0, git_repository_index(index.GetPointer(), repo3));

	EXPECT_TRUE(CStringUtils::WriteStringToTextFile(testFile, L"crlf\r\ncrlf\r\n"));
	EXPECT_EQ(-1, git_index_add_bypath(index, "safecrlf-failure.txt"));
}
예제 #5
0
void CCheckForUpdatesDlg::FillDownloads(CAutoConfig& versioncheck, const CString version)
{
#if WIN64
	const CString x86x64 = _T("64");
#else
	const CString x86x64 = _T("32");
#endif

	versioncheck.GetString(_T("tortoisegit.baseurl"), m_sFilesURL);
	if (m_sFilesURL.IsEmpty())
		m_sFilesURL.Format(_T("http://updater.download.tortoisegit.org/tgit/%s/"), (LPCTSTR)version);

	bool isHotfix = false;
	versioncheck.GetBool(_T("tortoisegit.hotfix"), isHotfix);

	if (isHotfix)
		m_ctrlFiles.InsertItem(0, _T("TortoiseGit Hotfix"));
	else
		m_ctrlFiles.InsertItem(0, _T("TortoiseGit"));
	CString filenameMain, filenamePattern;
	versioncheck.GetString(_T("tortoisegit.mainfilename"), filenamePattern);
	if (filenamePattern.IsEmpty())
		filenamePattern = _T("TortoiseGit-%1!s!-%2!s!bit.msi");
	filenameMain.FormatMessage(filenamePattern, version, x86x64);
	m_ctrlFiles.SetItemData(0, (DWORD_PTR)(new CUpdateListCtrl::Entry(filenameMain, CUpdateListCtrl::STATUS_NONE)));
	m_ctrlFiles.SetCheck(0 , TRUE);

	if (isHotfix)
	{
		DialogEnableWindow(IDC_BUTTON_UPDATE, TRUE);
		return;
	}

	struct LangPack
	{
		CString m_PackName;
		CString m_LangName;
		DWORD m_LocaleID;
		CString m_LangCode;
		bool m_Installed;
	};
	struct LanguagePacks
	{
		std::vector<LangPack> availableLangs;
		std::vector<DWORD> installedLangs;
	} languagePacks;
	{
		// set up the language selecting combobox
		CString path = CPathUtils::GetAppParentDirectory();
		path = path + _T("Languages\\");
		CSimpleFileFind finder(path, _T("*.dll"));
		while (finder.FindNextFileNoDirectories())
		{
			CString file = finder.GetFilePath();
			CString filename = finder.GetFileName();
			if (filename.Left(12).CompareNoCase(_T("TortoiseProc")) == 0)
			{
				CString sVer = _T(STRPRODUCTVER);
				sVer = sVer.Left(sVer.ReverseFind('.'));
				CString sFileVer = CPathUtils::GetVersionFromFile(file);
				sFileVer = sFileVer.Left(sFileVer.ReverseFind('.'));
				CString sLoc = filename.Mid(12);
				sLoc = sLoc.Left(sLoc.GetLength() - 4); // cut off ".dll"
				if ((sLoc.Left(2) == L"32") && (sLoc.GetLength() > 5))
					continue;
				DWORD loc = _tstoi(filename.Mid(12));
				languagePacks.installedLangs.push_back(loc);
			}
		}
	}

	git_config_get_multivar_foreach(versioncheck, "tortoisegit.langs", nullptr, [](const git_config_entry* configentry, void* payload) -> int
	{
		LanguagePacks* languagePacks = (LanguagePacks*)payload;
		CString langs = CUnicodeUtils::GetUnicode(configentry->value);

		int nextTokenPos = langs.Find(_T(";"), 5); // be extensible for the future
		if (nextTokenPos > 0)
			langs = langs.Left(nextTokenPos);
		CString sLang = _T("TortoiseGit Language Pack ") + langs.Mid(5);

		DWORD loc = _tstoi(langs.Mid(0, 4));
		TCHAR buf[MAX_PATH] = { 0 };
		GetLocaleInfo(loc, LOCALE_SNATIVELANGNAME, buf, _countof(buf));
		CString sLang2(buf);
		GetLocaleInfo(loc, LOCALE_SNATIVECTRYNAME, buf, _countof(buf));
		if (buf[0])
		{
			sLang2 += _T(" (");
			sLang2 += buf;
			sLang2 += _T(")");
		}

		bool installed = std::find(languagePacks->installedLangs.cbegin(), languagePacks->installedLangs.cend(), loc) != languagePacks->installedLangs.cend();
		LangPack pack = { sLang, sLang2, loc, langs.Mid(5), installed };
		languagePacks->availableLangs.push_back(pack);

		return 0;
	}, &languagePacks);
	std::stable_sort(languagePacks.availableLangs.begin(), languagePacks.availableLangs.end(), [&](const LangPack& a, const LangPack& b) -> int
	{
		return (a.m_Installed && !b.m_Installed) ? 1 : (!a.m_Installed && b.m_Installed) ? 0 : (a.m_PackName.Compare(b.m_PackName) < 0);
	});
	filenamePattern.Empty();
	versioncheck.GetString(_T("tortoisegit.languagepackfilename"), filenamePattern);
	if (filenamePattern.IsEmpty())
		filenamePattern = _T("TortoiseGit-LanguagePack-%1!s!-%2!s!bit-%3!s!.msi");
	for (const auto& langs : languagePacks.availableLangs)
	{
		int pos = m_ctrlFiles.InsertItem(m_ctrlFiles.GetItemCount(), langs.m_PackName);
		m_ctrlFiles.SetItemText(pos, 1, langs.m_LangName);

		CString filename;
		filename.FormatMessage(filenamePattern, version, x86x64, langs.m_LangCode, langs.m_LocaleID);
		m_ctrlFiles.SetItemData(pos, (DWORD_PTR)(new CUpdateListCtrl::Entry(filename, CUpdateListCtrl::STATUS_NONE)));

		if (langs.m_Installed)
			m_ctrlFiles.SetCheck(pos , TRUE);
	}
	DialogEnableWindow(IDC_BUTTON_UPDATE, TRUE);
}
void CSettingsBugtraqConfig::LoadDataImpl(CAutoConfig& config)
{
	if (m_iConfigSource == 0)
	{
		// use project properties here, so that we correctly get the default values
		ProjectProperties props;
		props.ReadProps();
		m_URL = props.sUrl;
		m_Logregex = props.sCheckRe + _T("\n") + props.sBugIDRe;
		m_Label = props.sLabel;
		m_Message = props.sMessage;
		m_UUID32 = props.sProviderUuid;
		m_UUID64 = props.sProviderUuid64;
		m_Params = props.sProviderParams;
		// read legacy registry values
		CBugTraqAssociations bugtraq_associations;
		bugtraq_associations.Load(props.GetProviderUUID(), props.sProviderParams);
		CBugTraqAssociation bugtraq_association;
		if (bugtraq_associations.FindProvider(g_Git.m_CurrentDir, &bugtraq_association))
		{
#if _WIN64
			m_UUID64 = bugtraq_association.GetProviderClassAsString();
#else
			m_UUID32 = bugtraq_association.GetProviderClassAsString();
			if (m_UUID64.IsEmpty())
				m_UUID64 = m_UUID32;
#endif
			m_Params = bugtraq_association.GetParameters();
		}

		if (props.bAppend)
			m_cAppend.SetCurSel(1);
		else
			m_cAppend.SetCurSel(2);

		if (props.bNumber)
			m_cNumber.SetCurSel(1);
		else
			m_cNumber.SetCurSel(2);

		if (props.bWarnIfNoIssue)
			m_cWarningifnoissue.SetCurSel(1);
		else
			m_cWarningifnoissue.SetCurSel(2);

		m_bInheritURL = FALSE;
		m_bInheritMessage = FALSE;
		m_bInheritLabel = FALSE;
		m_bInheritLogregex = FALSE;
		m_bInheritParams = FALSE;
		m_bInheritUUID32 = FALSE;
		m_bInheritUUID64 = FALSE;
	}
	else
	{
		m_bInheritURL = (config.GetString(BUGTRAQPROPNAME_URL, m_URL) == GIT_ENOTFOUND);
		m_bInheritMessage = (config.GetString(BUGTRAQPROPNAME_MESSAGE, m_Message) == GIT_ENOTFOUND);
		m_bInheritLabel = (config.GetString(BUGTRAQPROPNAME_LABEL, m_Label) == GIT_ENOTFOUND);
		GetBoolConfigValueComboBox(config, BUGTRAQPROPNAME_NUMBER, m_cNumber);
		GetBoolConfigValueComboBox(config, BUGTRAQPROPNAME_APPEND, m_cAppend);
		GetBoolConfigValueComboBox(config, BUGTRAQPROPNAME_WARNIFNOISSUE, m_cWarningifnoissue);
		m_bInheritLogregex = (config.GetString(BUGTRAQPROPNAME_LOGREGEX, m_Logregex) == GIT_ENOTFOUND);
		m_bInheritParams = (config.GetString(BUGTRAQPROPNAME_PROVIDERPARAMS, m_Params) == GIT_ENOTFOUND);
		m_bInheritUUID32 = (config.GetString(BUGTRAQPROPNAME_PROVIDERUUID, m_UUID32) == GIT_ENOTFOUND);
		m_bInheritUUID64 = (config.GetString(BUGTRAQPROPNAME_PROVIDERUUID64, m_UUID64) == GIT_ENOTFOUND);
	}

	m_Logregex.Trim();
	m_Logregex.Replace(_T("\n"), _T("\r\n"));

	m_bNeedSave = false;
	SetModified(FALSE);
	UpdateData(FALSE);
}