Skip to content

Commit 98c2f11

Browse files
authored
Upload all files
1 parent ebe0a8e commit 98c2f11

File tree

8 files changed

+316
-0
lines changed

8 files changed

+316
-0
lines changed

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
net = dotnet
2+
3+
publish:
4+
$(net) publish -r linux-x64 -p:PublishSingleFile=true -c Release --output ./out/publish
5+
6+
run:
7+
$(net) run
8+
9+
build:
10+
$(net) publish -r linux-x64 -p:PublishSingleFile=true -c Debug --output ./out/build

Program.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// System libraries
2+
using System;
3+
using System.Threading;
4+
using System.Diagnostics;
5+
using devunity.components;
6+
7+
namespace devunity
8+
{
9+
class Program
10+
{
11+
// Definitions
12+
static Process[] processlist = Process.GetProcesses();
13+
14+
// Main function
15+
static int Main(string[] args)
16+
{
17+
// Clear console
18+
Console.Clear();
19+
20+
// Save current color
21+
int origColor = (int) Console.ForegroundColor;
22+
23+
// Print app info
24+
Console.ForegroundColor = ConsoleColor.DarkMagenta;
25+
Console.WriteLine("Devunity - by Rudra Saraswat");
26+
Console.WriteLine("============================");
27+
Console.WriteLine();
28+
Console.ForegroundColor = (ConsoleColor) origColor;
29+
30+
// Parse arguments
31+
if (!(args.Length == 0))
32+
foreach (string arg in args) {
33+
switch (arg) {
34+
case "-pm": case "--process-monitor":
35+
UnityProcessMonitor.ProcessMonitor();
36+
break;
37+
38+
case "-rb": case "--report-bug":
39+
UnityBugReporter.BugReporter();
40+
break;
41+
42+
case "-ru": case "--restart-unity":
43+
UnityRestart.RestartUnity();
44+
break;
45+
46+
case "-gp": case "--get-process-status":
47+
UnityProcessStatus.ProcessStatus();
48+
break;
49+
50+
default:
51+
Console.ForegroundColor = ConsoleColor.Red;
52+
Console.WriteLine("ERROR: NO SUCH COMMAND");
53+
return 127;
54+
}
55+
}
56+
else
57+
Console.WriteLine("Devunity is a program for debugging Unity7.\n\nSYNTAX:\n\n\tdevunity ARGUMENT\n\nwhere ARGUMENT stands for one of the following:\n\n\t-pm | --process-monitor: Unity Process Monitor\n\n\t-rb | --report-bug: Unity Bug Report Generator\n\n\t-ru | --restart-unity: Restart Unity\n\n\t-gp | --get-process-status: Detailed Process Status");
58+
59+
return 0;
60+
}
61+
}
62+
}

components/UnityBugReporter.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// System libraries
2+
using System;
3+
using System.Diagnostics;
4+
using System.IO;
5+
6+
namespace devunity.components
7+
{
8+
public class UnityBugReporter
9+
{
10+
// Main function
11+
public static void BugReporter()
12+
{
13+
try {
14+
string fileToWrite = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds().ToString() + ".br";
15+
16+
Console.WriteLine("Writing to file " + fileToWrite);
17+
18+
using (StreamWriter file = new StreamWriter(fileToWrite, false))
19+
{
20+
file.WriteLine("UNITY PROCESSES -->");
21+
Process[] processlist = Process.GetProcesses();
22+
foreach (Process process in processlist)
23+
{
24+
if (process.ProcessName.Contains("unity"))
25+
{
26+
file.WriteLine("Process Name: {0}; Memory usage: {1}", process.ProcessName, process.WorkingSet64);
27+
}
28+
}
29+
file.WriteLine();
30+
Console.WriteLine("Please type the bug details:");
31+
string bugDetails = Console.ReadLine();
32+
file.WriteLine("BUG DETAILS -->");
33+
file.WriteLine(bugDetails);
34+
file.WriteLine();
35+
Console.WriteLine("Please enter the affected Unity7 program (if you do not know, please type 'do not know'):");
36+
string affectedProgram = Console.ReadLine();
37+
file.WriteLine("AFFECTED PROGRAM -->");
38+
file.WriteLine(affectedProgram);
39+
Console.WriteLine("Please send the file (or its contents): " + fileToWrite + " when reporting the bug.");
40+
}
41+
} catch {
42+
Console.ForegroundColor = ConsoleColor.Red;
43+
Console.WriteLine("ERROR: FAILED");
44+
Environment.Exit(-1);
45+
}
46+
}
47+
}
48+
}

