Skip to content
This repository was archived by the owner on Apr 7, 2025. It is now read-only.

Commit da6acc3

Browse files
authored
v1.1 Patch 1 (#6)
* Patch 1 v1.1 Changelog for the v1.1.1: - Fixed #3 - Fixed #4 - Fixed #5 - Created a usefull workflow for adding paramaters to fpprocess. - Some minor changes, typos solved, and renames. - Metadata updated.
1 parent f8157bb commit da6acc3

File tree

4 files changed

+119
-57
lines changed

4 files changed

+119
-57
lines changed

Program.cs

Lines changed: 93 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,38 @@
1-
using System.Diagnostics;
1+
using System.Diagnostics;
2+
3+
const string NO_COLOR = "--no-color";
4+
const string INTERVAL = "-i";
5+
const string HELP = "-h";
26

37
bool running = true;
48
bool isColorOutput = true;
59
bool isIntervalMode = false;
6-
Stopwatch stopWatch = new Stopwatch();
710
int interval = 1500;
11+
int paramIndex = 0;
12+
var usedParameters = new List<string>();
13+
var availableParameters = new[] { new Parameter { parameter=HELP , execution=HelpParameter },
14+
new Parameter { parameter=INTERVAL, execution=IntervalParameter },
15+
new Parameter { parameter=NO_COLOR, execution=NoColorParameter } };
816

917
void StopRunning(object? sender, ConsoleCancelEventArgs args) => running = false;
1018

1119
Console.CancelKeyPress += StopRunning;
1220

13-
if (args.Length > 0 && args.Contains("--no-color"))
14-
{
15-
isColorOutput = false;
16-
args = args.Except(new[] { "--no-color" }).ToArray();
17-
}
21+
ProcessParameters();
1822

19-
if (args.Length > 0 && args.Contains("-i"))
23+
if (isIntervalMode)
2024
{
21-
var temp = string.Empty;
22-
for (int i = 0; i < args.Length; i++)
23-
if (args[i] == "-i")
24-
{
25-
try
26-
{
27-
temp = args[i + 1];
28-
interval = Convert.ToInt32(temp);
29-
break;
30-
}
31-
catch
32-
{
33-
return;
34-
}
35-
}
36-
isIntervalMode = true;
37-
args = args.Except(new[] { "-i" , temp}).ToArray();
25+
Stopwatch stopWatch = new Stopwatch();
26+
stopWatch.Start();
27+
do
28+
{
29+
if (stopWatch.ElapsedMilliseconds < interval) continue;
30+
stopWatch.Restart();
31+
MainAlgorithm();
32+
} while (running);
3833
}
39-
40-
stopWatch.Start();
41-
do
42-
{
43-
if (stopWatch.ElapsedMilliseconds < interval && isIntervalMode) continue;
44-
stopWatch.Restart();
34+
else
4535
MainAlgorithm();
46-
} while (isIntervalMode);
47-
stopWatch.Stop();
4836

4937
void MainAlgorithm()
5038
{
@@ -125,6 +113,62 @@ void MainAlgorithm()
125113
}
126114
}
127115
}
116+
void ProcessParameters()
117+
{
118+
if (args.Length <= 0) return;
119+
for (int i = 0; i < args.Length; i++)
120+
{
121+
if(args[i][0] != '-') continue;
122+
foreach (var param in availableParameters)
123+
{
124+
if (param.parameter != args[i]) continue;
125+
paramIndex = i;
126+
param.execution();
127+
paramIndex = 0;
128+
break;
129+
}
130+
}
131+
args = args.Except(usedParameters).ToArray();
132+
usedParameters.Clear();
133+
}
134+
135+
#region PARAMETERS
136+
void NoColorParameter()
137+
{
138+
isColorOutput = false;
139+
usedParameters.Add(NO_COLOR);
140+
}
141+
142+
void IntervalParameter()
143+
{
144+
isIntervalMode = true;
145+
try
146+
{
147+
var temp = args[paramIndex + 1];
148+
interval = Convert.ToInt32(temp);
149+
usedParameters.AddRange(new[] { args[paramIndex], temp });
150+
}
151+
catch
152+
{
153+
usedParameters.Add(args[paramIndex]);
154+
}
155+
}
156+
157+
void HelpParameter()
158+
{
159+
running = false;
160+
try
161+
{
162+
var temp = args[paramIndex + 1];
163+
//Do something with temp.
164+
usedParameters.AddRange(new[] { args[paramIndex], temp });
165+
}
166+
catch
167+
{
168+
usedParameters.Add(args[paramIndex]);
169+
}
170+
}
171+
#endregion PARAMETERS
128172

