Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
CabinetAPI.cs140 linesDownload Raw Back to help
1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT License.3 4using System.Diagnostics.CodeAnalysis;5 6namespace System.Management.Automation.Internal7{8    /// <summary>9    /// CabinetExtractor interface, implemented by CabinetExtractor10    /// in native code to handle the extraction of cabinet files.11    /// </summary>12    internal abstract class ICabinetExtractor : IDisposable13    {14        /// <summary>15        /// Extracts a cabinet file.16        /// </summary>17        /// <param name="cabinetName">Cabinet file name.</param>18        /// <param name="srcPath">Cabinet directory name, must be back slash terminated.</param>19        /// <param name="destPath">Destination directory name, must be back slash terminated.</param>20        internal abstract bool Extract(string cabinetName, string srcPath, string destPath);21 22        #region IDisposable Interface23        //24        // This is a special case of the IDisposable pattern because the resource25        // to be disposed is managed by the derived class. The implementation here26        // enables derived classes to handle it cleanly.27        //28 29        /// <summary>30        /// Flag: Has Dispose already been called?31        /// </summary>32        private bool _disposed = false;33 34        /// <summary>35        /// Disposes the instance, callable by consumers.36        /// </summary>37        public void Dispose()38        {39            Dispose(true);40            GC.SuppressFinalize(this);41        }42 43        protected virtual void Dispose(bool disposing)44        {45            if (_disposed)46            {47                // Nothing to do since the resource has already been disposed.48                return;49            }50 51            // If this class had to free objects:52            // Free managed objects if disposing == true;53            // Free unmanaged objects regardless.54 55            _disposed = true;56        }57 58        ~ICabinetExtractor()59        {60            Dispose(false);61        }62 63        #endregion64    }65 66    /// <summary>67    /// Abstract class which defines a CabinetExtractor loader. An implementation68    /// of this class will be instantiated onetime from the C++/CLI69    /// assembly using reflection.70    /// </summary>71    /// <remarks>The C++/CLI implementation of this class needs to be72    /// static</remarks>73    internal abstract class ICabinetExtractorLoader74    {75        internal virtual ICabinetExtractor GetCabinetExtractor() { return null; }76    }77 78    /// <summary>79    /// Used to create a CabinetExtractor class.80    /// </summary>81    internal static class CabinetExtractorFactory82    {83        private static readonly ICabinetExtractorLoader s_cabinetLoader;84        internal static readonly ICabinetExtractor EmptyExtractor = new EmptyCabinetExtractor();85 86        /// <summary>87        /// Static constructor.88        /// </summary>89        [SuppressMessage("Microsoft.Reliability", "CA2001:AvoidCallingProblematicMethods", MessageId = "System.Reflection.Assembly.LoadFrom")]90        static CabinetExtractorFactory()91        {92            s_cabinetLoader = CabinetExtractorLoader.GetInstance();93        }94 95        /// <summary>96        /// Provider a CabinetExtractor instance.97        /// </summary>98        /// <returns>Tracer instance.</returns>99        internal static ICabinetExtractor GetCabinetExtractor()100        {101            if (s_cabinetLoader != null)102            {103                return s_cabinetLoader.GetCabinetExtractor();104            }105            else106            {107                return EmptyExtractor;108            }109        }110    }111 112    /// <summary>113    /// Dummy cabinet extractor implementation.114    /// </summary>115    internal sealed class EmptyCabinetExtractor : ICabinetExtractor116    {117        /// <summary>118        /// Extracts a cabinet file.119        /// </summary>120        /// <param name="cabinetName">Cabinet file name.</param>121        /// <param name="srcPath">Cabinet directory name, must be back slash terminated.</param>122        /// <param name="destPath">Destination directory name, must be back slash terminated.</param>123        internal override bool Extract(string cabinetName, string srcPath, string destPath)124        {125            // its intentional that this method has no definition126            return false;127        }128 129        /// <summary>130        /// Disposes the instance.131        /// </summary>132        /// <param name="disposing"></param>133        protected override void Dispose(bool disposing)134        {135            // it's intentional that this method has no definition since there is nothing to dispose.136            // If a resource is added to this class, it should implement IDisposable for derived classes.137        }138    }139}140