Exemple #1
0
        protected override bool RunInternal(Area ws, Versionr.Status status, IList <Versionr.Status.StatusEntry> targets, FileBaseCommandVerbOptions options)
        {
            BomCheckEOLOptions localOptions = options as BomCheckEOLOptions;

            LocalOptions = localOptions;
            try
            {
                List <Versionr.Status.StatusEntry> realTargets = new List <Status.StatusEntry>();
                foreach (var x in targets)
                {
                    if (!x.IsDirectory && x.FilesystemEntry != null)
                    {
                        if (localOptions.Recorded && x.Staged == false)
                        {
                            continue;
                        }
                        realTargets.Add(x);
                    }
                }
                Printer.PrintMessage("{0} files in initial list...", realTargets.Count);

                CheckEOLStats cs = new CheckEOLStats();

                List <Task> tasks = new List <Task>();
                foreach (var x in realTargets)
                {
                    tasks.Add(GetTaskFactory(options).StartNew(() =>
                    {
                        var newFileType = Versionr.Utilities.FileClassifier.Classify(x.FilesystemEntry.Info);
                        if (newFileType == Versionr.Utilities.FileEncoding.Binary)
                        {
                            return;
                        }
                        // Displaying local modifications
                        Encoding encoding = BomClean.VSREncodingToEncoding(newFileType);
                        string fullText;
                        using (var fs = x.FilesystemEntry.Info.OpenRead())
                            using (var sr = new System.IO.StreamReader(fs, encoding))
                            {
                                fullText = sr.ReadToEnd();
                            }
                        IdentifyLineEndings(x.CanonicalName, fullText, localOptions, cs);
                    }));
                    if (System.Diagnostics.Debugger.IsAttached)
                    {
                        tasks[tasks.Count - 1].Wait();
                    }
                }
                Task.WaitAll(tasks.ToArray());
                if ((cs.CRLFFiles + cs.CRFiles + cs.LFFiles + cs.MixedFiles) > 1)
                {
                    Printer.PrintMessage("Final Count:");
                    if (cs.CRLFFiles > 0)
                    {
                        Printer.PrintMessage("\t#b#{0}## CRLF", cs.CRLFFiles);
                    }
                    if (cs.LFFiles > 0)
                    {
                        Printer.PrintMessage("\t#b#{0}## LF", cs.LFFiles);
                    }
                    if (cs.CRFiles > 0)
                    {
                        Printer.PrintMessage("\t#b#{0}## CR", cs.CRFiles);
                    }
                    if (cs.MixedFiles > 0)
                    {
                        Printer.PrintMessage("\t#w#{0}## Mixed", cs.MixedFiles);
                    }
                }
            }
            finally
            {
            }
            return(true);
        }
Exemple #2
0
        protected override bool RunInternal(Area ws, Versionr.Status status, IList <Versionr.Status.StatusEntry> targets, FileBaseCommandVerbOptions options)
        {
            BomSetEOLOptions localOptions = options as BomSetEOLOptions;

            LocalOptions = localOptions;
            try
            {
                List <Versionr.Status.StatusEntry> realTargets = new List <Status.StatusEntry>();
                foreach (var x in targets)
                {
                    if (!x.IsDirectory && x.FilesystemEntry != null)
                    {
                        if (localOptions.Recorded && x.Staged == false)
                        {
                            continue;
                        }
                        realTargets.Add(x);
                    }
                }
                Printer.PrintMessage("{0} files in initial list...", realTargets.Count);

                EOLStats cs = new EOLStats();

                List <Task> tasks = new List <Task>();
                foreach (var x in realTargets)
                {
                    tasks.Add(GetTaskFactory(options).StartNew(() =>
                    {
                        var newFileType = Versionr.Utilities.FileClassifier.Classify(x.FilesystemEntry.Info);
                        if (newFileType == Versionr.Utilities.FileEncoding.Binary)
                        {
                            return;
                        }
                        // Displaying local modifications
                        Encoding encoding = BomClean.VSREncodingToEncoding(newFileType);
                        string fullText;
                        using (var fs = x.FilesystemEntry.Info.OpenRead())
                            using (var sr = new System.IO.StreamReader(fs, encoding))
                            {
                                fullText = sr.ReadToEnd();
                            }
                        string resultString;
                        BomClean.LineEndingType let;
                        if (UnifyLineEndings(fullText, localOptions, out resultString, out let))
                        {
                            x.FilesystemEntry.Info.IsReadOnly = false;
                            using (var fs = x.FilesystemEntry.Info.Open(System.IO.FileMode.Create))
                                using (var sw = new System.IO.StreamWriter(fs, encoding))
                                {
                                    sw.Write(resultString);
                                }
                            cs.LEFixes++;
                            Printer.PrintMessage("#b#{0}##: => #s#{1}", x.CanonicalName, let == BomClean.LineEndingType.CR ? "CR" : let == BomClean.LineEndingType.CRLF ? "CRLF" : "LF");
                        }
                    }));
                    if (System.Diagnostics.Debugger.IsAttached)
                    {
                        tasks[tasks.Count - 1].Wait();
                    }
                }
                Task.WaitAll(tasks.ToArray());
                if (cs.LEFixes > 0)
                {
                    Printer.PrintMessage("Updated line endings for {0} files.", cs.LEFixes);
                }
            }
            finally
            {
            }
            return(true);
        }