private async void Export_Click(object sender, RoutedEventArgs e) { try { this.IsEnabled = false; System.Windows.Input.Mouse.OverrideCursor = Cursors.Wait; // ---- Configure Paths FileInfo filePath = null; try { filePath = new FileInfo(tbFilePath.Text); } catch (ArgumentException) { ShowError("Export path is not valid."); return; } if (!filePath.Directory.Exists) { filePath.Directory.Create(); } var fileNameNoExtension = Path.GetFileNameWithoutExtension(filePath.Name); var buildDirectoryPath = Path.Combine(filePath.Directory.FullName, fileNameNoExtension); if (!Directory.Exists(buildDirectoryPath)) { Directory.CreateDirectory(buildDirectoryPath); } var log = new LogFile(buildDirectoryPath); // ---- Gather sytem info try { await Step_GatherAdditionalInfo(log, buildDirectoryPath); } catch (Exception ex) { log.Error("Error gather system info", ex); } // ---- Export the Logs try { log.Info("Exporting Logs..."); var assLocation = new FileInfo(typeof(OctgnDetails).Assembly.Location); var logsFolder = assLocation.Directory.FullName; logsFolder = Path.Combine(logsFolder, "Logs"); foreach (var file in Directory.EnumerateFiles(logsFolder, "*.log")) { var fileName = Path.GetFileName(file); var copyToPath = Path.Combine(buildDirectoryPath, fileName); log.Info($"Copying log {file} to {copyToPath}"); File.Copy(file, copyToPath); } } catch (Exception ex) { log.Error("Error exporting logs", ex); } // ---- Export installer logs try { var installerLogsFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Temp"); foreach (var file in Directory.EnumerateFiles(installerLogsFolder, "Octgn*.log")) { var fileName = Path.GetFileName(file); var copyToPath = Path.Combine(buildDirectoryPath, fileName); log.Info("Copying installer log : " + file); File.Copy(file, copyToPath); } } catch (Exception ex) { log.Error("Error exporting installer logs", ex); } // ---- Create Zip File log.Info("Creating zip file " + filePath.FullName); ZipFile.CreateFromDirectory(buildDirectoryPath, filePath.FullName); // ---- Delete build directory await Task.Delay(5000); Directory.Delete(buildDirectoryPath, true); } catch (Exception ex) { ShowError("Unexpected Error", ex); } finally { tbFilePath.Text = CreateDumpPath(); this.IsEnabled = true; System.Windows.Input.Mouse.OverrideCursor = null; } }
private async Task Step_GatherAdditionalInfo(LogFile log, string buildDirectoryPath) { var computerInfo = new ComputerInfo(); // windows version log.Info(computerInfo.OSFullName + " " + computerInfo.OSVersion); log.Info("OS Bit: " + (Environment.Is64BitOperatingSystem ? "64" : "32")); log.Info("Program Bit: " + (Environment.Is64BitProcess ? "64" : "32")); // Highest .net version installed var dotNetVersion = GetDotNetVersion(); log.Info(".Net Version: " + dotNetVersion); // processor count log.Info("Processors: " + Environment.ProcessorCount); // total ram var totalGBRam = Convert.ToInt32((computerInfo.TotalPhysicalMemory / (Math.Pow(1024, 3))) + 0.5); log.Info("Total Ram: " + totalGBRam + "GB"); // ram usage var availableGBRam = Math.Round(computerInfo.AvailablePhysicalMemory / (Math.Pow(1024, 3)), 2); log.Info("Available Ram: " + availableGBRam + "GB"); // pings to various sites var octgnPing = await Ping("octgn.net"); log.Info("OCTGN Ping: " + octgnPing); var googlePing = await Ping("google.com"); log.Info("Google Ping: " + googlePing); var yahooPing = await Ping("yahoo.com"); log.Info("Yahoo Ping: " + yahooPing); var mygetPing = await Ping("myget.org"); log.Info("MyGet Ping: " + mygetPing); // OCTGN Details var details = new OctgnDetails(); details.FillDetails(); // Is octgn installed log.Info("Octgn Installed: " + details.Location); log.Info("Data Path File: " + details.DataPathFile); log.Info("Data Directory Env Var : " + details.DataDirectoryEnvironmentalVariable); log.Info("OCTGN Version: " + details.Version); log.Info("Running Instance Count: " + details.RunningInstances); var copyTo = Path.Combine(buildDirectoryPath, "settings.json"); try { File.Copy(details.ConfigPath, copyTo); } catch (Exception ex) { log.Error($"Couldn't copy {details.ConfigPath} to {copyTo}", ex); } }