本文整理汇总了C#中FilePath.ToRelative方法的典型用法代码示例。如果您正苦于以下问题:C# FilePath.ToRelative方法的具体用法?C# FilePath.ToRelative怎么用?C# FilePath.ToRelative使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FilePath
的用法示例。
在下文中一共展示了FilePath.ToRelative方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindSourceFile
/// <summary>
/// Finds the source file.
/// </summary>
/// <returns>The source file.</returns>
/// <param name="originalFile">File from .mdb/.pdb.</param>
/// <param name="hash">Hash of original file stored in .mdb/.pdb.</param>
public static FilePath FindSourceFile (FilePath originalFile, byte[] hash)
{
if (directMapping.ContainsKey (originalFile))
return directMapping [originalFile];
foreach (var folder in possiblePaths) {
//file = /tmp/ci_build/mono/System/Net/Http/HttpClient.cs
var relativePath = originalFile.ToRelative (folder.Item1);
//relativePath = System/Net/Http/HttpClient.cs
var newFile = folder.Item2.Combine (relativePath);
//newPossiblePath = C:\GIT\mono_source\System\Net\Http\HttpClient.cs
if (CheckFileMd5 (newFile, hash)) {
directMapping.Add (originalFile, newFile);
return newFile;
}
}
foreach (var document in IdeApp.Workbench.Documents.Where((d) => d.FileName.FileName == originalFile.FileName)) {
//Check if it's already added to avoid MD5 checking
if (!directMapping.ContainsKey (originalFile)) {
if (CheckFileMd5 (document.FileName, hash)) {
AddLoadedFile (document.FileName, originalFile);
return document.FileName;
}
}
}
foreach (var bp in DebuggingService.Breakpoints.GetBreakpoints().Where((bp) => Path.GetFileName(bp.FileName) == originalFile.FileName)) {
//Check if it's already added to avoid MD5 checking
if (!directMapping.ContainsKey (originalFile)) {
if (CheckFileMd5 (bp.FileName, hash)) {
AddLoadedFile (bp.FileName, originalFile);
return bp.FileName;
}
}
}
return FilePath.Null;
}
示例2: IsVersioned
public override bool IsVersioned(FilePath localPath)
{
bool isVersioned = false;
string relativePath = localPath.ToRelative(
_coreRepository.WorkingDirectory.FullName).ToString().Replace('\\', '/');
if (_coreRepository == null || _coreRepository.Directory == null)
isVersioned = false;
else
isVersioned = CachedStatus != null && !CachedStatus.Untracked.Contains(relativePath);
return isVersioned;
}
示例3: Compile
public void Compile (PythonProject project,
FilePath fileName,
PythonConfiguration config,
BuildResult result)
{
if (String.IsNullOrEmpty (fileName))
throw new ArgumentNullException ("fileName");
else if (config == null)
throw new ArgumentNullException ("config");
else if (result == null)
throw new ArgumentNullException ("result");
else if (Runtime == null)
throw new InvalidOperationException ("No supported runtime!");
// Get our relative path within the project
if (!fileName.IsChildPathOf (project.BaseDirectory)) {
Console.WriteLine ("File is not within our project!");
return;
}
FilePath relName = fileName.ToRelative (project.BaseDirectory);
string outFile = relName.ToAbsolute (config.OutputDirectory);
if (!outFile.EndsWith (".py"))
return;
// Create the destination directory
FileInfo fileInfo = new FileInfo (outFile);
if (!fileInfo.Directory.Exists)
fileInfo.Directory.Create ();
// Create and start our process to generate the byte code
Process process = BuildCompileProcess (fileName, outFile, config.Optimize);
process.Start ();
process.WaitForExit ();
// Parse errors and warnings
string output = process.StandardError.ReadToEnd ();
// Extract potential Warnings
foreach (Match m in m_WarningRegex.Matches (output)) {
string lineNum = m.Groups[m_WarningRegex.GroupNumberFromName ("line")].Value;
string message = m.Groups[m_WarningRegex.GroupNumberFromName ("message")].Value;
result.AddWarning (fileName, Int32.Parse (lineNum), 0, String.Empty, message);
}
// Extract potential SyntaxError
foreach (Match m in m_ErrorRegex.Matches (output)) {
string lineNum = m.Groups[m_ErrorRegex.GroupNumberFromName ("line")].Value;
result.AddError (fileName, Int32.Parse (lineNum), 0, String.Empty, "SyntaxError");
}
}
示例4: TransferFiles
public void TransferFiles (IProgressMonitor monitor, Project sourceProject, FilePath sourcePath, Project targetProject,
FilePath targetPath, bool removeFromSource, bool copyOnlyProjectFiles)
{
// When transfering directories, targetPath is the directory where the source
// directory will be transfered, including the destination directory or file name.
// For example, if sourcePath is /a1/a2/a3 and targetPath is /b1/b2, the
// new folder or file will be /b1/b2
if (targetProject == null)
throw new ArgumentNullException ("targetProject");
if (!targetPath.IsChildPathOf (targetProject.BaseDirectory))
throw new ArgumentException ("Invalid project folder: " + targetPath);
if (sourceProject != null && !sourcePath.IsChildPathOf (sourceProject.BaseDirectory))
throw new ArgumentException ("Invalid project folder: " + sourcePath);
if (copyOnlyProjectFiles && sourceProject == null)
throw new ArgumentException ("A source project must be specified if copyOnlyProjectFiles is True");
bool sourceIsFolder = Directory.Exists (sourcePath);
bool movingFolder = (removeFromSource && sourceIsFolder && (
!copyOnlyProjectFiles ||
IsDirectoryHierarchyEmpty (sourcePath)));
// We need to remove all files + directories from the source project
// but when dealing with the VCS addins we need to process only the
// files so we do not create a 'file' in the VCS which corresponds
// to a directory in the project and blow things up.
List<ProjectFile> filesToRemove = null;
List<ProjectFile> filesToMove = null;
try {
//get the real ProjectFiles
if (sourceProject != null) {
if (sourceIsFolder) {
var virtualPath = sourcePath.ToRelative (sourceProject.BaseDirectory);
// Grab all the child nodes of the folder we just dragged/dropped
filesToRemove = sourceProject.Files.GetFilesInVirtualPath (virtualPath).ToList ();
// Add the folder itself so we can remove it from the soruce project if its a Move operation
var folder = sourceProject.Files.Where (f => f.ProjectVirtualPath == virtualPath).FirstOrDefault ();
if (folder != null)
filesToRemove.Add (folder);
} else {
filesToRemove = new List<ProjectFile> ();
var pf = sourceProject.Files.GetFileWithVirtualPath (sourceProject.GetRelativeChildPath (sourcePath));
if (pf != null)
filesToRemove.Add (pf);
}
}
//get all the non-project files and create fake ProjectFiles
if (!copyOnlyProjectFiles || sourceProject == null) {
var col = new List<ProjectFile> ();
GetAllFilesRecursive (sourcePath, col);
if (sourceProject != null) {
var names = new HashSet<string> (filesToRemove.Select (f => sourceProject.BaseDirectory.Combine (f.ProjectVirtualPath).ToString ()));
foreach (var f in col)
if (names.Add (f.Name))
filesToRemove.Add (f);
} else {
filesToRemove = col;
}
}
} catch (Exception ex) {
monitor.ReportError (GettextCatalog.GetString ("Could not get any file from '{0}'.", sourcePath), ex);
return;
}
// Strip out all the directories to leave us with just the files.
filesToMove = filesToRemove.Where (f => f.Subtype != Subtype.Directory).ToList ();
// If copying a single file, bring any grouped children along
ProjectFile sourceParent = null;
if (filesToMove.Count == 1 && sourceProject != null) {
var pf = filesToMove[0];
if (pf != null && pf.HasChildren)
foreach (ProjectFile child in pf.DependentChildren)
filesToMove.Add (child);
sourceParent = pf;
}
// Ensure that the destination folder is created, even if no files
// are copied
try {
if (sourceIsFolder && !Directory.Exists (targetPath) && !movingFolder)
FileService.CreateDirectory (targetPath);
} catch (Exception ex) {
monitor.ReportError (GettextCatalog.GetString ("Could not create directory '{0}'.", targetPath), ex);
return;
}
// Transfer files
// If moving a folder, do it all at once
if (movingFolder) {
try {
FileService.MoveDirectory (sourcePath, targetPath);
} catch (Exception ex) {
monitor.ReportError (GettextCatalog.GetString ("Directory '{0}' could not be moved.", sourcePath), ex);
//.........这里部分代码省略.........
示例5: GetLocalStatus
private LocalStatus GetLocalStatus(FilePath localPath)
{
var st = new LocalStatus();
var commit = _coreRepository.Resolve(GitSharp.Core.Constants.HEAD);
if (commit != null)
st.Revision = commit.ToString();
string relativePath = (localPath.ToRelative(_coreRepository.WorkingDirectory.FullName)).ToString()
.Replace('\\', '/');
if (CachedStatus.Untracked.Contains(relativePath))
st.VersionStatus = VersionStatus.Unversioned;
if (CachedStatus.Added.Contains(relativePath))
st.VersionStatus = VersionStatus.Versioned | VersionStatus.ScheduledAdd;
if (CachedStatus.Removed.Contains(relativePath))
st.VersionStatus = VersionStatus.Versioned | VersionStatus.ScheduledDelete;
if (CachedStatus.Modified.Contains(relativePath))
st.VersionStatus = VersionStatus.Versioned | VersionStatus.Modified;
if (CachedStatus.Removed.Contains(relativePath))
st.VersionStatus = VersionStatus.Versioned | VersionStatus.ScheduledDelete;
// TODO: Missing some version statuses to check.
return st;
}
示例6: MakeRelative
static string MakeRelative(FilePath abs)
{
return abs.ToRelative(UnityModeAddin.UnityProjectState.BaseDirectory).ToString().Replace('\\', '/');
}
示例7: AddFile
void AddFile (FilePath filePath)
{
var relativePath = filePath.ToRelative (baseDirectory);
TreeIter iter = GetPath (relativePath.ParentDirectory);
object[] values = new object[] {
//FIXME: look these pixbufs up lazily in the renderer
DesktopService.GetIconForFile (filePath, IconSize.Menu),
null,
filePath.FileName,
filePath.ToString (),
false
};
if (iter.Equals (TreeIter.Zero)) {
store.AppendValues (values);
return;
}
store.AppendValues (iter, values);
}
示例8: GetBaseText
public override string GetBaseText (FilePath localFile)
{
StringReader sr = RunCommand ("show \":" + localFile.ToRelative (path) + "\"", true);
return sr.ReadToEnd ();
}
示例9: GetTextAtRevision
public override string GetTextAtRevision (FilePath repositoryPath, Revision revision)
{
StringReader sr = RunCommand ("show \"" + revision.ToString () + ":" + repositoryPath.ToRelative (path) + "\"", true);
return sr.ReadToEnd ();
}
示例10: ToCmdPath
string ToCmdPath (FilePath filePath)
{
return "\"" + filePath.ToRelative (path) + "\"";
}
示例11: ExpandWildcardFilePath
static IEnumerable<MSBuildItemEvaluated> ExpandWildcardFilePath (ProjectInfo pinfo, MSBuildProject project, MSBuildEvaluationContext context, MSBuildItem sourceItem, FilePath basePath, FilePath baseRecursiveDir, bool recursive, string[] filePath, int index)
{
var res = Enumerable.Empty<MSBuildItemEvaluated> ();
if (index >= filePath.Length)
return res;
var path = filePath [index];
if (path == "..")
return ExpandWildcardFilePath (pinfo, project, context, sourceItem, basePath.ParentDirectory, baseRecursiveDir, recursive, filePath, index + 1);
if (path == ".")
return ExpandWildcardFilePath (pinfo, project, context, sourceItem, basePath, baseRecursiveDir, recursive, filePath, index + 1);
if (!Directory.Exists (basePath))
return res;
if (path == "**") {
// if this is the last component of the path, there isn't any file specifier, so there is no possible match
if (index + 1 >= filePath.Length)
return res;
// If baseRecursiveDir has already been set, don't overwrite it.
if (baseRecursiveDir.IsNullOrEmpty)
baseRecursiveDir = basePath;
return ExpandWildcardFilePath (pinfo, project, context, sourceItem, basePath, baseRecursiveDir, true, filePath, index + 1);
}
if (recursive) {
// Recursive search. Try to match the remaining subpath in all subdirectories.
foreach (var dir in Directory.GetDirectories (basePath))
res = res.Concat (ExpandWildcardFilePath (pinfo, project, context, sourceItem, dir, baseRecursiveDir, true, filePath, index));
}
if (index == filePath.Length - 1) {
// Last path component. It has to be a file specifier.
string baseDir = basePath.ToRelative (project.BaseDirectory).ToString().Replace ('/','\\');
if (baseDir == ".")
baseDir = "";
else if (!baseDir.EndsWith ("\\", StringComparison.Ordinal))
baseDir += '\\';
var recursiveDir = baseRecursiveDir.IsNullOrEmpty ? FilePath.Null : basePath.ToRelative (baseRecursiveDir);
res = res.Concat (Directory.GetFiles (basePath, path).Select (f => {
context.SetItemContext (f, recursiveDir);
var ev = baseDir + Path.GetFileName (f);
return CreateEvaluatedItem (context, pinfo, project, sourceItem, ev);
}));
}
else {
// Directory specifier
// Look for matching directories.
// The search here is non-recursive, not matter what the 'recursive' parameter says, since we are trying to match a subpath.
// The recursive search is done below.
if (path.IndexOfAny (wildcards) != -1) {
foreach (var dir in Directory.GetDirectories (basePath, path))
res = res.Concat (ExpandWildcardFilePath (pinfo, project, context, sourceItem, dir, baseRecursiveDir, false, filePath, index + 1));
} else
res = res.Concat (ExpandWildcardFilePath (pinfo, project, context, sourceItem, basePath.Combine (path), baseRecursiveDir, false, filePath, index + 1));
}
return res;
}
示例12: SetNibProperty
static bool SetNibProperty (PlistDictionary dict, IPhoneProject proj, FilePath mainNibProp, string propName)
{
if (!dict.ContainsKey (propName)) {
if (mainNibProp.IsNullOrEmpty) {
return false;
} else {
string mainNib = mainNibProp.ToRelative (proj.BaseDirectory);
if (mainNib.EndsWith (".nib") || mainNib.EndsWith (".xib"))
mainNib = mainNib.Substring (0, mainNib.Length - 4).Replace ('\\', '/');
dict[propName] = mainNib;
}
}
return true;
}
示例13: AddIconRelativeIfNotEmpty
static bool AddIconRelativeIfNotEmpty (IPhoneProject proj, PlistArray arr, FilePath iconFullPath, string name)
{
var icon = iconFullPath.ToRelative (proj.BaseDirectory).ToString ();
if (string.IsNullOrEmpty (icon) || icon == ".")
return false;
arr.Add (null ?? icon);
return true;
}
示例14: TransferFiles
public void TransferFiles (IProgressMonitor monitor, Project sourceProject, FilePath sourcePath, Project targetProject,
FilePath targetPath, bool removeFromSource, bool copyOnlyProjectFiles)
{
// When transfering directories, targetPath is the directory where the source
// directory will be transfered, including the destination directory or file name.
// For example, if sourcePath is /a1/a2/a3 and targetPath is /b1/b2, the
// new folder or file will be /b1/b2
if (targetProject == null)
throw new ArgumentNullException ("targetProject");
if (!targetPath.IsChildPathOf (targetProject.BaseDirectory))
throw new ArgumentException ("Invalid project folder: " + targetPath);
if (sourceProject != null && !sourcePath.IsChildPathOf (sourceProject.BaseDirectory))
throw new ArgumentException ("Invalid project folder: " + sourcePath);
if (copyOnlyProjectFiles && sourceProject == null)
throw new ArgumentException ("A source project must be specified if copyOnlyProjectFiles is True");
bool sourceIsFolder = Directory.Exists (sourcePath);
bool movingFolder = (removeFromSource && sourceIsFolder && (
!copyOnlyProjectFiles ||
IsDirectoryHierarchyEmpty (sourcePath)));
// Get the list of files to copy
List<ProjectFile> filesToMove = null;
try {
//get the real ProjectFiles
if (sourceProject != null) {
var virtualPath = sourcePath.ToRelative (sourceProject.BaseDirectory);
filesToMove = sourceProject.Files.GetFilesInVirtualPath (virtualPath).ToList ();
}
//get all the non-project files and create fake ProjectFiles
if (!copyOnlyProjectFiles || sourceProject == null) {
var col = new List<ProjectFile> ();
GetAllFilesRecursive (sourcePath, col);
if (sourceProject != null) {
var names = new HashSet<string> (filesToMove.Select (f => sourceProject.BaseDirectory.Combine (f.ProjectVirtualPath).ToString ()));
foreach (var f in col)
if (names.Add (f.Name))
filesToMove.Add (f);
} else {
filesToMove = col;
}
}
} catch (Exception ex) {
monitor.ReportError (GettextCatalog.GetString ("Could not get any file from '{0}'.", sourcePath), ex);
return;
}
// If copying a single file, bring any grouped children along
if (filesToMove.Count == 1 && sourceProject != null) {
var pf = filesToMove[0];
if (pf != null && pf.HasChildren)
foreach (ProjectFile child in pf.DependentChildren)
filesToMove.Add (child);
}
// Ensure that the destination folder is created, even if no files
// are copied
try {
if (sourceIsFolder && !Directory.Exists (targetPath) && !movingFolder)
FileService.CreateDirectory (targetPath);
} catch (Exception ex) {
monitor.ReportError (GettextCatalog.GetString ("Could not create directory '{0}'.", targetPath), ex);
return;
}
// Transfer files
// If moving a folder, do it all at once
if (movingFolder) {
try {
FileService.MoveDirectory (sourcePath, targetPath);
} catch (Exception ex) {
monitor.ReportError (GettextCatalog.GetString ("Directory '{0}' could not be moved.", sourcePath), ex);
return;
}
}
monitor.BeginTask (GettextCatalog.GetString ("Copying files..."), filesToMove.Count);
foreach (ProjectFile file in filesToMove) {
bool fileIsLink = file.Project != null && file.IsLink;
var sourceFile = fileIsLink
? file.Project.BaseDirectory.Combine (file.ProjectVirtualPath)
: file.FilePath;
var newFile = sourceIsFolder ? targetPath.Combine (sourceFile.ToRelative (sourcePath)) : targetPath;
if (!movingFolder && !fileIsLink) {
try {
FilePath fileDir = newFile.ParentDirectory;
if (!Directory.Exists (fileDir) && !file.IsLink)
FileService.CreateDirectory (fileDir);
if (removeFromSource)
//.........这里部分代码省略.........