System.Data.SQLite

Check-in [f808de76f7]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Work in progress on the design-time components installer.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | designTimeInstaller
Files: files | file ages | folders
SHA1: f808de76f758c72caff51af5c4cc59e443c4d87e
User & Date: mistachkin 2017-12-06 21:28:52.831
Context
2017-12-06
22:32
Fix typo. Fix RegistryKey lifetime issue. Cleanup output format and improve code. Closed-Leaf check-in: a5dd05dc21 user: mistachkin tags: designTimeInstaller
21:28
Work in progress on the design-time components installer. check-in: f808de76f7 user: mistachkin tags: designTimeInstaller
2017-12-04
18:01
Minor corrections to test suite infrastructure. check-in: 8314652c94 user: mistachkin tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to tools/install/Installer.cs.
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
            {
                return dateTime.ToString(Iso8601DateTimeOutputFormat);
            }

            ///////////////////////////////////////////////////////////////////

            [MethodImpl(MethodImplOptions.NoInlining)]
            private static string GetMethodName(
                StackTrace stackTrace,
                int level
                )
            {
                try
                {
                    //







|







485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
            {
                return dateTime.ToString(Iso8601DateTimeOutputFormat);
            }

            ///////////////////////////////////////////////////////////////////

            [MethodImpl(MethodImplOptions.NoInlining)]
            public static string GetMethodName(
                StackTrace stackTrace,
                int level
                )
            {
                try
                {
                    //
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
            ///////////////////////////////////////////////////////////////////

            public static void DebugCore(
                string message,
                string category
                )
            {
                lock (syncRoot)
                {
                    if (debugListeners != null)
                    {
                        foreach (TraceListener listener in debugListeners)
                        {
                            listener.WriteLine(message, category);
                            listener.Flush();
                        }
                    }
                }
            }

            ///////////////////////////////////////////////////////////////////

            public static void TraceCore(
                string message,
                string category
                )
            {
                lock (syncRoot)
                {
                    //
                    // NOTE: Write the message to all the active trace
                    //       listeners.
                    //
                    Trace.WriteLine(message, category);
                    Trace.Flush();







|



















|







553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
            ///////////////////////////////////////////////////////////////////

            public static void DebugCore(
                string message,
                string category
                )
            {
                lock (syncRoot) /* TRANSACTIONAL */
                {
                    if (debugListeners != null)
                    {
                        foreach (TraceListener listener in debugListeners)
                        {
                            listener.WriteLine(message, category);
                            listener.Flush();
                        }
                    }
                }
            }

            ///////////////////////////////////////////////////////////////////

            public static void TraceCore(
                string message,
                string category
                )
            {
                lock (syncRoot) /* TRANSACTIONAL */
                {
                    //
                    // NOTE: Write the message to all the active trace
                    //       listeners.
                    //
                    Trace.WriteLine(message, category);
                    Trace.Flush();
1465
1466
1467
1468
1469
1470
1471




















































































































































































































1472
1473
1474
1475
1476
1477
1478

                return this.Name;
            }
            #endregion

            ///////////////////////////////////////////////////////////////////





















































































































































































































            #region Implicit Conversion Operators
            //
            // BUGBUG: Remove me?  This should be safe because in "what-if"
            //         mode all keys are opened read-only.
            //
            public static implicit operator RegistryKey(
                MockRegistryKey key







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690

                return this.Name;
            }
            #endregion

            ///////////////////////////////////////////////////////////////////

            #region Public Static Methods
            public static bool NameEquals(
                string name1,
                string name2
                )
            {
                return String.Equals(
                    name1, name2, StringComparison.OrdinalIgnoreCase);
            }

            ///////////////////////////////////////////////////////////////////

            public static bool ValueEquals(
                object value1,
                object value2
                )
            {
                if ((value1 == null) || (value2 == null))
                    return ((value1 == null) && (value2 == null));

                if (Object.ReferenceEquals(value1, value2))
                    return true;

                Type type1 = value1.GetType();
                Type type2 = value2.GetType();

                if (!Object.ReferenceEquals(type1, type2))
                    return false;

                if (type1 == typeof(int)) // DWord
                {
                    return ((int)value1 == (int)value2);
                }
                else if (type1 == typeof(long)) // QWord
                {
                    return ((long)value1 == (long)value2);
                }
                else if (type1 == typeof(string)) // String / ExpandString
                {
                    return String.Equals(
                        (string)value1, (string)value2,
                        StringComparison.Ordinal);
                }
                else if (type1 == typeof(string[])) // MultiString
                {
                    string[] array1 = (string[])value1;
                    string[] array2 = (string[])value2;

                    int length1 = array1.Length;

                    if (length1 != array2.Length)
                        return false;

                    for (int index1 = 0; index1 < length1; index1++)
                    {
                        if (!String.Equals(
                                array1[index1], array2[index1],
                                StringComparison.Ordinal))
                        {
                            return false;
                        }
                    }

                    return true;
                }
                else if (type1 == typeof(byte[])) // Binary
                {
                    byte[] array1 = (byte[])value1;
                    byte[] array2 = (byte[])value2;

                    int length1 = array1.Length;

                    if (length1 != array2.Length)
                        return false;

                    for (int index1 = 0; index1 < length1; index1++)
                        if (array1[index1] != array2[index1])
                            return false;

                    return true;
                }

                return false;
            }

            ///////////////////////////////////////////////////////////////////

            public static int ValueHashCode(
                object value
                )
            {
                int result = 0;

                if (value != null)
                {
                    Type type = value.GetType();

                    if ((type == typeof(int)) || // DWord
                        (type == typeof(long)) || // QWord
                        (type == typeof(string))) // String / ExpandString
                    {
                        result = value.GetHashCode();
                    }
                    else if ((type == typeof(string[])) || // MultiString
                        (type == typeof(byte[]))) // Binary
                    {
                        Array array = (Array)value;
                        int length = array.Length;

                        for (int index = 0; index < length; index++)
                        {
                            object element = array.GetValue(index);

                            if (element == null)
                                continue;

                            result ^= element.GetHashCode();
                        }
                    }
                }

                return result;
            }

            ///////////////////////////////////////////////////////////////////

            public static string ValueToString(
                object value,
                string delimiter,
                string nullValue
                )
            {
                string result = null;

                if (value != null)
                {
                    Type type = value.GetType();

                    if ((type == typeof(int)) || // DWord
                        (type == typeof(long)) || // QWord
                        (type == typeof(string))) // String / ExpandString
                    {
                        result = value.ToString();
                    }
                    else if ((type == typeof(string[])) || // MultiString
                        (type == typeof(byte[]))) // Binary
                    {
                        StringBuilder builder = new StringBuilder();
                        Array array = (Array)value;
                        int length = array.Length;

                        for (int index = 0; index < length; index++)
                        {
                            if ((index > 0) && (delimiter != null))
                                builder.Append(delimiter);

                            object element = array.GetValue(index);

                            if (element == null)
                            {
                                if (nullValue != null)
                                    builder.Append(nullValue);

                                continue;
                            }

                            builder.Append(element.ToString());
                        }

                        result = builder.ToString();
                    }
                }

                return result;
            }

            ///////////////////////////////////////////////////////////////////

            public static bool Equals(
                MockRegistryKey key1,
                MockRegistryKey key2
                )
            {
                if ((key1 == null) || (key2 == null))
                    return ((key1 == null) && (key2 == null));

                if (Object.ReferenceEquals(key1, key2))
                    return true;

                return NameEquals(key1.Name, key2.Name);
            }

            ///////////////////////////////////////////////////////////////////

            public static int GetHashCode(
                MockRegistryKey key
                )
            {
                if (key != null)
                {
                    string name = key.Name;

                    if (name != null)
                        return name.GetHashCode();
                }

                return 0;
            }
            #endregion

            ///////////////////////////////////////////////////////////////////

            #region Implicit Conversion Operators
            //
            // BUGBUG: Remove me?  This should be safe because in "what-if"
            //         mode all keys are opened read-only.
            //
            public static implicit operator RegistryKey(
                MockRegistryKey key
1602
1603
1604
1605
1606
1607
1608










1609









1610
1611
1612
1613
1614
1615
1616
        };
        #endregion

        ///////////////////////////////////////////////////////////////////////

        private static class RegistryHelper
        {










            #region Public Static Properties









            private static MockRegistry readOnlyRegistry;
            public static MockRegistry ReadOnlyRegistry
            {
                get { return readOnlyRegistry; }
            }

            ///////////////////////////////////////////////////////////////////







>
>
>
>
>
>
>
>
>
>

>
>
>
>
>
>
>
>
>







1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
        };
        #endregion

        ///////////////////////////////////////////////////////////////////////

        private static class RegistryHelper
        {
            #region Private Data
            //
            // NOTE: This is used to synchronize access to the list of logged
            //       registry operations (just below).
            //
            private static object syncRoot = new object();
            #endregion

            ///////////////////////////////////////////////////////////////////

            #region Public Static Properties
            private static RegistryOperationList operationList;
            public static RegistryOperationList OperationList
            {
                get { lock (syncRoot) { return operationList; } }
                set { lock (syncRoot) { operationList = value; } }
            }

            ///////////////////////////////////////////////////////////////////

            private static MockRegistry readOnlyRegistry;
            public static MockRegistry ReadOnlyRegistry
            {
                get { return readOnlyRegistry; }
            }

            ///////////////////////////////////////////////////////////////////
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
                MockRegistry registry,
                string name
                )
            {
                if (registry == null)
                    return null;

                if (String.Equals(
                        name, RegistryRootKeyNames.HKEY_CLASSES_ROOT,
                        StringComparison.OrdinalIgnoreCase) ||
                    String.Equals(
                        name, RegistryRootKeyNames.HKCR,
                        StringComparison.OrdinalIgnoreCase))
                {
                    return registry.ClassesRoot;
                }
                else if (String.Equals(
                        name, RegistryRootKeyNames.HKEY_CURRENT_CONFIG,
                        StringComparison.OrdinalIgnoreCase) ||
                    String.Equals(
                        name, RegistryRootKeyNames.HKCC,
                        StringComparison.OrdinalIgnoreCase))
                {
                    return registry.CurrentConfig;
                }
                else if (String.Equals(
                        name, RegistryRootKeyNames.HKEY_CURRENT_USER,
                        StringComparison.OrdinalIgnoreCase) ||
                    String.Equals(
                        name, RegistryRootKeyNames.HKCU,
                        StringComparison.OrdinalIgnoreCase))
                {
                    return registry.CurrentUser;
                }
                else if (String.Equals(
                        name, RegistryRootKeyNames.HKEY_DYN_DATA,
                        StringComparison.OrdinalIgnoreCase) ||
                    String.Equals(
                        name, RegistryRootKeyNames.HKDD,
                        StringComparison.OrdinalIgnoreCase))
                {
                    return registry.DynData;
                }
                else if (String.Equals(
                        name, RegistryRootKeyNames.HKEY_LOCAL_MACHINE,
                        StringComparison.OrdinalIgnoreCase) ||
                    String.Equals(
                        name, RegistryRootKeyNames.HKLM,
                        StringComparison.OrdinalIgnoreCase))
                {
                    return registry.LocalMachine;
                }
                else if (String.Equals(
                        name, RegistryRootKeyNames.HKEY_PERFORMANCE_DATA,
                        StringComparison.OrdinalIgnoreCase) ||
                    String.Equals(
                        name, RegistryRootKeyNames.HKPD,
                        StringComparison.OrdinalIgnoreCase))
                {
                    return registry.PerformanceData;
                }
                else if (String.Equals(
                        name, RegistryRootKeyNames.HKEY_USERS,
                        StringComparison.OrdinalIgnoreCase) ||
                    String.Equals(
                        name, RegistryRootKeyNames.HKU,
                        StringComparison.OrdinalIgnoreCase))
                {
                    return registry.Users;
                }

                return null;
            }








|
|
<
|
|
<



|
|
<
|
|
<



|
|
<
|
|
<



|
|
<
|
|
<



|
|
<
|
|
<



|
|
<
|
|
<



|
|
<
|
|
<







1941
1942
1943
1944
1945
1946
1947
1948
1949

1950
1951

1952
1953
1954
1955
1956

1957
1958

1959
1960
1961
1962
1963

1964
1965

1966
1967
1968
1969
1970

1971
1972

1973
1974
1975
1976
1977

1978
1979

1980
1981
1982
1983
1984

1985
1986

1987
1988
1989
1990
1991

1992
1993

1994
1995
1996
1997
1998
1999
2000
                MockRegistry registry,
                string name
                )
            {
                if (registry == null)
                    return null;

                if (MockRegistryKey.NameEquals(
                        name, RegistryRootKeyNames.HKEY_CLASSES_ROOT) ||

                    MockRegistryKey.NameEquals(
                        name, RegistryRootKeyNames.HKCR))

                {
                    return registry.ClassesRoot;
                }
                else if (MockRegistryKey.NameEquals(
                        name, RegistryRootKeyNames.HKEY_CURRENT_CONFIG) ||

                    MockRegistryKey.NameEquals(
                        name, RegistryRootKeyNames.HKCC))

                {
                    return registry.CurrentConfig;
                }
                else if (MockRegistryKey.NameEquals(
                        name, RegistryRootKeyNames.HKEY_CURRENT_USER) ||

                    MockRegistryKey.NameEquals(
                        name, RegistryRootKeyNames.HKCU))

                {
                    return registry.CurrentUser;
                }
                else if (MockRegistryKey.NameEquals(
                        name, RegistryRootKeyNames.HKEY_DYN_DATA) ||

                    MockRegistryKey.NameEquals(
                        name, RegistryRootKeyNames.HKDD))

                {
                    return registry.DynData;
                }
                else if (MockRegistryKey.NameEquals(
                        name, RegistryRootKeyNames.HKEY_LOCAL_MACHINE) ||

                    MockRegistryKey.NameEquals(
                        name, RegistryRootKeyNames.HKLM))

                {
                    return registry.LocalMachine;
                }
                else if (MockRegistryKey.NameEquals(
                        name, RegistryRootKeyNames.HKEY_PERFORMANCE_DATA) ||

                    MockRegistryKey.NameEquals(
                        name, RegistryRootKeyNames.HKPD))

                {
                    return registry.PerformanceData;
                }
                else if (MockRegistryKey.NameEquals(
                        name, RegistryRootKeyNames.HKEY_USERS) ||

                    MockRegistryKey.NameEquals(
                        name, RegistryRootKeyNames.HKU))

                {
                    return registry.Users;
                }

                return null;
            }

1935
1936
1937
1938
1939
1940
1941


1942
1943
1944
1945
1946
1947
1948
                        return new MockRegistryKey(
                            rootKey.CreateSubKey(subKeyName), whatIf, false,
                            false);
                    }
                }
                finally
                {


                    subKeysCreated++;
                }
            }

            ///////////////////////////////////////////////////////////////////

            [MethodImpl(MethodImplOptions.NoInlining)]







>
>







2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
                        return new MockRegistryKey(
                            rootKey.CreateSubKey(subKeyName), whatIf, false,
                            false);
                    }
                }
                finally
                {
                    MaybeLogOperation(GetMethodName(), rootKey, subKeyName);

                    subKeysCreated++;
                }
            }

            ///////////////////////////////////////////////////////////////////

            [MethodImpl(MethodImplOptions.NoInlining)]
