Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Fix typo. Fix RegistryKey lifetime issue. Cleanup output format and improve code. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | designTimeInstaller |
Files: | files | file ages | folders |
SHA1: |
a5dd05dc2146f226b459b3b200179f00 |
User & Date: | mistachkin 2017-12-06 22:32:23.274 |
Context
2017-12-06
| ||
22:38 | Enhance the design-time components installer to support creating a log file of all registry write operations. check-in: 297b44b1ef user: mistachkin tags: trunk | |
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 | |
Changes
Changes to tools/install/Installer.cs.
︙ | ︙ | |||
1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 | // should be just like calling Dispose. // Dispose(true); } /////////////////////////////////////////////////////////////////// public MockRegistryKey CreateSubKey( string subKeyName ) { CheckDisposed(); CheckReadOnly(); | > > > > > > > > > | 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 | // should be just like calling Dispose. // Dispose(true); } /////////////////////////////////////////////////////////////////// public void DisableClose() { CheckDisposed(); noClose = true; } /////////////////////////////////////////////////////////////////// public MockRegistryKey CreateSubKey( string subKeyName ) { CheckDisposed(); CheckReadOnly(); |
︙ | ︙ | |||
1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 | /////////////////////////////////////////////////////////////////// public bool safe; public bool Safe { get { CheckDisposed(); return safe; } } #endregion /////////////////////////////////////////////////////////////////// #region Private Methods private void CheckReadOnly() { | > > > > > > > > | 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 | /////////////////////////////////////////////////////////////////// public bool safe; public bool Safe { get { CheckDisposed(); return safe; } } /////////////////////////////////////////////////////////////////// public bool noClose; public bool NoClose { get { CheckDisposed(); return noClose; } } #endregion /////////////////////////////////////////////////////////////////// #region Private Methods private void CheckReadOnly() { |
︙ | ︙ | |||
1719 1720 1721 1722 1723 1724 1725 | { //////////////////////////////////// // dispose managed resources here... //////////////////////////////////// if (key != null) { | > | > | 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 | { //////////////////////////////////// // dispose managed resources here... //////////////////////////////////// if (key != null) { if (!noClose) key.Close(); key = null; } } ////////////////////////////////////// // release unmanaged resources here... ////////////////////////////////////// |
︙ | ︙ | |||
1820 1821 1822 1823 1824 1825 1826 | { #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(); | < > | | < > | < < < < > | 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 | { #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(); // // NOTE: This is the list of registry write operations when it is // set to non-null. // private static RegistryOperationList operationList; #endregion /////////////////////////////////////////////////////////////////// #region Public Static Properties private static MockRegistry readOnlyRegistry; public static MockRegistry ReadOnlyRegistry { get { return readOnlyRegistry; } } /////////////////////////////////////////////////////////////////// |
︙ | ︙ | |||
1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 | get { return keyValuesDeleted; } } #endregion /////////////////////////////////////////////////////////////////// #region Public Static Methods public static void ReinitializeDefaultRegistries( bool whatIf, bool safe ) { if (readOnlyRegistry != null) { | > > > > > > > > > > > > > > > > > > > > > | 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 | get { return keyValuesDeleted; } } #endregion /////////////////////////////////////////////////////////////////// #region Public Static Methods public static void EnableOrDisableOperationList( bool enable ) { lock (syncRoot) /* TRANSACTIONAL */ { if (enable) { if (operationList == null) operationList = new RegistryOperationList(); } else if (operationList != null) { operationList.Dispose(); operationList = null; } } } /////////////////////////////////////////////////////////////////// public static void ReinitializeDefaultRegistries( bool whatIf, bool safe ) { if (readOnlyRegistry != null) { |
︙ | ︙ | |||
2334 2335 2336 2337 2338 2339 2340 2341 | MaybeLogOperation(GetMethodName(), key, name, null); keyValuesDeleted++; } /////////////////////////////////////////////////////////////////// public static int WriteOperationList( | > | > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > | 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 | MaybeLogOperation(GetMethodName(), key, name, null); keyValuesDeleted++; } /////////////////////////////////////////////////////////////////// [MethodImpl(MethodImplOptions.NoInlining)] public static int WriteOperationList( string fileName, bool verbose ) { int count = 0; if (String.IsNullOrEmpty(fileName)) { if (verbose) { TraceOps.DebugAndTrace(TracePriority.Highest, debugCallback, traceCallback, "Registry operation log file name not set.", traceCategory); } return count; } lock (syncRoot) /* TRANSACTIONAL */ { if (operationList == null) { if (verbose) { TraceOps.DebugAndTrace(TracePriority.Highest, debugCallback, traceCallback, "Registry operation list is invalid.", traceCategory); } return count; } using (StreamWriter streamWriter = new StreamWriter( fileName)) { foreach (RegistryOperation operation in operationList) { if (operation == null) continue; streamWriter.WriteLine(operation.ToString()); count++; } streamWriter.Flush(); } } if (verbose) { TraceOps.DebugAndTrace(TracePriority.Highest, debugCallback, traceCallback, String.Format( "Wrote {0} registry operations to its log file.", count), traceCategory); } return count; } #endregion /////////////////////////////////////////////////////////////////// |
︙ | ︙ | |||
2427 2428 2429 2430 2431 2432 2433 | } #endregion /////////////////////////////////////////////////////////////////////// #region RegistryOperationList Class [Serializable()] | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 | } #endregion /////////////////////////////////////////////////////////////////////// #region RegistryOperationList Class [Serializable()] private sealed class RegistryOperationList : List<RegistryOperation>, IDisposable { #region Public Constructors public RegistryOperationList() { // do nothing. } #endregion /////////////////////////////////////////////////////////////////// #region IDisposable "Pattern" Members private bool disposed; private void CheckDisposed() /* throw */ { if (!disposed) return; throw new ObjectDisposedException( typeof(RegistryOperationList).Name); } /////////////////////////////////////////////////////////////////// private /* protected virtual */ void Dispose( bool disposing ) { if (!disposed) { if (disposing) { //////////////////////////////////// // dispose managed resources here... //////////////////////////////////// foreach (RegistryOperation operation in this) { if (operation == null) continue; operation.Dispose(); } Clear(); } ////////////////////////////////////// // 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 ~RegistryOperationList() { Dispose(false); } #endregion } #endregion /////////////////////////////////////////////////////////////////////// #region RegistryOperation Class private sealed class RegistryOperation { #region Private Constants private const char FieldDelimiter = '\t'; #endregion /////////////////////////////////////////////////////////////////// #region Public Constructors public RegistryOperation( string methodName, MockRegistryKey key, string subKeyName, string valueName, object value |
︙ | ︙ | |||
2473 2474 2475 2476 2477 2478 2479 | ) { if (key != null) { // // NOTE: Make sure this copy of the root registry key // cannot be used to accidentally make registry | | > > > > > | 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 | ) { if (key != null) { // // NOTE: Make sure this copy of the root registry key // cannot be used to accidentally make registry // changes. Also, prevent this MockRegistryKey // object from closing its underlying registry // key as we will need it later. This instance // will close it. // this.key = new MockRegistryKey(key, true, true, true); key.DisableClose(); } else { this.key = null; } } #endregion |
︙ | ︙ | |||
2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 | 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 | > > > > | 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 | public override string ToString() { CheckDisposed(); StringBuilder builder = new StringBuilder(); builder.Append(ForDisplay(methodName)); builder.Append(FieldDelimiter); builder.Append(ForDisplay(key)); builder.Append(FieldDelimiter); builder.Append(ForDisplay(subKeyName)); builder.Append(FieldDelimiter); builder.Append(ForDisplay(valueName)); builder.Append(FieldDelimiter); builder.Append(ForDisplay( MockRegistryKey.ValueToString(value, ", ", "<null>"))); return builder.ToString(); } #endregion |
︙ | ︙ | |||
4364 4365 4366 4367 4368 4369 4370 | // 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) { | | < | | 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 | // 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.EnableOrDisableOperationList(true); 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 |
︙ | ︙ | |||
8981 8982 8983 8984 8985 8986 8987 | #region Write Registry Log (Optional) // // NOTE: If applicable, write the list of registry write // operations now. // RegistryHelper.WriteOperationList( | | > > > | 9131 9132 9133 9134 9135 9136 9137 9138 9139 9140 9141 9142 9143 9144 9145 9146 9147 9148 | #region Write Registry Log (Optional) // // NOTE: If applicable, write the list of registry write // operations now. // RegistryHelper.WriteOperationList( configuration.RegistryLogFileName, configuration.Verbose); RegistryHelper.EnableOrDisableOperationList(false); #endregion /////////////////////////////////////////////////////////// TraceOps.DebugAndTrace(TracePriority.MediumHigh, debugCallback, traceCallback, "Success.", traceCategory); |
︙ | ︙ |