string ShellOpenSearch(string className) { using (RegistryKey rk = Registry.ClassesRoot.OpenSubKey(className + "\\shell\\open\\command", false)) { if (rk == null) { return(null); } string cmdLine = rk.GetValue("") as string; if (string.IsNullOrEmpty(cmdLine)) { return(null); } string program, args; if (!SvnTools.TrySplitCommandLine(cmdLine, SubstituteEmpty, out program, out args)) { return(null); } else { return(program); } } }
static void Test10() { var homeUri = new Uri("http://192.168.1.105/svn/BIST/release"); var tgtUri = SvnTools.GetNormalizedUri(new Uri("http://192.168.1.105/svn/BIST/../modelsBinaries/missiontrModels/trunk")); var client = new SvnClient(); SvnInfoEventArgs homeInfo; if (!client.GetInfo(homeUri, out homeInfo)) { return; } string homeRepoUrl = homeInfo.RepositoryRoot.AbsoluteUri; SvnInfoEventArgs tgtInfo; if (!client.GetInfo(tgtUri, out tgtInfo)) { return; } string tgtRepoUrl = tgtInfo.RepositoryRoot.AbsoluteUri; string relativizedUrl; Exter.TryMakeRelativeReference(client, tgtUri.AbsoluteUri, homeRepoUrl, out relativizedUrl); }
private bool MaybeProcessAncestorRename(string oldName, string newName) { // If the name of the node itself doesn't change in a rename, it's most likely // a parent rename. if (!string.Equals(Path.GetFileName(oldName), Path.GetFileName(newName))) { return(false); } string oldNode = SvnTools.GetNormalizedDirectoryName(oldName); string newNode = SvnTools.GetNormalizedDirectoryName(newName); if (oldNode == null || newNode == null || String.Equals(oldNode, newNode)) { return(false); } if (_alreadyProcessed.Contains(newNode)) { return(true); } if (MaybeProcessAncestorRename(oldNode, newNode)) { return(true); } if (!_fileOrigins.ContainsKey(newNode)) { return(false); } return(ProcessRename(oldNode, newNode)); }
/// <summary> /// Fixes working copies which are invalidated by a rename operation /// </summary> /// <param name="rgszMkOldNames"></param> /// <param name="rgszMkNewNames"></param> private void ProcessRenames(string[] rgszMkOldNames, string[] rgszMkNewNames) { if (rgszMkNewNames == null || rgszMkOldNames == null || rgszMkOldNames.Length != rgszMkNewNames.Length) { return; } for (int i = 0; i < rgszMkOldNames.Length; i++) { string oldName = rgszMkOldNames[i]; string newName = rgszMkNewNames[i]; if (!SvnItem.IsValidPath(oldName)) { continue; } if (!SvnItem.IsValidPath(newName)) { continue; } oldName = SvnTools.GetNormalizedFullPath(oldName); newName = SvnTools.GetNormalizedFullPath(newName); if (!MaybeProcessAncestorRename(oldName, newName)) { ProcessRename(oldName, newName); } } }
private static string GetAppLocation(string app) { if (string.IsNullOrEmpty(app)) { throw new ArgumentNullException("app"); } app = app.Trim(); if (app.Length == 0) { return(null); } if (app[0] == '\"') { int n = app.IndexOf('\"', 1); if (n > 0) { app = app.Substring(1, n - 1).Trim(); } else { app = app.Substring(1).Trim(); } } if (app.Contains("%")) { app = Environment.ExpandEnvironmentVariables(app); } return(SvnTools.GetNormalizedFullPath(app)); }
public void Normalize800000() { for (int i = 0; i < 800000; i++) { GC.KeepAlive(SvnTools.GetNormalizedFullPath("C:\\Users\\Bert\\AppData\\Local\\Microsoft\\VisualStudio\\10.0\\Extensions\\Microsoft\\Productivity Power Tools\\10.0.20626.18\\package\\services\\digital-signature\\xml-signature\\yp5utn4wx4uezottryfbg9mac.psdsxs")); } }
/// <summary> /// Stores the item in the caching dictionary/ies /// </summary> /// <param name="item"></param> public void StoreItem(SvnItem item) { if (item == null) { throw new ArgumentNullException("item"); } Map[item.FullPath] = item; SvnDirectory dir; if (DirectoryMap.TryGetValue(item.FullPath, out dir)) { if (item.IsDirectory) { ((ISvnDirectoryUpdate)dir).Store(item); } else { ScheduleForCleanup(dir); } } var parentDir = SvnTools.GetNormalizedDirectoryName(item.FullPath); if (string.IsNullOrEmpty(parentDir) || parentDir == item.FullPath) { return; // Skip root directory } if (DirectoryMap.TryGetValue(item.FullPath, out dir)) { ((ISvnDirectoryUpdate)dir)?.Store(item); } }
public void DontCanonicalizeToDotSlash() { SvnPathTarget path = new SvnPathTarget(".\\bladiebla.txt"); Assert.That(path.TargetName, Is.EqualTo("bladiebla.txt")); Assert.That(Path.GetFullPath("c:\\windows\\"), Is.EqualTo("c:\\windows\\")); Assert.That(SvnTools.GetNormalizedFullPath("c:\\windows\\"), Is.EqualTo("C:\\windows")); Assert.That(SvnRevision.Base == SvnRevision.Base); Assert.That(SvnRevision.Base.Equals(SvnRevision.Base)); Assert.That(SvnRevision.Base.Equals(SvnRevisionType.Base)); Assert.That(SvnRevision.Base == SvnRevisionType.Base); Assert.That(SvnRevision.Working == SvnRevision.Working); Assert.That(SvnRevision.Working.Equals(SvnRevision.Working)); Assert.That(SvnRevision.Working.Equals(SvnRevisionType.Working)); Assert.That(SvnRevision.Working == SvnRevisionType.Working); DirectoryInfo dir = new DirectoryInfo("c:\\"); foreach (FileInfo file in dir.GetFiles()) { Assert.That(file.FullName.StartsWith("c:\\")); } dir = new DirectoryInfo("C:\\"); foreach (FileInfo file in dir.GetFiles()) { Assert.That(file.FullName.StartsWith("C:\\")); } }
void ProcessOk() { UpdateDirectories(); string fileText = fileNameBox.Text; if (string.IsNullOrEmpty(fileText)) { return; } Uri dirUri; Uri fileUri; if (Uri.TryCreate(urlBox.Text, UriKind.Absolute, out dirUri) && Uri.TryCreate(fileText, UriKind.Relative, out fileUri)) { Uri combined = SvnTools.AppendPathSuffix(dirUri, SvnTools.UriPartToPath(fileText)); AnkhAction fill = delegate() { CheckResult(combined); }; fill.BeginInvoke(null, null); } }
/// <summary> /// 初始化 如果没有被管理,则签出 /// </summary> /// <returns></returns> public bool Init() { ShowInfo("正在初始化...."); bool result = true; HandEvents(); if(!SvnTools.IsManagedPath(GetAppLoc()))//查看某目录是否是受svn管理的状态, 即是否为工作副本 { notiny = "正在检出文件."; ShowInfo(); result = SC.CheckOut(new SvnUriTarget(svnurl), GetAppLoc()); ShowInfo("文件检出完成."); } ShowInfo("初始化完毕."); return result; }
public void Path_NormalizePathSharpFail() { string result = null; bool gotException = false; try { result = SvnTools.GetNormalizedFullPath("c:\\<>\\..\\123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"); } catch (ArgumentException) { Assert.That(Environment.Version.Major, Is.LessThan(4)); gotException = true; } if (Environment.Version.Major >= 4) { Assert.That(result, Is.Not.Null); } else { Assert.That(gotException, "Got exception"); } }
/// <summary> /// /// </summary> /// <returns></returns> public override bool ResolveFiles() { SvnClient client = new SvnClient(); SvnInfoArgs infoArgs = new SvnInfoArgs(); infoArgs.ThrowOnError = false; infoArgs.Depth = SvnDepth.Files; foreach (SourceFile file in State.SourceFiles.Values) { if (file.IsResolved) { continue; } string dirName = SvnTools.GetTruePath(SvnTools.GetNormalizedDirectoryName(file.FullName), true); client.Info(dirName, infoArgs, delegate(object sender, SvnInfoEventArgs e) { SourceFile infoFile; string path = e.FullPath; if (State.SourceFiles.TryGetValue(path, out infoFile) && !infoFile.IsResolved) { infoFile.SourceReference = new SubversionSourceReference(this, infoFile, e.RepositoryRoot, e.RepositoryRoot.MakeRelativeUri(e.Uri), e.LastChangeRevision, e.Revision); } }); } return(true); }
public PathListViewItem(LogChangedPathsView view, ISvnLogItem logItem, SvnChangeItem change, Uri reposRoot, bool isInSelection, Color[] colorInfo) : base(view) { if (logItem == null) { throw new ArgumentNullException("logItem"); } if (change == null) { throw new ArgumentNullException("change"); } _logItem = logItem; _change = change; _isInSelection = isInSelection; Uri uri; string path = change.Path.TrimStart('/'); if (string.IsNullOrEmpty(path)) { uri = reposRoot; } else { uri = SvnTools.AppendPathSuffix(reposRoot, path); } _origin = new SvnOrigin(new SvnUriTarget(uri, logItem.Revision), reposRoot); RefreshText(); UpdateColors(colorInfo); }
public void SetUris(IEnumerable <SvnOrigin> uris) { deleteList.ClearSelected(); SortedDictionary <Uri, SvnOrigin> d = new SortedDictionary <Uri, SvnOrigin>(UriComparer.Default); foreach (SvnOrigin o in uris) { SvnUriTarget ut = o.Target as SvnUriTarget; if (ut != null) { d[ut.Uri] = o; } else { d[o.Uri] = o; } } _uris = new Uri[d.Count]; List <Uri> newUris = new List <Uri>(); foreach (SvnOrigin o in d.Values) { deleteList.Items.Add(o.Uri); newUris.Add(SvnTools.GetNormalizedUri(o.Uri)); } _uris = newUris.ToArray(); }
public IEnumerable <Selection.SccProject> GetAllProjectsContaining(string path) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } ThreadHelper.ThrowIfNotOnUIThread(); path = SvnTools.GetNormalizedFullPath(path); SccProjectFile file; if (TryGetFile(path, out file)) { foreach (SccProjectData pd in file.GetOwnerProjects()) { yield return(pd.SvnProject); } } if (string.Equals(path, SolutionFilename, StringComparison.OrdinalIgnoreCase)) { yield return(SccProject.Solution); } }
public void RefreshItem(bool refreshParent) { if (TreeNode != null) { Uri uri = null; if (refreshParent && null != TreeNode.Parent && null != TreeNode.Origin) { uri = ((RepositoryTreeNode)this.TreeNode.Parent).NormalizedUri; } else { uri = TreeNode.NormalizedUri; } if (uri != null && this.TreeNode.TreeView is RepositoryTreeView) { RepositoryTreeView rtv = (RepositoryTreeView)this.TreeNode.TreeView; rtv.Reload(uri); } } else if (ListViewItem != null) { RepositoryExplorerControl rec = GetRepositoryExplorerControl(); if (rec != null) { // This always reloads the parent and its children (not only when requested) Uri uri = new Uri(SvnTools.GetNormalizedUri(this.Uri), "./"); // parent uri rec.Reload(uri); } } }
void LoadSolutionInfo() { string dir, path, user; _rawSolutionDirectory = null; _solutionDirectory = null; _solutionFile = ""; IVsSolution sol = GetService <IVsSolution>(typeof(SVsSolution)); if (sol == null || !VSErr.Succeeded(sol.GetSolutionInfo(out dir, out path, out user))) { return; } if (string.IsNullOrEmpty(dir) || string.IsNullOrEmpty(path)) { // Cache negative result; will be returned as null } else { if (IsSafeSccPath(dir)) { _rawSolutionDirectory = dir; _solutionDirectory = SvnTools.GetTruePath(dir, true) ?? SvnTools.GetNormalizedFullPath(dir); } if (IsSafeSccPath(path)) { _solutionFile = SvnTools.GetTruePath(path, true) ?? SvnTools.GetNormalizedFullPath(path); } } }
public int FilesChanged(uint cChanges, string[] rgpszFile, uint[] rggrfChange) { if (rgpszFile == null || cChanges == 0) { return(VSErr.S_OK); } try { string[] nFiles = new string[cChanges]; for (int i = 0; i < cChanges; i++) { nFiles[i] = SvnTools.GetNormalizedFullPath(rgpszFile[i]); } IFileStatusMonitor monitor = GetService <IFileStatusMonitor>(); monitor.ScheduleSvnStatus(nFiles); } catch (Exception ex) { IAnkhErrorHandler eh = GetService <IAnkhErrorHandler>(); if (eh != null && eh.IsEnabled(ex)) { eh.OnError(ex); } else { throw; } } return(VSErr.S_OK); }
internal void DoCreateDirectory() { RepositoryTreeNode tn = SelectedNode; if (tn == null) { return; } Uri u = tn.RawUri; using (Ankh.UI.SccManagement.CreateDirectoryDialog dialog = new Ankh.UI.SccManagement.CreateDirectoryDialog()) { if (dialog.ShowDialog(Context) != DialogResult.OK) { return; } Uri newDir = SvnTools.AppendPathSuffix(u, dialog.NewDirectoryName); Context.GetService <IProgressRunner>().RunModal( RepositoryStrings.CreatingDirectory, delegate(object sender, ProgressWorkerArgs a) { SvnCreateDirectoryArgs args = new SvnCreateDirectoryArgs(); args.CreateParents = true; args.LogMessage = dialog.LogMessage; a.Client.RemoteCreateDirectory(newDir, args); }); AddRoot(newDir); } }
string SafeRepositoryPath(SvnItem item) { if (item == null || item.Uri == null) { return(""); } SvnWorkingCopy wc = item.WorkingCopy; if (wc != null) { Uri root = wc.RepositoryRoot; if (root != null) { Uri relative = root.MakeRelativeUri(item.Uri); if (!relative.IsAbsoluteUri) { string v = SvnTools.UriPartToPath(relative.ToString()).Replace(Path.DirectorySeparatorChar, '/'); if (!string.IsNullOrEmpty(v) && !v.StartsWith("/") && !v.StartsWith("../") && v != ".") { return("^/" + v); } } } } return(item.Uri.ToString()); }
private void dirUpButton_Click(object sender, EventArgs e) { Uri uri; if (Uri.TryCreate(urlBox.Text.Trim(), UriKind.Absolute, out uri)) { Uri parentUri = new Uri(uri, "../"); if (parentUri == uri || _repositoryRoots.Contains(uri)) { return; } Uri fileUri; string fileText = fileNameBox.Text.Trim(); if (!string.IsNullOrEmpty(fileText) && Uri.TryCreate(fileText.Trim(), UriKind.Relative, out fileUri)) { fileUri = parentUri.MakeRelativeUri(SvnTools.AppendPathSuffix(uri, fileText.Trim())); fileNameBox.Text = fileUri.ToString(); } SetDirectory(parentUri); RefreshBox(parentUri); } }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (DesignMode) { return; } string directory = File.Exists(PathToAdd) ? Path.GetDirectoryName(PathToAdd) : PathToAdd; string root = Path.GetPathRoot(directory); projectNameBox.Text = Path.GetFileNameWithoutExtension(PathToAdd); localFolder.Items.Add(directory); while (!root.Equals(directory, StringComparison.OrdinalIgnoreCase)) { directory = SvnTools.GetNormalizedDirectoryName(directory); localFolder.Items.Add(directory); } if (localFolder.Items.Count > 0) { localFolder.SelectedIndex = 0; } }
void UpdateVersionable() { bool versionable; SvnItemState state; if (TryGetState(SvnItemState.Versioned, out state) && state != 0) { versionable = true; } else if (Exists && SvnTools.IsBelowManagedPath(FullPath)) // Will call GetState again! { versionable = true; } else { versionable = false; } if (versionable) { SetState(SvnItemState.Versionable, SvnItemState.None); } else { SetState(SvnItemState.None, SvnItemState.Versionable); } }
private void okButton_Click(object sender, EventArgs e) { string path = directory.Text; if (!SvnItem.IsValidPath(path) || File.Exists(path)) { MessageBox.Show(this, "Path is not valid", "Open Project from Subversion", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } directory.Text = path = SvnTools.GetNormalizedFullPath(path); if (Directory.Exists(path)) { DirectoryInfo di = new DirectoryInfo(path); if (EnumTools.GetFirst(di.GetFileSystemInfos()) != null) { if (MessageBox.Show(this, string.Format("{0} already contains files or directories.\nWould you like to continue?", path) , "Open Project from Subversion", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) != DialogResult.Yes) { return; } } } else { Directory.CreateDirectory(path); } DialogResult = DialogResult.OK; }
public override void OnExecute(CommandEventArgs e) { ISvnRepositoryItem item = EnumTools.GetSingle(e.Selection.GetSelection <ISvnRepositoryItem>()); if (item == null) { return; } string newName = item.Origin.Target.FileName; if (e.Argument != null) { string[] items = e.Argument as string[]; if (items != null) { if (items.Length == 1) { newName = items[0]; } else if (items.Length > 1) { newName = items[1]; } } } string logMessage; using (RenameDialog dlg = new RenameDialog()) { dlg.Context = e.Context; dlg.OldName = item.Origin.Target.FileName; dlg.NewName = newName; if (DialogResult.OK != dlg.ShowDialog(e.Context)) { return; } newName = dlg.NewName; logMessage = dlg.LogMessage; } try { Uri itemUri = SvnTools.GetNormalizedUri(item.Origin.Uri); e.GetService <IProgressRunner>().RunModal(CommandStrings.RenamingNodes, delegate(object sender, ProgressWorkerArgs we) { SvnMoveArgs ma = new SvnMoveArgs(); ma.LogMessage = logMessage; we.Client.RemoteMove(itemUri, new Uri(itemUri, newName), ma); }); } finally { item.RefreshItem(true); } }
public void CreateDirectory_CreateTrunk() { SvnSandBox sbox = new SvnSandBox(this); Uri ReposUrl = sbox.CreateRepository(SandBoxRepository.Empty); using (SvnClient client = NewSvnClient(true, false)) { Uri trunkUri = new Uri(ReposUrl, "trunk/"); client.RemoteCreateDirectory(trunkUri); string trunkPath = sbox.Wc; client.CheckOut(trunkUri, trunkPath); TouchFile(Path.Combine(trunkPath, "test.txt")); Assert.That(SvnTools.IsManagedPath(trunkPath)); Assert.That(SvnTools.IsBelowManagedPath(trunkPath)); Assert.That(SvnTools.IsBelowManagedPath(Path.Combine(trunkPath, "q/r/s/t/u/v/test.txt"))); client.Add(Path.Combine(trunkPath, "test.txt")); Directory.CreateDirectory(Path.Combine(trunkPath, "dir")); TouchFile(Path.Combine(trunkPath, "dir/test.txt")); SvnAddArgs aa = new SvnAddArgs(); aa.AddParents = true; client.Add(Path.Combine(trunkPath, "dir/test.txt"), aa); client.Commit(trunkPath); client.RemoteDelete(trunkUri, new SvnDeleteArgs()); } }
protected override void UndoExcludeItems(string projectFile, string[] itemNames) { List <string> changed = null; foreach (string item in itemNames) { if (!IsSafeSccPath(item)) { continue; } string path = SvnTools.GetNormalizedFullPath(item); if (ProjectMap.SccRemoveExcluded(path)) { if (changed == null) { changed = new List <string>(); } changed.Add(path); } } if (changed != null) { PendingChanges.Refresh(changed); } }
protected override void ExcludeItems(string projectFile, string[] itemNames) { List <string> changed = null; foreach (string item in itemNames) { if (!IsSafeSccPath(item)) { continue; } string path = SvnTools.GetNormalizedFullPath(item); if (!ProjectMap.IsSccExcluded(path)) { ProjectMap.SccExclude(path); if (changed == null) { changed = new List <string>(); } changed.Add(path); StatusCache.SetSolutionContained(path, ProjectMap.ContainsFile(path), true); } } if (changed != null) { PendingChanges.Refresh(changed); } }
public override void OnExecute(CommandEventArgs e) { List <SvnItem> toResolve = new List <SvnItem>(); foreach (SvnItem item in e.Selection.GetSelectedSvnItems(false)) { if (item.IsCasingConflicted) { toResolve.Add(item); } } try { foreach (SvnItem item in toResolve) { string svnPath = GetSvnCasing(item); string actualPath = SvnTools.GetTruePath(item.FullPath); if (svnPath == null || actualPath == null) { continue; // not found } if (!string.Equals(svnPath, actualPath, StringComparison.OrdinalIgnoreCase)) { continue; // More than casing rename } string svnName = Path.GetFileName(svnPath); string actualName = Path.GetFileName(actualPath); if (svnName == actualName) { continue; // Can't fix directories! } IAnkhOpenDocumentTracker odt = e.GetService <IAnkhOpenDocumentTracker>(); using (odt.LockDocument(svnPath, DocumentLockType.NoReload)) using (odt.LockDocument(actualPath, DocumentLockType.NoReload)) { try { // Try the actual rename File.Move(actualPath, svnPath); } catch { } try { // And try to fix the project+document system VsShellUtilities.RenameDocument(e.Context, actualPath, svnPath); } catch { } } } } finally { e.GetService <IFileStatusMonitor>().ScheduleSvnStatus(SvnItem.GetPaths(toResolve)); } }
public override EnvDTE80.SourceControlBindings GetBindings(string ItemPath) { if (!IsSafeSccPath(ItemPath)) { return(null); } return(new AnkhSccSourceControlBinding(this, SvnTools.GetNormalizedFullPath(ItemPath))); }