129173
static void WriteLineColor(string content, ConsoleColor color, params ConsoleColor[] background)
130174
{
@@ -145,7 +189,7 @@ static string FindIndexedProcessName(int pId)
145189
for (var i = 0; i < processesByName.Length; i++)
146190
{
147191
processIdName = i == 0 ? processName : $"{processName}#{i}";
148-
var processId = new PerformanceCounter("Process", "ID Process", processIdName);
192+
using var processId = new PerformanceCounter("Process", "ID Process", processIdName);
149193
if ((int)processId.NextValue() == pId) return processIdName;
150194
}
151195

@@ -156,20 +200,19 @@ static string FindIndexedProcessName(int pId)
156200
return string.Empty;
157201
}
158202
}
159-
160-
static Process? FindPidFromIndexedProcessName(string indexedProcessName)
203+
static Process? FindCreatingProcessID(string indexedProcessName)
161204
{
162205
try
163206
{
164-
return Process.GetProcessById((int)new PerformanceCounter("Process", "Creating Process ID", indexedProcessName).NextValue());
207+
using var processParent = new PerformanceCounter("Process", "Creating Process ID", indexedProcessName);
208+
return Process.GetProcessById((int)processParent.NextValue());
165209
}
166210
catch
167211
{
168212
return null;
169213
}
170214
}
171-
172-
static Process? GetParent(Process process) => FindPidFromIndexedProcessName(FindIndexedProcessName(process.Id));
215+
static Process? GetParent(Process process) => FindCreatingProcessID(FindIndexedProcessName(process.Id));
173216

