예제 #1
0
        /// <summary>
        /// Throws an exception if the specified function fails.
        /// </summary>
        /// <param name="hresult">An HRESULT value from a function return to check.</param>
        /// <param name="session">An optional <see cref="DismSession"/> to reload if necessary.</param>
        internal static void ThrowIfFail(int hresult, DismSession session = null)
        {
            if (hresult == DismApi.DISMAPI_S_RELOAD_IMAGE_SESSION_REQUIRED && session != null)
            {
                // Reload the session if necessary
                session.Reload();

                return;
            }

            if (hresult != DismApi.ERROR_SUCCESS)
            {
                throw DismException.GetDismExceptionForHResult(hresult);
            }
        }
예제 #2
0
        /// <summary>
        /// Throws an exception if the specified function fails.
        /// </summary>
        /// <param name="hresult">An HRESULT value from a function return to check.</param>
        /// <param name="session">An optional <see cref="DismSession" /> to reload if necessary.</param>
        /// <param name="callerMemberName">The name of the calling member.</param>
        internal static void ThrowIfFail(int hresult, DismSession session = null, [CallerMemberName] string callerMemberName = null)
        {
            if (hresult == DismApi.DISMAPI_S_RELOAD_IMAGE_SESSION_REQUIRED)
            {
                if (session == null)
                {
                    throw new DismException(hresult, $"The {callerMemberName} function returned {nameof(DismApi.DISMAPI_S_RELOAD_IMAGE_SESSION_REQUIRED)} but was not passed a session to reload.");
                }

                // Reload the session if necessary
                session.Reload();

                return;
            }

            if (hresult != DismApi.ERROR_SUCCESS)
            {
                throw DismException.GetDismExceptionForHResult(hresult) ?? new DismException(hresult, $"The {callerMemberName} function returned the error code 0x{hresult:X8}");
            }
        }