1965
1966
1967
1968
1969
1970
1971


1972
1973
1974
1975
1976
1977
1978

                if (rootKey == null)
                    return;

                if (!whatIf)
                    rootKey.DeleteSubKey(subKeyName, throwOnMissing);



                subKeysDeleted++;
            }

            ///////////////////////////////////////////////////////////////////

            [MethodImpl(MethodImplOptions.NoInlining)]
            public static void DeleteSubKeyTree(







>
>







2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199

                if (rootKey == null)
                    return;

                if (!whatIf)
                    rootKey.DeleteSubKey(subKeyName, throwOnMissing);

                MaybeLogOperation(GetMethodName(), rootKey, subKeyName);

                subKeysDeleted++;
            }

            ///////////////////////////////////////////////////////////////////

            [MethodImpl(MethodImplOptions.NoInlining)]
            public static void DeleteSubKeyTree(
1992
1993
1994
1995
1996
1997
1998


1999
2000
2001
2002
2003
2004
2005
                }

                if (rootKey == null)
                    return;

                if (!whatIf)
                    rootKey.DeleteSubKeyTree(subKeyName);



                subKeysDeleted++;
            }

            ///////////////////////////////////////////////////////////////////

            [MethodImpl(MethodImplOptions.NoInlining)]







>
>







