Skip to content

Commit 728a081

Browse files
authored
Merge pull request #234 from Hirogen/portable-mode-all-in-same-folder
Add PortableMode for Session Files
2 parents 310be23 + c796070 commit 728a081

File tree

8 files changed

+135
-37
lines changed

8 files changed

+135
-37
lines changed

src/LogExpert/Classes/Persister/Persister.cs

+17-3
Original file line numberDiff line numberDiff line change
@@ -147,28 +147,42 @@ public static PersistenceData LoadOptionsOnly(string fileName)
147147

148148
private static string BuildPersisterFileName(string logFileName, Preferences preferences)
149149
{
150-
string dir = null;
151-
string file = null;
150+
string dir;
151+
string file;
152+
152153
switch (preferences.saveLocation)
153154
{
154155
case SessionSaveLocation.SameDir:
155156
default:
157+
{
156158
FileInfo fileInfo = new FileInfo(logFileName);
157159
dir = fileInfo.DirectoryName;
158160
file = fileInfo.DirectoryName + Path.DirectorySeparatorChar + fileInfo.Name + ".lxp";
159161
break;
162+
}
160163
case SessionSaveLocation.DocumentsDir:
164+
{
161165
dir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) +
162166
Path.DirectorySeparatorChar +
163167
"LogExpert";
164168
file = dir + Path.DirectorySeparatorChar + BuildSessionFileNameFromPath(logFileName);
165169
break;
170+
}
166171
case SessionSaveLocation.OwnDir:
172+
{
167173
dir = preferences.sessionSaveDirectory;
168174
file = dir + Path.DirectorySeparatorChar + BuildSessionFileNameFromPath(logFileName);
169175
break;
176+
}
177+
case SessionSaveLocation.ApplicationStartupDir:
178+
{
179+
dir = Application.StartupPath;
180+
file = dir + Path.DirectorySeparatorChar + BuildSessionFileNameFromPath(logFileName);
181+
break;
182+
}
170183
}
171-
if (!string.IsNullOrWhiteSpace(dir) && !Directory.Exists(dir))
184+
185+
if (string.IsNullOrWhiteSpace(dir) == false && Directory.Exists(dir) == false)
172186
{
173187
try
174188
{

src/LogExpert/Config/ConfigManager.cs

+8-5
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,12 @@ public static ConfigManager Instance
6060
}
6161
}
6262

63-
public static string ConfigDir => Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\LogExpert";
63+
public static string ConfigDir => Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + Path.DirectorySeparatorChar + "LogExpert";
6464

65-
public static string PortableMode => Application.StartupPath + "\\portableMode.json";
65+
/// <summary>
66+
/// Application.StartupPath + portableMode.json
67+
/// </summary>
68+
public static string PortableMode => Application.StartupPath + Path.DirectorySeparatorChar + "portableMode.json";
6669

6770
public static Settings Settings => Instance._settings;
6871

@@ -112,14 +115,14 @@ private Settings Load()
112115
Directory.CreateDirectory(dir);
113116
}
114117

115-
if (!File.Exists(dir + "\\settings.json"))
118+
if (!File.Exists(dir + Path.DirectorySeparatorChar + "settings.json"))
116119
{
117120
return LoadOrCreateNew(null);
118121
}
119122

120123
try
121124
{
122-
FileInfo fileInfo = new FileInfo(dir + "\\settings.json");
125+
FileInfo fileInfo = new FileInfo(dir + Path.DirectorySeparatorChar + "settings.json");
123126
return LoadOrCreateNew(fileInfo);
124127
}
125128
catch (Exception e)
@@ -298,7 +301,7 @@ private void Save(Settings settings, SettingsFlags flags)
298301
Directory.CreateDirectory(dir);
299302
}
300303

301-
FileInfo fileInfo = new FileInfo(dir + "\\settings.json");
304+
FileInfo fileInfo = new FileInfo(dir + Path.DirectorySeparatorChar + "settings.json");
302305
Save(fileInfo, settings);
303306
}
304307

src/LogExpert/Config/SessionSaveLocation.cs

+13
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,22 @@ namespace LogExpert.Config
55
[Serializable]
66
public enum SessionSaveLocation
77
{
8+
//Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + Path.DirectorySeparatorChar + "LogExpert"
9+
/// <summary>
10+
/// <see cref="Environment.SpecialFolder.MyDocuments"/>
11+
/// </summary>
812
DocumentsDir,
13+
//same directory as the logfile
914
SameDir,
15+
//uses configured folder to save the session files
16+
/// <summary>
17+
/// <see cref="Preferences.sessionSaveDirectory"/>
18+
/// </summary>
1019
OwnDir,
20+
/// <summary>
21+
/// <see cref="System.Windows.Forms.Application.StartupPath"/>
22+
/// </summary>
23+
ApplicationStartupDir,
1124
LoadedSessionFile
1225
}
1326
}

src/LogExpert/Dialogs/SettingsDialog.Designer.cs

+35-19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/LogExpert/Dialogs/SettingsDialog.cs