components/UnityProcessMonitor.cs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// System libraries
2+
using System;
3+
using System.Threading;
4+
using System.Diagnostics;
5+
using devunity.includes;
6+
7+
namespace devunity.components
8+
{
9+
public class UnityProcessMonitor
10+
{
11+
// Definitions
12+
static Process[] processlist = Process.GetProcesses();
13+
14+
// Main function
15+
public static void ProcessMonitor()
16+
{
17+
// Clear console
18+
Console.Clear();
19+
// Print info
20+
printInfo();
21+
// Start printing debug info
22+
for (;;)
23+
{
24+
printProcesses();
25+
Thread.Sleep(1000);
26+
Console.Clear();
27+
updateProcesses();
28+
printInfo();
29+
}
30+
}
31+
32+
// Print info
33+
static void printInfo()
34+
{
35+
// Save current color
36+
int origColor = (int) Console.ForegroundColor;
37+
// Print app info
38+
Console.ForegroundColor = ConsoleColor.DarkMagenta;
39+
Console.WriteLine("Devunity - by Rudra Saraswat");
40+
Console.WriteLine("============================");
41+
Console.WriteLine();
42+
Console.ForegroundColor = (ConsoleColor) origColor;
43+
}
44+
45+
// Print processes
46+
static void printProcesses()
47+
{
48+
Table.PrintLine();
49+
Table.PrintRow("Process", "ID", "Time Started");
50+
Table.PrintLine();
51+
foreach(Process process in processlist)
52+
{
53+
if (process.ProcessName.Contains("unity"))
54+
{
55+
Table.PrintRow(process.ProcessName, process.Id + "", process.StartTime.ToString("dd/MM/yyyy HH:mm:ss"));
56+
Table.PrintLine();
57+
}
58+
}
59+
}
60+
61+
static void updateProcesses()
62+
{
63+
processlist = Process.GetProcesses();
64+
}
65+
}
66+
}

components/UnityProcessStatus.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// System libraries
2+
using System;
3+
using System.Diagnostics;
4+
5+
namespace devunity.components
6+
{
7+
public class UnityProcessStatus
8+
{
9+
// Main function
10+
public static void ProcessStatus()
11+
{
12+
Console.Write("Process to get status of: ");
13+
string pName = Console.ReadLine();
14+
if (pName.Contains("unity"))
15+
{
16+
try
17+
{
18+
Process[] pArray = Process.GetProcessesByName(pName);
19+
foreach (Process p in pArray)
20+
{
21+
Console.WriteLine($"{pName}:");
22+
Console.WriteLine();
23+
Console.WriteLine($" Process ID : {p.Id}");
24+
Console.WriteLine($" Physical memory usage : {p.WorkingSet64}");
25+
Console.WriteLine($" User processor time : {p.UserProcessorTime}");
26+
Console.WriteLine($" Privileged processor time : {p.PrivilegedProcessorTime}");
27+
Console.WriteLine($" Total processor time : {p.TotalProcessorTime}");
28+
Console.WriteLine(" -----------------------------------------------------");
29+
Console.WriteLine();
30+
}
31+
32+
} catch {
33+
Console.ForegroundColor = ConsoleColor.Red;
34+
Console.WriteLine("ERROR: NO SUCH PROCESS");
35+
Environment.Exit(127);
36+
}
37+
} else {
38+
Console.ForegroundColor = ConsoleColor.Red;
39+
Console.WriteLine("ERROR: NOT A UNITY PROCESS");
40+
Environment.Exit(-1);
41+
}
42+
}
43+
}
44+
}

components/UnityRestart.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// System libraries
2+
using System;
3+
using System.Diagnostics;
4+
5+
namespace devunity.components
6+
{
7+
public class UnityRestart
8+
{
9+
// Main function
10+
public static void RestartUnity()
11+
{
12+
Console.Write("Are you sure? Some apps might close. In a dual monitor setup, some apps might move to the other display. To proceed, press ENTER, and to cancel, press ^C.");
13+
Console.ReadLine();
14+
15+
new Process()
16+
{
17+
StartInfo = new ProcessStartInfo
18+
{
19+
FileName = "unity",
20+
UseShellExecute = false,
21+
CreateNoWindow = true,
22+
}
23+
}.Start();
24+
}
25+
}
26+
}

devunity.csproj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp3.1</TargetFramework>
6+
</PropertyGroup>
7+
8+
<PropertyGroup>
9+
<DebPackageArchitecture>amd64</DebPackageArchitecture>
10+
<PackagePrefix>devunity</PackagePrefix>
11+
<PackageName>devunity-0.1.0</PackageName>
12+
<Version>0.1.0</Version>
13+
<Authors>Rudra Saraswat</Authors>
14+
<Company>Unity7 Maintainers</Company>
15+
<Product>Devunity</Product>
16+
<Description>A debugging tool for Unity7</Description>
17+
</PropertyGroup>
18+
19+
</Project>

includes/Table.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
3+
namespace devunity.includes
4+
{
5+
public class Table
6+
{
7+
public static int tableWidth = 90;
8+
9+
public static void PrintLine()
10+
{
11+
Console.WriteLine(new string('-', tableWidth));
12+
}
13+
14+
public static void PrintRow(params string[] columns)
15+
{
16+
int width = (tableWidth - columns.Length) / columns.Length;
17+
string row = "|";
18+
19+
foreach (string column in columns)
20+
{
21+
row += AlignCentre(column, width) + "|";
22+
}
23+
24+
Console.WriteLine(row);
25+
}
26+
27+
public static string AlignCentre(string text, int width)
28+
{
29+
text = text.Length > width ? text.Substring(0, width - 3) + "..." : text;
30+
31+
if (string.IsNullOrEmpty(text))
32+
{
33+
return new string(' ', width);
34+
}
35+
else
36+
{
37+
return text.PadRight(width - (width - text.Length) / 2).PadLeft(width);
38+
}
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)