diff --git a/DisplayMagician/DisplayMagician.csproj b/DisplayMagician/DisplayMagician.csproj index f5138c7..5e78170 100644 --- a/DisplayMagician/DisplayMagician.csproj +++ b/DisplayMagician/DisplayMagician.csproj @@ -84,6 +84,7 @@ + diff --git a/DisplayMagician/Program.cs b/DisplayMagician/Program.cs index ad57fae..e8fb419 100644 --- a/DisplayMagician/Program.cs +++ b/DisplayMagician/Program.cs @@ -103,6 +103,7 @@ namespace DisplayMagician { // Load the program settings AppProgramSettings = ProgramSettings.LoadSettings(); + // Rules for mapping loggers to targets /*NLog.LogLevel logLevel = null; @@ -132,6 +133,8 @@ namespace DisplayMagician { // 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. NLog.LogLevel logLevel = NLog.LogLevel.Trace; + AppProgramSettings.LogLevel = "Trace"; + // Create the log file target var logfile = new NLog.Targets.FileTarget("logfile") diff --git a/DisplayMagician/Properties/AssemblyInfo.cs b/DisplayMagician/Properties/AssemblyInfo.cs index 3488c8c..017f85e 100644 --- a/DisplayMagician/Properties/AssemblyInfo.cs +++ b/DisplayMagician/Properties/AssemblyInfo.cs @@ -26,8 +26,8 @@ using System.Resources; [assembly: Guid("e4ceaf5e-ad01-4695-b179-31168eb74c48")] // Version information -[assembly: AssemblyVersion("2.1.0.18")] -[assembly: AssemblyFileVersion("2.1.0.18")] +[assembly: AssemblyVersion("2.1.0.26")] +[assembly: AssemblyFileVersion("2.1.0.26")] [assembly: NeutralResourcesLanguageAttribute( "en" )] [assembly: CLSCompliant(true)] diff --git a/DisplayMagician/UIForms/SettingsForm.Designer.cs b/DisplayMagician/UIForms/SettingsForm.Designer.cs index 0564dcd..710ac07 100644 --- a/DisplayMagician/UIForms/SettingsForm.Designer.cs +++ b/DisplayMagician/UIForms/SettingsForm.Designer.cs @@ -51,8 +51,8 @@ namespace DisplayMagician.UIForms this.label2 = new System.Windows.Forms.Label(); this.cb_upgrade_prerelease = new System.Windows.Forms.CheckBox(); 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.label3 = new System.Windows.Forms.Label(); this.gb_general.SuspendLayout(); this.gb_hotkeys.SuspendLayout(); this.gb_upgrades.SuspendLayout(); @@ -341,17 +341,6 @@ namespace DisplayMagician.UIForms this.gb_support.TabStop = false; 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 // 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.Size = new System.Drawing.Size(183, 33); 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.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 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); diff --git a/DisplayMagician/UIForms/SettingsForm.cs b/DisplayMagician/UIForms/SettingsForm.cs index 93ebad9..ccb5893 100644 --- a/DisplayMagician/UIForms/SettingsForm.cs +++ b/DisplayMagician/UIForms/SettingsForm.cs @@ -104,8 +104,8 @@ namespace DisplayMagician.UIForms logger.Info($"SettingsForm/SettingsForm_Load: AppProgramSettings LogLevel set to Fatal"); break; default: - cmb_loglevel.SelectedIndex = cmb_loglevel.FindStringExact(logLevelText["Info"]); - logger.Info($"SettingsForm/SettingsForm_Load: AppProgramSettings LogLevel set to Info"); + cmb_loglevel.SelectedIndex = cmb_loglevel.FindStringExact(logLevelText["Trace"]); + logger.Info($"SettingsForm/SettingsForm_Load: AppProgramSettings LogLevel set to Trace"); break; } @@ -475,42 +475,92 @@ namespace DisplayMagician.UIForms private void btn_create_support_package_Click(object sender, EventArgs e) { - string zipFilePath = ""; - using (var archiveStream = new FileStream(zipFilePath, FileMode.Create)) + try { - using (var archive = new ZipArchive(archiveStream, ZipArchiveMode.Create, true)) + using (SaveFileDialog saveFileDialog = new SaveFileDialog()) { - // Get the list of files to zip - List listOfFiles = new List { - // Add the DisplayMagician.log file - Path.Combine(Program.AppLogPath,"DisplayMagician.log"), - // Add the DisplayMagician.log file - Path.Combine(Program.AppProfilePath,"DisplayProfile_2.1.json"), - // Add the DisplayMagician.log file - Path.Combine(Program.AppShortcutPath,"Shortcuts_2.0.json"), - // Add the DisplayMagician.log file - Path.Combine(Program.AppDataPath,"Settings_2.0.json") - }; + 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"; - foreach (string filename in listOfFiles) + if (saveFileDialog.ShowDialog() == DialogResult.OK) { - var zipArchiveEntry = archive.CreateEntry(filename, CompressionLevel.Fastest); - - using (Stream zipStream = zipArchiveEntry.Open()) + //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)) { - using (StreamWriter writer = new StreamWriter(zipStream)) - { - writer.WriteLine(filename); - } + File.Delete(zipFilePath); } - + + ZipArchive archive = ZipFile.Open(zipFilePath, ZipArchiveMode.Create); + + // Get the list of files to zip + List listOfFiles = new List { + // Add the DisplayMagician.log file + Path.Combine(Program.AppLogPath,"DisplayMagician.log"), + // Add the DisplayMagician.log file + Path.Combine(Program.AppProfilePath,"DisplayProfiles_2.1.json"), + // Add the DisplayMagician.log file + Path.Combine(Program.AppShortcutPath,"Shortcuts_2.0.json"), + // Add the DisplayMagician.log file + Path.Combine(Program.AppDataPath,"Settings_2.0.json") + }; + foreach (string filename in listOfFiles) + { + try + { + if (File.Exists(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."); + } + + + } + + 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."); } } - - zip + } + 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."); } - return archiveFile; + } } }