174217
static void DisplayProcessInfo(string tab, Process p, Process? parent)
175218
{
@@ -179,12 +222,17 @@ static void DisplayProcessInfo(string tab, Process p, Process? parent)
179222
Console.Write($"{tab}Module Name | "); WriteLineColor($"{p.MainModule?.ModuleName}", ConsoleColor.DarkMagenta);
180223
Console.Write($"{tab}Module Path | "); WriteLineColor($"{p.MainModule?.FileName.Replace(p.MainModule?.ModuleName ?? string.Empty, string.Empty)}", ConsoleColor.DarkMagenta);
181224
}
182-
183225
static void DisplayProcessInfoWhite(string tab, Process p, Process? parent)
184226
{
185-
Console.WriteLine($"{tab}Parent PID | {parent?.Id}");
186-
Console.WriteLine($"{tab}Name | {p.ProcessName}");
187-
Console.WriteLine($"{tab}Working Set (x64) | {(float)(p.WorkingSet64 * 0.0000001)} mb");
188-
Console.WriteLine($"{tab}Module Name | {p.MainModule?.ModuleName}");
189-
Console.WriteLine($"{tab}Module Path | {p.MainModule?.FileName.Replace(p.MainModule?.ModuleName ?? string.Empty, string.Empty)}");
227+
Console.Write($"{tab}Parent PID | "); Console.WriteLine($"{parent?.Id}");
228+
Console.Write($"{tab}Name | "); Console.WriteLine($"{p.ProcessName}");
229+
Console.Write($"{tab}Working Set (x64) | "); Console.WriteLine($"{(float)(p.WorkingSet64 * 0.0000001)} mb");
230+
Console.Write($"{tab}Module Name | "); Console.WriteLine($"{p.MainModule?.ModuleName}");
231+
Console.Write($"{tab}Module Path | "); Console.WriteLine($"{p.MainModule?.FileName.Replace(p.MainModule?.ModuleName ?? string.Empty, string.Empty)}");
232+
}
233+
234+
struct Parameter
235+
{
236+
public string parameter;
237+
public Action execution;
190238
}

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# fpprocess v1.1.0 [![CodeQL](https://github.com/Papishushi/fpprocess/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/Papishushi/fpprocess/actions/workflows/codeql-analysis.yml) [![.NET](https://github.com/Papishushi/fpprocess/actions/workflows/dotnet.yml/badge.svg)](https://github.com/Papishushi/fpprocess/actions/workflows/dotnet.yml)
1+
# fpprocess v1.1.1 [![CodeQL](https://github.com/Papishushi/fpprocess/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/Papishushi/fpprocess/actions/workflows/codeql-analysis.yml) [![.NET](https://github.com/Papishushi/fpprocess/actions/workflows/dotnet.yml/badge.svg)](https://github.com/Papishushi/fpprocess/actions/workflows/dotnet.yml)
22
Terminal tool targeted for Windows, its purpose is to find the full list of parent processes based on supplied PIDs or process names by stdin.
33
# Usage
44
* ### Get process info from PID '4'.
@@ -30,21 +30,21 @@ Terminal tool targeted for Windows, its purpose is to find the full list of pare
3030
* Use it on your terminal!
3131
## NuGet Package
3232
* ### Package Manager
33-
Install-Package fpprocess -Version 1.1.0
33+
Install-Package fpprocess -Version 1.1.1
3434
* ### .NET CLI
35-
dotnet add package fpprocess --version 1.1.0
35+
dotnet add package fpprocess --version 1.1.1
3636
* ### PackageReference (XML Node)
37-
<PackageReference Include="fpprocess" Version="1.1.0" />
37+
<PackageReference Include="fpprocess" Version="1.1.1" />
3838
* ### Paket CLI
39-
paket add fpprocess --version 1.1.0
39+
paket add fpprocess --version 1.1.1
4040
* ### Script & Interactive
41-
#r "nuget: fpprocess, 1.1.0"
41+
#r "nuget: fpprocess, 1.1.1"
4242
* ### Cake
4343
// Install fpprocess as a Cake Addin
44-
#addin nuget:?package=fpprocess&version=1.1.0
44+
#addin nuget:?package=fpprocess&version=1.1.1
4545

4646
// Install fpprocess as a Cake Tool
47-
#tool nuget:?package=fpprocess&version=1.1.0
47+
#tool nuget:?package=fpprocess&version=1.1.1
4848
* ### Github Package
4949
pip install git+git://github.com/Papishushi/fpprocess.git
5050
## DIY Compilation

app.manifest

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
3-
<assemblyIdentity version="1.1.0.0" name="fpprocess.app"/>
3+
<assemblyIdentity version="1.1.1.0" name="fpprocess.app"/>
44
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
55
<security>
66
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
7+
78
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
9+
810
</requestedPrivileges>
911
</security>
1012
</trustInfo>
1113

1214
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
1315
<application>
16+
17+
<!-- Windows Vista -->
18+
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->
19+
1420
<!-- Windows 7 -->
1521
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->
1622

fpprocess.csproj

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,17 @@
4040

4141
<PropertyGroup>
4242
<PackageLicenseFile>LICENSE</PackageLicenseFile>
43-
<Version>1.1.0</Version>
43+
<Version>1.1.1</Version>
4444
<PackageTags>windows ; cli; terminal; parent; elevated-rights; processmonitoring; dotnet6; processparent</PackageTags>
45-
<PackageReleaseNotes>* Better looking colors! * A lot of bug fixing, yeah! * Added support for process names, instead of PIDs. (You can mix inputs) * Added support for parameters. * Added new functionality for changing background color to WriteLineColor method. * Color output mode switch with --no-color parameter * Now you can run the script at an interval with -i parameter</PackageReleaseNotes>
45+
<PackageReleaseNotes>
46+
Changelog for the v1.1.1:
47+
- Fixed #3
48+
- Fixed #4
49+
- Fixed #5
50+
- Created a usefull workflow for adding paramaters to fpprocess.
51+
- Some minor changes, typos solved, and renames.
52+
- Metadata updated.
53+
</PackageReleaseNotes>
4654
</PropertyGroup>
4755

4856
<ItemGroup>

0 commit comments

Comments
 (0)