2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
                }

                if (rootKey == null)
                    return;

                if (!whatIf)
                    rootKey.DeleteSubKeyTree(subKeyName);

                MaybeLogOperation(GetMethodName(), rootKey, subKeyName);

                subKeysDeleted++;
            }

            ///////////////////////////////////////////////////////////////////

            [MethodImpl(MethodImplOptions.NoInlining)]
2074
2075
2076
2077
2078
2079
2080


2081
2082
2083
2084
2085
2086
2087

                if (key == null)
                    return;

                if (!whatIf)
                    key.SetValue(name, value);



                keyValuesWritten++;
            }

            ///////////////////////////////////////////////////////////////////

            [MethodImpl(MethodImplOptions.NoInlining)]
            public static void DeleteValue(







>
>







2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312

                if (key == null)
                    return;

                if (!whatIf)
                    key.SetValue(name, value);

                MaybeLogOperation(GetMethodName(), key, name, value);

                keyValuesWritten++;
            }

            ///////////////////////////////////////////////////////////////////

            [MethodImpl(MethodImplOptions.NoInlining)]
            public static void DeleteValue(
2102
2103
2104
2105
2106
2107
2108


2109
2110

















































































































































































































































































































































2111
2112
2113
2114
2115
2116
2117

                if (key == null)
                    return;

                if (!whatIf)
                    key.DeleteValue(name, throwOnMissing);



                keyValuesDeleted++;
            }

















































































































































































































































































































































            #endregion
        }
        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region StringList Class







