2017-11-20 05:07:16 +00:00
|
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
|
// Aaru Data Preservation Suite
|
2017-11-20 05:07:16 +00:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : DumpLog.cs
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2017-11-20 05:07:16 +00:00
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Component : Core algorithms.
|
2017-11-20 05:07:16 +00:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Contains glue logic for writing a dump log.
|
2017-11-20 05:07:16 +00:00
|
|
|
|
//
|
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
|
// it under the terms of the GNU General Public License as
|
|
|
|
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
|
//
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
//
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2022-12-03 16:07:10 +00:00
|
|
|
|
// Copyright © 2011-2023 Natalia Portillo
|
2017-11-20 05:07:16 +00:00
|
|
|
|
// ****************************************************************************/
|
2017-12-19 03:50:57 +00:00
|
|
|
|
|
2017-11-20 05:07:16 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Reflection;
|
2019-07-15 15:33:46 +01:00
|
|
|
|
using System.Runtime.InteropServices;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Aaru.CommonTypes.Interop;
|
|
|
|
|
|
using Aaru.Devices;
|
|
|
|
|
|
using PlatformID = Aaru.CommonTypes.Interop.PlatformID;
|
|
|
|
|
|
using Version = Aaru.CommonTypes.Interop.Version;
|
2017-12-19 19:33:46 +00:00
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
|
namespace Aaru.Core.Logging;
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <summary>Creates a dump log</summary>
|
|
|
|
|
|
public sealed class DumpLog
|
2017-11-20 05:07:16 +00:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
readonly StreamWriter _logSw;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>Initializes the dump log</summary>
|
|
|
|
|
|
/// <param name="outputFile">Output log file</param>
|
|
|
|
|
|
/// <param name="dev">Device</param>
|
|
|
|
|
|
/// <param name="private">Disable saving paths or serial numbers in log</param>
|
|
|
|
|
|
public DumpLog(string outputFile, Device dev, bool @private)
|
2017-11-20 05:07:16 +00:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(string.IsNullOrEmpty(outputFile))
|
|
|
|
|
|
return;
|
2017-11-20 05:07:16 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
_logSw = new StreamWriter(outputFile, true);
|
2017-12-21 06:06:19 +00:00
|
|
|
|
|
2022-11-23 16:06:46 +00:00
|
|
|
|
_logSw.WriteLine(Localization.Core.Start_logging_at_0, DateTime.Now);
|
2017-11-20 05:07:16 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
PlatformID platId = DetectOS.GetRealPlatformID();
|
|
|
|
|
|
string platVer = DetectOS.GetVersion();
|
2017-11-20 05:07:16 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
var assemblyVersion =
|
|
|
|
|
|
Attribute.GetCustomAttribute(typeof(DumpLog).Assembly, typeof(AssemblyInformationalVersionAttribute)) as
|
|
|
|
|
|
AssemblyInformationalVersionAttribute;
|
2020-01-09 15:02:21 +00:00
|
|
|
|
|
2022-11-23 16:06:46 +00:00
|
|
|
|
_logSw.WriteLine(Localization.Core.System_information);
|
2017-11-20 05:07:16 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
_logSw.WriteLine("{0} {1} ({2}-bit)", DetectOS.GetPlatformName(platId, platVer), platVer,
|
|
|
|
|
|
Environment.Is64BitOperatingSystem ? 64 : 32);
|
2020-01-09 15:02:21 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(DetectOS.IsMono)
|
|
|
|
|
|
_logSw.WriteLine("Mono {0}", Version.GetMonoVersion());
|
|
|
|
|
|
else if(DetectOS.IsNetCore)
|
|
|
|
|
|
_logSw.WriteLine(".NET Core {0}", Version.GetNetCoreVersion());
|
|
|
|
|
|
else
|
|
|
|
|
|
_logSw.WriteLine(RuntimeInformation.FrameworkDescription);
|
2020-01-09 15:02:21 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
_logSw.WriteLine();
|
2017-12-29 01:26:58 +00:00
|
|
|
|
|
2022-11-23 16:06:46 +00:00
|
|
|
|
_logSw.WriteLine(Localization.Core.Program_information);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
_logSw.WriteLine("Aaru {0}", assemblyVersion?.InformationalVersion);
|
2022-11-23 16:06:46 +00:00
|
|
|
|
_logSw.WriteLine(Localization.Core.Running_in_0_bit, Environment.Is64BitProcess ? 64 : 32);
|
|
|
|
|
|
|
|
|
|
|
|
_logSw.WriteLine(DetectOS.IsAdmin ? Localization.Core.Running_as_superuser_Yes
|
|
|
|
|
|
: Localization.Core.Running_as_superuser_No);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
#if DEBUG
|
2022-11-23 16:06:46 +00:00
|
|
|
|
_logSw.WriteLine(Localization.Core.DEBUG_version);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
if(@private)
|
|
|
|
|
|
{
|
|
|
|
|
|
string[] args = Environment.GetCommandLineArgs();
|
2017-11-20 05:07:16 +00:00
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
|
for(int i = 0; i < args.Length; i++)
|
2020-03-11 15:28:04 +00:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(args[i].StartsWith("/dev", StringComparison.OrdinalIgnoreCase) ||
|
|
|
|
|
|
args[i].StartsWith("aaru://", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
|
continue;
|
2020-03-11 15:28:04 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
try
|
2020-03-11 15:28:04 +00:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
args[i] = Path.GetFileName(args[i]);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
// Do nothing
|
2020-03-11 15:28:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-23 16:06:46 +00:00
|
|
|
|
_logSw.WriteLine(Localization.Core.Command_line_0, string.Join(" ", args));
|
2022-03-06 13:29:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
2022-11-23 16:06:46 +00:00
|
|
|
|
_logSw.WriteLine(Localization.Core.Command_line_0, Environment.CommandLine);
|
2020-01-09 15:02:21 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
_logSw.WriteLine();
|
2020-01-09 15:02:21 +00:00
|
|
|
|
|
2022-03-26 19:35:13 +00:00
|
|
|
|
if(dev is Aaru.Devices.Remote.Device remoteDev)
|
2022-03-06 13:29:38 +00:00
|
|
|
|
{
|
2022-11-23 16:06:46 +00:00
|
|
|
|
_logSw.WriteLine(Localization.Core.Remote_information);
|
|
|
|
|
|
_logSw.WriteLine(Localization.Core.Server_0, remoteDev.RemoteApplication);
|
|
|
|
|
|
_logSw.WriteLine(Localization.Core.Version_0, remoteDev.RemoteVersion);
|
2019-10-21 23:36:57 +01:00
|
|
|
|
|
2022-11-23 16:06:46 +00:00
|
|
|
|
_logSw.WriteLine(Localization.Core.Operating_system_0_1, remoteDev.RemoteOperatingSystem,
|
2022-03-26 19:35:13 +00:00
|
|
|
|
remoteDev.RemoteOperatingSystemVersion);
|
2020-03-11 15:28:04 +00:00
|
|
|
|
|
2022-11-23 16:06:46 +00:00
|
|
|
|
_logSw.WriteLine(Localization.Core.Architecture_0, remoteDev.RemoteArchitecture);
|
|
|
|
|
|
_logSw.WriteLine(Localization.Core.Protocol_version_0, remoteDev.RemoteProtocolVersion);
|
|
|
|
|
|
|
|
|
|
|
|
_logSw.WriteLine(DetectOS.IsAdmin ? Localization.Core.Running_as_superuser_Yes
|
|
|
|
|
|
: Localization.Core.Running_as_superuser_No);
|
|
|
|
|
|
|
|
|
|
|
|
_logSw.WriteLine(Localization.Core.Log_section_separator);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
}
|
2020-03-11 15:28:04 +00:00
|
|
|
|
|
2022-11-23 16:06:46 +00:00
|
|
|
|
_logSw.WriteLine(Localization.Core.Device_information);
|
|
|
|
|
|
_logSw.WriteLine(Localization.Core.Manufacturer_0, dev.Manufacturer);
|
|
|
|
|
|
_logSw.WriteLine(Localization.Core.Model_0, dev.Model);
|
|
|
|
|
|
_logSw.WriteLine(Localization.Core.Firmware_revision_0, dev.FirmwareRevision);
|
2020-01-09 15:02:21 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(!@private)
|
2022-11-23 16:06:46 +00:00
|
|
|
|
_logSw.WriteLine(Localization.Core.Serial_number_0, dev.Serial);
|
2020-03-11 15:28:04 +00:00
|
|
|
|
|
2022-11-23 16:06:46 +00:00
|
|
|
|
_logSw.WriteLine(Localization.Core.Removable_device_0, dev.IsRemovable);
|
|
|
|
|
|
_logSw.WriteLine(Localization.Core.Device_type_0, dev.Type);
|
|
|
|
|
|
_logSw.WriteLine(Localization.Core.CompactFlash_device_0, dev.IsCompactFlash);
|
|
|
|
|
|
_logSw.WriteLine(Localization.Core.PCMCIA_device_0, dev.IsPcmcia);
|
|
|
|
|
|
_logSw.WriteLine(Localization.Core.USB_device_0, dev.IsUsb);
|
2020-03-11 15:28:04 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(dev.IsUsb)
|
|
|
|
|
|
{
|
2022-11-23 16:06:46 +00:00
|
|
|
|
_logSw.WriteLine(Localization.Core.USB_manufacturer_0, dev.UsbManufacturerString);
|
|
|
|
|
|
_logSw.WriteLine(Localization.Core.USB_product_0, dev.UsbProductString);
|
2017-12-29 01:26:58 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(!@private)
|
2022-11-23 16:06:46 +00:00
|
|
|
|
_logSw.WriteLine(Localization.Core.USB_serial_0, dev.UsbSerialString);
|
2020-01-09 15:02:21 +00:00
|
|
|
|
|
2022-11-23 16:06:46 +00:00
|
|
|
|
_logSw.WriteLine(Localization.Core.USB_vendor_ID_0, dev.UsbVendorId);
|
|
|
|
|
|
_logSw.WriteLine(Localization.Core.USB_product_ID_0, dev.UsbProductId);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
}
|
2020-03-11 15:28:04 +00:00
|
|
|
|
|
2022-11-23 16:06:46 +00:00
|
|
|
|
_logSw.WriteLine(Localization.Core.FireWire_device_0, dev.IsFireWire);
|
2020-03-11 15:28:04 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(dev.IsFireWire)
|
|
|
|
|
|
{
|
2022-11-23 16:06:46 +00:00
|
|
|
|
_logSw.WriteLine(Localization.Core.FireWire_vendor_0, dev.FireWireVendorName);
|
|
|
|
|
|
_logSw.WriteLine(Localization.Core.FireWire_model_0, dev.FireWireModelName);
|
2017-12-29 01:26:58 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(!@private)
|
2022-11-23 16:06:46 +00:00
|
|
|
|
_logSw.WriteLine(Localization.Core.FireWire_GUID_0, dev.FireWireGuid);
|
2017-12-21 06:06:19 +00:00
|
|
|
|
|
2022-11-23 16:06:46 +00:00
|
|
|
|
_logSw.WriteLine(Localization.Core.FireWire_vendor_ID_0, dev.FireWireVendor);
|
|
|
|
|
|
_logSw.WriteLine(Localization.Core.FireWire_product_ID_0, dev.FireWireModel);
|
2017-11-20 05:07:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-23 16:06:46 +00:00
|
|
|
|
_logSw.WriteLine(Localization.Core.Log_section_separator);
|
2017-12-21 06:06:19 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
_logSw.WriteLine();
|
2022-11-23 16:06:46 +00:00
|
|
|
|
_logSw.WriteLine(Localization.Core.Dumping_progress_log);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
_logSw.Flush();
|
|
|
|
|
|
}
|
2017-11-20 05:07:16 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <summary>Adds a new line to the dump log</summary>
|
|
|
|
|
|
/// <param name="format">Format string</param>
|
|
|
|
|
|
/// <param name="args">Arguments</param>
|
|
|
|
|
|
public void WriteLine(string format, params object[] args)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(_logSw == null)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
|
string text = string.Format(format, args);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
_logSw.WriteLine("{0:s} {1}", DateTime.Now, text);
|
|
|
|
|
|
_logSw.Flush();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>Finishes and closes the dump log</summary>
|
|
|
|
|
|
public void Close()
|
|
|
|
|
|
{
|
2022-11-23 16:06:46 +00:00
|
|
|
|
_logSw?.WriteLine(Localization.Core.Log_section_separator);
|
|
|
|
|
|
_logSw?.WriteLine(Localization.Core.End_logging_at_0, DateTime.Now);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
_logSw?.Close();
|
2017-11-20 05:07:16 +00:00
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|