Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
6.4 KiB

  1. ��Imports EnvDTE
  2. Imports System.Diagnostics
  3. Public Module Perforce
  4. Function FindInPath(ByVal exeName As String)
  5. Dim env = System.Environment.GetEnvironmentVariable("Path")
  6. Dim Paths = Split(env, ";")
  7. Dim Element
  8. Dim p4Filename = ""
  9. For Each Element In Paths
  10. If Right(Element, 1) <> "\" And Right(Element, 1) <> "/" Then
  11. Element = Element + "\"
  12. End If
  13. If System.IO.File.Exists(Element + exeName) Then
  14. Return Element + exeName
  15. End If
  16. Next
  17. FindInPath = ""
  18. End Function
  19. Function StripLastDir(ByVal curPath As String)
  20. Dim testPath = curPath.Replace("/", "\")
  21. Dim lastIndex = testPath.LastIndexOf("\")
  22. If lastIndex = -1 Then
  23. Return ""
  24. Else
  25. Return Left(testPath, lastIndex)
  26. End If
  27. End Function
  28. Function EZRunCommand(ByVal exeName As String, ByVal args As String, ByVal p4StartDir As String)
  29. ' Find the p4 command.
  30. Dim p4Filename = FindInPath(exeName)
  31. If p4Filename = "" Then
  32. MsgBox("Can't find " + exeName + " in path.")
  33. Return ""
  34. End If
  35. ' Run p4 edit <filename>
  36. Dim p = New System.Diagnostics.Process
  37. p.StartInfo.UseShellExecute = False
  38. p.StartInfo.RedirectStandardError = True
  39. p.StartInfo.Arguments = args
  40. p.StartInfo.FileName = p4Filename
  41. p.StartInfo.CreateNoWindow = True
  42. p.StartInfo.WorkingDirectory = ""
  43. p.Start()
  44. Dim outputStr = p.StandardError.ReadToEnd()
  45. p.WaitForExit()
  46. If p.ExitCode <> 0 Then
  47. MsgBox(outputStr)
  48. Return False
  49. Else
  50. Return True
  51. End If
  52. End Function
  53. Sub OutputDebugStr(ByVal str As String)
  54. Dim win As Window = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput)
  55. ' Create handles to the Output window and its panes.
  56. Dim OW As OutputWindow = win.Object
  57. Dim OWp As OutputWindowPane
  58. ' Add a new pane to the Output window.
  59. Try
  60. OWp = OW.OutputWindowPanes.Item("Build")
  61. Catch e As System.Exception
  62. OWp = OW.OutputWindowPanes.Add("Build")
  63. End Try
  64. ' Add a line of text to the new pane.
  65. OWp.OutputString(str + System.Environment.NewLine)
  66. End Sub
  67. Sub EditCurrentFile()
  68. If EZRunCommand("p4.exe", "edit " + Chr(34) + ActiveDocument.FullName + Chr(34), ActiveDocument.FullName) Then
  69. OutputDebugStr(ActiveDocument.FullName + " edited successfully.")
  70. End If
  71. End Sub
  72. Sub AddCurrentFile()
  73. If EZRunCommand("p4.exe", "add " + Chr(34) + ActiveDocument.FullName + Chr(34), ActiveDocument.FullName) Then
  74. OutputDebugStr(ActiveDocument.FullName + " added successfully.")
  75. End If
  76. End Sub
  77. Sub RevertCurrentFile()
  78. If EZRunCommand("p4.exe", "revert " + Chr(34) + ActiveDocument.FullName + Chr(34), ActiveDocument.FullName) Then
  79. OutputDebugStr(ActiveDocument.FullName + " reverted successfully.")
  80. End If
  81. End Sub
  82. End Module