/// <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; } }
public static void Main(string[] args) { DateTime start; DateTime end; System.Console.Clear(); System.Console.Write( "\u001b[32m . ,,\n" + "\u001b[32m ;,. '0d.\n" + "\u001b[32m oc oWd \u001b[31m" + @"__/\\\\\\\\\\\\_____/\\\\\\\\\\\________/\\\\\\\\\_ " + "\n\u001b[0m" + "\u001b[32m ;X. 'WN' \u001b[31m" + @" _\/\\\////////\\\__\/////\\\///______/\\\////////__ " + "\n\u001b[0m" + "\u001b[32m oMo cMM: \u001b[31m" + @" _\/\\\______\//\\\_____\/\\\_______/\\\/___________ " + "\n\u001b[0m" + "\u001b[32m ;MM. .MMM; \u001b[31m" + @" _\/\\\_______\/\\\_____\/\\\______/\\\_____________ " + "\n\u001b[0m" + "\u001b[32m NMM WMMW \u001b[31m" + @" _\/\\\_______\/\\\_____\/\\\_____\/\\\_____________ " + "\n\u001b[0m" + "\u001b[32m 'MMM MMMM; \u001b[31m" + @" _\/\\\_______\/\\\_____\/\\\_____\//\\\____________ " + "\n\u001b[0m" + "\u001b[32m ,MMM: dMMMM: \u001b[31m" + @" _\/\\\_______/\\\______\/\\\______\///\\\__________ " + "\n\u001b[0m" + "\u001b[32m .MMMW. :MMMMM. \u001b[31m" + @" _\/\\\\\\\\\\\\/____/\\\\\\\\\\\____\////\\\\\\\\\_ " + "\n\u001b[0m" + "\u001b[32m XMMMW: .:xKNMMMMMMN0d, lMMMMMd \u001b[31m" + @" _\////////////_____\///////////________\/////////__" + "\n\u001b[0m" + "\u001b[32m :MMMMMK; cWMNkl:;;;:lxKMXc .0MMMMMO\u001b[0m\n" + "\u001b[32m ..KMMMMMMNo,. ,OMMMMMMW:,. \u001b[37;1m DiscImageChef Website\u001b[0m\n" + "\u001b[32m .;d0NMMMMMMMMMMMMMMW0d:' .;lOWMMMMMMMMMMMMMXkl. \u001b[37;1m Version \u001b[0m\u001b[33m{0}\u001b[37;1m-\u001b[0m\u001b[31m{1}\u001b[0m\n" + "\u001b[32m :KMMMMMMMMMMMMMMMMMMMMMMMMc WMMMMMMMMMMMMMMMMMMMMMMWk'\u001b[0m\n" + "\u001b[32m ;NMMMMWX0kkkkO0XMMMMMMMMMMM0' dNMMMMMMMMMMW0xl:;,;:oOWMMX; \u001b[37;1m Running under \u001b[35;1m{2}\u001b[37;1m, \u001b[35m{3}-bit\u001b[37;1m in \u001b[35m{4}-bit\u001b[37;1m mode.\u001b[0m\n" + "\u001b[32m xMMWk:. .c0MMMMMW' OMMMMMM0c'.. .oNMO \u001b[37;1m Using \u001b[33;1m{5}\u001b[37;1m version \u001b[31;1m{6}\u001b[0m\n" + "\u001b[32m OMNc .MNc oWMMk 'WMMNl. .MMK ;KX.\u001b[0m\n" + "\u001b[32m xMO WMN ; ., , ': ,MMx lK\u001b[0m\n" + "\u001b[32m ,Md cMMl .XMMMWWMMMO XMW. :\u001b[0m\n" + "\u001b[32m Ok xMMl XMMMMMMMMc 0MW,\u001b[0m\n" + "\u001b[32m 0 oMM0' lMMMMMMMM. :NMN'\u001b[0m\n" + "\u001b[32m . .0MMKl ;MMMMMMMM oNMWd\u001b[0m\n" + "\u001b[32m .dNW cMMMMMMMM, XKl\u001b[0m\n" + "\u001b[32m 0MMMMMMMMK\u001b[0m\n" + "\u001b[32m ;MMMMMMMMMMO \u001b[37;1m Proudly presented to you by:\u001b[0m\n" + "\u001b[32m 'WMMMMKxMMMMM0 \u001b[34;1m Natalia Portillo\u001b[0m\n" + "\u001b[32m oMMMMNc :WMMMMN:\u001b[0m\n" + "\u001b[32m .dWMMM0; dWMMMMXl. \u001b[37;1m Thanks to all contributors, collaborators, translators, donators and friends.\u001b[0m\n" + "\u001b[32m .......,cd0WMMNk: c0MMMMMWKkolc:clodc'\u001b[0m\n" + "\u001b[32m .';loddol:'. ':oxkkOkkxoc,.\u001b[0m\n" + "\u001b[0m\n", Version.GetVersion(), #if DEBUG "DEBUG" #else "RELEASE" #endif , DetectOS.GetPlatformName(DetectOS.GetRealPlatformID()), Environment.Is64BitOperatingSystem ? 64 : 32, Environment.Is64BitProcess ? 64 : 32, DetectOS.IsMono ? "Mono" : ".NET Core", DetectOS.IsMono ? Version.GetMonoVersion() : Version.GetNetCoreVersion()); IHost host = CreateHostBuilder(args).Build(); using (IServiceScope scope = host.Services.CreateScope()) { IServiceProvider services = scope.ServiceProvider; try { start = DateTime.Now; System.Console.WriteLine("\u001b[31;1mUpdating database with Entity Framework...\u001b[0m"); var context = services.GetRequiredService <DicServerContext>(); context.Database.Migrate(); end = DateTime.Now; System.Console.WriteLine("\u001b[31;1mTook \u001b[32;1m{0} seconds\u001b[31;1m...\u001b[0m", (end - start).TotalSeconds); } catch (Exception ex) { System.Console.WriteLine("\u001b[31;1mCould not open database...\u001b[0m"); #if DEBUG System.Console.WriteLine("\u001b[31;1mException: {0}\u001b[0m", ex.Message); #endif return; } } System.Console.WriteLine("\u001b[31;1mStarting web server...\u001b[0m"); host.Run(); }
/// <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(); }
protected void OnBtnSaveClicked(object sender, EventArgs e) { SaveFileDialog 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 { FileStream logFs = new FileStream(dlgSave.FileName, FileMode.Create, FileAccess.ReadWrite); StreamWriter logSw = new StreamWriter(logFs); logSw.WriteLine("Log saved at {0}", DateTime.Now); PlatformID platId = DetectOS.GetRealPlatformID(); string platVer = DetectOS.GetVersion(); AssemblyInformationalVersionAttribute assemblyVersion = Attribute.GetCustomAttribute(typeof(DicConsole).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); 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); DicConsole.ErrorWriteLine("Console", exception.Message); DicConsole.ErrorWriteLine("Console", exception.StackTrace); } }
public Remote(string host) { _host = host; var ipHostEntry = Dns.GetHostEntry(host); var ipAddress = ipHostEntry.AddressList.FirstOrDefault(a => a.AddressFamily == AddressFamily.InterNetwork); if (ipAddress is null) { DicConsole.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); DicConsole.WriteLine("Connected to {0}", host); var hdrBuf = new byte[Marshal.SizeOf <DicPacketHeader>()]; var len = Receive(_socket, hdrBuf, hdrBuf.Length, SocketFlags.Peek); if (len < hdrBuf.Length) { DicConsole.ErrorWriteLine("Could not read from the network..."); throw new IOException(); } var hdr = Marshal.ByteArrayToStructureLittleEndian <DicPacketHeader>(hdrBuf); if (hdr.remote_id != Consts.RemoteId || hdr.packet_id != Consts.PacketId) { DicConsole.ErrorWriteLine("Received data is not a DIC Remote Packet..."); throw new ArgumentException(); } byte[] buf; if (hdr.packetType != DicPacketType.Hello) { if (hdr.packetType != DicPacketType.Nop) { DicConsole.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) { DicConsole.ErrorWriteLine("Could not read from the network..."); throw new IOException(); } var nop = Marshal.ByteArrayToStructureLittleEndian <DicPacketNop>(buf); DicConsole.ErrorWriteLine($"{nop.reason}"); throw new ArgumentException(); } if (hdr.version != Consts.PacketVersion) { DicConsole.ErrorWriteLine("Unrecognized packet version..."); throw new ArgumentException(); } buf = new byte[hdr.len]; len = Receive(_socket, buf, buf.Length, SocketFlags.None); if (len < buf.Length) { DicConsole.ErrorWriteLine("Could not read from the network..."); throw new IOException(); } var serverHello = Marshal.ByteArrayToStructureLittleEndian <DicPacketHello>(buf); ServerApplication = serverHello.application; ServerVersion = serverHello.version; ServerOperatingSystem = serverHello.sysname; ServerOperatingSystemVersion = serverHello.release; ServerArchitecture = serverHello.machine; ServerProtocolVersion = serverHello.maxProtocol; var clientHello = new DicPacketHello { application = "DiscImageChef", version = Version.GetVersion(), maxProtocol = Consts.MaxProtocol, sysname = DetectOS.GetPlatformName( DetectOS.GetRealPlatformID(), DetectOS.GetVersion()), release = DetectOS.GetVersion(), machine = RuntimeInformation.ProcessArchitecture.ToString(), hdr = new DicPacketHeader { remote_id = Consts.RemoteId, packet_id = Consts.PacketId, len = (uint)Marshal.SizeOf <DicPacketHello>(), version = Consts.PacketVersion, packetType = DicPacketType.Hello } }; buf = Marshal.StructureToByteArrayLittleEndian(clientHello); len = _socket.Send(buf, SocketFlags.None); if (len >= buf.Length) { return; } DicConsole.ErrorWriteLine("Could not write to the network..."); throw new IOException(); }
/// <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(); } }