1 |
#define DISABLE_VERBOSE_LOGGING_FOR_PERFORMANCE_BOOST // when defined will disable verbose logging for performance speed-up |
//#define DISABLE_VERBOSE_LOGGING_FOR_PERFORMANCE_BOOST // when defined will disable verbose logging for performance speed-up |
2 |
|
#define DISALLOW_VERBOSE_LOGGING // when defined will disallow verbose logging for performance reasons |
3 |
using System; |
using System; |
4 |
using System.Collections.Generic; |
using System.Collections.Generic; |
5 |
using System.Linq; |
using System.Linq; |
28 |
} |
} |
29 |
private void init() |
private void init() |
30 |
{ |
{ |
31 |
loggerflags flags = logger.GetLoggingFlags(); |
// loggerflags flags = logger.GetLoggingFlags(); |
32 |
|
|
33 |
#if DISABLE_VERBOSE_LOGGING_FOR_PERFORMANCE_BOOST |
//#if DISABLE_VERBOSE_LOGGING_FOR_PERFORMANCE_BOOST |
34 |
ushort performance_flags = flags.Value; |
// ushort performance_flags = flags.Value; |
35 |
if (flags.HasFlag(loggerflags.VERBOSE_DEBUG)) |
// if (flags.HasFlag(loggerflags.VERBOSE_DEBUG)) |
36 |
{ |
// { |
37 |
performance_flags = (ushort)(performance_flags &~ loggerflags.VERBOSE_DEBUG.Value); |
// performance_flags = (ushort)(performance_flags &~ loggerflags.VERBOSE_DEBUG.Value); |
38 |
} |
// } |
39 |
if (flags.HasFlag(loggerflags.VERBOSE_ERROR)) |
// if (flags.HasFlag(loggerflags.VERBOSE_ERROR)) |
40 |
{ |
// { |
41 |
performance_flags = (ushort)(performance_flags &~ loggerflags.VERBOSE_ERROR.Value); |
// performance_flags = (ushort)(performance_flags &~ loggerflags.VERBOSE_ERROR.Value); |
42 |
} |
// } |
43 |
#endif |
//#endif |
44 |
logger.SetLoggingFlags(performance_flags); |
// logger.SetLoggingFlags(performance_flags); |
45 |
|
|
46 |
List<ProcContainer> proc_list = new List<ProcContainer>(); |
List<ProcContainer> proc_list = new List<ProcContainer>(); |
47 |
foreach (Process proc in Process.GetProcesses()) |
foreach (Process proc in Process.GetProcesses()) |
53 |
string proc_user = ThreadControl.GetProcessOwner(proc.Handle, out isSystem).ToLower(); |
string proc_user = ThreadControl.GetProcessOwner(proc.Handle, out isSystem).ToLower(); |
54 |
if (isSystem) |
if (isSystem) |
55 |
{ |
{ |
56 |
|
#if !DISALLOW_VERBOSE_LOGGING |
57 |
logger.VerboseDebug.WriteLine(" not adding process {0} because it is a system process", proc_name); |
logger.VerboseDebug.WriteLine(" not adding process {0} because it is a system process", proc_name); |
58 |
|
#endif |
59 |
continue; |
continue; |
60 |
} |
} |
61 |
ProcContainer container = null; |
ProcContainer container = null; |
62 |
try |
try |
63 |
{ |
{ |
64 |
container = new ProcContainer(proc); |
container = new ProcContainer(proc); |
65 |
|
#if !DISALLOW_VERBOSE_LOGGING |
66 |
logger.VerboseDebug.WriteLine(" adding process {0} ", proc_name); |
logger.VerboseDebug.WriteLine(" adding process {0} ", proc_name); |
67 |
|
#endif |
68 |
proc_list.Add(container); |
proc_list.Add(container); |
69 |
} |
} |
70 |
catch (FileNotFoundException) { } |
catch (FileNotFoundException) { } |
71 |
catch (Exception ex) |
catch (Exception ex) |
72 |
{ |
{ |
73 |
//throw; |
//throw; |
74 |
|
#if !DISALLOW_VERBOSE_LOGGING |
75 |
logger.VerboseError.WriteLine(" not adding process {0} because it thew an exception [{1}]", proc_name, ex.ToString()); |
logger.VerboseError.WriteLine(" not adding process {0} because it thew an exception [{1}]", proc_name, ex.ToString()); |
76 |
|
#endif |
77 |
//continue; |
//continue; |
78 |
} |
} |
79 |
} |
} |
81 |
{ |
{ |
82 |
if (!((uint)ex.ErrorCode == 0x80004005)) |
if (!((uint)ex.ErrorCode == 0x80004005)) |
83 |
{ |
{ |
84 |
|
#if !DISALLOW_VERBOSE_LOGGING |
85 |
logger.VerboseError.WriteLine(" not adding process {0} because it thew an exception [{1}]", proc_name, ex.ToString()); |
logger.VerboseError.WriteLine(" not adding process {0} because it thew an exception [{1}]", proc_name, ex.ToString()); |
86 |
|
#endif |
87 |
} |
} |
88 |
//continue; |
//continue; |
89 |
} |
} |
90 |
catch (Exception ex) |
catch (Exception ex) |
91 |
{ |
{ |
92 |
|
#if !DISALLOW_VERBOSE_LOGGING |
93 |
logger.VerboseError.WriteLine(" not adding process {0} because it thew an exception [{1}]", proc_name, ex.ToString()); |
logger.VerboseError.WriteLine(" not adding process {0} because it thew an exception [{1}]", proc_name, ex.ToString()); |
94 |
|
#endif |
95 |
//continue; |
//continue; |
96 |
} |
} |
97 |
} |
} |
99 |
Predicate<ProcContainer> predicate = new Predicate<ProcContainer>(IsNotValidProcess); |
Predicate<ProcContainer> predicate = new Predicate<ProcContainer>(IsNotValidProcess); |
100 |
proc_list.RemoveAll(predicate); |
proc_list.RemoveAll(predicate); |
101 |
ValidProcessesForPlugin = proc_list; |
ValidProcessesForPlugin = proc_list; |
102 |
logger.SetLoggingFlags(flags); // reset flags |
//logger.SetLoggingFlags(flags); // reset flags |
103 |
} |
} |
104 |
|
|
105 |
protected abstract bool IsNotValidProcess(ProcContainer p); |
protected abstract bool IsNotValidProcess(ProcContainer p); |