/// <summary> /// Loads saved statistics from disk /// </summary> public static void LoadStats() { if (File.Exists(Path.Combine(Settings.Settings.StatsPath, "Statistics.xml"))) { AllStats = new Stats(); CurrentStats = new Stats { OperatingSystems = new List <OsStats> { new OsStats { name = DetectOS.GetRealPlatformID().ToString(), Value = 1, version = DetectOS.GetVersion() } }, Versions = new List <NameValueStats> { new NameValueStats { name = Version.GetVersion(), Value = 1 } } }; XmlSerializer xs = new XmlSerializer(AllStats.GetType()); StreamReader sr = new StreamReader(Path.Combine(Settings.Settings.StatsPath, "Statistics.xml")); AllStats = (Stats)xs.Deserialize(sr); sr.Close(); } else if (Settings.Settings.Current.Stats != null) { AllStats = new Stats(); CurrentStats = new Stats { OperatingSystems = new List <OsStats> { new OsStats { name = DetectOS.GetRealPlatformID().ToString(), Value = 1, version = DetectOS.GetVersion() } }, Versions = new List <NameValueStats> { new NameValueStats { name = Version.GetVersion(), Value = 1 } } }; } else { AllStats = null; CurrentStats = null; } }
/// <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) { if (string.IsNullOrEmpty(outputFile)) { return; } _logSw = new StreamWriter(outputFile, true); _logSw.WriteLine("Start logging at {0}", DateTime.Now); PlatformID platId = DetectOS.GetRealPlatformID(); string platVer = DetectOS.GetVersion(); var assemblyVersion = Attribute.GetCustomAttribute(typeof(DumpLog).Assembly, typeof(AssemblyInformationalVersionAttribute)) as AssemblyInformationalVersionAttribute; _logSw.WriteLine("################# System information #################"); _logSw.WriteLine("{0} {1} ({2}-bit)", DetectOS.GetPlatformName(platId, platVer), platVer, Environment.Is64BitOperatingSystem ? 64 : 32); 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); } _logSw.WriteLine(); _logSw.WriteLine("################# Program information ################"); _logSw.WriteLine("Aaru {0}", assemblyVersion?.InformationalVersion); _logSw.WriteLine("Running in {0}-bit", Environment.Is64BitProcess ? 64 : 32); _logSw.WriteLine("Running as superuser: {0}", DetectOS.IsAdmin ? "Yes" : "No"); #if DEBUG _logSw.WriteLine("DEBUG version"); #endif if (@private) { string[] args = Environment.GetCommandLineArgs(); for (int i = 0; i < args.Length; i++) { if (args[i].StartsWith("/dev", StringComparison.OrdinalIgnoreCase) || args[i].StartsWith("aaru://", StringComparison.OrdinalIgnoreCase)) { continue; } try { args[i] = Path.GetFileName(args[i]); } catch { // Do nothing } } _logSw.WriteLine("Command line: {0}", string.Join(" ", args)); } else { _logSw.WriteLine("Command line: {0}", Environment.CommandLine); } _logSw.WriteLine(); if (dev.IsRemote) { _logSw.WriteLine("################# Remote information #################"); _logSw.WriteLine("Server: {0}", dev.RemoteApplication); _logSw.WriteLine("Version: {0}", dev.RemoteVersion); _logSw.WriteLine("Operating system: {0} {1}", dev.RemoteOperatingSystem, dev.RemoteOperatingSystemVersion); _logSw.WriteLine("Architecture: {0}", dev.RemoteArchitecture); _logSw.WriteLine("Protocol version: {0}", dev.RemoteProtocolVersion); _logSw.WriteLine("Running as superuser: {0}", dev.IsRemoteAdmin ? "Yes" : "No"); _logSw.WriteLine("######################################################"); } _logSw.WriteLine("################# Device information #################"); _logSw.WriteLine("Manufacturer: {0}", dev.Manufacturer); _logSw.WriteLine("Model: {0}", dev.Model); _logSw.WriteLine("Firmware revision: {0}", dev.FirmwareRevision); if (!@private) { _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); if (!@private) { _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); if (!@private) { _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); } _logSw.WriteLine("######################################################"); _logSw.WriteLine(); _logSw.WriteLine("################ Dumping progress log ################"); _logSw.Flush(); }
/// <summary>Initializes the dump log</summary> /// <param name="outputFile">Output log file</param> /// <param name="dev">Device</param> public DumpLog(string outputFile, Device dev) { if (string.IsNullOrEmpty(outputFile)) { return; } logSw = new StreamWriter(outputFile, true); logSw.WriteLine("Start logging at {0}", DateTime.Now); PlatformID platId = DetectOS.GetRealPlatformID(); string platVer = DetectOS.GetVersion(); var assemblyVersion = Attribute.GetCustomAttribute(typeof(DumpLog).Assembly, typeof(AssemblyInformationalVersionAttribute)) as AssemblyInformationalVersionAttribute; logSw.WriteLine("################# System information #################"); logSw.WriteLine("{0} {1} ({2}-bit)", DetectOS.GetPlatformName(platId, platVer), platVer, Environment.Is64BitOperatingSystem ? 64 : 32); 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); } logSw.WriteLine(); logSw.WriteLine("################# Program information ################"); logSw.WriteLine("DiscImageChef {0}", assemblyVersion?.InformationalVersion); logSw.WriteLine("Running in {0}-bit", Environment.Is64BitProcess ? 64 : 32); #if DEBUG logSw.WriteLine("DEBUG version"); #endif logSw.WriteLine("Command line: {0}", Environment.CommandLine); logSw.WriteLine(); if (dev.IsRemote) { logSw.WriteLine("################# Remote information #################"); logSw.WriteLine("Server: {0}", dev.RemoteApplication); logSw.WriteLine("Version: {0}", dev.RemoteVersion); logSw.WriteLine("Operating system: {0} {1}", dev.RemoteOperatingSystem, dev.RemoteOperatingSystemVersion); logSw.WriteLine("Architecture: {0}", dev.RemoteArchitecture); logSw.WriteLine("Protocol version: {0}", dev.RemoteProtocolVersion); logSw.WriteLine("######################################################"); } logSw.WriteLine("################# Device information #################"); logSw.WriteLine("Manufacturer: {0}", dev.Manufacturer); logSw.WriteLine("Model: {0}", dev.Model); logSw.WriteLine("Firmware revision: {0}", dev.FirmwareRevision); 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); } logSw.WriteLine("######################################################"); logSw.WriteLine(); logSw.WriteLine("################ Dumping progress log ################"); logSw.Flush(); }
public Remote(string host) { _host = host; IPHostEntry ipHostEntry = Dns.GetHostEntry(host); IPAddress ipAddress = ipHostEntry.AddressList.FirstOrDefault(a => a.AddressFamily == AddressFamily.InterNetwork); if (ipAddress is null) { AaruConsole.ErrorWriteLine("Host not found"); throw new SocketException(11001); } var ipEndPoint = new IPEndPoint(ipAddress, 6666); _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); _socket.Connect(ipEndPoint); AaruConsole.WriteLine("Connected to {0}", host); byte[] hdrBuf = new byte[Marshal.SizeOf <AaruPacketHeader>()]; int len = Receive(_socket, hdrBuf, hdrBuf.Length, SocketFlags.Peek); if (len < hdrBuf.Length) { AaruConsole.ErrorWriteLine("Could not read from the network..."); throw new IOException(); } AaruPacketHeader hdr = Marshal.ByteArrayToStructureLittleEndian <AaruPacketHeader>(hdrBuf); if (hdr.remote_id != Consts.RemoteId || hdr.packet_id != Consts.PacketId) { AaruConsole.ErrorWriteLine("Received data is not an Aaru Remote Packet..."); throw new ArgumentException(); } byte[] buf; if (hdr.packetType != AaruPacketType.Hello) { if (hdr.packetType != AaruPacketType.Nop) { AaruConsole.ErrorWriteLine("Expected Hello Packet, got packet type {0}...", hdr.packetType); throw new ArgumentException(); } buf = new byte[hdr.len]; len = Receive(_socket, buf, buf.Length, SocketFlags.None); if (len < buf.Length) { AaruConsole.ErrorWriteLine("Could not read from the network..."); throw new IOException(); } AaruPacketNop nop = Marshal.ByteArrayToStructureLittleEndian <AaruPacketNop>(buf); AaruConsole.ErrorWriteLine($"{nop.reason}"); throw new ArgumentException(); } if (hdr.version != Consts.PacketVersion) { AaruConsole.ErrorWriteLine("Unrecognized packet version..."); throw new ArgumentException(); } buf = new byte[hdr.len]; len = Receive(_socket, buf, buf.Length, SocketFlags.None); if (len < buf.Length) { AaruConsole.ErrorWriteLine("Could not read from the network..."); throw new IOException(); } AaruPacketHello serverHello = Marshal.ByteArrayToStructureLittleEndian <AaruPacketHello>(buf); ServerApplication = serverHello.application; ServerVersion = serverHello.version; ServerOperatingSystem = serverHello.sysname; ServerOperatingSystemVersion = serverHello.release; ServerArchitecture = serverHello.machine; ServerProtocolVersion = serverHello.maxProtocol; var clientHello = new AaruPacketHello { application = "Aaru", version = Version.GetVersion(), maxProtocol = Consts.MaxProtocol, sysname = DetectOS.GetPlatformName(DetectOS.GetRealPlatformID(), DetectOS.GetVersion()), release = DetectOS.GetVersion(), machine = RuntimeInformation.ProcessArchitecture.ToString(), hdr = new AaruPacketHeader { remote_id = Consts.RemoteId, packet_id = Consts.PacketId, len = (uint)Marshal.SizeOf <AaruPacketHello>(), version = Consts.PacketVersion, packetType = AaruPacketType.Hello } }; buf = Marshal.StructureToByteArrayLittleEndian(clientHello); len = _socket.Send(buf, SocketFlags.None); if (len >= buf.Length) { return; } AaruConsole.ErrorWriteLine("Could not write to the network..."); throw new IOException(); }
protected void OnBtnSaveClicked(object sender, EventArgs e) { var dlgSave = new SaveFileDialog { CheckFileExists = true }; dlgSave.Filters.Add(new FileFilter { Extensions = new[] { "log" }, Name = "Log files" }); DialogResult result = dlgSave.ShowDialog(this); if (result != DialogResult.Ok) { return; } try { var logFs = new FileStream(dlgSave.FileName, FileMode.Create, FileAccess.ReadWrite); var logSw = new StreamWriter(logFs); logSw.WriteLine("Log saved at {0}", DateTime.Now); PlatformID platId = DetectOS.GetRealPlatformID(); string platVer = DetectOS.GetVersion(); var assemblyVersion = Attribute.GetCustomAttribute(typeof(AaruConsole).Assembly, typeof(AssemblyInformationalVersionAttribute)) as AssemblyInformationalVersionAttribute; logSw.WriteLine("################# System information #################"); logSw.WriteLine("{0} {1} ({2}-bit)", DetectOS.GetPlatformName(platId, platVer), platVer, Environment.Is64BitOperatingSystem ? 64 : 32); 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); } logSw.WriteLine(); logSw.WriteLine("################# Program information ################"); logSw.WriteLine("Aaru {0}", assemblyVersion?.InformationalVersion); logSw.WriteLine("Running in {0}-bit", Environment.Is64BitProcess ? 64 : 32); logSw.WriteLine("Running GUI mode using {0}", Application.Instance.Platform.ID); #if DEBUG logSw.WriteLine("DEBUG version"); #endif logSw.WriteLine("Command line: {0}", Environment.CommandLine); logSw.WriteLine(); logSw.WriteLine("################# Console ################"); foreach (LogEntry entry in ConsoleHandler.Entries) { if (entry.Type != "Info") { logSw.WriteLine("{0}: ({1}) {2}", entry.Timestamp, entry.Type.ToLower(), entry.Message); } else { logSw.WriteLine("{0}: {1}", entry.Timestamp, entry.Message); } } logSw.Close(); logFs.Close(); } catch (Exception exception) { MessageBox.Show("Exception {0} trying to save logfile, details has been sent to console.", exception.Message); AaruConsole.ErrorWriteLine("Console", exception.Message); AaruConsole.ErrorWriteLine("Console", exception.StackTrace); } }
/// <summary> /// Saves statistics to disk /// </summary> public static void SaveStats() { if (AllStats == null) { return; } if (AllStats.OperatingSystems != null) { long count = 0; OsStats old = null; foreach (OsStats nvs in AllStats.OperatingSystems.Where(nvs => nvs.name == DetectOS .GetRealPlatformID().ToString() && nvs.version == DetectOS.GetVersion())) { count = nvs.Value + 1; old = nvs; break; } if (old != null) { AllStats.OperatingSystems.Remove(old); } count++; AllStats.OperatingSystems.Add(new OsStats { name = DetectOS.GetRealPlatformID().ToString(), Value = count, version = DetectOS.GetVersion() }); } else if (CurrentStats != null) { AllStats.OperatingSystems = CurrentStats.OperatingSystems; } if (AllStats.Versions != null) { long count = 0; NameValueStats old = null; foreach (NameValueStats nvs in AllStats.Versions.Where(nvs => nvs.name == Version.GetVersion())) { count = nvs.Value + 1; old = nvs; break; } if (old != null) { AllStats.Versions.Remove(old); } count++; AllStats.Versions.Add(new NameValueStats { name = Version.GetVersion(), Value = count }); } else if (CurrentStats != null) { AllStats.Versions = CurrentStats.Versions; } FileStream fs = new FileStream(Path.Combine(Settings.Settings.StatsPath, "Statistics.xml"), FileMode.Create); XmlSerializer xs = new XmlSerializer(AllStats.GetType()); xs.Serialize(fs, AllStats); fs.Close(); if (CurrentStats != null) { string partial = $"PartialStats_{DateTime.UtcNow:yyyyMMddHHmmssfff}.xml"; fs = new FileStream(Path.Combine(Settings.Settings.StatsPath, partial), FileMode.Create); xs = new XmlSerializer(CurrentStats.GetType()); xs.Serialize(fs, CurrentStats); fs.Close(); } if (Settings.Settings.Current.Stats != null && Settings.Settings.Current.Stats.ShareStats) { SubmitStats(); } }