diff --git a/src/LogExpert/Classes/Persister/Persister.cs b/src/LogExpert/Classes/Persister/Persister.cs index a4e3be7f..e88bc840 100644 --- a/src/LogExpert/Classes/Persister/Persister.cs +++ b/src/LogExpert/Classes/Persister/Persister.cs @@ -147,28 +147,42 @@ public static PersistenceData LoadOptionsOnly(string fileName) private static string BuildPersisterFileName(string logFileName, Preferences preferences) { - string dir = null; - string file = null; + string dir; + string file; + switch (preferences.saveLocation) { case SessionSaveLocation.SameDir: default: + { FileInfo fileInfo = new FileInfo(logFileName); dir = fileInfo.DirectoryName; file = fileInfo.DirectoryName + Path.DirectorySeparatorChar + fileInfo.Name + ".lxp"; break; + } case SessionSaveLocation.DocumentsDir: + { dir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + Path.DirectorySeparatorChar + "LogExpert"; file = dir + Path.DirectorySeparatorChar + BuildSessionFileNameFromPath(logFileName); break; + } case SessionSaveLocation.OwnDir: + { dir = preferences.sessionSaveDirectory; file = dir + Path.DirectorySeparatorChar + BuildSessionFileNameFromPath(logFileName); break; + } + case SessionSaveLocation.ApplicationStartupDir: + { + dir = Application.StartupPath; + file = dir + Path.DirectorySeparatorChar + BuildSessionFileNameFromPath(logFileName); + break; + } } - if (!string.IsNullOrWhiteSpace(dir) && !Directory.Exists(dir)) + + if (string.IsNullOrWhiteSpace(dir) == false && Directory.Exists(dir) == false) { try { diff --git a/src/LogExpert/Config/ConfigManager.cs b/src/LogExpert/Config/ConfigManager.cs index bd248d3d..eef4e27f 100644 --- a/src/LogExpert/Config/ConfigManager.cs +++ b/src/LogExpert/Config/ConfigManager.cs @@ -60,9 +60,12 @@ public static ConfigManager Instance } } - public static string ConfigDir => Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\LogExpert"; + public static string ConfigDir => Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + Path.DirectorySeparatorChar + "LogExpert"; - public static string PortableMode => Application.StartupPath + "\\portableMode.json"; + /// + /// Application.StartupPath + portableMode.json + /// + public static string PortableMode => Application.StartupPath + Path.DirectorySeparatorChar + "portableMode.json"; public static Settings Settings => Instance._settings; @@ -112,14 +115,14 @@ private Settings Load() Directory.CreateDirectory(dir); } - if (!File.Exists(dir + "\\settings.json")) + if (!File.Exists(dir + Path.DirectorySeparatorChar + "settings.json")) { return LoadOrCreateNew(null); } try { - FileInfo fileInfo = new FileInfo(dir + "\\settings.json"); + FileInfo fileInfo = new FileInfo(dir + Path.DirectorySeparatorChar + "settings.json"); return LoadOrCreateNew(fileInfo); } catch (Exception e) @@ -298,7 +301,7 @@ private void Save(Settings settings, SettingsFlags flags) Directory.CreateDirectory(dir); } - FileInfo fileInfo = new FileInfo(dir + "\\settings.json"); + FileInfo fileInfo = new FileInfo(dir + Path.DirectorySeparatorChar + "settings.json"); Save(fileInfo, settings); } diff --git a/src/LogExpert/Config/SessionSaveLocation.cs b/src/LogExpert/Config/SessionSaveLocation.cs index b97abe27..540147b8 100644 --- a/src/LogExpert/Config/SessionSaveLocation.cs +++ b/src/LogExpert/Config/SessionSaveLocation.cs @@ -5,9 +5,22 @@ namespace LogExpert.Config [Serializable] public enum SessionSaveLocation { + //Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + Path.DirectorySeparatorChar + "LogExpert" + /// + /// + /// DocumentsDir, + //same directory as the logfile SameDir, + //uses configured folder to save the session files + /// + /// + /// OwnDir, + /// + /// + /// + ApplicationStartupDir, LoadedSessionFile } } \ No newline at end of file diff --git a/src/LogExpert/Dialogs/SettingsDialog.Designer.cs b/src/LogExpert/Dialogs/SettingsDialog.Designer.cs index 178da80c..d9a8b28f 100644 --- a/src/LogExpert/Dialogs/SettingsDialog.Designer.cs +++ b/src/LogExpert/Dialogs/SettingsDialog.Designer.cs @@ -121,14 +121,15 @@ private void InitializeComponent() this.panelPlugin = new System.Windows.Forms.Panel(); this.buttonConfigPlugin = new System.Windows.Forms.Button(); this.tabPageSessions = new System.Windows.Forms.TabPage(); + this.checkBoxPortableMode = new System.Windows.Forms.CheckBox(); this.checkBoxSaveFilter = new System.Windows.Forms.CheckBox(); this.groupBoxPersistantFileLocation = new System.Windows.Forms.GroupBox(); - this.checkBoxPortableMode = new System.Windows.Forms.CheckBox(); this.labelSessionSaveOwnDir = new System.Windows.Forms.Label(); this.buttonSessionSaveDir = new System.Windows.Forms.Button(); this.radioButtonSessionSaveOwn = new System.Windows.Forms.RadioButton(); this.radioButtonsessionSaveDocuments = new System.Windows.Forms.RadioButton(); this.radioButtonSessionSameDir = new System.Windows.Forms.RadioButton(); + this.radioButtonSessionApplicationStartupDir = new System.Windows.Forms.RadioButton(); this.checkBoxSaveSessions = new System.Windows.Forms.CheckBox(); this.tabPageMemory = new System.Windows.Forms.TabPage(); this.groupBoxCPUAndStuff = new System.Windows.Forms.GroupBox(); @@ -399,9 +400,9 @@ private void InitializeComponent() this.checkBoxSingleInstance.Location = new System.Drawing.Point(9, 66); this.checkBoxSingleInstance.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.checkBoxSingleInstance.Name = "checkBoxSingleInstance"; - this.checkBoxSingleInstance.Size = new System.Drawing.Size(173, 24); + this.checkBoxSingleInstance.Size = new System.Drawing.Size(183, 24); this.checkBoxSingleInstance.TabIndex = 1; - this.checkBoxSingleInstance.Text = "Allow only 1 window"; + this.checkBoxSingleInstance.Text = "Allow only 1 Instance"; this.checkBoxSingleInstance.UseVisualStyleBackColor = true; // // checkBoxAskCloseTabs @@ -1289,6 +1290,7 @@ private void InitializeComponent() // // tabPageSessions // + this.tabPageSessions.Controls.Add(this.checkBoxPortableMode); this.tabPageSessions.Controls.Add(this.checkBoxSaveFilter); this.tabPageSessions.Controls.Add(this.groupBoxPersistantFileLocation); this.tabPageSessions.Controls.Add(this.checkBoxSaveSessions); @@ -1301,6 +1303,20 @@ private void InitializeComponent() this.tabPageSessions.Text = "Persistence"; this.tabPageSessions.UseVisualStyleBackColor = true; // + // checkBoxPortableMode + // + this.checkBoxPortableMode.AutoSize = true; + this.checkBoxPortableMode.Location = new System.Drawing.Point(34, 377); + this.checkBoxPortableMode.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.checkBoxPortableMode.Name = "checkBoxPortableMode"; + this.checkBoxPortableMode.Size = new System.Drawing.Size(199, 24); + this.checkBoxPortableMode.TabIndex = 3; + this.checkBoxPortableMode.Text = "Activate Portable Mode"; + this.toolTip.SetToolTip(this.checkBoxPortableMode, "If this mode is activated, the save file will be loaded from the Executable Locat" + + "ion"); + this.checkBoxPortableMode.UseVisualStyleBackColor = true; + this.checkBoxPortableMode.CheckedChanged += new System.EventHandler(this.OnPortableModeCheckedChanged); + // // checkBoxSaveFilter // this.checkBoxSaveFilter.AutoSize = true; @@ -1314,12 +1330,12 @@ private void InitializeComponent() // // groupBoxPersistantFileLocation // - this.groupBoxPersistantFileLocation.Controls.Add(this.checkBoxPortableMode); this.groupBoxPersistantFileLocation.Controls.Add(this.labelSessionSaveOwnDir); this.groupBoxPersistantFileLocation.Controls.Add(this.buttonSessionSaveDir); this.groupBoxPersistantFileLocation.Controls.Add(this.radioButtonSessionSaveOwn); this.groupBoxPersistantFileLocation.Controls.Add(this.radioButtonsessionSaveDocuments); this.groupBoxPersistantFileLocation.Controls.Add(this.radioButtonSessionSameDir); + this.groupBoxPersistantFileLocation.Controls.Add(this.radioButtonSessionApplicationStartupDir); this.groupBoxPersistantFileLocation.Location = new System.Drawing.Point(34, 134); this.groupBoxPersistantFileLocation.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.groupBoxPersistantFileLocation.Name = "groupBoxPersistantFileLocation"; @@ -1329,20 +1345,6 @@ private void InitializeComponent() this.groupBoxPersistantFileLocation.TabStop = false; this.groupBoxPersistantFileLocation.Text = "Persistence file location"; // - // checkBoxPortableMode - // - this.checkBoxPortableMode.AutoSize = true; - this.checkBoxPortableMode.Location = new System.Drawing.Point(10, 172); - this.checkBoxPortableMode.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); - this.checkBoxPortableMode.Name = "checkBoxPortableMode"; - this.checkBoxPortableMode.Size = new System.Drawing.Size(199, 24); - this.checkBoxPortableMode.TabIndex = 3; - this.checkBoxPortableMode.Text = "Activate Portable Mode"; - this.toolTip.SetToolTip(this.checkBoxPortableMode, "If this mode is activated, the save file will be loaded from the Executable Locat" + - "ion"); - this.checkBoxPortableMode.UseVisualStyleBackColor = true; - this.checkBoxPortableMode.CheckedChanged += new System.EventHandler(this.OnPortableModeCheckedChanged); - // // labelSessionSaveOwnDir // this.labelSessionSaveOwnDir.Location = new System.Drawing.Point(39, 142); @@ -1399,6 +1401,19 @@ private void InitializeComponent() this.radioButtonSessionSameDir.Text = "Same directory as log file"; this.radioButtonSessionSameDir.UseVisualStyleBackColor = true; // + // radioButtonSessionApplicationStartupDir + // + this.radioButtonSessionApplicationStartupDir.AutoSize = true; + this.radioButtonSessionApplicationStartupDir.Location = new System.Drawing.Point(8, 177); + this.radioButtonSessionApplicationStartupDir.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.radioButtonSessionApplicationStartupDir.Name = "radioButtonSessionApplicationStartupDir"; + this.radioButtonSessionApplicationStartupDir.Size = new System.Drawing.Size(230, 24); + this.radioButtonSessionApplicationStartupDir.TabIndex = 5; + this.radioButtonSessionApplicationStartupDir.TabStop = true; + this.radioButtonSessionApplicationStartupDir.Text = "Application startup directory"; + this.toolTip.SetToolTip(this.radioButtonSessionApplicationStartupDir, "This path is based on the executable and where it has been started from."); + this.radioButtonSessionApplicationStartupDir.UseVisualStyleBackColor = true; + // // checkBoxSaveSessions // this.checkBoxSaveSessions.AutoSize = true; @@ -1609,7 +1624,7 @@ private void InitializeComponent() this.buttonOk.TabIndex = 0; this.buttonOk.Text = "OK"; this.buttonOk.UseVisualStyleBackColor = true; - this.buttonOk.Click += new System.EventHandler(this.okButton_Click); + this.buttonOk.Click += new System.EventHandler(this.OnOkButtonClick); // // helpProvider // @@ -1851,5 +1866,6 @@ private void InitializeComponent() private System.Windows.Forms.Label labelMaximumFilterEntriesDisplayed; private System.Windows.Forms.CheckBox checkBoxAutoPick; private System.Windows.Forms.CheckBox checkBoxPortableMode; + private System.Windows.Forms.RadioButton radioButtonSessionApplicationStartupDir; } } diff --git a/src/LogExpert/Dialogs/SettingsDialog.cs b/src/LogExpert/Dialogs/SettingsDialog.cs index 4eebbd82..cf2e2de9 100644 --- a/src/LogExpert/Dialogs/SettingsDialog.cs +++ b/src/LogExpert/Dialogs/SettingsDialog.cs @@ -103,6 +103,7 @@ private void FillDialog() checkBoxTimeSpread.Checked = Preferences.showTimeSpread; checkBoxReverseAlpha.Checked = Preferences.reverseAlpha; + radioButtonTimeView.Checked = Preferences.timeSpreadTimeMode; radioButtonLineView.Checked = !Preferences.timeSpreadTimeMode; @@ -123,8 +124,19 @@ private void FillDialog() case SessionSaveLocation.DocumentsDir: { radioButtonsessionSaveDocuments.Checked = true; + break; } - break; + case SessionSaveLocation.ApplicationStartupDir: + { + radioButtonSessionApplicationStartupDir.Checked = true; + break; + } + } + + //overwrite preferences save location in portable mode to always be application startup directory + if (checkBoxPortableMode.Checked) + { + radioButtonSessionApplicationStartupDir.Checked = true; } upDownMaximumFilterEntriesDisplayed.Value = Preferences.maximumFilterEntriesDisplayed; @@ -582,7 +594,7 @@ private void changeFontButton_Click(object sender, EventArgs e) DisplayFontName(); } - private void okButton_Click(object sender, EventArgs e) + private void OnOkButtonClick(object sender, EventArgs e) { Preferences.timestampControl = checkBoxTimestamp.Checked; Preferences.filterSync = checkBoxSyncFilter.Checked; @@ -627,6 +639,10 @@ private void okButton_Click(object sender, EventArgs e) { Preferences.saveLocation = SessionSaveLocation.OwnDir; } + else if (radioButtonSessionApplicationStartupDir.Checked) + { + Preferences.saveLocation = SessionSaveLocation.ApplicationStartupDir; + } else { Preferences.saveLocation = SessionSaveLocation.SameDir; @@ -775,8 +791,8 @@ private void OnPortableModeCheckedChanged(object sender, EventArgs e) { case CheckState.Checked when !File.Exists(ConfigManager.PortableMode): { - File.Create(ConfigManager.PortableMode); - break; + using (File.Create(ConfigManager.PortableMode)) + break; } case CheckState.Unchecked when File.Exists(ConfigManager.PortableMode): { @@ -784,6 +800,16 @@ private void OnPortableModeCheckedChanged(object sender, EventArgs e) break; } } + + switch (checkBoxPortableMode.CheckState) + { + case CheckState.Unchecked: + checkBoxPortableMode.Text = @"Activate Portable Mode"; + break; + case CheckState.Checked: + checkBoxPortableMode.Text = @"Deactivate Portable Mode"; + break; + } } catch (Exception exception) { diff --git a/src/LogExpert/Dialogs/SettingsDialog.resx b/src/LogExpert/Dialogs/SettingsDialog.resx index 9426b76c..ded11c9a 100644 --- a/src/LogExpert/Dialogs/SettingsDialog.resx +++ b/src/LogExpert/Dialogs/SettingsDialog.resx @@ -120,6 +120,15 @@ 144, 17 + + 144, 17 + + + True + + + True + True @@ -132,12 +141,21 @@ True + + True + + + True + 17, 17 Note: You can always load your logfiles as MultiFile automatically if the files names follow the MultiFile naming rule (<filename>, <filename>.1, <filename>.2, ...). Simply choose 'MultiFile' from the File menu after loading the first file. + + 17, 17 + diff --git a/src/LogExpert/Program.cs b/src/LogExpert/Program.cs index c8572a94..599e5ef7 100644 --- a/src/LogExpert/Program.cs +++ b/src/LogExpert/Program.cs @@ -156,6 +156,11 @@ private static void Sub_Main(string[] orgArgs) _logger.Error(errMsg, "IpcClientChannel error, giving up: "); MessageBox.Show($"Cannot open connection to first instance ({errMsg})", "LogExpert"); } + + if (settings.preferences.allowOnlyOneInstance) + { + MessageBox.Show($"Only one instance allowed, uncheck \"View Settings => Allow only 1 Instances\" to start multiple instances!", "Logexpert"); + } } mutex.Close(); diff --git a/src/UnitTests/RolloverHandlerTestBase.cs b/src/UnitTests/RolloverHandlerTestBase.cs index ce495988..5e6675c9 100644 --- a/src/UnitTests/RolloverHandlerTestBase.cs +++ b/src/UnitTests/RolloverHandlerTestBase.cs @@ -86,14 +86,17 @@ protected string CreateFile(DirectoryInfo dInfo, string fileName) { int lineCount = 10; string fullName = dInfo == null ? fileName : dInfo.FullName + Path.DirectorySeparatorChar + fileName; - FileStream stream = File.Create(fullName); - StreamWriter writer = new StreamWriter(stream); - for (int i = 1; i <= lineCount; ++i) + + using (StreamWriter writer = new StreamWriter(File.Create(fullName))) { - writer.WriteLine("Line number " + i.ToString("D3") + " of File " + fullName); + for (int i = 1; i <= lineCount; ++i) + { + writer.WriteLine("Line number " + i.ToString("D3") + " of File " + fullName); + } + + writer.Flush(); } - writer.Flush(); - writer.Close(); + return fullName; } }