2017-11-20 05:07:16 +00:00
|
|
|
|
// /***************************************************************************
|
|
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// 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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Copyright © 2011-2018 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;
|
|
|
|
|
|
using DiscImageChef.Devices;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using DiscImageChef.Interop;
|
|
|
|
|
|
using PlatformID = DiscImageChef.Interop.PlatformID;
|
2017-12-19 19:33:46 +00:00
|
|
|
|
|
2017-11-20 05:07:16 +00:00
|
|
|
|
namespace DiscImageChef.Core.Logging
|
|
|
|
|
|
{
|
2017-12-23 01:46:08 +00:00
|
|
|
|
/// <summary>
|
2017-12-23 17:41:23 +00:00
|
|
|
|
/// Creates a dump log
|
2017-12-23 01:46:08 +00:00
|
|
|
|
/// </summary>
|
2017-11-20 05:07:16 +00:00
|
|
|
|
public class DumpLog
|
|
|
|
|
|
{
|
|
|
|
|
|
readonly StreamWriter logSw;
|
|
|
|
|
|
|
2017-12-23 01:46:08 +00:00
|
|
|
|
/// <summary>
|
2017-12-23 17:41:23 +00:00
|
|
|
|
/// Initializes the dump log
|
2017-12-23 01:46:08 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="outputFile">Output log file</param>
|
|
|
|
|
|
/// <param name="dev">Device</param>
|
2017-11-20 05:07:16 +00:00
|
|
|
|
public DumpLog(string outputFile, Device dev)
|
|
|
|
|
|
{
|
2017-12-21 06:06:19 +00:00
|
|
|
|
if(string.IsNullOrEmpty(outputFile)) return;
|
|
|
|
|
|
|
|
|
|
|
|
logSw = new StreamWriter(outputFile, true);
|
2017-11-20 05:07:16 +00:00
|
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
|
logSw.WriteLine("Start logging at {0}", DateTime.Now);
|
2017-11-20 05:07:16 +00:00
|
|
|
|
|
2017-12-21 14:30:38 +00:00
|
|
|
|
PlatformID platId = DetectOS.GetRealPlatformID();
|
|
|
|
|
|
string platVer = DetectOS.GetVersion();
|
2017-12-21 06:06:19 +00:00
|
|
|
|
Type monoRunType = Type.GetType("Mono.Runtime");
|
2017-11-20 05:07:16 +00:00
|
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
|
logSw.WriteLine("################# System information #################");
|
2017-12-21 14:30:38 +00:00
|
|
|
|
logSw.WriteLine("{0} {1} ({2}-bit)", DetectOS.GetPlatformName(platId, platVer), platVer,
|
2017-12-21 06:06:19 +00:00
|
|
|
|
Environment.Is64BitOperatingSystem ? 64 : 32);
|
|
|
|
|
|
if(monoRunType != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
string monoVer = "unknown version";
|
|
|
|
|
|
MethodInfo monoDisplayName =
|
|
|
|
|
|
monoRunType.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static);
|
|
|
|
|
|
if(monoDisplayName != null) monoVer = (string)monoDisplayName.Invoke(null, null);
|
|
|
|
|
|
logSw.WriteLine("Mono {0}", monoVer);
|
|
|
|
|
|
}
|
|
|
|
|
|
else logSw.WriteLine(".NET Framework {0}", Environment.Version);
|
|
|
|
|
|
logSw.WriteLine();
|
2017-11-20 05:07:16 +00:00
|
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
|
logSw.WriteLine("################# Program information ################");
|
|
|
|
|
|
logSw.WriteLine("DiscImageChef {0} running in {1}-bit", Version.GetVersion(),
|
|
|
|
|
|
Environment.Is64BitProcess ? 64 : 32);
|
2017-11-20 05:07:16 +00:00
|
|
|
|
#if DEBUG
|
2017-12-21 06:06:19 +00:00
|
|
|
|
logSw.WriteLine("DEBUG version");
|
2017-11-20 05:07:16 +00:00
|
|
|
|
#endif
|
2017-12-21 06:06:19 +00:00
|
|
|
|
logSw.WriteLine("Command line: {0}", Environment.CommandLine);
|
|
|
|
|
|
logSw.WriteLine();
|
2017-11-20 05:07:16 +00:00
|
|
|
|
|
2017-12-21 06:06:19 +00:00
|
|
|
|
logSw.WriteLine("################# Device information #################");
|
|
|
|
|
|
logSw.WriteLine("Manufacturer: {0}", dev.Manufacturer);
|
|
|
|
|
|
logSw.WriteLine("Model: {0}", dev.Model);
|
|
|
|
|
|
logSw.WriteLine("Firmware revision: {0}", dev.Revision);
|
|
|
|
|
|
logSw.WriteLine("Serial number: {0}", dev.Serial);
|
|
|
|
|
|
logSw.WriteLine("Removable device: {0}", dev.IsRemovable);
|
|
|
|
|
|
logSw.WriteLine("Device type: {0}", dev.Type);
|
|
|
|
|
|
logSw.WriteLine("CompactFlash device: {0}", dev.IsCompactFlash);
|
|
|
|
|
|
logSw.WriteLine("PCMCIA device: {0}", dev.IsPcmcia);
|
|
|
|
|
|
logSw.WriteLine("USB device: {0}", dev.IsUsb);
|
|
|
|
|
|
if(dev.IsUsb)
|
|
|
|
|
|
{
|
|
|
|
|
|
logSw.WriteLine("USB manufacturer: {0}", dev.UsbManufacturerString);
|
|
|
|
|
|
logSw.WriteLine("USB product: {0}", dev.UsbProductString);
|
|
|
|
|
|
logSw.WriteLine("USB serial: {0}", dev.UsbSerialString);
|
|
|
|
|
|
logSw.WriteLine("USB vendor ID: {0:X4}h", dev.UsbVendorId);
|
|
|
|
|
|
logSw.WriteLine("USB product ID: {0:X4}h", dev.UsbProductId);
|
|
|
|
|
|
}
|
|
|
|
|
|
logSw.WriteLine("FireWire device: {0}", dev.IsFireWire);
|
|
|
|
|
|
if(dev.IsFireWire)
|
|
|
|
|
|
{
|
|
|
|
|
|
logSw.WriteLine("FireWire vendor: {0}", dev.FireWireVendorName);
|
|
|
|
|
|
logSw.WriteLine("FireWire model: {0}", dev.FireWireModelName);
|
|
|
|
|
|
logSw.WriteLine("FireWire GUID: 0x{0:X16}", dev.FireWireGuid);
|
|
|
|
|
|
logSw.WriteLine("FireWire vendor ID: 0x{0:X8}", dev.FireWireVendor);
|
|
|
|
|
|
logSw.WriteLine("FireWire product ID: 0x{0:X8}", dev.FireWireModel);
|
2017-11-20 05:07:16 +00:00
|
|
|
|
}
|
2017-12-21 06:06:19 +00:00
|
|
|
|
logSw.WriteLine();
|
|
|
|
|
|
logSw.WriteLine("######################################################");
|
|
|
|
|
|
|
|
|
|
|
|
logSw.WriteLine();
|
|
|
|
|
|
logSw.WriteLine("################ Dumping progress log ################");
|
|
|
|
|
|
logSw.Flush();
|
2017-11-20 05:07:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-23 01:46:08 +00:00
|
|
|
|
/// <summary>
|
2017-12-23 17:41:23 +00:00
|
|
|
|
/// Adds a new line to the dump log
|
2017-12-23 01:46:08 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="format">Format string</param>
|
|
|
|
|
|
/// <param name="args">Arguments</param>
|
2017-11-20 05:07:16 +00:00
|
|
|
|
public void WriteLine(string format, params object[] args)
|
|
|
|
|
|
{
|
2017-12-21 06:06:19 +00:00
|
|
|
|
if(logSw == null) return;
|
|
|
|
|
|
|
|
|
|
|
|
string text = string.Format(format, args);
|
|
|
|
|
|
logSw.WriteLine("{0:s} {1}", DateTime.Now, text);
|
|
|
|
|
|
logSw.Flush();
|
2017-11-20 05:07:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-23 01:46:08 +00:00
|
|
|
|
/// <summary>
|
2017-12-23 17:41:23 +00:00
|
|
|
|
/// Finishes and closes the dump log
|
2017-12-23 01:46:08 +00:00
|
|
|
|
/// </summary>
|
2017-11-20 05:07:16 +00:00
|
|
|
|
public void Close()
|
|
|
|
|
|
{
|
2017-12-21 17:45:39 +00:00
|
|
|
|
logSw?.WriteLine("######################################################");
|
|
|
|
|
|
logSw?.WriteLine("End logging at {0}", DateTime.Now);
|
|
|
|
|
|
logSw?.Close();
|
2017-11-20 05:07:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|