|
| 1 | +// Copyright (c) Microsoft. All rights reserved. |
| 2 | +// Licensed under the MIT license. |
| 3 | + |
| 4 | +namespace Microsoft.WingetCreateCLI.Commands |
| 5 | +{ |
| 6 | + using System; |
| 7 | + using System.IO; |
| 8 | + using System.Threading.Tasks; |
| 9 | + using CommandLine; |
| 10 | + using Microsoft.WingetCreateCLI.Logging; |
| 11 | + using Microsoft.WingetCreateCLI.Properties; |
| 12 | + using Microsoft.WingetCreateCLI.Telemetry; |
| 13 | + using Microsoft.WingetCreateCLI.Telemetry.Events; |
| 14 | + using Microsoft.WingetCreateCore; |
| 15 | + using Microsoft.WingetCreateCore.Common; |
| 16 | + |
| 17 | + /// <summary> |
| 18 | + /// Info command to display general information regarding the tool. |
| 19 | + /// </summary> |
| 20 | + [Verb("info", HelpText = "InfoCommand_HelpText", ResourceType = typeof(Resources))] |
| 21 | + public class InfoCommand : BaseCommand |
| 22 | + { |
| 23 | + /// <summary> |
| 24 | + /// Executes the info command flow. |
| 25 | + /// </summary> |
| 26 | + /// <returns>Boolean representing success or fail of the command.</returns> |
| 27 | + public override async Task<bool> Execute() |
| 28 | + { |
| 29 | + CommandExecutedEvent commandEvent = new CommandExecutedEvent |
| 30 | + { |
| 31 | + Command = nameof(InfoCommand), |
| 32 | + }; |
| 33 | + |
| 34 | + DisplayApplicationHeaderAndCopyright(); |
| 35 | + Console.WriteLine(); |
| 36 | + DisplaySystemInformation(); |
| 37 | + Console.WriteLine(); |
| 38 | + DisplayInfoTable(); |
| 39 | + |
| 40 | + TelemetryManager.Log.WriteEvent(commandEvent); |
| 41 | + return await Task.FromResult(commandEvent.IsSuccessful = true); |
| 42 | + } |
| 43 | + |
| 44 | + private static void DisplayApplicationHeaderAndCopyright() |
| 45 | + { |
| 46 | + Console.WriteLine(string.Format( |
| 47 | + Resources.Heading, |
| 48 | + Utils.GetEntryAssemblyVersion()) + |
| 49 | + Environment.NewLine + |
| 50 | + Constants.MicrosoftCopyright); |
| 51 | + } |
| 52 | + |
| 53 | + private static void DisplaySystemInformation() |
| 54 | + { |
| 55 | + Logger.DebugLocalized(nameof(Resources.OperatingSystem_Info), Environment.OSVersion.VersionString); |
| 56 | + Logger.DebugLocalized(nameof(Resources.SystemArchitecture_Info), System.Runtime.InteropServices.RuntimeInformation.OSArchitecture); |
| 57 | + } |
| 58 | + |
| 59 | + private static void DisplayInfoTable() |
| 60 | + { |
| 61 | + string logsdirectory = Common.GetPathForDisplay(Path.Combine(Common.LocalAppStatePath, Constants.DiagnosticOutputDirectoryFolderName), UserSettings.AnonymizePaths); |
| 62 | + string settingsDirectory = Common.GetPathForDisplay(UserSettings.SettingsJsonPath, UserSettings.AnonymizePaths); |
| 63 | + string installerCacheDirectory = Common.GetPathForDisplay(PackageParser.InstallerDownloadPath, UserSettings.AnonymizePaths); |
| 64 | + |
| 65 | + new TableOutput(Resources.WingetCreateDirectories_Heading, Resources.Path_Heading) |
| 66 | + .AddRow(Resources.Logs_Heading, logsdirectory) |
| 67 | + .AddRow(Resources.UserSettings_Heading, settingsDirectory) |
| 68 | + .AddRow(Resources.InstallerCache_Heading, installerCacheDirectory) |
| 69 | + .Print(); |
| 70 | + |
| 71 | + Console.WriteLine(); |
| 72 | + |
| 73 | + new TableOutput(Resources.Links_Heading, string.Empty) |
| 74 | + .AddRow(Resources.PrivacyStatement_Heading, Constants.PrivacyStatementUrl) |
| 75 | + .AddRow(Resources.LicenseAgreement_Heading, Constants.LicenseUrl) |
| 76 | + .AddRow(Resources.ThirdPartyNotices_Heading, Constants.ThirdPartyNoticeUrl) |
| 77 | + .AddRow(Resources.Homepage_Heading, Constants.HomePageUrl) |
| 78 | + .Print(); |
| 79 | + } |
| 80 | + } |
| 81 | +} |
0 commit comments