diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4855efd --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +net = dotnet + +publish: + $(net) publish -r linux-x64 -p:PublishSingleFile=true -c Release --output ./out/publish + +run: + $(net) run + +build: + $(net) publish -r linux-x64 -p:PublishSingleFile=true -c Debug --output ./out/build \ No newline at end of file diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..f838ca3 --- /dev/null +++ b/Program.cs @@ -0,0 +1,62 @@ +// System libraries +using System; +using System.Threading; +using System.Diagnostics; +using devunity.components; + +namespace devunity +{ + class Program + { + // Definitions + static Process[] processlist = Process.GetProcesses(); + + // Main function + static int Main(string[] args) + { + // Clear console + Console.Clear(); + + // Save current color + int origColor = (int) Console.ForegroundColor; + + // Print app info + Console.ForegroundColor = ConsoleColor.DarkMagenta; + Console.WriteLine("Devunity - by Rudra Saraswat"); + Console.WriteLine("============================"); + Console.WriteLine(); + Console.ForegroundColor = (ConsoleColor) origColor; + + // Parse arguments + if (!(args.Length == 0)) + foreach (string arg in args) { + switch (arg) { + case "-pm": case "--process-monitor": + UnityProcessMonitor.ProcessMonitor(); + break; + + case "-rb": case "--report-bug": + UnityBugReporter.BugReporter(); + break; + + case "-ru": case "--restart-unity": + UnityRestart.RestartUnity(); + break; + + case "-gp": case "--get-process-status": + UnityProcessStatus.ProcessStatus(); + break; + + default: + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("ERROR: NO SUCH COMMAND"); + return 127; + } + } + else + 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"); + + return 0; + } + } +} diff --git a/components/UnityBugReporter.cs b/components/UnityBugReporter.cs new file mode 100644 index 0000000..35bea53 --- /dev/null +++ b/components/UnityBugReporter.cs @@ -0,0 +1,48 @@ +// System libraries +using System; +using System.Diagnostics; +using System.IO; + +namespace devunity.components +{ + public class UnityBugReporter + { + // Main function + public static void BugReporter() + { + try { + string fileToWrite = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds().ToString() + ".br"; + + Console.WriteLine("Writing to file " + fileToWrite); + + using (StreamWriter file = new StreamWriter(fileToWrite, false)) + { + file.WriteLine("UNITY PROCESSES -->"); + Process[] processlist = Process.GetProcesses(); + foreach (Process process in processlist) + { + if (process.ProcessName.Contains("unity")) + { + file.WriteLine("Process Name: {0}; Memory usage: {1}", process.ProcessName, process.WorkingSet64); + } + } + file.WriteLine(); + Console.WriteLine("Please type the bug details:"); + string bugDetails = Console.ReadLine(); + file.WriteLine("BUG DETAILS -->"); + file.WriteLine(bugDetails); + file.WriteLine(); + Console.WriteLine("Please enter the affected Unity7 program (if you do not know, please type 'do not know'):"); + string affectedProgram = Console.ReadLine(); + file.WriteLine("AFFECTED PROGRAM -->"); + file.WriteLine(affectedProgram); + Console.WriteLine("Please send the file (or its contents): " + fileToWrite + " when reporting the bug."); + } + } catch { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("ERROR: FAILED"); + Environment.Exit(-1); + } + } + } +} diff --git a/components/UnityProcessMonitor.cs b/components/UnityProcessMonitor.cs new file mode 100644 index 0000000..41a528a --- /dev/null +++ b/components/UnityProcessMonitor.cs @@ -0,0 +1,66 @@ +// System libraries +using System; +using System.Threading; +using System.Diagnostics; +using devunity.includes; + +namespace devunity.components +{ + public class UnityProcessMonitor + { + // Definitions + static Process[] processlist = Process.GetProcesses(); + + // Main function + public static void ProcessMonitor() + { + // Clear console + Console.Clear(); + // Print info + printInfo(); + // Start printing debug info + for (;;) + { + printProcesses(); + Thread.Sleep(1000); + Console.Clear(); + updateProcesses(); + printInfo(); + } + } + + // Print info + static void printInfo() + { + // Save current color + int origColor = (int) Console.ForegroundColor; + // Print app info + Console.ForegroundColor = ConsoleColor.DarkMagenta; + Console.WriteLine("Devunity - by Rudra Saraswat"); + Console.WriteLine("============================"); + Console.WriteLine(); + Console.ForegroundColor = (ConsoleColor) origColor; + } + + // Print processes + static void printProcesses() + { + Table.PrintLine(); + Table.PrintRow("Process", "ID", "Time Started"); + Table.PrintLine(); + foreach(Process process in processlist) + { + if (process.ProcessName.Contains("unity")) + { + Table.PrintRow(process.ProcessName, process.Id + "", process.StartTime.ToString("dd/MM/yyyy HH:mm:ss")); + Table.PrintLine(); + } + } + } + + static void updateProcesses() + { + processlist = Process.GetProcesses(); + } + } +} diff --git a/components/UnityProcessStatus.cs b/components/UnityProcessStatus.cs new file mode 100644 index 0000000..f73d8ce --- /dev/null +++ b/components/UnityProcessStatus.cs @@ -0,0 +1,44 @@ +// System libraries +using System; +using System.Diagnostics; + +namespace devunity.components +{ + public class UnityProcessStatus + { + // Main function + public static void ProcessStatus() + { + Console.Write("Process to get status of: "); + string pName = Console.ReadLine(); + if (pName.Contains("unity")) + { + try + { + Process[] pArray = Process.GetProcessesByName(pName); + foreach (Process p in pArray) + { + Console.WriteLine($"{pName}:"); + Console.WriteLine(); + Console.WriteLine($" Process ID : {p.Id}"); + Console.WriteLine($" Physical memory usage : {p.WorkingSet64}"); + Console.WriteLine($" User processor time : {p.UserProcessorTime}"); + Console.WriteLine($" Privileged processor time : {p.PrivilegedProcessorTime}"); + Console.WriteLine($" Total processor time : {p.TotalProcessorTime}"); + Console.WriteLine(" -----------------------------------------------------"); + Console.WriteLine(); + } + + } catch { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("ERROR: NO SUCH PROCESS"); + Environment.Exit(127); + } + } else { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("ERROR: NOT A UNITY PROCESS"); + Environment.Exit(-1); + } + } + } +} diff --git a/components/UnityRestart.cs b/components/UnityRestart.cs new file mode 100644 index 0000000..435f598 --- /dev/null +++ b/components/UnityRestart.cs @@ -0,0 +1,26 @@ +// System libraries +using System; +using System.Diagnostics; + +namespace devunity.components +{ + public class UnityRestart + { + // Main function + public static void RestartUnity() + { + 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."); + Console.ReadLine(); + + new Process() + { + StartInfo = new ProcessStartInfo + { + FileName = "unity", + UseShellExecute = false, + CreateNoWindow = true, + } + }.Start(); + } + } +} diff --git a/devunity.csproj b/devunity.csproj new file mode 100644 index 0000000..47b5695 --- /dev/null +++ b/devunity.csproj @@ -0,0 +1,19 @@ + + + + Exe + netcoreapp3.1 + + + + amd64 + devunity + devunity-0.1.0 + 0.1.0 + Rudra Saraswat + Unity7 Maintainers + Devunity + A debugging tool for Unity7 + + + diff --git a/includes/Table.cs b/includes/Table.cs new file mode 100644 index 0000000..bd31e5b --- /dev/null +++ b/includes/Table.cs @@ -0,0 +1,41 @@ +using System; + +namespace devunity.includes +{ + public class Table + { + public static int tableWidth = 90; + + public static void PrintLine() + { + Console.WriteLine(new string('-', tableWidth)); + } + + public static void PrintRow(params string[] columns) + { + int width = (tableWidth - columns.Length) / columns.Length; + string row = "|"; + + foreach (string column in columns) + { + row += AlignCentre(column, width) + "|"; + } + + Console.WriteLine(row); + } + + public static string AlignCentre(string text, int width) + { + text = text.Length > width ? text.Substring(0, width - 3) + "..." : text; + + if (string.IsNullOrEmpty(text)) + { + return new string(' ', width); + } + else + { + return text.PadRight(width - (width - text.Length) / 2).PadLeft(width); + } + } + } +} \ No newline at end of file