Added ability to generate Support ZIP from settings screen

This commit is contained in:
Terry MacDonald 2021-10-26 20:56:28 +13:00
parent 0434113e4b
commit 6d25635846
5 changed files with 97 additions and 43 deletions

View File

@ -84,6 +84,7 @@
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Management" /> <Reference Include="System.Management" />
<Reference Include="System.ServiceModel" /> <Reference Include="System.ServiceModel" />
<Reference Include="System.Web" /> <Reference Include="System.Web" />

View File

@ -104,6 +104,7 @@ namespace DisplayMagician {
// Load the program settings // Load the program settings
AppProgramSettings = ProgramSettings.LoadSettings(); AppProgramSettings = ProgramSettings.LoadSettings();
// Rules for mapping loggers to targets // Rules for mapping loggers to targets
/*NLog.LogLevel logLevel = null; /*NLog.LogLevel logLevel = null;
switch (AppProgramSettings.LogLevel) switch (AppProgramSettings.LogLevel)
@ -132,6 +133,8 @@ namespace DisplayMagician {
// While there are a large number of big changes taking place with DisplayMagician, this will minimise // While there are a large number of big changes taking place with DisplayMagician, this will minimise
// the backwards and forwards it takes to get the right level of log information for me to troubleshoot. // the backwards and forwards it takes to get the right level of log information for me to troubleshoot.
NLog.LogLevel logLevel = NLog.LogLevel.Trace; NLog.LogLevel logLevel = NLog.LogLevel.Trace;
AppProgramSettings.LogLevel = "Trace";
// Create the log file target // Create the log file target
var logfile = new NLog.Targets.FileTarget("logfile") var logfile = new NLog.Targets.FileTarget("logfile")

View File

@ -26,8 +26,8 @@ using System.Resources;
[assembly: Guid("e4ceaf5e-ad01-4695-b179-31168eb74c48")] [assembly: Guid("e4ceaf5e-ad01-4695-b179-31168eb74c48")]
// Version information // Version information
[assembly: AssemblyVersion("2.1.0.18")] [assembly: AssemblyVersion("2.1.0.26")]
[assembly: AssemblyFileVersion("2.1.0.18")] [assembly: AssemblyFileVersion("2.1.0.26")]
[assembly: NeutralResourcesLanguageAttribute( "en" )] [assembly: NeutralResourcesLanguageAttribute( "en" )]
[assembly: CLSCompliant(true)] [assembly: CLSCompliant(true)]

View File

@ -51,8 +51,8 @@ namespace DisplayMagician.UIForms
this.label2 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label();
this.cb_upgrade_prerelease = new System.Windows.Forms.CheckBox(); this.cb_upgrade_prerelease = new System.Windows.Forms.CheckBox();
this.gb_support = new System.Windows.Forms.GroupBox(); this.gb_support = new System.Windows.Forms.GroupBox();
this.label3 = new System.Windows.Forms.Label();
this.btn_create_support_package = new System.Windows.Forms.Button(); this.btn_create_support_package = new System.Windows.Forms.Button();
this.label3 = new System.Windows.Forms.Label();
this.gb_general.SuspendLayout(); this.gb_general.SuspendLayout();
this.gb_hotkeys.SuspendLayout(); this.gb_hotkeys.SuspendLayout();
this.gb_upgrades.SuspendLayout(); this.gb_upgrades.SuspendLayout();
@ -341,17 +341,6 @@ namespace DisplayMagician.UIForms
this.gb_support.TabStop = false; this.gb_support.TabStop = false;
this.gb_support.Text = "Support Settings"; this.gb_support.Text = "Support Settings";
// //
// label3
//
this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label3.Location = new System.Drawing.Point(105, 57);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(334, 32);
this.label3.TabIndex = 15;
this.label3.Text = "Use this button to save a support package to your computer. You can then upload t" +
"his file to GitHub when you have a problem";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// btn_create_support_package // btn_create_support_package
// //
this.btn_create_support_package.Anchor = System.Windows.Forms.AnchorStyles.Bottom; this.btn_create_support_package.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
@ -364,10 +353,21 @@ namespace DisplayMagician.UIForms
this.btn_create_support_package.Name = "btn_create_support_package"; this.btn_create_support_package.Name = "btn_create_support_package";
this.btn_create_support_package.Size = new System.Drawing.Size(183, 33); this.btn_create_support_package.Size = new System.Drawing.Size(183, 33);
this.btn_create_support_package.TabIndex = 48; this.btn_create_support_package.TabIndex = 48;
this.btn_create_support_package.Text = "Create a Support Package"; this.btn_create_support_package.Text = "Create a Support Zip File";
this.btn_create_support_package.UseVisualStyleBackColor = true; this.btn_create_support_package.UseVisualStyleBackColor = true;
this.btn_create_support_package.Click += new System.EventHandler(this.btn_create_support_package_Click); this.btn_create_support_package.Click += new System.EventHandler(this.btn_create_support_package_Click);
// //
// label3
//
this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label3.Location = new System.Drawing.Point(74, 57);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(378, 32);
this.label3.TabIndex = 15;
this.label3.Text = "Use this button to save a support zip file to your computer. You can then upload " +
"this file to GitHub when you have a problem you need me to fix";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// SettingsForm // SettingsForm
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

View File

@ -104,8 +104,8 @@ namespace DisplayMagician.UIForms
logger.Info($"SettingsForm/SettingsForm_Load: AppProgramSettings LogLevel set to Fatal"); logger.Info($"SettingsForm/SettingsForm_Load: AppProgramSettings LogLevel set to Fatal");
break; break;
default: default:
cmb_loglevel.SelectedIndex = cmb_loglevel.FindStringExact(logLevelText["Info"]); cmb_loglevel.SelectedIndex = cmb_loglevel.FindStringExact(logLevelText["Trace"]);
logger.Info($"SettingsForm/SettingsForm_Load: AppProgramSettings LogLevel set to Info"); logger.Info($"SettingsForm/SettingsForm_Load: AppProgramSettings LogLevel set to Trace");
break; break;
} }
@ -475,42 +475,92 @@ namespace DisplayMagician.UIForms
private void btn_create_support_package_Click(object sender, EventArgs e) private void btn_create_support_package_Click(object sender, EventArgs e)
{ {
string zipFilePath = ""; try
using (var archiveStream = new FileStream(zipFilePath, FileMode.Create))
{ {
using (var archive = new ZipArchive(archiveStream, ZipArchiveMode.Create, true)) using (SaveFileDialog saveFileDialog = new SaveFileDialog())
{ {
DateTime now = DateTime.Now;
saveFileDialog.InitialDirectory = Environment.SpecialFolder.MyDocuments.ToString();
saveFileDialog.Filter = "Zip Files(*.zip)| *.zip | All files(*.*) | *.*";
saveFileDialog.FilterIndex = 2;
saveFileDialog.RestoreDirectory = true;
saveFileDialog.FileName = $"DisplayMagician-Support-{now.ToString("yyyyMMdd-HHmm")}.zip";
saveFileDialog.Title = "Save a DisplayMagician Support ZIP file";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
//Get the path of specified file
string zipFilePath = saveFileDialog.FileName;
SharedLogger.logger.Trace($"SettingsForm/btn_create_support_package_Click: Creating support zip file at {zipFilePath}.");
if (File.Exists(zipFilePath))
{
File.Delete(zipFilePath);
}
ZipArchive archive = ZipFile.Open(zipFilePath, ZipArchiveMode.Create);
// Get the list of files to zip // Get the list of files to zip
List<string> listOfFiles = new List<string> { List<string> listOfFiles = new List<string> {
// Add the DisplayMagician.log file // Add the DisplayMagician.log file
Path.Combine(Program.AppLogPath,"DisplayMagician.log"), Path.Combine(Program.AppLogPath,"DisplayMagician.log"),
// Add the DisplayMagician.log file // Add the DisplayMagician.log file
Path.Combine(Program.AppProfilePath,"DisplayProfile_2.1.json"), Path.Combine(Program.AppProfilePath,"DisplayProfiles_2.1.json"),
// Add the DisplayMagician.log file // Add the DisplayMagician.log file
Path.Combine(Program.AppShortcutPath,"Shortcuts_2.0.json"), Path.Combine(Program.AppShortcutPath,"Shortcuts_2.0.json"),
// Add the DisplayMagician.log file // Add the DisplayMagician.log file
Path.Combine(Program.AppDataPath,"Settings_2.0.json") Path.Combine(Program.AppDataPath,"Settings_2.0.json")
}; };
foreach (string filename in listOfFiles) foreach (string filename in listOfFiles)
{ {
var zipArchiveEntry = archive.CreateEntry(filename, CompressionLevel.Fastest); try
using (Stream zipStream = zipArchiveEntry.Open())
{ {
using (StreamWriter writer = new StreamWriter(zipStream)) if (File.Exists(filename))
{ {
writer.WriteLine(filename); archive.CreateEntryFromFile(filename, Path.GetFileName(filename), CompressionLevel.Optimal);
} }
else
{
SharedLogger.logger.Warn($"SettingsForm/btn_create_support_package_Click: Couldn't add {filename} to the support ZIP file {zipFilePath} as it doesn't exist.");
} }
} }
catch (ArgumentNullException ex)
{
SharedLogger.logger.Warn(ex, $"SettingsForm/btn_create_support_package_Click: Argument Null Exception while adding files to the support zip file.");
}
catch (System.Runtime.InteropServices.ExternalException ex)
{
SharedLogger.logger.Warn(ex, $"SettingsForm/btn_create_support_package_Click: External InteropServices Exception while adding files to the support zip file.");
}
catch (Exception ex)
{
SharedLogger.logger.Warn(ex, $"SettingsForm/btn_create_support_package_Click: Exception while while adding files to the support zip file.");
} }
zip
} }
return archiveFile; archive.Dispose();
SharedLogger.logger.Trace($"SettingsForm/btn_create_support_package_Click: Finished creating support zip file at {zipFilePath}.");
MessageBox.Show($"Created DisplayMagician Support ZIP file {zipFilePath}. You can now attach this file to your GitHub issue.");
}
}
}
catch (ArgumentNullException ex)
{
SharedLogger.logger.Warn(ex, $"SettingsForm/btn_create_support_package_Click: Argument Null Exception while creating support zip file.");
}
catch (System.Runtime.InteropServices.ExternalException ex)
{
SharedLogger.logger.Warn(ex, $"SettingsForm/btn_create_support_package_Click: External InteropServices Exception while creating support zip file.");
}
catch (Exception ex)
{
SharedLogger.logger.Warn(ex, $"SettingsForm/btn_create_support_package_Click: Exception while while creating support zip file.");
}
} }
} }
} }