bool SVNDiff::ShowUnifiedDiff(const CTSVNPath& url1, const SVNRev& rev1, const CTSVNPath& url2, const SVNRev& rev2, SVNRev peg, const CString& options, bool bIgnoreAncestry /* = false */, bool /*blame*/, bool bIgnoreProperties /* = true */) { CTSVNPath tempfile; if (UnifiedDiff(tempfile, url1, rev1, url2, rev2, peg, options, bIgnoreAncestry, bIgnoreProperties)) { CString title; CTSVNPathList list; list.AddPath(url1); list.AddPath(url2); if (url1.IsEquivalentTo(url2)) title.FormatMessage(IDS_SVNDIFF_ONEURL, (LPCTSTR)rev1.ToString(), (LPCTSTR)rev2.ToString(), (LPCTSTR)url1.GetUIFileOrDirectoryName()); else { CTSVNPath root = list.GetCommonRoot(); CString u1 = url1.GetUIPathString().Mid(root.GetUIPathString().GetLength()); CString u2 = url2.GetUIPathString().Mid(root.GetUIPathString().GetLength()); title.FormatMessage(IDS_SVNDIFF_TWOURLS, (LPCTSTR)rev1.ToString(), (LPCTSTR)u1, (LPCTSTR)rev2.ToString(), (LPCTSTR)u2); } return !!CAppUtils::StartUnifiedDiffViewer(tempfile.GetWinPathString(), title); } return false; }
void CHooks::AddErrorParam(CString& sCmd, const CString& error) { CTSVNPath tempPath; tempPath = CTempFiles::Instance().GetTempFilePath(true); CStringUtils::WriteStringToTextFile(tempPath.GetWinPath(), (LPCTSTR)error); AddParam(sCmd, tempPath.GetWinPathString()); }
void CHooks::AddCWDParam(CString& sCmd, const CTSVNPathList& pathList) { CTSVNPath curDir = pathList.GetCommonRoot().GetDirectory(); while (!curDir.IsEmpty() && !curDir.Exists()) curDir = curDir.GetContainingDirectory(); AddParam(sCmd, curDir.GetWinPathString()); }
CTSVNPath CHooks::AddMessageFileParam(CString& sCmd, const CString& message) { CTSVNPath tempPath; tempPath = CTempFiles::Instance().GetTempFilePath(true); CStringUtils::WriteStringToTextFile(tempPath.GetWinPath(), (LPCTSTR)message); AddParam(sCmd, tempPath.GetWinPathString()); return tempPath; }
CStringA CCachedDirectory::GetCacheKey(const CTSVNPath& path) { // All we put into the cache as a key is just the end portion of the pathname // There's no point storing the path of the containing directory for every item CString lastElement = path.GetWinPathString().Mid(m_directoryPath.GetWinPathString().GetLength()); return CUnicodeUtils::GetUTF8 (lastElement); }
bool CTSVNPath::IsAncestorOf(const CTSVNPath& possibleDescendant) const { possibleDescendant.EnsureBackslashPathSet(); EnsureBackslashPathSet(); bool bPathStringsEqual = ArePathStringsEqual(m_sBackslashPath, possibleDescendant.m_sBackslashPath.Left(m_sBackslashPath.GetLength())); if (m_sBackslashPath.GetLength() >= possibleDescendant.GetWinPathString().GetLength()) { return bPathStringsEqual; } return (bPathStringsEqual && ((possibleDescendant.m_sBackslashPath[m_sBackslashPath.GetLength()] == '\\')|| (m_sBackslashPath.GetLength()==3 && m_sBackslashPath[1]==':'))); }
// Receive a notification from a child that its status has changed void CCachedDirectory::UpdateChildDirectoryStatus(const CTSVNPath& childDir, svn_wc_status_kind childStatus) { CStringA winPath = CUnicodeUtils::GetUTF8 (childDir.GetWinPathString()); svn_wc_status_kind currentStatus = svn_wc_status_none; { AutoLocker lock(m_critSec); auto it = m_childDirectories.find(winPath); if (it == m_childDirectories.end()) return; // this is not a child, or at least not a child connected to the parent currentStatus = it->second; } if ((currentStatus != childStatus)||(!IsOwnStatusValid())) { SetChildStatus(winPath, childStatus); UpdateCurrentStatus(); } }
bool CHooks::ManualPreCommit( HWND hWnd, const CTSVNPathList& pathList, CString& message, DWORD& exitcode, CString& error ) { hookiterator it = FindItem(manual_precommit, pathList); if (it == end()) return false; if (!ApproveHook(hWnd, it)) return false; CString sCmd = it->second.commandline; AddPathParam(sCmd, pathList); CTSVNPath temppath = AddMessageFileParam(sCmd, message); AddCWDParam(sCmd, pathList); exitcode = RunScript(sCmd, pathList, error, it->second.bWait, it->second.bShow); if (!exitcode && !temppath.IsEmpty()) { CStringUtils::ReadStringFromTextFile(temppath.GetWinPathString(), message); } return true; }
UINT CRevertDlg::RevertThread() { InterlockedExchange(&m_bThreadRunning, TRUE); // get the status of all selected file/folders recursively // and show the ones which can be reverted to the user // in a list control. DialogEnableWindow(ID_OK, false); m_bCancelled = false; if (!m_RevertList.GetStatus(m_pathList)) { m_RevertList.SetEmptyString(m_RevertList.GetLastErrorMessage()); } m_RevertList.Show(SVNSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS | SVNSLC_SHOWDIRECTFILES | SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO | SVNSLC_SHOWNESTED, CTSVNPathList(), // do not select all files, only the ones the user has selected directly SVNSLC_SHOWDIRECTFILES | SVNSLC_SHOWADDED | SVNSLC_SHOWADDEDINADDED, true, true); CTSVNPath commonDir = m_RevertList.GetCommonDirectory(false); CAppUtils::SetWindowTitle(m_hWnd, commonDir.GetWinPathString(), m_sWindowTitle); if (m_RevertList.HasUnversionedItems()) { if (DWORD(CRegStdDWORD(L"Software\\TortoiseSVN\\UnversionedAsModified", FALSE))) { GetDlgItem(IDC_UNVERSIONEDITEMS)->ShowWindow(SW_SHOW); } else GetDlgItem(IDC_UNVERSIONEDITEMS)->ShowWindow(SW_HIDE); } else GetDlgItem(IDC_UNVERSIONEDITEMS)->ShowWindow(SW_HIDE); InterlockedExchange(&m_bThreadRunning, FALSE); RefreshCursor(); return 0; }
bool CHooks::CheckCommit(HWND hWnd, const CTSVNPathList& pathList, CString& message, DWORD& exitcode, CString& error) { exitcode = 0; hookiterator it = FindItem(check_commit_hook, pathList); if (it == end()) return false; if (!ApproveHook(hWnd, it)) { exitcode = 1; error.LoadString(IDS_ERR_HOOKNOTAPPROVED); return false; } CString sCmd = it->second.commandline; AddPathParam(sCmd, pathList); CTSVNPath temppath = AddMessageFileParam(sCmd, message); AddCWDParam(sCmd, pathList); exitcode = RunScript(sCmd, pathList, error, it->second.bWait, it->second.bShow); if (!exitcode && !temppath.IsEmpty()) { CStringUtils::ReadStringFromTextFile(temppath.GetWinPathString(), message); } return true; }
UINT CDeleteUnversionedDlg::StatusThread() { // get the status of all selected file/folders recursively // and show the ones which are unversioned/ignored to the user // in a list control. DialogEnableWindow(IDOK, false); m_bCancelled = false; if (!m_StatusList.GetStatus(m_pathList, false, true)) { m_StatusList.SetEmptyString(m_StatusList.GetLastErrorMessage()); } m_StatusList.Show(SVNSLC_SHOWUNVERSIONED | SVNSLC_SHOWIGNORED, CTSVNPathList(), SVNSLC_SHOWUNVERSIONED | SVNSLC_SHOWIGNORED, true, true); CTSVNPath commonDir = m_StatusList.GetCommonDirectory(false); CAppUtils::SetWindowTitle(m_hWnd, commonDir.GetWinPathString(), m_sWindowTitle); InterlockedExchange(&m_bThreadRunning, FALSE); RefreshCursor(); return 0; }
void ContainingDirectoryTest() { CTSVNPath testPath; testPath.SetFromWin(L"c:\\a\\b\\c\\d\\e"); CTSVNPath dir; dir = testPath.GetContainingDirectory(); ATLASSERT(dir.GetWinPathString() == L"c:\\a\\b\\c\\d"); dir = dir.GetContainingDirectory(); ATLASSERT(dir.GetWinPathString() == L"c:\\a\\b\\c"); dir = dir.GetContainingDirectory(); ATLASSERT(dir.GetWinPathString() == L"c:\\a\\b"); dir = dir.GetContainingDirectory(); ATLASSERT(dir.GetWinPathString() == L"c:\\a"); dir = dir.GetContainingDirectory(); ATLASSERT(dir.GetWinPathString() == L"c:\\"); dir = dir.GetContainingDirectory(); ATLASSERT(dir.IsEmpty()); ATLASSERT(dir.GetWinPathString().IsEmpty()); }
void CHooks::AddPathParam(CString& sCmd, const CTSVNPathList& pathList) { CTSVNPath temppath = CTempFiles::Instance().GetTempFilePath(true); pathList.WriteToFile(temppath.GetWinPathString(), true); AddParam(sCmd, temppath.GetWinPathString()); }
bool SyncCommand::Execute() { bool bRet = false; CRegString rSyncPath(L"Software\\TortoiseSVN\\SyncPath"); CTSVNPath syncPath = CTSVNPath(CString(rSyncPath)); CTSVNPath syncFolder = syncPath; CRegDWORD regCount(L"Software\\TortoiseSVN\\SyncCounter"); CRegDWORD regSyncAuth(L"Software\\TortoiseSVN\\SyncAuth"); bool bSyncAuth = DWORD(regSyncAuth) != 0; if (!cmdLinePath.IsEmpty()) syncPath = cmdLinePath; if (syncPath.IsEmpty() && !parser.HasKey(L"askforpath")) { return false; } syncPath.AppendPathString(L"tsvnsync.tsex"); BOOL bWithLocals = FALSE; if (parser.HasKey(L"askforpath")) { // ask for the path first, then for the password // this is used for a manual import/export CString path; bool bGotPath = FileOpenSave(path, bWithLocals, !!parser.HasKey(L"load"), GetExplorerHWND()); if (bGotPath) { syncPath = CTSVNPath(path); if (!parser.HasKey(L"load") && syncPath.GetFileExtension().IsEmpty()) syncPath.AppendRawString(L".tsex"); } else return false; } CSimpleIni iniFile; iniFile.SetMultiLine(true); SVNAuthData authData; CAutoRegKey hMainKey; RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\TortoiseSVN", 0, KEY_READ, hMainKey.GetPointer()); FILETIME filetime = { 0 }; RegQueryInfoKey(hMainKey, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &filetime); bool bCloudIsNewer = false; if (!parser.HasKey(L"save")) { // open the file in read mode CAutoFile hFile = CreateFile(syncPath.GetWinPathString(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile.IsValid()) { // load the file LARGE_INTEGER fsize = { 0 }; if (GetFileSizeEx(hFile, &fsize)) { auto filebuf = std::make_unique<char[]>(DWORD(fsize.QuadPart)); DWORD bytesread = 0; if (ReadFile(hFile, filebuf.get(), DWORD(fsize.QuadPart), &bytesread, NULL)) { // decrypt the file contents std::string encrypted; if (bytesread > 0) encrypted = std::string(filebuf.get(), bytesread); CRegString regPW(L"Software\\TortoiseSVN\\SyncPW"); CString password; if (parser.HasKey(L"askforpath") && parser.HasKey(L"load")) { INT_PTR dlgret = 0; bool bPasswordMatches = true; do { bPasswordMatches = true; CPasswordDlg passDlg(CWnd::FromHandle(GetExplorerHWND())); passDlg.m_bForSave = !!parser.HasKey(L"save"); dlgret = passDlg.DoModal(); password = passDlg.m_sPW1; if ((dlgret == IDOK) && (parser.HasKey(L"load"))) { std::string passworda = CUnicodeUtils::StdGetUTF8((LPCWSTR)password); std::string decrypted = CStringUtils::Decrypt(encrypted, passworda); if ((decrypted.size() < 3) || (decrypted.substr(0, 3) != "***")) { bPasswordMatches = false; } } } while ((dlgret == IDOK) && !bPasswordMatches); if (dlgret != IDOK) return false; } else { auto passwordbuf = CStringUtils::Decrypt(CString(regPW)); if (passwordbuf.get()) { password = passwordbuf.get(); } else { // password does not match or it couldn't be read from // the registry! // TaskDialog(GetExplorerHWND(), AfxGetResourceHandle(), MAKEINTRESOURCE(IDS_APPNAME), MAKEINTRESOURCE(IDS_ERR_ERROROCCURED), MAKEINTRESOURCE(IDS_SYNC_WRONGPASSWORD), TDCBF_OK_BUTTON, TD_ERROR_ICON, NULL); CString sCmd = L" /command:settings /page:21"; CAppUtils::RunTortoiseProc(sCmd); return false; } } std::string passworda = CUnicodeUtils::StdGetUTF8((LPCWSTR)password); std::string decrypted = CStringUtils::Decrypt(encrypted, passworda); if (decrypted.size() >= 3) { if (decrypted.substr(0, 3) == "***") { decrypted = decrypted.substr(3); // pass the decrypted data to the ini file iniFile.LoadFile(decrypted.c_str(), decrypted.size()); int inicount = _wtoi(iniFile.GetValue(L"sync", L"synccounter", L"")); if (inicount != 0) { if (int(DWORD(regCount)) < inicount) { bCloudIsNewer = true; regCount = inicount; } } // load the auth data, but do not overwrite already stored auth data! if (bSyncAuth) authData.ImportAuthData(syncFolder.GetWinPathString(), password); } else { CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Error decrypting, password may be wrong\n"); return false; } } } } } else { CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Error opening file %s, Error %u\n", syncPath.GetWinPath(), GetLastError()); auto lasterr = GetLastError(); if ((lasterr != ERROR_FILE_NOT_FOUND) && (lasterr != ERROR_PATH_NOT_FOUND)) return false; } } if (parser.HasKey(L"load")) bCloudIsNewer = true; if (parser.HasKey(L"save")) bCloudIsNewer = false; bool bHaveChanges = false; if (bWithLocals || parser.HasKey(L"local")) { // remove all blocks that are allowed for local exports for (const auto& allow : regBlockLocalArray) { regBlockArray.erase(std::remove(regBlockArray.begin(), regBlockArray.end(), allow), regBlockArray.end()); } } // go through all registry values and update either the registry // or the ini file, depending on which is newer for (const auto& regname : regUseArray) { bool bChanges = HandleRegistryKey(regname, iniFile, bCloudIsNewer); bHaveChanges = bHaveChanges || bChanges; } if (bWithLocals || parser.HasKey(L"local")) { for (const auto& regname : regUseLocalArray) { bool bChanges = HandleRegistryKey(regname, iniFile, bCloudIsNewer); bHaveChanges = bHaveChanges || bChanges; } } if (bCloudIsNewer) { CString regpath = L"Software\\"; CSimpleIni::TNamesDepend keys; iniFile.GetAllKeys(L"registry_dword", keys); for (const auto& k : keys) { CRegDWORD reg(regpath + k); reg = _wtol(iniFile.GetValue(L"registry_dword", k, L"")); } keys.clear(); iniFile.GetAllKeys(L"registry_qword", keys); for (const auto& k : keys) { CRegQWORD reg(regpath + k); reg = _wtoi64(iniFile.GetValue(L"registry_qword", k, L"")); } keys.clear(); iniFile.GetAllKeys(L"registry_string", keys); for (const auto& k : keys) { CRegString reg(regpath + k); reg = CString(iniFile.GetValue(L"registry_string", k, L"")); } } { // sync project monitor settings CString sDataFilePath = CPathUtils::GetAppDataDirectory(); sDataFilePath += L"\\MonitoringData.ini"; CSimpleIni monitorIni; monitorIni.SetMultiLine(true); if (bCloudIsNewer) { CSimpleIni origMonitorIni; origMonitorIni.SetMultiLine(true); origMonitorIni.LoadFile(sDataFilePath); CSimpleIni::TNamesDepend keys; iniFile.GetAllKeys(L"ini_monitor", keys); for (const auto& k : keys) { CString sKey = k; CString sSection = sKey.Left(sKey.Find('.')); sKey = sKey.Mid(sKey.Find('.') + 1); if (sKey.CompareNoCase(L"name") == 0) { // make sure the non-synced values are still used monitorIni.SetValue(sSection, L"lastchecked", origMonitorIni.GetValue(sSection, L"lastchecked", L"0")); monitorIni.SetValue(sSection, L"lastcheckedrobots", origMonitorIni.GetValue(sSection, L"lastcheckedrobots", L"0")); monitorIni.SetValue(sSection, L"lastHEAD", origMonitorIni.GetValue(sSection, L"lastHEAD", L"0")); monitorIni.SetValue(sSection, L"UnreadItems", origMonitorIni.GetValue(sSection, L"UnreadItems", L"0")); monitorIni.SetValue(sSection, L"unreadFirst", origMonitorIni.GetValue(sSection, L"unreadFirst", L"0")); monitorIni.SetValue(sSection, L"WCPathOrUrl", origMonitorIni.GetValue(sSection, L"WCPathOrUrl", L"")); } CString sValue = CString(iniFile.GetValue(L"ini_monitor", k, L"")); if ((sKey.Compare(L"username") == 0) || (sKey.Compare(L"password") == 0)) { sValue = CStringUtils::Encrypt(sValue); } monitorIni.SetValue(sSection, sKey, sValue); } FILE * pFile = NULL; errno_t err = 0; int retrycount = 5; CString sTempfile = CTempFiles::Instance().GetTempFilePathString(); do { err = _tfopen_s(&pFile, sTempfile, L"wb"); if ((err == 0) && pFile) { monitorIni.SaveFile(pFile); err = fclose(pFile); } if (err) { CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Error saving %s, retrycount %d\n", (LPCWSTR)sTempfile, retrycount); Sleep(500); } } while (err && retrycount--); if (err == 0) { if (!CopyFile(sTempfile, sDataFilePath, FALSE)) CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Error copying %s to %s, Error %u\n", (LPCWSTR)sTempfile, (LPCWSTR)sDataFilePath, GetLastError()); else { // now send a message to a possible running monitor to force it // to reload the ini file. Otherwise it would overwrite the ini // file without using the synced data! HWND hWnd = FindWindow(NULL, CString(MAKEINTRESOURCE(IDS_MONITOR_DLGTITLE))); if (hWnd) { UINT TSVN_COMMITMONITOR_RELOADINI = RegisterWindowMessage(L"TSVNCommitMonitor_ReloadIni"); PostMessage(hWnd, TSVN_COMMITMONITOR_RELOADINI, 0, 0); } } } } else { CSimpleIni::TNamesDepend mitems; if (PathFileExists(sDataFilePath)) { int retrycount = 5; SI_Error err = SI_OK; do { err = monitorIni.LoadFile(sDataFilePath); if (err == SI_FILE) { CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Error loading %s, retrycount %d\n", (LPCWSTR)sDataFilePath, retrycount); Sleep(500); } } while ((err == SI_FILE) && retrycount--); if (err == SI_FILE) { return false; } monitorIni.GetAllSections(mitems); } for (const auto& mitem : mitems) { CString sSection = mitem; CString Name = monitorIni.GetValue(mitem, L"Name", L""); if (!Name.IsEmpty()) { CString newval = monitorIni.GetValue(mitem, L"WCPathOrUrl", L""); iniFile.SetValue(L"ini_monitor", sSection + L".Name", Name); CString oldval = iniFile.GetValue(L"ini_monitor", sSection + L".WCPathOrUrl", L""); bHaveChanges |= ((newval != oldval) && (!oldval.IsEmpty())); // only save monitored working copies if local settings are included, or // if the monitored path is an url. // Don't save paths to working copies for non-local stores if (bWithLocals || newval.IsEmpty() || !PathIsDirectory(newval)) iniFile.SetValue(L"ini_monitor", sSection + L".WCPathOrUrl", newval); newval = monitorIni.GetValue(mitem, L"interval", L"5"); oldval = iniFile.GetValue(L"ini_monitor", sSection + L".interval", L"0"); bHaveChanges |= newval != oldval; iniFile.SetValue(L"ini_monitor", sSection + L".interval", newval); newval = monitorIni.GetValue(mitem, L"minminutesinterval", L"0"); oldval = iniFile.GetValue(L"ini_monitor", sSection + L".minminutesinterval", L"0"); bHaveChanges |= newval != oldval; iniFile.SetValue(L"ini_monitor", sSection + L".minminutesinterval", newval); newval = CStringUtils::Decrypt(monitorIni.GetValue(mitem, L"username", L"")).get(); oldval = iniFile.GetValue(L"ini_monitor", sSection + L".username", L""); bHaveChanges |= newval != oldval; iniFile.SetValue(L"ini_monitor", sSection + L".username", newval); newval = CStringUtils::Decrypt(monitorIni.GetValue(mitem, L"password", L"")).get(); oldval = iniFile.GetValue(L"ini_monitor", sSection + L".password", L""); bHaveChanges |= newval != oldval; iniFile.SetValue(L"ini_monitor", sSection + L".password", newval); newval = monitorIni.GetValue(mitem, L"MsgRegex", L""); oldval = iniFile.GetValue(L"ini_monitor", sSection + L".MsgRegex", L""); bHaveChanges |= newval != oldval; iniFile.SetValue(L"ini_monitor", sSection + L".MsgRegex", newval); newval = monitorIni.GetValue(mitem, L"ignoreauthors", L""); oldval = iniFile.GetValue(L"ini_monitor", sSection + L".ignoreauthors", L""); bHaveChanges |= newval != oldval; iniFile.SetValue(L"ini_monitor", sSection + L".ignoreauthors", newval); newval = monitorIni.GetValue(mitem, L"parentTreePath", L""); oldval = iniFile.GetValue(L"ini_monitor", sSection + L".parentTreePath", L""); bHaveChanges |= newval != oldval; iniFile.SetValue(L"ini_monitor", sSection + L".parentTreePath", newval); newval = monitorIni.GetValue(mitem, L"uuid", L""); oldval = iniFile.GetValue(L"ini_monitor", sSection + L".uuid", L""); bHaveChanges |= newval != oldval; iniFile.SetValue(L"ini_monitor", sSection + L".uuid", newval); newval = monitorIni.GetValue(mitem, L"root", L""); oldval = iniFile.GetValue(L"ini_monitor", sSection + L".root", L""); bHaveChanges |= newval != oldval; iniFile.SetValue(L"ini_monitor", sSection + L".root", newval); ProjectProperties ProjProps; ProjProps.LoadFromIni(monitorIni, sSection); ProjProps.SaveToIni(iniFile, L"ini_monitor", sSection + L".pp_"); } else if (sSection.CompareNoCase(L"global") == 0) { CString newval = monitorIni.GetValue(mitem, L"PlaySound", L"1"); CString oldval = iniFile.GetValue(L"ini_monitor", sSection + L".PlaySound", L"1"); bHaveChanges |= newval != oldval; iniFile.SetValue(L"ini_monitor", sSection + L".PlaySound", newval); newval = monitorIni.GetValue(mitem, L"ShowNotifications", L"1"); oldval = iniFile.GetValue(L"ini_monitor", sSection + L".ShowNotifications", L"1"); bHaveChanges |= newval != oldval; iniFile.SetValue(L"ini_monitor", sSection + L".ShowNotifications", newval); } } } } { // sync TortoiseMerge regex filters CSimpleIni regexIni; regexIni.SetMultiLine(true); CString sDataFilePath = CPathUtils::GetAppDataDirectory(); sDataFilePath += L"\\regexfilters.ini"; if (bCloudIsNewer) { CSimpleIni origRegexIni; if (PathFileExists(sDataFilePath)) { int retrycount = 5; SI_Error err = SI_OK; do { err = origRegexIni.LoadFile(sDataFilePath); if (err == SI_FILE) { CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Error loading %s, retrycount %d\n", (LPCWSTR)sDataFilePath, retrycount); Sleep(500); } } while ((err == SI_FILE) && retrycount--); if (err == SI_FILE) { return false; } } CSimpleIni::TNamesDepend keys; iniFile.GetAllKeys(L"ini_tmergeregex", keys); for (const auto& k : keys) { CString sKey = k; CString sSection = sKey.Left(sKey.Find('.')); sKey = sKey.Mid(sKey.Find('.') + 1); CString sValue = CString(iniFile.GetValue(L"ini_tmergeregex", k, L"")); regexIni.SetValue(sSection, sKey, sValue); } FILE * pFile = NULL; errno_t err = 0; int retrycount = 5; CString sTempfile = CTempFiles::Instance().GetTempFilePathString(); do { err = _tfopen_s(&pFile, sTempfile, L"wb"); if ((err == 0) && pFile) { regexIni.SaveFile(pFile); err = fclose(pFile); } if (err) { CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Error saving %s, retrycount %d\n", (LPCWSTR)sTempfile, retrycount); Sleep(500); } } while (err && retrycount--); if (err == 0) { if (!CopyFile(sTempfile, sDataFilePath, FALSE)) CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Error copying %s to %s, Error: %u\n", (LPCWSTR)sTempfile, (LPCWSTR)sDataFilePath, GetLastError()); } } else { if (PathFileExists(sDataFilePath)) { int retrycount = 5; SI_Error err = SI_OK; do { err = regexIni.LoadFile(sDataFilePath); if (err == SI_FILE) { CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Error loading %s, retrycount %d\n", (LPCWSTR)sDataFilePath, retrycount); Sleep(500); } } while ((err == SI_FILE) && retrycount--); if (err == SI_FILE) { return false; } } CSimpleIni::TNamesDepend mitems; regexIni.GetAllSections(mitems); for (const auto& mitem : mitems) { CString sSection = mitem; CString newval = regexIni.GetValue(mitem, L"regex", L""); CString oldval = iniFile.GetValue(L"ini_tmergeregex", sSection + L".regex", L""); bHaveChanges |= newval != oldval; iniFile.SetValue(L"ini_tmergeregex", sSection + L".regex", newval); newval = regexIni.GetValue(mitem, L"replace", L"5"); oldval = iniFile.GetValue(L"ini_tmergeregex", sSection + L".replace", L"0"); bHaveChanges |= newval != oldval; iniFile.SetValue(L"ini_tmergeregex", sSection + L".replace", newval); } } } if (bHaveChanges) { iniFile.SetValue(L"sync", L"version", TSVN_SYNC_VERSION_STR); DWORD count = regCount; ++count; regCount = count; CString tmp; tmp.Format(L"%lu", count); iniFile.SetValue(L"sync", L"synccounter", tmp); // save the ini file std::string iniData; iniFile.SaveString(iniData); iniData = "***" + iniData; // encrypt the string CString password; if (parser.HasKey(L"askforpath")) { CPasswordDlg passDlg(CWnd::FromHandle(GetExplorerHWND())); passDlg.m_bForSave = true; if (passDlg.DoModal() != IDOK) return false; password = passDlg.m_sPW1; } else { CRegString regPW(L"Software\\TortoiseSVN\\SyncPW"); auto passwordbuf = CStringUtils::Decrypt(CString(regPW)); if (passwordbuf.get()) { password = passwordbuf.get(); } } std::string passworda = CUnicodeUtils::StdGetUTF8((LPCWSTR)password); std::string encrypted = CStringUtils::Encrypt(iniData, passworda); CPathUtils::MakeSureDirectoryPathExists(syncPath.GetContainingDirectory().GetWinPathString()); CString sTempfile = CTempFiles::Instance().GetTempFilePathString(); CAutoFile hFile = CreateFile(sTempfile, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile.IsValid()) { DWORD written = 0; if (WriteFile(hFile, encrypted.c_str(), DWORD(encrypted.size()), &written, NULL)) { if (hFile.CloseHandle()) { if (!CopyFile(sTempfile, syncPath.GetWinPath(), FALSE)) { CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Error copying %s to %s, Error: %u\n", (LPCWSTR)sTempfile, syncPath.GetWinPath(), GetLastError()); } else bRet = true; } else CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Error closing file %s, Error: %u\n", (LPCWSTR)sTempfile, GetLastError()); } else CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Error writing to file %s, Error: %u\n", (LPCWSTR)sTempfile, GetLastError()); } else CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Error creating file %s for writing, Error: %u\n", (LPCWSTR)sTempfile, GetLastError()); if (bSyncAuth) { // now save all auth data CPathUtils::MakeSureDirectoryPathExists(syncFolder.GetWinPathString() + L"\\auth"); CPathUtils::MakeSureDirectoryPathExists(syncFolder.GetWinPathString() + L"\\auth\\svn.simple"); CPathUtils::MakeSureDirectoryPathExists(syncFolder.GetWinPathString() + L"\\auth\\svn.ssl.client-passphrase"); CPathUtils::MakeSureDirectoryPathExists(syncFolder.GetWinPathString() + L"\\auth\\svn.ssl.server"); CPathUtils::MakeSureDirectoryPathExists(syncFolder.GetWinPathString() + L"\\auth\\svn.username"); authData.ExportAuthData(syncFolder.GetWinPathString(), password); } } return bRet; }
bool SVNDiff::DiffProps(const CTSVNPath& filePath, const SVNRev& rev1, const SVNRev& rev2, svn_revnum_t &baseRev) const { bool retvalue = false; // diff the properties SVNProperties propswc(filePath, rev1, false, false); SVNProperties propsbase(filePath, rev2, false, false); #define MAX_PATH_LENGTH 80 WCHAR pathbuf1[MAX_PATH] = {0}; if (filePath.GetWinPathString().GetLength() >= MAX_PATH) { std::wstring str = filePath.GetWinPath(); std::wregex rx(L"^(\\w+:|(?:\\\\|/+))((?:\\\\|/+)[^\\\\/]+(?:\\\\|/)[^\\\\/]+(?:\\\\|/)).*((?:\\\\|/)[^\\\\/]+(?:\\\\|/)[^\\\\/]+)$"); std::wstring replacement = L"$1$2...$3"; std::wstring str2 = std::regex_replace(str, rx, replacement); if (str2.size() >= MAX_PATH) str2 = str2.substr(0, MAX_PATH-2); PathCompactPathEx(pathbuf1, str2.c_str(), MAX_PATH_LENGTH, 0); } else PathCompactPathEx(pathbuf1, filePath.GetWinPath(), MAX_PATH_LENGTH, 0); if ((baseRev == 0) && (!filePath.IsUrl()) && (rev1.IsBase() || rev2.IsBase())) { SVNStatus stat; CTSVNPath dummy; svn_client_status_t * s = stat.GetFirstFileStatus(filePath, dummy); if (s) baseRev = s->revision; } // check for properties that got removed for (int baseindex = 0; baseindex < propsbase.GetCount(); ++baseindex) { std::string basename = propsbase.GetItemName(baseindex); tstring basenameU = CUnicodeUtils::StdGetUnicode(basename); tstring basevalue = (LPCTSTR)CUnicodeUtils::GetUnicode(propsbase.GetItemValue(baseindex).c_str()); bool bFound = false; for (int wcindex = 0; wcindex < propswc.GetCount(); ++wcindex) { if (basename.compare (propswc.GetItemName(wcindex))==0) { bFound = true; break; } } if (!bFound) { // write the old property value to temporary file CTSVNPath wcpropfile = CTempFiles::Instance().GetTempFilePath(false); CTSVNPath basepropfile = CTempFiles::Instance().GetTempFilePath(false); FILE * pFile; _tfopen_s(&pFile, wcpropfile.GetWinPath(), L"wb"); if (pFile) { fclose(pFile); FILE * pFile2; _tfopen_s(&pFile2, basepropfile.GetWinPath(), L"wb"); if (pFile2) { fputs(CUnicodeUtils::StdGetUTF8(basevalue).c_str(), pFile2); fclose(pFile2); } else return false; } else return false; SetFileAttributes(wcpropfile.GetWinPath(), FILE_ATTRIBUTE_READONLY); SetFileAttributes(basepropfile.GetWinPath(), FILE_ATTRIBUTE_READONLY); CString n1, n2; bool bSwitch = false; if (rev1.IsWorking()) n1.Format(IDS_DIFF_PROP_WCNAME, basenameU.c_str()); if (rev1.IsBase()) { if (baseRev) n1.FormatMessage(IDS_DIFF_PROP_BASENAMEREV, basenameU.c_str(), baseRev); else n1.Format(IDS_DIFF_PROP_BASENAME, basenameU.c_str()); } if (rev1.IsHead()) n1.Format(IDS_DIFF_PROP_REMOTENAME, basenameU.c_str()); if (n1.IsEmpty()) { CString temp; temp.Format(IDS_DIFF_REVISIONPATCHED, (LONG)rev1); n1 = basenameU.c_str(); n1 += L" " + temp; bSwitch = true; } else { n1 = CString(pathbuf1) + L" - " + n1; } if (rev2.IsWorking()) n2.Format(IDS_DIFF_PROP_WCNAME, basenameU.c_str()); if (rev2.IsBase()) { if (baseRev) n2.FormatMessage(IDS_DIFF_PROP_BASENAMEREV, basenameU.c_str(), baseRev); else n2.Format(IDS_DIFF_PROP_BASENAME, basenameU.c_str()); } if (rev2.IsHead()) n2.Format(IDS_DIFF_PROP_REMOTENAME, basenameU.c_str()); if (n2.IsEmpty()) { CString temp; temp.Format(IDS_DIFF_REVISIONPATCHED, (LONG)rev2); n2 = basenameU.c_str(); n2 += L" " + temp; bSwitch = true; } else { n2 = CString(pathbuf1) + L" - " + n2; } if (bSwitch) { retvalue = !!CAppUtils::StartExtDiffProps(wcpropfile, basepropfile, n1, n2, TRUE, TRUE); } else { retvalue = !!CAppUtils::StartExtDiffProps(basepropfile, wcpropfile, n2, n1, TRUE, TRUE); } } } for (int wcindex = 0; wcindex < propswc.GetCount(); ++wcindex) { std::string wcname = propswc.GetItemName(wcindex); tstring wcnameU = CUnicodeUtils::StdGetUnicode(wcname); tstring wcvalue = (LPCTSTR)CUnicodeUtils::GetUnicode(propswc.GetItemValue(wcindex).c_str()); tstring basevalue; bool bDiffRequired = true; for (int baseindex = 0; baseindex < propsbase.GetCount(); ++baseindex) { if (propsbase.GetItemName(baseindex).compare(wcname)==0) { basevalue = CUnicodeUtils::GetUnicode(propsbase.GetItemValue(baseindex).c_str()); if (basevalue.compare(wcvalue)==0) { // name and value are identical bDiffRequired = false; break; } } } if (bDiffRequired) { // write both property values to temporary files CTSVNPath wcpropfile = CTempFiles::Instance().GetTempFilePath(false); CTSVNPath basepropfile = CTempFiles::Instance().GetTempFilePath(false); FILE * pFile; _tfopen_s(&pFile, wcpropfile.GetWinPath(), L"wb"); if (pFile) { fputs(CUnicodeUtils::StdGetUTF8(wcvalue).c_str(), pFile); fclose(pFile); FILE * pFile2; _tfopen_s(&pFile2, basepropfile.GetWinPath(), L"wb"); if (pFile2) { fputs(CUnicodeUtils::StdGetUTF8(basevalue).c_str(), pFile2); fclose(pFile2); } else return false; } else return false; SetFileAttributes(wcpropfile.GetWinPath(), FILE_ATTRIBUTE_READONLY); SetFileAttributes(basepropfile.GetWinPath(), FILE_ATTRIBUTE_READONLY); CString n1, n2; if (rev1.IsWorking()) n1.Format(IDS_DIFF_WCNAME, wcnameU.c_str()); if (rev1.IsBase()) n1.Format(IDS_DIFF_BASENAME, wcnameU.c_str()); if (rev1.IsHead()) n1.Format(IDS_DIFF_REMOTENAME, wcnameU.c_str()); if (n1.IsEmpty()) n1.FormatMessage(IDS_DIFF_PROP_REVISIONNAME, wcnameU.c_str(), (LPCTSTR)rev1.ToString()); else n1 = CString(pathbuf1) + L" - " + n1; if (rev2.IsWorking()) n2.Format(IDS_DIFF_WCNAME, wcnameU.c_str()); if (rev2.IsBase()) n2.Format(IDS_DIFF_BASENAME, wcnameU.c_str()); if (rev2.IsHead()) n2.Format(IDS_DIFF_REMOTENAME, wcnameU.c_str()); if (n2.IsEmpty()) n2.FormatMessage(IDS_DIFF_PROP_REVISIONNAME, wcnameU.c_str(), (LPCTSTR)rev2.ToString()); else n2 = CString(pathbuf1) + L" - " + n2; retvalue = !!CAppUtils::StartExtDiffProps(basepropfile, wcpropfile, n2, n1, TRUE, TRUE); } } return retvalue; }
void CExportDlg::OnOK() { if (!UpdateData(TRUE)) return; // don't dismiss dialog (error message already shown by MFC framework) if (::IsWindow(m_pLogDlg->GetSafeHwnd())&&(m_pLogDlg->IsWindowVisible())) { m_pLogDlg->SendMessage(WM_CLOSE); return; } // check it the export path is a valid windows path CTSVNPath ExportDirectory; if (::PathIsRelative(m_strExportDirectory)) { ExportDirectory = CTSVNPath(sOrigCWD); ExportDirectory.AppendPathString(L"\\" + m_strExportDirectory); m_strExportDirectory = ExportDirectory.GetWinPathString(); } else ExportDirectory = CTSVNPath(m_strExportDirectory); if (!ExportDirectory.IsValidOnWindows()) { ShowEditBalloon(IDC_CHECKOUTDIRECTORY, IDS_ERR_NOVALIDPATH, IDS_ERR_ERROR, TTI_ERROR); return; } // check if the specified revision is valid if (GetCheckedRadioButton(IDC_REVISION_HEAD, IDC_REVISION_N) == IDC_REVISION_HEAD) { Revision = SVNRev(L"HEAD"); } else Revision = SVNRev(m_sRevision); if (!Revision.IsValid()) { ShowEditBalloon(IDC_REVISION_NUM, IDS_ERR_INVALIDREV, IDS_ERR_ERROR, TTI_ERROR); return; } bool bAutoCreateTargetName = m_bAutoCreateTargetName; m_bAutoCreateTargetName = false; m_URLCombo.SaveHistory(); m_URL = m_URLCombo.GetString(); // we need an url to export from - local paths won't work if (!SVN::PathIsURL(CTSVNPath(m_URL))) { m_tooltips.ShowBalloon(IDC_URLCOMBO, IDS_ERR_MUSTBEURL, IDS_ERR_ERROR, TTI_ERROR); m_bAutoCreateTargetName = bAutoCreateTargetName; return; } if (m_strExportDirectory.IsEmpty()) { m_bAutoCreateTargetName = bAutoCreateTargetName; return; } // if the export directory does not exist, where should we export to? // We ask if the directory should be created... if (!PathFileExists(m_strExportDirectory)) { CPathUtils::MakeSureDirectoryPathExists(m_strExportDirectory); } // if the directory we should export to is not empty, show a warning: // maybe the user doesn't want to overwrite the existing files. if (!PathIsDirectoryEmpty(m_strExportDirectory)) { CString message; message.Format(CString(MAKEINTRESOURCE(IDS_WARN_FOLDERNOTEMPTY)),(LPCTSTR)m_strExportDirectory); CTaskDialog taskdlg(message, CString(MAKEINTRESOURCE(IDS_WARN_FOLDERNOTEMPTY_TASK2)), L"TortoiseSVN", 0, TDF_ENABLE_HYPERLINKS | TDF_USE_COMMAND_LINKS | TDF_ALLOW_DIALOG_CANCELLATION | TDF_POSITION_RELATIVE_TO_WINDOW | TDF_SIZE_TO_CONTENT); taskdlg.AddCommandControl(1, CString(MAKEINTRESOURCE(IDS_WARN_FOLDERNOTEMPTY_TASK3_1))); taskdlg.AddCommandControl(2, CString(MAKEINTRESOURCE(IDS_WARN_FOLDERNOTEMPTY_TASK4))); taskdlg.SetCommonButtons(TDCBF_CANCEL_BUTTON); taskdlg.SetDefaultCommandControl(2); taskdlg.SetMainIcon(TD_WARNING_ICON); bool doIt = (taskdlg.DoModal(GetExplorerHWND()) == 1); if (!doIt) { m_bAutoCreateTargetName = bAutoCreateTargetName; return; //don't dismiss the dialog } } m_eolCombo.GetWindowText(m_eolStyle); if (m_eolStyle.Compare(L"default")==0) m_eolStyle.Empty(); switch (m_depthCombo.GetCurSel()) { case 0: m_depth = svn_depth_infinity; break; case 1: m_depth = svn_depth_immediates; break; case 2: m_depth = svn_depth_files; break; case 3: m_depth = svn_depth_empty; break; default: m_depth = svn_depth_empty; break; } UpdateData(FALSE); CRegDWORD regNoExt(L"Software\\TortoiseSVN\\noext"); regNoExt = m_bNoExternals; CResizableStandAloneDialog::OnOK(); }
void CShellUpdater::WorkerThread() { HANDLE hWaitHandles[2]; hWaitHandles[0] = m_hTerminationEvent; hWaitHandles[1] = m_hWakeEvent; for(;;) { DWORD waitResult = WaitForMultipleObjects(_countof(hWaitHandles), hWaitHandles, FALSE, INFINITE); // exit event/working loop if the first event (m_hTerminationEvent) // has been signaled or if one of the events has been abandoned // (i.e. ~CShellUpdater() is being executed) if(waitResult == WAIT_OBJECT_0 || waitResult == WAIT_ABANDONED_0 || waitResult == WAIT_ABANDONED_0+1) { // Termination event break; } // wait some time before we notify the shell Sleep(50); for(;;) { CTSVNPath workingPath; if (!m_bRunning) return; Sleep(0); { AutoLocker lock(m_critSec); if(m_pathsToUpdate.empty()) { // Nothing left to do break; } if(InterlockedExchange(&m_bItemsAddedSinceLastUpdate, FALSE)) { m_pathsToUpdate.erase(std::unique(m_pathsToUpdate.begin(), m_pathsToUpdate.end(), &CTSVNPath::PredLeftEquivalentToRight), m_pathsToUpdate.end()); } workingPath = m_pathsToUpdate.front(); m_pathsToUpdate.pop_front(); } if (workingPath.IsEmpty()) continue; CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": shell notification for %s\n", workingPath.GetWinPath()); if (workingPath.IsDirectory()) { // first send a notification about a sub folder change, so explorer doesn't discard // the folder notification. Since we only know for sure that the subversion admin // dir is present, we send a notification for that folder. CString admindir = workingPath.GetWinPathString() + L"\\" + g_SVNAdminDir.GetAdminDirName(); SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH | SHCNF_FLUSHNOWAIT, (LPCTSTR)admindir, NULL); SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH | SHCNF_FLUSHNOWAIT, workingPath.GetWinPath(), NULL); // Sending an UPDATEDIR notification somehow overwrites/deletes the UPDATEITEM message. And without // that message, the folder overlays in the current view don't get updated without hitting F5. // Drawback is, without UPDATEDIR, the left tree view isn't always updated... //SHChangeNotify(SHCNE_UPDATEDIR, SHCNF_PATH | SHCNF_FLUSHNOWAIT, workingPath.GetWinPath(), NULL); } else SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH | SHCNF_FLUSHNOWAIT, workingPath.GetWinPath(), NULL); } } _endthread(); }
bool CheckoutCommand::Execute() { bool bRet = false; // Get the directory supplied in the command line. If there isn't // one then we should use first the default checkout path // specified in the settings dialog, and fall back to the current // working directory instead if no such path was specified. CTSVNPath checkoutDirectory; CRegString regDefCheckoutPath(_T("Software\\TortoiseSVN\\DefaultCheckoutPath")); if (cmdLinePath.IsEmpty()) { if (CString(regDefCheckoutPath).IsEmpty()) { checkoutDirectory.SetFromWin(sOrigCWD, true); DWORD len = ::GetTempPath(0, NULL); std::unique_ptr<TCHAR[]> tszPath(new TCHAR[len]); ::GetTempPath(len, tszPath.get()); if (_tcsncicmp(checkoutDirectory.GetWinPath(), tszPath.get(), len-2 /* \\ and \0 */) == 0) { // if the current directory is set to a temp directory, // we don't use that but leave it empty instead. checkoutDirectory.Reset(); } } else { checkoutDirectory.SetFromWin(CString(regDefCheckoutPath)); } } else { checkoutDirectory = cmdLinePath; } CCheckoutDlg dlg; dlg.m_URLs.LoadFromAsteriskSeparatedString (parser.GetVal(_T("url"))); if (dlg.m_URLs.GetCount()==0) { SVN svn; if (svn.IsRepository(cmdLinePath)) { CString url; // The path points to a local repository. // Add 'file:///' so the repository browser recognizes // it as an URL to the local repository. if (cmdLinePath.GetWinPathString().GetAt(0) == '\\') // starts with '\' means an UNC path { CString p = cmdLinePath.GetWinPathString(); p.TrimLeft('\\'); url = _T("file://")+p; } else url = _T("file:///")+cmdLinePath.GetWinPathString(); url.Replace('\\', '/'); dlg.m_URLs.AddPath(CTSVNPath(url)); checkoutDirectory.AppendRawString(L"wc"); } } dlg.m_strCheckoutDirectory = checkoutDirectory.GetWinPathString(); // if there is no url specified on the command line, check if there's one // specified in the settings dialog to use as the default and use that CRegString regDefCheckoutUrl(_T("Software\\TortoiseSVN\\DefaultCheckoutUrl")); if (!CString(regDefCheckoutUrl).IsEmpty()) { // if the URL specified is a child of the default URL, we also // adjust the default checkout path // e.g. // Url specified on command line: http://server.com/repos/project/trunk/folder // Url specified as default : http://server.com/repos/project/trunk // checkout path specified : c:\work\project // --> // checkout path adjusted : c:\work\project\folder CTSVNPath clurl = dlg.m_URLs.GetCommonDirectory(); CTSVNPath defurl = CTSVNPath(CString(regDefCheckoutUrl)); if (defurl.IsAncestorOf(clurl)) { // the default url is the parent of the specified url if (CTSVNPath::CheckChild(CTSVNPath(CString(regDefCheckoutPath)), CTSVNPath(dlg.m_strCheckoutDirectory))) { dlg.m_strCheckoutDirectory = CString(regDefCheckoutPath) + clurl.GetWinPathString().Mid(defurl.GetWinPathString().GetLength()); dlg.m_strCheckoutDirectory.Replace(_T("\\\\"), _T("\\")); } } if (dlg.m_URLs.GetCount() == 0) dlg.m_URLs.AddPath (defurl); } for (int i = 0; i < dlg.m_URLs.GetCount(); ++i) { CString pathString = dlg.m_URLs[i].GetWinPathString(); if (pathString.Left(5).Compare(_T("tsvn:"))==0) { pathString = pathString.Mid(5); if (pathString.Find('?') >= 0) { dlg.Revision = SVNRev(pathString.Mid(pathString.Find('?')+1)); pathString = pathString.Left(pathString.Find('?')); } } dlg.m_URLs[i].SetFromWin (pathString); } if (parser.HasKey(_T("revision"))) { SVNRev Rev = SVNRev(parser.GetVal(_T("revision"))); dlg.Revision = Rev; } dlg.m_blockPathAdjustments = parser.HasKey(L"blockpathadjustments"); if (dlg.DoModal() == IDOK) { checkoutDirectory.SetFromWin(dlg.m_strCheckoutDirectory, true); CSVNProgressDlg progDlg; theApp.m_pMainWnd = &progDlg; bool useStandardCheckout = dlg.m_standardCheckout || ((dlg.m_URLs.GetCount() > 1) && dlg.m_bIndependentWCs); progDlg.SetCommand (useStandardCheckout ? dlg.m_checkoutDepths.size() ? CSVNProgressDlg::SVNProgress_SparseCheckout : CSVNProgressDlg::SVNProgress_Checkout : dlg.m_parentExists && (dlg.m_URLs.GetCount() == 1) ? CSVNProgressDlg::SVNProgress_Update : CSVNProgressDlg::SVNProgress_SingleFileCheckout); if (dlg.m_checkoutDepths.size()) progDlg.SetPathDepths(dlg.m_checkoutDepths); progDlg.SetAutoClose (parser); progDlg.SetOptions(dlg.m_bNoExternals ? ProgOptIgnoreExternals : ProgOptNone); progDlg.SetPathList(CTSVNPathList(checkoutDirectory)); progDlg.SetUrl(dlg.m_URLs.CreateAsteriskSeparatedString()); progDlg.SetRevision(dlg.Revision); progDlg.SetDepth(dlg.m_depth); progDlg.DoModal(); bRet = !progDlg.DidErrorsOccur(); } return bRet; }
void CCachedDirectory::SetChildStatus(const CTSVNPath& childDir, svn_wc_status_kind childStatus) { CStringA winPath = CUnicodeUtils::GetUTF8(childDir.GetWinPathString()); SetChildStatus(winPath, childStatus); }
void CFileDiffDlg::OnContextMenu(CWnd* pWnd, CPoint point) { if ((pWnd==0)||(pWnd != &m_cFileList)) return; if (m_cFileList.GetSelectedCount() == 0) return; // if the context menu is invoked through the keyboard, we have to use // a calculated position on where to anchor the menu on if ((point.x == -1) && (point.y == -1)) { CRect rect; m_cFileList.GetItemRect(m_cFileList.GetSelectionMark(), &rect, LVIR_LABEL); m_cFileList.ClientToScreen(&rect); point = rect.CenterPoint(); } CIconMenu popup; if (!popup.CreatePopupMenu()) return; popup.AppendMenuIcon(ID_COMPARE, IDS_LOG_POPUP_COMPARETWO, IDI_DIFF); popup.AppendMenuIcon(ID_UNIFIEDDIFF, IDS_LOG_POPUP_GNUDIFF, IDI_DIFF); popup.AppendMenuIcon(ID_BLAME, IDS_FILEDIFF_POPBLAME, IDI_BLAME); popup.AppendMenu(MF_SEPARATOR, NULL); popup.AppendMenuIcon(ID_SAVEAS, IDS_FILEDIFF_POPSAVELIST, IDI_SAVEAS); popup.AppendMenuIcon(ID_CLIPBOARD, IDS_FILEDIFF_POPCLIPBOARD, IDI_COPYCLIP); popup.AppendMenuIcon(ID_EXPORT, IDS_FILEDIFF_POPEXPORT, IDI_EXPORT); int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0); m_bCancelled = false; switch (cmd) { case ID_COMPARE: { POSITION pos = m_cFileList.GetFirstSelectedItemPosition(); while (pos) { int index = m_cFileList.GetNextSelectedItem(pos); DoDiff(index, false); } } break; case ID_UNIFIEDDIFF: { CTSVNPath diffFile = CTempFiles::Instance().GetTempFilePath(false); POSITION pos = m_cFileList.GetFirstSelectedItemPosition(); while (pos) { int index = m_cFileList.GetNextSelectedItem(pos); CFileDiffDlg::FileDiff fd = m_arFilteredList[index]; CTSVNPath url1 = CTSVNPath(m_path1.GetSVNPathString() + _T("/") + fd.path.GetSVNPathString()); CTSVNPath url2 = m_bDoPegDiff ? url1 : CTSVNPath(m_path2.GetSVNPathString() + _T("/") + fd.path.GetSVNPathString()); if (m_bDoPegDiff) { PegDiff(url1, m_peg, m_rev1, m_rev2, CTSVNPath(), m_depth, m_bIgnoreancestry, false, true, CString(), true, diffFile); } else { Diff(url1, m_rev1, url2, m_rev2, CTSVNPath(), m_depth, m_bIgnoreancestry, false, true, CString(), true, diffFile); } } CAppUtils::StartUnifiedDiffViewer(diffFile, CString(), false); } break; case ID_BLAME: { POSITION pos = m_cFileList.GetFirstSelectedItemPosition(); while (pos) { int index = m_cFileList.GetNextSelectedItem(pos); DoDiff(index, true); } } break; case ID_SAVEAS: if (m_cFileList.GetSelectedCount() > 0) { CTSVNPath savePath; CString pathSave; if (!CAppUtils::FileOpenSave(pathSave, NULL, IDS_REPOBROWSE_SAVEAS, IDS_COMMONFILEFILTER, false, m_hWnd)) { break; } savePath = CTSVNPath(pathSave); // now open the selected file for writing try { CStdioFile file(savePath.GetWinPathString(), CFile::typeBinary | CFile::modeReadWrite | CFile::modeCreate); CString temp; temp.FormatMessage(IDS_FILEDIFF_CHANGEDLISTINTRO, (LPCTSTR)m_path1.GetSVNPathString(), (LPCTSTR)m_rev1.ToString(), (LPCTSTR)m_path2.GetSVNPathString(), (LPCTSTR)m_rev2.ToString()); file.WriteString(temp + _T("\n")); POSITION pos = m_cFileList.GetFirstSelectedItemPosition(); while (pos) { int index = m_cFileList.GetNextSelectedItem(pos); FileDiff fd = m_arFilteredList[index]; file.WriteString(fd.path.GetSVNPathString()); file.WriteString(_T("\n")); } file.Close(); } catch (CFileException* pE) { pE->ReportError(); pE->Delete(); } } break; case ID_CLIPBOARD: CopySelectionToClipboard(); break; case ID_EXPORT: { // export all changed files to a folder CBrowseFolder browseFolder; browseFolder.m_style = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS; if (browseFolder.Show(GetSafeHwnd(), m_strExportDir) == CBrowseFolder::OK) { m_arSelectedFileList.RemoveAll(); POSITION pos = m_cFileList.GetFirstSelectedItemPosition(); while (pos) { int index = m_cFileList.GetNextSelectedItem(pos); CFileDiffDlg::FileDiff fd = m_arFilteredList[index]; m_arSelectedFileList.Add(fd); } m_pProgDlg = new CProgressDlg(); InterlockedExchange(&m_bThreadRunning, TRUE); if (AfxBeginThread(ExportThreadEntry, this)==NULL) { InterlockedExchange(&m_bThreadRunning, FALSE); OnCantStartThread(); } } } break; } }
CStatusCacheEntry CCachedDirectory::GetStatusForMember(const CTSVNPath& path, bool bRecursive, bool bFetch /* = true */) { CStringA strCacheKey; bool bThisDirectoryIsUnversioned = false; bool bRequestForSelf = false; if(path.IsEquivalentToWithoutCase(m_directoryPath)) { bRequestForSelf = true; } // In all most circumstances, we ask for the status of a member of this directory. ATLASSERT(m_directoryPath.IsEquivalentToWithoutCase(path.GetContainingDirectory()) || bRequestForSelf); long long dbFileTime = CSVNStatusCache::Instance().WCRoots()->GetDBFileTime(m_directoryPath); bool wcDbFileTimeChanged = (m_wcDbFileTime != dbFileTime); if ( !wcDbFileTimeChanged ) { if(m_wcDbFileTime == 0) { // We are a folder which is not in a working copy bThisDirectoryIsUnversioned = true; m_ownStatus.SetStatus(NULL, false, false); // If a user removes the .svn directory, we get here with m_entryCache // not being empty, but still us being unversioned if (!m_entryCache.empty()) { m_entryCache.clear(); } ATLASSERT(m_entryCache.empty()); // However, a member *DIRECTORY* might be the top of WC // so we need to ask them to get their own status if(!path.IsDirectory()) { if ((PathFileExists(path.GetWinPath()))||(bRequestForSelf)) return CStatusCacheEntry(); // the entry doesn't exist anymore! // but we can't remove it from the cache here: // the GetStatusForMember() method is called only with a read // lock and not a write lock! // So mark it for crawling, and let the crawler remove it // later CSVNStatusCache::Instance().AddFolderForCrawling(path.GetContainingDirectory()); return CStatusCacheEntry(); } else { // If we're in the special case of a directory being asked for its own status // and this directory is unversioned, then we should just return that here if(bRequestForSelf) { return CStatusCacheEntry(); } } } if (CSVNStatusCache::Instance().GetDirectoryCacheEntryNoCreate(path) != NULL) { // We don't have directory status in our cache // Ask the directory if it knows its own status CCachedDirectory * dirEntry = CSVNStatusCache::Instance().GetDirectoryCacheEntry(path); if ((dirEntry)&&(dirEntry->IsOwnStatusValid())) { // To keep recursive status up to date, we'll request that children are all crawled again // We have to do this because the directory watcher isn't very reliable (especially under heavy load) // and also has problems with SUBSTed drives. // If nothing has changed in those directories, this crawling is fast and only // accesses two files for each directory. if (bRecursive) { AutoLocker lock(dirEntry->m_critSec); ChildDirStatus::const_iterator it; for(it = dirEntry->m_childDirectories.begin(); it != dirEntry->m_childDirectories.end(); ++it) { CTSVNPath newpath; CString winPath = CUnicodeUtils::GetUnicode (it->first); newpath.SetFromWin(winPath, true); CSVNStatusCache::Instance().AddFolderForCrawling(newpath); } } return dirEntry->GetOwnStatus(bRecursive); } } else { { // if we currently are fetching the status of the directory // we want the status for, we just return an empty entry here // and don't wait for that fetching to finish. // That's because fetching the status can take a *really* long // time (e.g. if a commit is also in progress on that same // directory), and we don't want to make the explorer appear // to hang. if ((!bFetch)&&(m_FetchingStatus)) { if (m_directoryPath.IsAncestorOf(path)) { m_currentFullStatus = m_mostImportantFileStatus = svn_wc_status_none; return GetCacheStatusForMember(path); } } } // Look up a file in our own cache AutoLocker lock(m_critSec); strCacheKey = GetCacheKey(path); CacheEntryMap::iterator itMap = m_entryCache.find(strCacheKey); if(itMap != m_entryCache.end()) { // We've hit the cache - check for timeout if(!itMap->second.HasExpired((long)GetTickCount())) { if(itMap->second.DoesFileTimeMatch(path.GetLastWriteTime())) { if ((itMap->second.GetEffectiveStatus()!=svn_wc_status_missing)||(!PathFileExists(path.GetWinPath()))) { // Note: the filetime matches after a modified has been committed too. // So in that case, we would return a wrong status (e.g. 'modified' instead // of 'normal') here. return itMap->second; } } } } } } else { if ((!bFetch)&&(m_FetchingStatus)) { if (m_directoryPath.IsAncestorOf(path)) { // returning empty status (status fetch in progress) // also set the status to 'none' to have the status change and // the shell updater invoked in the crawler m_currentFullStatus = m_mostImportantFileStatus = svn_wc_status_none; CSVNStatusCache::Instance().AddFolderForCrawling(m_directoryPath.GetDirectory()); return GetCacheStatusForMember(path); } } // if we're fetching the status for the explorer, // we don't refresh the status but use the one // we already have (to save time and make the explorer // more responsive in stress conditions). // We leave the refreshing to the crawler. if ((!bFetch)&&(m_wcDbFileTime)) { CSVNStatusCache::Instance().AddFolderForCrawling(m_directoryPath.GetDirectory()); return GetCacheStatusForMember(path); } AutoLocker lock(m_critSec); m_entryCache.clear(); strCacheKey = GetCacheKey(path); } // We've not got this item in the cache - let's add it // We never bother asking SVN for the status of just one file, always for its containing directory if (g_SVNAdminDir.IsAdminDirPath(path.GetWinPathString())) { // We're being asked for the status of an .SVN directory // It's not worth asking for this return CStatusCacheEntry(); } { if ((!bFetch)&&(m_FetchingStatus)) { if (m_directoryPath.IsAncestorOf(path)) { m_currentFullStatus = m_mostImportantFileStatus = svn_wc_status_none; return GetCacheStatusForMember(path); } } } { AutoLocker lock(m_critSec); m_mostImportantFileStatus = svn_wc_status_none; m_childDirectories.clear(); m_entryCache.clear(); m_ownStatus.SetStatus(NULL, false, false); } if(!bThisDirectoryIsUnversioned) { if (!SvnUpdateMembersStatus()) { m_wcDbFileTime = 0; return CStatusCacheEntry(); } } // Now that we've refreshed our SVN status, we can see if it's // changed the 'most important' status value for this directory. // If it has, then we should tell our parent UpdateCurrentStatus(); m_wcDbFileTime = dbFileTime; if (path.IsDirectory()) { CCachedDirectory * dirEntry = CSVNStatusCache::Instance().GetDirectoryCacheEntry(path); if ((dirEntry)&&(dirEntry->IsOwnStatusValid())) { //CSVNStatusCache::Instance().AddFolderForCrawling(path); return dirEntry->GetOwnStatus(bRecursive); } // If the status *still* isn't valid here, it means that // the current directory is unversioned, and we shall need to ask its children for info about themselves if ((dirEntry)&&(dirEntry != this)) return dirEntry->GetStatusForMember(path,bRecursive); // add the path for crawling: if it's really unversioned, the crawler will // only check for the admin dir and do nothing more. But if it is // versioned (could happen in a nested layout) the crawler will update its // status correctly CSVNStatusCache::Instance().AddFolderForCrawling(path); return CStatusCacheEntry(); } else { CacheEntryMap::iterator itMap = m_entryCache.find(strCacheKey); if(itMap != m_entryCache.end()) { return itMap->second; } } AddEntry(path, NULL, false, false); return CStatusCacheEntry(); }
bool CDirectoryWatcher::AddPath(const CTSVNPath& path, bool bCloseInfoMap) { if (!CSVNStatusCache::Instance().IsPathAllowed(path)) return false; if ((!blockedPath.IsEmpty())&&(blockedPath.IsAncestorOf(path))) { if (GetTickCount64() < blockTickCount) { CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Path %s prevented from being watched\n", path.GetWinPath()); return false; } } // ignore the recycle bin PTSTR pFound = StrStrI(path.GetWinPath(), L":\\RECYCLER"); if (pFound != NULL) { if ((*(pFound + 10) == '\0') || (*(pFound + 10) == '\\')) return false; } pFound = StrStrI(path.GetWinPath(), L":\\$Recycle.Bin"); if (pFound != NULL) { if ((*(pFound + 14) == '\0') || (*(pFound + 14) == '\\')) return false; } AutoLocker lock(m_critSec); for (int i=0; i<watchedPaths.GetCount(); ++i) { if (watchedPaths[i].IsAncestorOf(path)) return false; // already watched (recursively) } // now check if with the new path we might have a new root CTSVNPath newroot; for (int i=0; i<watchedPaths.GetCount(); ++i) { const CString& watched = watchedPaths[i].GetWinPathString(); const CString& sPath = path.GetWinPathString(); int minlen = min(sPath.GetLength(), watched.GetLength()); int len = 0; for (len = 0; len < minlen; ++len) { if (watched.GetAt(len) != sPath.GetAt(len)) { if ((len > 1)&&(len < minlen)) { if (sPath.GetAt(len)=='\\') { newroot = CTSVNPath(sPath.Left(len)); } else if (watched.GetAt(len)=='\\') { newroot = CTSVNPath(watched.Left(len)); } } break; } } if (len == minlen) { if (sPath.GetLength() == minlen) { if (watched.GetLength() > minlen) { if (watched.GetAt(len)=='\\') { newroot = path; } else if (sPath.GetLength() == 3 && sPath[1] == ':') { newroot = path; } } } else { if (sPath.GetLength() > minlen) { if (sPath.GetAt(len)=='\\') { newroot = CTSVNPath(watched); } else if (watched.GetLength() == 3 && watched[1] == ':') { newroot = CTSVNPath(watched); } } } } } if (!newroot.IsEmpty() && SVNHelper::IsVersioned(newroot, false)) { CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": AddPath for %s\n", newroot.GetWinPath()); watchedPaths.AddPath(newroot); watchedPaths.RemoveChildren(); if (bCloseInfoMap) ClearInfoMap(); return true; } if (!SVNHelper::IsVersioned(path, false)) { CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Path %s prevented from being watched: not versioned\n", path.GetWinPath()); return false; } CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": AddPath for %s\n", path.GetWinPath()); watchedPaths.AddPath(path); if (bCloseInfoMap) ClearInfoMap(); return true; }
bool CheckoutCommand::Execute() { bool bRet = false; // Get the directory supplied in the command line. If there isn't // one then we should use first the default checkout path // specified in the settings dialog, and fall back to the current // working directory instead if no such path was specified. CTSVNPath checkoutDirectory; CRegString regDefCheckoutPath(_T("Software\\TortoiseGit\\DefaultCheckoutPath")); if (cmdLinePath.IsEmpty()) { if (CString(regDefCheckoutPath).IsEmpty()) { checkoutDirectory.SetFromWin(sOrigCWD, true); DWORD len = ::GetTempPath(0, NULL); TCHAR * tszPath = new TCHAR[len]; ::GetTempPath(len, tszPath); if (_tcsncicmp(checkoutDirectory.GetWinPath(), tszPath, len-2 /* \\ and \0 */) == 0) { // if the current directory is set to a temp directory, // we don't use that but leave it empty instead. checkoutDirectory.Reset(); } delete [] tszPath; } else { checkoutDirectory.SetFromWin(CString(regDefCheckoutPath)); } } else { checkoutDirectory = cmdLinePath; } CCheckoutDlg dlg; dlg.m_strCheckoutDirectory = checkoutDirectory.GetWinPathString(); dlg.m_URL = parser.GetVal(_T("url")); // if there is no url specified on the command line, check if there's one // specified in the settings dialog to use as the default and use that CRegString regDefCheckoutUrl(_T("Software\\TortoiseGit\\DefaultCheckoutUrl")); if (!CString(regDefCheckoutUrl).IsEmpty()) { // if the URL specified is a child of the default URL, we also // adjust the default checkout path // e.g. // Url specified on command line: http://server.com/repos/project/trunk/folder // Url specified as default : http://server.com/repos/project/trunk // checkout path specified : c:\work\project // --> // checkout path adjusted : c:\work\project\folder CTSVNPath clurl = CTSVNPath(dlg.m_URL); CTSVNPath defurl = CTSVNPath(CString(regDefCheckoutUrl)); if (defurl.IsAncestorOf(clurl)) { // the default url is the parent of the specified url if (CTSVNPath::CheckChild(CTSVNPath(CString(regDefCheckoutPath)), CTSVNPath(dlg.m_strCheckoutDirectory))) { dlg.m_strCheckoutDirectory = CString(regDefCheckoutPath) + clurl.GetWinPathString().Mid(defurl.GetWinPathString().GetLength()); dlg.m_strCheckoutDirectory.Replace(_T("\\\\"), _T("\\")); } } if (dlg.m_URL.IsEmpty()) dlg.m_URL = regDefCheckoutUrl; } if (dlg.m_URL.Left(5).Compare(_T("tsvn:"))==0) { dlg.m_URL = dlg.m_URL.Mid(5); if (dlg.m_URL.Find('?') >= 0) { dlg.Revision = SVNRev(dlg.m_URL.Mid(dlg.m_URL.Find('?')+1)); dlg.m_URL = dlg.m_URL.Left(dlg.m_URL.Find('?')); } } if (parser.HasKey(_T("revision"))) { SVNRev Rev = SVNRev(parser.GetVal(_T("revision"))); dlg.Revision = Rev; } if (dlg.m_URL.Find('*')>=0) { // multiple URL's specified // ask where to check them out to CBrowseFolder foldbrowse; foldbrowse.SetInfo(CString(MAKEINTRESOURCE(IDS_PROC_CHECKOUTTO))); foldbrowse.SetCheckBoxText(CString(MAKEINTRESOURCE(IDS_PROC_CHECKOUTTOPONLY))); foldbrowse.SetCheckBoxText2(CString(MAKEINTRESOURCE(IDS_PROC_CHECKOUTNOEXTERNALS))); foldbrowse.m_style = BIF_NEWDIALOGSTYLE | BIF_RETURNONLYFSDIRS | BIF_USENEWUI | BIF_VALIDATE; TCHAR checkoutpath[MAX_PATH]; if (foldbrowse.Show(hwndExplorer, checkoutpath, MAX_PATH, CString(regDefCheckoutPath))==CBrowseFolder::OK) { CSVNProgressDlg progDlg; theApp.m_pMainWnd = &progDlg; if (parser.HasVal(_T("closeonend"))) progDlg.SetAutoClose(parser.GetLongVal(_T("closeonend"))); progDlg.SetCommand(CSVNProgressDlg::SVNProgress_Checkout); progDlg.SetOptions(foldbrowse.m_bCheck2 ? ProgOptIgnoreExternals : ProgOptNone); progDlg.SetPathList(CTSVNPathList(CTSVNPath(CString(checkoutpath)))); progDlg.SetUrl(dlg.m_URL); progDlg.SetRevision(dlg.Revision); progDlg.SetDepth(foldbrowse.m_bCheck ? svn_depth_empty : svn_depth_infinity); progDlg.DoModal(); bRet = !progDlg.DidErrorsOccur(); } } else if (dlg.DoModal() == IDOK) { checkoutDirectory.SetFromWin(dlg.m_strCheckoutDirectory, true); CSVNProgressDlg progDlg; theApp.m_pMainWnd = &progDlg; progDlg.SetCommand(CSVNProgressDlg::SVNProgress_Checkout); if (parser.HasVal(_T("closeonend"))) progDlg.SetAutoClose(parser.GetLongVal(_T("closeonend"))); progDlg.SetOptions(dlg.m_bNoExternals ? ProgOptIgnoreExternals : ProgOptNone); progDlg.SetPathList(CTSVNPathList(checkoutDirectory)); progDlg.SetUrl(dlg.m_URL); progDlg.SetRevision(dlg.Revision); progDlg.SetDepth(dlg.m_depth); progDlg.DoModal(); bRet = !progDlg.DidErrorsOccur(); } return bRet; }