>
>


>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681

                if (key == null)
                    return;

                if (!whatIf)
                    key.DeleteValue(name, throwOnMissing);

                MaybeLogOperation(GetMethodName(), key, name, null);

                keyValuesDeleted++;
            }

            ///////////////////////////////////////////////////////////////////

            public static int WriteOperationList(
                string fileName
                )
            {
                int count = 0;

                if (String.IsNullOrEmpty(fileName))
                    return count;

                lock (syncRoot) /* TRANSACTIONAL */
                {
                    if (operationList == null)
                        return count;

                    using (StreamWriter streamWriter = new StreamWriter(
                            fileName))
                    {
                        foreach (RegistryOperation operation in operationList)
                        {
                            if (operation == null)
                                continue;

                            streamWriter.WriteLine(operationList.ToString());
                            count++;
                        }

                        streamWriter.Flush();
                    }
                }

                return count;
            }
            #endregion

            ///////////////////////////////////////////////////////////////////

            #region Private Static Methods
            [MethodImpl(MethodImplOptions.NoInlining)]
            private static string GetMethodName()
            {
                return TraceOps.GetMethodName(null, 1);
            }

            ///////////////////////////////////////////////////////////////////

            private static void MaybeLogOperation(
                string methodName,
                MockRegistryKey key,
                string subKeyName
                )
            {
                MaybeLogOperation(methodName, key, subKeyName, null, null);
            }

            ///////////////////////////////////////////////////////////////////

            private static void MaybeLogOperation(
                string methodName,
                MockRegistryKey key,
                string valueName,
                object value
                )
            {
                MaybeLogOperation(methodName, key, null, valueName, value);
            }

            ///////////////////////////////////////////////////////////////////

            private static void MaybeLogOperation(
                string methodName,
                MockRegistryKey key,
                string subKeyName,
                string valueName,
                object value
                )
            {
                lock (syncRoot) /* TRANSACTIONAL */
                {
                    if (operationList == null)
                        return;

                    operationList.Add(new RegistryOperation(
                        methodName, key, subKeyName, valueName, value));
                }
            }
            #endregion
        }
        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region RegistryOperationList Class
        [Serializable()]
        private sealed class RegistryOperationList : List<RegistryOperation>
        {
            #region Public Constructors
            public RegistryOperationList()
            {
                // do nothing.
            }
            #endregion
        }
        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region RegistryOperation Class
        private sealed class RegistryOperation
        {
            #region Public Constructors
            public RegistryOperation(
                string methodName,
                MockRegistryKey key,
                string subKeyName,
                string valueName,
                object value
                )
            {
                this.methodName = methodName;
                this.subKeyName = subKeyName;
                this.valueName = valueName;
                this.value = value;

                SetKey(key);
            }
            #endregion

            ///////////////////////////////////////////////////////////////////

            #region Private Methods
            private void SetKey(
                MockRegistryKey key
                )
            {
                if (key != null)
                {
                    //
                    // NOTE: Make sure this copy of the root registry key
                    //       cannot be used to accidentally make registry
                    //       changes.
                    //
                    this.key = new MockRegistryKey(key, true, true, true);
                }
                else
                {
                    this.key = null;
                }
            }
            #endregion

            ///////////////////////////////////////////////////////////////////

            #region Public Properties
            private string methodName;
            public string MethodName
            {
                get { CheckDisposed(); return methodName; }
            }

            ///////////////////////////////////////////////////////////////////

            private MockRegistryKey key;
            public MockRegistryKey Key
            {
                get { CheckDisposed(); return key; }
            }

            ///////////////////////////////////////////////////////////////////

            private string subKeyName;
            public string SubKeyName
            {
                get { CheckDisposed(); return subKeyName; }
            }

            ///////////////////////////////////////////////////////////////////

            private string valueName;
            public string ValueName
            {
                get { CheckDisposed(); return valueName; }
            }

            ///////////////////////////////////////////////////////////////////

            private object value;
            public object Value
            {
                get { CheckDisposed(); return value; }
            }
            #endregion

            ///////////////////////////////////////////////////////////////////

            #region System.Object Overrides
            public override bool Equals(
                object obj
                )
            {
                CheckDisposed();

                RegistryOperation operation = obj as RegistryOperation;

                if (operation == null)
                    return false;

                if (!String.Equals(operation.methodName, methodName))
                    return false;

                if (!MockRegistryKey.Equals(operation.key, key))
                    return false;

                if (!MockRegistryKey.NameEquals(
                        operation.subKeyName, subKeyName))
                {
                    return false;
                }

                if (!String.Equals(operation.valueName, valueName))
                    return false;

                if (!MockRegistryKey.ValueEquals(operation.value, value))
                    return false;

                return true;
            }

            ///////////////////////////////////////////////////////////////////

            public override int GetHashCode()
            {
                CheckDisposed();

                int result = 0;

                if (methodName != null)
                    result ^= methodName.GetHashCode();

                result ^= MockRegistryKey.GetHashCode(key);

                if (subKeyName != null)
                    result ^= subKeyName.GetHashCode();

                if (valueName != null)
                    result ^= valueName.GetHashCode();

                result ^= MockRegistryKey.ValueHashCode(value);

                return result;
            }

            ///////////////////////////////////////////////////////////////////

            public override string ToString()
            {
                CheckDisposed();

                StringBuilder builder = new StringBuilder();

                builder.Append(ForDisplay(methodName));
                builder.Append(ForDisplay(key));
                builder.Append(ForDisplay(subKeyName));
                builder.Append(ForDisplay(valueName));

                builder.Append(ForDisplay(
                    MockRegistryKey.ValueToString(value, ", ", "<null>")));

                return builder.ToString();
            }
            #endregion

            ///////////////////////////////////////////////////////////////////

            #region IDisposable "Pattern" Members
            private bool disposed;
            private void CheckDisposed() /* throw */
            {
                if (!disposed)
                    return;

                throw new ObjectDisposedException(
                    typeof(RegistryOperation).Name);
            }

            ///////////////////////////////////////////////////////////////////

            private /* protected virtual */ void Dispose(
                bool disposing
                )
            {
                if (!disposed)
                {
                    if (disposing)
                    {
                        ////////////////////////////////////
                        // dispose managed resources here...
                        ////////////////////////////////////

                        if (key != null)
                        {
                            key.Close();
                            key = null;
                        }
                    }

                    //////////////////////////////////////
                    // release unmanaged resources here...
                    //////////////////////////////////////

                    //
                    // NOTE: This object is now disposed.
                    //
                    disposed = true;
                }
            }
            #endregion

            ///////////////////////////////////////////////////////////////////

            #region IDisposable Members
            public void Dispose()
            {
                Dispose(true);
                GC.SuppressFinalize(this);
            }
            #endregion

            ///////////////////////////////////////////////////////////////////

            #region Destructor
            ~RegistryOperation()
            {
                Dispose(false);
            }
            #endregion
        }
        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region StringList Class
