예제 #1
0
        static async Task <string> CompareFiles(string ofi, string nfi, PathMatchLevel matchLevel)
        {
            FileComparer cmp = GetComparerForFile(ofi);

            string diff = await cmp.Compare(ofi, nfi);

            if (!String.IsNullOrWhiteSpace(diff) || matchLevel != PathMatchLevel.FullMatch)
            {
                StringBuilder output = new StringBuilder();
                output.AppendLine("Diff " + ofi + " vs " + nfi + ":");
                switch (matchLevel)
                {
                case PathMatchLevel.CaseInsensitiveMatch:
                    output.AppendLine("(NOTE: File paths differ in case)");
                    break;

                case PathMatchLevel.SubstitutionMatch:
                    output.AppendLine("(NOTE: New file has no exact counterpart in old tree, using a substitution)");
                    break;
                }
                output.AppendLine(diff);
                return(output.ToString());
            }
            return(String.Empty);
        }
예제 #2
0
        static string FindOldFile(FileInfo nfi, string rootOld, string rootNew, out PathMatchLevel matchLevel)
        {
            int rootLength = rootNew.Length;

            if (!rootNew.EndsWith(Path.DirectorySeparatorChar.ToString()))
            {
                rootLength++;
            }
            string nameOnly = nfi.FullName.Substring(rootLength);

            // try exact match first
            string ofi = Path.Combine(rootOld, nameOnly);

            if (File.Exists(ofi))
            {
                string exactName = Tools.GetProperFilePathCapitalization(ofi);
                if (ofi == exactName)
                {
                    matchLevel = PathMatchLevel.FullMatch;
                }
                else
                {
                    matchLevel = PathMatchLevel.CaseInsensitiveMatch;
                }
                return(exactName);
            }

            // try a substitution if exact/case-insensitive match failed
            foreach (var subst in substitutions)
            {
                if (nameOnly.ToLower().StartsWith(subst.Key.ToLower()))
                {
                    string substNameOnly = subst.Value + nameOnly.Substring(subst.Key.Length);
                    ofi = Path.Combine(rootOld, substNameOnly);
                    if (File.Exists(ofi))
                    {
                        matchLevel = PathMatchLevel.SubstitutionMatch;
                        return(ofi);
                    }
                }
            }

            // give up, there's no good old file to diff this new file against
            matchLevel = PathMatchLevel.None;
            return(null);
        }