winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

WinGetLogging.cs (2351B)


      1 // -----------------------------------------------------------------------------
      2 // <copyright file="WinGetLogging.cs" company="Microsoft Corporation">
      3 //     Copyright (c) Microsoft Corporation. Licensed under the MIT License.
      4 // </copyright>
      5 // -----------------------------------------------------------------------------
      6 
      7 namespace Microsoft.WinGetUtil.Api
      8 {
      9     using System;
     10     using System.IO;
     11     using System.Runtime.InteropServices;
     12     using Microsoft.WinGetUtil.Common;
     13     using Microsoft.WinGetUtil.Interfaces;
     14 
     15     /// <summary>
     16     /// Wrapper class around WinGetUtil log native implementation.
     17     /// For dll entry points are defined here:
     18     ///     https://github.com/microsoft/winget-cli/blob/master/src/WinGetUtil/WinGetUtil.h.
     19     /// </summary>
     20     public sealed class WinGetLogging : IWinGetLogging
     21     {
     22         /// <summary>
     23         /// Initializes a new instance of the <see cref="WinGetLogging"/> class.
     24         /// </summary>
     25         /// <param name="logFile">Open index file. Must be closed at dispose.</param>
     26         internal WinGetLogging(string logFile)
     27         {
     28             this.LogFile = logFile;
     29         }
     30 
     31         /// <summary>
     32         /// Gets log file.
     33         /// </summary>
     34         public string LogFile { get; private set; }
     35 
     36         /// <summary>
     37         /// Dispose method.
     38         /// </summary>
     39         public void Dispose()
     40         {
     41             this.Dispose(true);
     42             GC.SuppressFinalize(this);
     43         }
     44 
     45         /// <summary>
     46         /// Dispose method to dispose the Git desktop process runner.
     47         /// </summary>
     48         /// <param name="disposing">Bool value indicating if Dispose is being run.</param>
     49         public void Dispose(bool disposing)
     50         {
     51             if (disposing)
     52             {
     53                 if (File.Exists(this.LogFile))
     54                 {
     55                     WinGetLoggingTerm(this.LogFile);
     56                 }
     57             }
     58         }
     59 
     60         //// <summary>
     61         //// Closes the index log file.
     62         //// </summary>
     63         //// <param name="logPath">Log path to close. Null for all.</param>
     64         //// <returns>HRESULT.</returns>
     65         [DllImport(Constants.DllName, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, PreserveSig = false)]
     66         private static extern IntPtr WinGetLoggingTerm(string logPath);
     67     }
     68 }