2330
2331
2332
2333
2334
2335
2336

2337
2338
2339
2340
2341
2342
2343

            ///////////////////////////////////////////////////////////////////

            #region Private Constructors
            private Configuration(
                Assembly assembly,
                string logFileName,

                string directory,
                string coreFileName,
                string linqFileName,
                string ef6FileName,
                string designerFileName,
                string registryVersion,
                string configVersion,







>







2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908

            ///////////////////////////////////////////////////////////////////

            #region Private Constructors
            private Configuration(
                Assembly assembly,
                string logFileName,
                string registryLogFileName,
                string directory,
                string coreFileName,
                string linqFileName,
                string ef6FileName,
                string designerFileName,
                string registryVersion,
                string configVersion,
2380
2381
2382
2383
2384
2385
2386

2387
2388
2389
2390
2391
2392
2393
                bool debug,
                bool verbose,
                bool confirm
                )
            {
                this.assembly = assembly;
                this.logFileName = logFileName;

                this.directory = directory;
                this.coreFileName = coreFileName;
                this.linqFileName = linqFileName;
                this.ef6FileName = ef6FileName;
                this.designerFileName = designerFileName;
                this.registryVersion = registryVersion;
                this.configVersion = configVersion;







>







2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
                bool debug,
                bool verbose,
                bool confirm
                )
            {
                this.assembly = assembly;
                this.logFileName = logFileName;
                this.registryLogFileName = registryLogFileName;
                this.directory = directory;
                this.coreFileName = coreFileName;
                this.linqFileName = linqFileName;
                this.ef6FileName = ef6FileName;
                this.designerFileName = designerFileName;
                this.registryVersion = registryVersion;
                this.configVersion = configVersion;
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
                string designerFileName = null;

                GetDefaultFileNames(
                    ref directory, ref coreFileName, ref linqFileName,
                    ref ef6FileName, ref designerFileName);

                return new Configuration(
                    thisAssembly, null, directory, coreFileName, linqFileName,
                    ef6FileName, designerFileName, null, null, null,
                    TraceOps.DebugFormat, TraceOps.TraceFormat,
                    InstallFlags.Default, ProviderFlags.Default,
                    TracePriority.Default, TracePriority.Default, false, true,
                    false, false, false, false, false, false, false, false,
                    false, false, false, false, false, false, false, false,
                    false, false, false, false, false, false, false, false,
                    false, true, true, false, false, false);
            }







|
|
|







3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
                string designerFileName = null;

                GetDefaultFileNames(
                    ref directory, ref coreFileName, ref linqFileName,
                    ref ef6FileName, ref designerFileName);

                return new Configuration(
                    thisAssembly, null, null, directory, coreFileName,
                    linqFileName, ef6FileName, designerFileName, null, null,
                    null, TraceOps.DebugFormat, TraceOps.TraceFormat,
                    InstallFlags.Default, ProviderFlags.Default,
                    TracePriority.Default, TracePriority.Default, false, true,
                    false, false, false, false, false, false, false, false,
                    false, false, false, false, false, false, false, false,
                    false, false, false, false, false, false, false, false,
                    false, true, true, false, false, false);
            }
