Skip to content

Commit

Permalink
Merge pull request #234 from Hirogen/portable-mode-all-in-same-folder
Browse files Browse the repository at this point in the history
Add PortableMode for Session Files
  • Loading branch information
Hirogen authored Jul 15, 2022
2 parents 310be23 + c796070 commit 728a081
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 37 deletions.
20 changes: 17 additions & 3 deletions src/LogExpert/Classes/Persister/Persister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
13 changes: 8 additions & 5 deletions src/LogExpert/Config/ConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
/// <summary>
/// Application.StartupPath + portableMode.json
/// </summary>
public static string PortableMode => Application.StartupPath + Path.DirectorySeparatorChar + "portableMode.json";

public static Settings Settings => Instance._settings;

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}

Expand Down
13 changes: 13 additions & 0 deletions src/LogExpert/Config/SessionSaveLocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,22 @@ namespace LogExpert.Config
[Serializable]
public enum SessionSaveLocation
{
//Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + Path.DirectorySeparatorChar + "LogExpert"
/// <summary>
/// <see cref="Environment.SpecialFolder.MyDocuments"/>
/// </summary>
DocumentsDir,
//same directory as the logfile
SameDir,
//uses configured folder to save the session files
/// <summary>
/// <see cref="Preferences.sessionSaveDirectory"/>
/// </summary>
OwnDir,
/// <summary>
/// <see cref="System.Windows.Forms.Application.StartupPath"/>
/// </summary>
ApplicationStartupDir,
LoadedSessionFile
}
}
54 changes: 35 additions & 19 deletions src/LogExpert/Dialogs/SettingsDialog.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 30 additions & 4 deletions src/LogExpert/Dialogs/SettingsDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ private void FillDialog()

checkBoxTimeSpread.Checked = Preferences.showTimeSpread;
checkBoxReverseAlpha.Checked = Preferences.reverseAlpha;

radioButtonTimeView.Checked = Preferences.timeSpreadTimeMode;
radioButtonLineView.Checked = !Preferences.timeSpreadTimeMode;

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -775,15 +791,25 @@ 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):
{
File.Delete(ConfigManager.PortableMode);
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)
{
Expand Down
18 changes: 18 additions & 0 deletions src/LogExpert/Dialogs/SettingsDialog.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@
<metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>144, 17</value>
</metadata>
<metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>144, 17</value>
</metadata>
<metadata name="columnFileMask.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="columnColumnizer.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="columnFileMask.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
Expand All @@ -132,12 +141,21 @@
<metadata name="columnHighlightGroup.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="columnFileName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="columnHighlightGroup.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="helpProvider.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<data name="labelNoteMultiFile.Text" xml:space="preserve">
<value>Note: You can always load your logfiles as MultiFile automatically if the files names follow the MultiFile naming rule (&lt;filename&gt;, &lt;filename&gt;.1, &lt;filename&gt;.2, ...). Simply choose 'MultiFile' from the File menu after loading the first file.</value>
</data>
<metadata name="helpProvider.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
Expand Down
5 changes: 5 additions & 0 deletions src/LogExpert/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading

0 comments on commit 728a081

Please sign in to comment.