Skip to content

Commit 40c9a67

Browse files
committed
* Clean all processes when using drag and drop
* Minor settings logic fix
1 parent 3a49a6d commit 40c9a67

File tree

4 files changed

+31
-13
lines changed

4 files changed

+31
-13
lines changed

MemPlus/Business/LOG/LogController.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,20 @@ internal void SetSaveToFile(bool saveToFile)
186186
DisposeFileResources();
187187
}
188188

189-
if (saveToFile)
189+
if (_logPath != null && saveToFile && _logPath.Length > 0)
190190
{
191191
// Generate a new FileStream that allows other handles to access the file
192192
_fileStream = new FileStream(_logPath,
193193
FileMode.Append,
194194
FileAccess.Write,
195195
FileShare.ReadWrite);
196196
_streamWriter = new StreamWriter(_fileStream) {AutoFlush = true};
197+
_saveToFile = true;
198+
}
199+
else
200+
{
201+
_saveToFile = false;
197202
}
198-
199-
_saveToFile = saveToFile;
200203
}
201204

202205
/// <summary>
@@ -205,6 +208,7 @@ internal void SetSaveToFile(bool saveToFile)
205208
/// <param name="saveDirectory">The directory to which logs can be saved</param>
206209
internal void SetSaveDirectory(string saveDirectory)
207210
{
211+
if (string.IsNullOrEmpty(saveDirectory)) throw new ArgumentNullException(nameof(saveDirectory));
208212
if (!Directory.Exists(saveDirectory)) throw new IOException("The selected log directory (" + saveDirectory + ") does not exist!");
209213

210214
// Format the directory string

MemPlus/Business/UTILS/Utils.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,20 +286,21 @@ internal static bool AutoStartUp()
286286
/// </summary>
287287
/// <param name="file">The file for which the Process object should be retrieved</param>
288288
/// <returns></returns>
289-
internal static Process GetProcessForFile(string file)
289+
internal static List<Process> GetProcessesForFile(string file)
290290
{
291+
List<Process> processes = new List<Process>();
291292
foreach (Process p in Process.GetProcesses())
292293
{
293294
try
294295
{
295-
if (p.MainModule.FileName == file) return p;
296+
if (p.MainModule.FileName == file) processes.Add(p);
296297
}
297298
catch (Exception)
298299
{
299300
// ignored
300301
}
301302
}
302-
return null;
303+
return processes;
303304
}
304305
}
305306
}

MemPlus/Views/Windows/MainWindow.xaml.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.ComponentModel;
34
using System.Diagnostics;
45
using System.Reflection;
@@ -57,6 +58,15 @@ public MainWindow()
5758
{
5859
try
5960
{
61+
if (Properties.Settings.Default.SaveLogsToFile)
62+
{
63+
if (string.IsNullOrEmpty(Properties.Settings.Default.LogPath))
64+
{
65+
Properties.Settings.Default.SaveLogsToFile = false;
66+
Properties.Settings.Default.Save();
67+
}
68+
}
69+
6070
_logController = new LogController
6171
(
6272
Properties.Settings.Default.LoggingEnabled,
@@ -1079,18 +1089,20 @@ private void MainWindow_Drop(object sender, System.Windows.DragEventArgs e)
10791089
if (!e.Data.GetDataPresent(DataFormats.FileDrop)) return;
10801090
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
10811091
if (files == null) return;
1082-
if (!System.IO.File.Exists(files[0])) return;
10831092

10841093
foreach (string s in files)
10851094
{
1086-
Process process = Utils.GetProcessForFile(s);
1095+
if (!System.IO.File.Exists(s)) continue;
1096+
List<Process> processes = Utils.GetProcessesForFile(s);
10871097
try
10881098
{
1089-
if (process == null) continue;
1090-
1091-
_logController.AddLog(new RamLog("Emptying working set for process: " + process.ProcessName));
1092-
NativeMethods.EmptyWorkingSet(process.Handle);
1093-
_logController.AddLog(new RamLog("Successfully emptied working set for process " + process.ProcessName));
1099+
if (processes.Count == 0) return;
1100+
foreach (Process p in processes)
1101+
{
1102+
_logController.AddLog(new RamLog("Emptying working set for process: " + p.ProcessName));
1103+
NativeMethods.EmptyWorkingSet(p.Handle);
1104+
_logController.AddLog(new RamLog("Successfully emptied working set for process " + p.ProcessName));
1105+
}
10941106
}
10951107
catch (Exception ex)
10961108
{

MemPlus/Views/Windows/SettingsWindow.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ private void ResetSettings()
345345

346346
_logController.SetAutoClear(Properties.Settings.Default.LogClearAuto);
347347
_logController.SetAutoClearInterval(Properties.Settings.Default.LogClearInterval);
348+
_logController.SetSaveDirectory(Properties.Settings.Default.LogPath);
348349
_logController.SetSaveToFile(Properties.Settings.Default.SaveLogsToFile);
349350

350351
ChangeVisualStyle();

0 commit comments

Comments
 (0)