3470
3471
3472
3473
3474
3475
3476




3477
3478
3479
3480
3481
3482
3483
                                if (strict)
                                    return false;

                                continue;
                            }

                            configuration.providerFlags = (ProviderFlags)value;




                        }
                        else if (MatchOption(newArg, "registryVersion"))
                        {
                            configuration.registryVersion = text;
                        }
                        else if (MatchOption(newArg, "strict"))
                        {







>
>
>
>







4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
                                if (strict)
                                    return false;

                                continue;
                            }

                            configuration.providerFlags = (ProviderFlags)value;
                        }
                        else if (MatchOption(newArg, "registryLogFileName"))
                        {
                            configuration.registryLogFileName = text;
                        }
                        else if (MatchOption(newArg, "registryVersion"))
                        {
                            configuration.registryVersion = text;
                        }
                        else if (MatchOption(newArg, "strict"))
                        {
3783
3784
3785
3786
3787
3788
3789




















3790
3791
3792
3793
3794
3795
3796
                    {
                        TraceOps.DebugAndTrace(TracePriority.MediumHigh,
                            debugCallback, traceCallback,
                            "No actual changes will be made to this " +
                            "system because \"what-if\" mode is enabled.",
                            traceCategory);
                    }





















                    //
                    // NOTE: If the command line has not been manually
                    //       confirmed (i.e. via the explicit command line
                    //       option), then stop processing now.  We enforce
                    //       this rule so that simply double-clicking the
                    //       executable will not result in any changes being







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
                    {
                        TraceOps.DebugAndTrace(TracePriority.MediumHigh,
                            debugCallback, traceCallback,
                            "No actual changes will be made to this " +
                            "system because \"what-if\" mode is enabled.",
                            traceCategory);
                    }

                    //
                    // NOTE: If the registry log file name has been set, its
                    //       value will be used verbatim as the place where
                    //       all registry write operations will (eventually)
                    //       be logged.  Make sure the registry helper class
                    //       has a valid operation list; otherwise, it will
                    //       not perform any logging.
                    //
                    if (configuration.registryLogFileName != null)
                    {
                        RegistryHelper.OperationList =
                            new RegistryOperationList();

                        TraceOps.DebugAndTrace(TracePriority.MediumHigh,
                            debugCallback, traceCallback, String.Format(
                            "Registry logging to file \"{0}\" enabled.",
                            ForDisplay(configuration.registryLogFileName)),
                            traceCategory);
                    }

                    //
                    // NOTE: If the command line has not been manually
                    //       confirmed (i.e. via the explicit command line
                    //       option), then stop processing now.  We enforce
                    //       this rule so that simply double-clicking the
                    //       executable will not result in any changes being
4318
4319
4320
4321
4322
4323
4324





4325
4326
4327
4328
4329
4330
4331
                    traceCallback(String.Format(NameAndValueFormat,
                        "Assembly", ForDisplay(assembly)),
                        traceCategory);

                    traceCallback(String.Format(NameAndValueFormat,
                        "LogFileName", ForDisplay(logFileName)),
                        traceCategory);






                    traceCallback(String.Format(NameAndValueFormat,
                        "Directory", ForDisplay(directory)),
                        traceCategory);

                    traceCallback(String.Format(NameAndValueFormat,
                        "CoreFileName", ForDisplay(coreFileName)),







>
>
>
>
>







4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
                    traceCallback(String.Format(NameAndValueFormat,
                        "Assembly", ForDisplay(assembly)),
                        traceCategory);

                    traceCallback(String.Format(NameAndValueFormat,
                        "LogFileName", ForDisplay(logFileName)),
                        traceCategory);

                    traceCallback(String.Format(NameAndValueFormat,
                        "RegistryLogFileName",
                        ForDisplay(registryLogFileName)),
                        traceCategory);

                    traceCallback(String.Format(NameAndValueFormat,
                        "Directory", ForDisplay(directory)),
                        traceCategory);

                    traceCallback(String.Format(NameAndValueFormat,
                        "CoreFileName", ForDisplay(coreFileName)),
4663
4664
4665
4666
4667
4668
4669









4670
4671
4672
4673
4674
4675
4676

            private string logFileName;
            public string LogFileName
            {
                get { return logFileName; }
                set { logFileName = value; }
            }










            ///////////////////////////////////////////////////////////////////

            private string directory;
            public string Directory
            {
                get { return directory; }







>
>
>
>
>
>
>
>
>







5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280

            private string logFileName;
            public string LogFileName
            {
                get { return logFileName; }
                set { logFileName = value; }
            }

            ///////////////////////////////////////////////////////////////////

            private string registryLogFileName;
            public string RegistryLogFileName
            {
                get { return registryLogFileName; }
                set { registryLogFileName = value; }
            }

            ///////////////////////////////////////////////////////////////////

            private string directory;
            public string Directory
            {
                get { return directory; }
5455
5456
5457
5458
5459
5460
5461






5462
5463
5464
5465
5466
5467
5468
            }
            else if (type == typeof(DataReceivedEventArgs))
            {
                DataReceivedEventArgs eventArgs = (DataReceivedEventArgs)value;

                result = ForDisplay(eventArgs.Data); /* RECURSIVE */
            }






            else
            {
                result = value.ToString();

                if (result.Length == 0)
                    return "<empty>";








>
>
>
>
>
>







6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
            }
            else if (type == typeof(DataReceivedEventArgs))
            {
                DataReceivedEventArgs eventArgs = (DataReceivedEventArgs)value;

                result = ForDisplay(eventArgs.Data); /* RECURSIVE */
            }
            else if (type == typeof(MockRegistryKey))
            {
                MockRegistryKey key = (MockRegistryKey)value;

                result = ForDisplay(key.ToString()); /* RECURSIVE */
            }
            else
            {
                result = value.ToString();

                if (result.Length == 0)
                    return "<empty>";

8362
8363
8364
8365
8366
8367
8368











8369
8370
8371
8372
8373
8374
8375
                    TraceOps.DebugAndTrace(TracePriority.MediumHigh,
                        debugCallback, traceCallback, String.Format(
                        "filesCreated = {0}, filesModified = {1}, " +
                        "filesDeleted = {2}", ForDisplay(filesCreated),
                        ForDisplay(filesModified), ForDisplay(filesDeleted)),
                        traceCategory);
                    #endregion












                    ///////////////////////////////////////////////////////////

                    TraceOps.DebugAndTrace(TracePriority.MediumHigh,
                        debugCallback, traceCallback, "Success.",
                        traceCategory);








>
>
>
>
>
>
>
>
>
>
>







8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
                    TraceOps.DebugAndTrace(TracePriority.MediumHigh,
                        debugCallback, traceCallback, String.Format(
                        "filesCreated = {0}, filesModified = {1}, " +
                        "filesDeleted = {2}", ForDisplay(filesCreated),
                        ForDisplay(filesModified), ForDisplay(filesDeleted)),
                        traceCategory);
                    #endregion

                    ///////////////////////////////////////////////////////////

                    #region Write Registry Log (Optional)
                    //
                    // NOTE: If applicable, write the list of registry write
                    //       operations now.
                    //
                    RegistryHelper.WriteOperationList(
                        configuration.RegistryLogFileName);
                    #endregion

                    ///////////////////////////////////////////////////////////

                    TraceOps.DebugAndTrace(TracePriority.MediumHigh,
                        debugCallback, traceCallback, "Success.",
                        traceCategory);