Dumps the VSS project/file hierarchy to a text writer.
Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.Default;

            var invalidArg = false;
            var argIndex   = 0;

            while (argIndex < args.Length && args[argIndex].StartsWith("/"))
            {
                var option = args[argIndex].Substring(1).Split(':');
                switch (option[0])
                {
                case "encoding":
                {
                    string encodingName;
                    if (option.Length > 1)
                    {
                        encodingName = option[1];
                    }
                    else if (argIndex + 1 < args.Length)
                    {
                        encodingName = args[++argIndex];
                    }
                    else
                    {
                        invalidArg = true;
                        goto InvalidArg;
                    }

                    Encoding encoding;
                    try
                    {
                        int codePage;
                        if (int.TryParse(encodingName, out codePage))
                        {
                            encoding = Encoding.GetEncoding(codePage);
                        }
                        else
                        {
                            encoding = Encoding.GetEncoding(encodingName);
                        }
                    }
                    catch
                    {
                        Console.WriteLine("Invalid encoding: {0}", encodingName);
                        invalidArg = true;
                        goto InvalidArg;
                    }

                    Console.OutputEncoding = encoding;
                    break;
                }

                case "encodings":
                {
                    var encodings = Encoding.GetEncodings();
                    Console.WriteLine("{0,-6} {1,-25} {2}", "CP", "IANA", "Description");
                    foreach (var encoding in encodings)
                    {
                        var codePage = encoding.CodePage;
                        switch (codePage)
                        {
                        case 1200:
                        case 1201:
                        case 12000:
                        case 12001:
                            // UTF-16 and 32 are managed-only
                            continue;
                        }
                        Console.WriteLine("{0,-6} {1,-25} {2}", codePage, encoding.Name, encoding.DisplayName);
                    }
                    return;
                }
                }
                ++argIndex;
            }

InvalidArg:
            if (invalidArg || argIndex >= args.Length)
            {
                Console.WriteLine("Syntax: VssDump [options] <vss-base-path>");
                Console.WriteLine("Options:");
                Console.WriteLine("  /encoding:<encoding>    Output encoding IANA name or code page");
                Console.WriteLine("  /encodings              List supported encodings and terminate");
                return;
            }

            var repoPath = args[argIndex];
            var df       = new VssDatabaseFactory(repoPath);
            var db       = df.Open();

            Console.WriteLine("File hierarchy:");
            Console.WriteLine(Separator);
            var tree = new TreeDumper(Console.Out)
            {
                IncludeRevisions = false
            };

            tree.DumpProject(db.RootProject);
            Console.WriteLine();

            Console.WriteLine("Log file contents:");
            for (char c = 'a'; c <= 'z'; ++c)
            {
                string[] dataPaths = Directory.GetFiles(
                    Path.Combine(db.DataPath, c.ToString()), "*.");
                foreach (string dataPath in dataPaths)
                {
                    var dataFile = Path.GetFileName(dataPath).ToUpper();
                    var orphaned = !tree.PhysicalNames.Contains(dataFile);
                    Console.WriteLine(Separator);
                    Console.WriteLine("{0}{1}", dataPath, orphaned ? " (orphaned)" : "");
                    DumpLogFile(dataPath);
                }
            }
            Console.WriteLine();

            Console.WriteLine("Name file contents:");
            Console.WriteLine(Separator);
            var namePath = Path.Combine(db.DataPath, "names.dat");

            DumpNameFile(namePath);
            Console.WriteLine();

            Console.WriteLine(Separator);
            Console.WriteLine("Project actions: {0}", FormatCollection(projectActions));
            Console.WriteLine("File actions: {0}", FormatCollection(fileActions));
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.Default;

            var invalidArg = false;
            var listRevisions = false;
            var argIndex = 0;
            while (!invalidArg && argIndex < args.Length && args[argIndex].StartsWith("--"))
            {
                var option = args[argIndex].Substring(2).Split(':');
                switch (option[0])
                {
                    case "revisions":
                        {
                            listRevisions = true;
                            break;
                        }

                    case "encoding":
                        {
                            string encodingName;
                            if (option.Length > 1)
                            {
                                encodingName = option[1];
                            }
                            else if (argIndex + 1 < args.Length)
                            {
                                encodingName = args[++argIndex];
                            }
                            else
                            {
                                invalidArg = true;
                                goto InvalidArg;
                            }

                            Encoding encoding;
                            try
                            {
                                int codePage;
                                if (int.TryParse(encodingName, out codePage))
                                {
                                    encoding = Encoding.GetEncoding(codePage);
                                }
                                else
                                {
                                    encoding = Encoding.GetEncoding(encodingName);
                                }
                            }
                            catch
                            {
                                Console.WriteLine("Invalid encoding: {0}", encodingName);
                                invalidArg = true;
                                goto InvalidArg;
                            }

                            Console.OutputEncoding = encoding;
                            break;
                        }

                    case "encodings":
                        {
                            var encodings = Encoding.GetEncodings();
                            Console.WriteLine("{0,-6} {1,-25} {2}", "CP", "IANA", "Description");
                            foreach (var encoding in encodings)
                            {
                                var codePage = encoding.CodePage;
                                switch (codePage)
                                {
                                    case 1200:
                                    case 1201:
                                    case 12000:
                                    case 12001:
                                        // UTF-16 and 32 are managed-only
                                        continue;
                                }
                                Console.WriteLine("{0,-6} {1,-25} {2}", codePage, encoding.Name, encoding.DisplayName);
                            }
                            return;
                        }

                    default:
                        {
                            invalidArg = true;
                            break;
                        }
                }
                ++argIndex;
            }

            InvalidArg:
            if (invalidArg || argIndex >= args.Length)
            {
                Console.WriteLine("Syntax: VssDump [options] <vss-base-path>");
                Console.WriteLine("Options:");
                Console.WriteLine("  --encoding:<encoding>    Output encoding IANA name or code page");
                Console.WriteLine("  --encodings              List supported encodings and terminate");
                Console.WriteLine("  --revisions              Include file revision information");
                return;
            }

            var repoPath = args[argIndex];
            var df = new VssDatabaseFactory(repoPath);
            var db = df.Open();

            Console.WriteLine("File hierarchy:");
            Console.WriteLine(Separator);
            var tree = new TreeDumper(Console.Out) { IncludeRevisions = false };
            tree.IncludeRevisions = listRevisions;
            tree.DumpProject(db.RootProject);
            Console.WriteLine();

            Console.WriteLine("Log file contents:");
            for (char c = 'a'; c <= 'z'; ++c)
            {
                string[] dataPaths = Directory.GetFiles(
                    Path.Combine(db.DataPath, c.ToString()), "*.");
                foreach (string dataPath in dataPaths)
                {
                    var dataFile = Path.GetFileName(dataPath).ToUpper();
                    if (Type.GetType("Mono.Runtime") != null)
                    {
                        dataFile = dataFile.ToLower();
                    }
                    var orphaned = !tree.PhysicalNames.Contains(dataFile);
                    Console.WriteLine(Separator);
                    Console.WriteLine("{0}{1}", dataPath, orphaned ? " (orphaned)" : "");
                    DumpLogFile(dataPath);
                }
            }
            Console.WriteLine();

            Console.WriteLine("Name file contents:");
            Console.WriteLine(Separator);
            var namePath = Path.Combine(db.DataPath, "names.dat");
            DumpNameFile(namePath);
            Console.WriteLine();

            Console.WriteLine(Separator);
            Console.WriteLine("Project actions: {0}", FormatCollection(projectActions));
            Console.WriteLine("File actions: {0}", FormatCollection(fileActions));
        }