示例#1
0
        public SourceDumper(string referenceDirectory, HashSet<Option> options)
        {
            _referenceDirectory = referenceDirectory;
            _directoryPath = new UPath(_referenceDirectory);

            _options = options;
        }
示例#2
0
 public IEnumerable<string> Dump(IEnumerable<string> sources)
 {
     var list = new List<string>();
     foreach (var source in sources)
     {
         var res = source;
         if (_options.Contains(SourceDumperOptions.UnixPaths))
         {
             res = res.Replace('\\', '/');
         }
         if (_options.Contains(SourceDumperOptions.RelativePaths))
         {
             UPath file;
             if (IsPathRooted(res))
             {
                 if (res.Contains(':') && _referenceDirectory.Contains(':'))
                 {
                     if (_referenceDirectory[0] != res[0])
                     {
                         throw new InvalidOperationException("csproj in " + _referenceDirectory +
                                                             " is not on the same drive that " + res);
                     }
                 }
                 file = new UPath(res);
             }
             else
             {
                 file = new UPath(_referenceDirectory, res);
             }
             res = _directoryPath.MakeRelativeUPath(file).ToString();
         }
         if (_options.Contains(SourceDumperOptions.WindowsPaths))
         {
             res = res.Replace('/', '\\');
         }
         if (_options.Contains(SourceDumperOptions.AbsolutePaths))
         {
             if (!IsPathRooted(res)) // if path is rooted
             {
                 var file = new UPath(res);
                 if (file.HasAbsolute)
                 {
                     res = file.Absolute.ToString();
                 }
             }
         }
         list.Add(res);
     }
     return list;
 }
示例#3
0
        /// <summary>
        ///     Add missing items in the project and removes items not found in source file.
        ///     Note that there are some files which are generated, so file existence should not be checked.
        /// </summary>
        /// <param name="comparison">The comparison.</param>
        public void Update(SourceComparison comparison)
        {
            RemoveDuplicates();
            ReplaceByLinks();
            if (!_configuration.Options.Contains(ProgramOptions.NoDelete))
            {
                var hash = comparison.MissingFilesInSource.Select(x => x.Path.ToLower()).ToHashSet();
                var items = _project.GetItems("Compile").ToArray();
                foreach (var item in items)
                {
                    var key = item.EvaluatedInclude.Replace('\\', '/').ToLower();
                    if (hash.Contains(key))
                    {
                        _project.RemoveItem(item);
                    }
                }
            }

            foreach (var item in comparison.MissingFilesInProject)
            {
                var fileName = Path.Combine(directory, item.Path);
                var path = new UPath(directory);
                var fileUPath = new UPath(fileName);
                var res = path.MakeRelativeUPath(fileUPath);
                var metadata = ExtractMetadata(directory, res.ToString());
                _project.AddItem("Compile", res.ToString(), metadata);
            }
            RemoveNotExisting();
            _project.Save();
        }
示例#4
0
文件: UPath.cs 项目: stormleoxia/lx
 public UPath MakeRelativeUPath(UPath file)
 {
     if (file.HasAbsolute && HasAbsolute)
     {
         return MakeRelativeUPath(_absolute, file._absolute);
     }
     if (file.HasRelative && HasRelative)
     {
         return MakeRelativeUPath(_relative, file._relative);
     }
     if (file.HasRelative && HasAbsolute)
     {
         return file;
     }
     throw new InvalidOperationException(
         "We cannot make relative path between two not found relative and absolute paths:" + this + " and " +
         file);
 }