+30-4
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ private void FillDialog()
103103

104104
checkBoxTimeSpread.Checked = Preferences.showTimeSpread;
105105
checkBoxReverseAlpha.Checked = Preferences.reverseAlpha;
106+
106107
radioButtonTimeView.Checked = Preferences.timeSpreadTimeMode;
107108
radioButtonLineView.Checked = !Preferences.timeSpreadTimeMode;
108109

@@ -123,8 +124,19 @@ private void FillDialog()
123124
case SessionSaveLocation.DocumentsDir:
124125
{
125126
radioButtonsessionSaveDocuments.Checked = true;
127+
break;
126128
}
127-
break;
129+
case SessionSaveLocation.ApplicationStartupDir:
130+
{
131+
radioButtonSessionApplicationStartupDir.Checked = true;
132+
break;
133+
}
134+
}
135+
136+
//overwrite preferences save location in portable mode to always be application startup directory
137+
if (checkBoxPortableMode.Checked)
138+
{
139+
radioButtonSessionApplicationStartupDir.Checked = true;
128140
}
129141

130142
upDownMaximumFilterEntriesDisplayed.Value = Preferences.maximumFilterEntriesDisplayed;
@@ -582,7 +594,7 @@ private void changeFontButton_Click(object sender, EventArgs e)
582594
DisplayFontName();
583595
}
584596

585-
private void okButton_Click(object sender, EventArgs e)
597+
private void OnOkButtonClick(object sender, EventArgs e)
586598
{
587599
Preferences.timestampControl = checkBoxTimestamp.Checked;
588600
Preferences.filterSync = checkBoxSyncFilter.Checked;
@@ -627,6 +639,10 @@ private void okButton_Click(object sender, EventArgs e)
627639
{
628640
Preferences.saveLocation = SessionSaveLocation.OwnDir;
629641
}
642+
else if (radioButtonSessionApplicationStartupDir.Checked)
643+
{
644+
Preferences.saveLocation = SessionSaveLocation.ApplicationStartupDir;
645+
}
630646
else
631647
{
632648
Preferences.saveLocation = SessionSaveLocation.SameDir;
@@ -775,15 +791,25 @@ private void OnPortableModeCheckedChanged(object sender, EventArgs e)
775791
{
776792
case CheckState.Checked when !File.Exists(ConfigManager.PortableMode):
777793
{
778-
File.Create(ConfigManager.PortableMode);
779-
break;
794+
using (File.Create(ConfigManager.PortableMode))
795+
break;
780796
}
781797
case CheckState.Unchecked when File.Exists(ConfigManager.PortableMode):
782798
{
783799
File.Delete(ConfigManager.PortableMode);
784800
break;
785801
}
786802
}
803+
804+
switch (checkBoxPortableMode.CheckState)
805+
{
806+
case CheckState.Unchecked:
807+
checkBoxPortableMode.Text = @"Activate Portable Mode";
808+
break;
809+
case CheckState.Checked:
810+
checkBoxPortableMode.Text = @"Deactivate Portable Mode";
811+
break;
812+
}
787813
}
788814
catch (Exception exception)
789815
{

src/LogExpert/Dialogs/SettingsDialog.resx

+18
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,15 @@
120120
<metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
121121
<value>144, 17</value>
122122
</metadata>
123+
<metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
124+
<value>144, 17</value>
125+
</metadata>
126+
<metadata name="columnFileMask.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
127+
<value>True</value>
128+
</metadata>
129+
<metadata name="columnColumnizer.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
130+
<value>True</value>
131+
</metadata>
123132
<metadata name="columnFileMask.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
124133
<value>True</value>
125134
</metadata>
@@ -132,12 +141,21 @@
132141
<metadata name="columnHighlightGroup.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
133142
<value>True</value>
134143
</metadata>
144+
<metadata name="columnFileName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
145+
<value>True</value>
146+
</metadata>
147+
<metadata name="columnHighlightGroup.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
148+
<value>True</value>
149+
</metadata>
135150
<metadata name="helpProvider.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
136151
<value>17, 17</value>
137152
</metadata>
138153
<data name="labelNoteMultiFile.Text" xml:space="preserve">
139154
<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>
140155
</data>
156+
<metadata name="helpProvider.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
157+
<value>17, 17</value>
158+
</metadata>
141159
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
142160
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
143161
<value>

src/LogExpert/Program.cs

+5
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ private static void Sub_Main(string[] orgArgs)
156156
_logger.Error(errMsg, "IpcClientChannel error, giving up: ");
157157
MessageBox.Show($"Cannot open connection to first instance ({errMsg})", "LogExpert");
158158
}
159+
160+
if (settings.preferences.allowOnlyOneInstance)
161+
{
162+
MessageBox.Show($"Only one instance allowed, uncheck \"View Settings => Allow only 1 Instances\" to start multiple instances!", "Logexpert");
163+
}
159164
}
160165

161166
mutex.Close();

0 commit comments

Comments
 (0)