From 979f8bcfeee6f1b5dc76807fd94bda19445cd615 Mon Sep 17 00:00:00 2001 From: Wojciech Figat Date: Mon, 19 Dec 2022 10:10:12 +0100 Subject: [PATCH] Remove `Flax.Stats` project --- Source/Tools/Flax.Stats/App.config | 6 - Source/Tools/Flax.Stats/CodeFrame.cs | 323 --------- Source/Tools/Flax.Stats/CodeFrameNode.cs | 308 -------- Source/Tools/Flax.Stats/Flax.Stats.Build.cs | 36 - Source/Tools/Flax.Stats/Flax.Stats.csproj | 71 -- Source/Tools/Flax.Stats/Form1.Designer.cs | 73 -- Source/Tools/Flax.Stats/Form1.cs | 57 -- Source/Tools/Flax.Stats/Languages.cs | 30 - Source/Tools/Flax.Stats/Program.cs | 190 ----- .../Flax.Stats/Properties/AssemblyInfo.cs | 15 - Source/Tools/Flax.Stats/TaskType.cs | 25 - Source/Tools/Flax.Stats/Tools.cs | 683 ------------------ 12 files changed, 1817 deletions(-) delete mode 100644 Source/Tools/Flax.Stats/App.config delete mode 100644 Source/Tools/Flax.Stats/CodeFrame.cs delete mode 100644 Source/Tools/Flax.Stats/CodeFrameNode.cs delete mode 100644 Source/Tools/Flax.Stats/Flax.Stats.Build.cs delete mode 100644 Source/Tools/Flax.Stats/Flax.Stats.csproj delete mode 100644 Source/Tools/Flax.Stats/Form1.Designer.cs delete mode 100644 Source/Tools/Flax.Stats/Form1.cs delete mode 100644 Source/Tools/Flax.Stats/Languages.cs delete mode 100644 Source/Tools/Flax.Stats/Program.cs delete mode 100644 Source/Tools/Flax.Stats/Properties/AssemblyInfo.cs delete mode 100644 Source/Tools/Flax.Stats/TaskType.cs delete mode 100644 Source/Tools/Flax.Stats/Tools.cs diff --git a/Source/Tools/Flax.Stats/App.config b/Source/Tools/Flax.Stats/App.config deleted file mode 100644 index 8227adb98..000000000 --- a/Source/Tools/Flax.Stats/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/Source/Tools/Flax.Stats/CodeFrame.cs b/Source/Tools/Flax.Stats/CodeFrame.cs deleted file mode 100644 index e35a0a62e..000000000 --- a/Source/Tools/Flax.Stats/CodeFrame.cs +++ /dev/null @@ -1,323 +0,0 @@ -// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved. - -using System; -using System.IO; - -namespace Flax.Stats -{ - /// - /// Represents single Code Frame captured to the file - /// - public sealed class CodeFrame : IDisposable - { - /// - /// Root node for code frames - /// - public CodeFrameNode Root; - - /// - /// Code frame date - /// - public DateTime Date; - - /// - /// Capture code stats in current working directory - /// - /// Directory path to capture - /// Created code frame - public static CodeFrame Capture(string directory) - { - // Create code frame - var frame = new CodeFrame(); - - // Create root node and all children - frame.Root = CodeFrameNode.Capture(new DirectoryInfo(directory)); - - // Save capture time - frame.Date = DateTime.Now; - - // Return result - return frame; - } - - /// - /// Load code frame from the file - /// - /// Path of the file to load - /// Loaded code frame - public static CodeFrame Load(string path) - { - // Create and load - var frame = new CodeFrame(); - using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) - { - frame.load(fs); - } - return frame; - } - - private void load(Stream stream) - { - // Clear state - if (Root != null) - { - Root.Dispose(); - Root = null; - } - - // Header - if (stream.ReadInt() != 1032) - { - throw new FileLoadException("Invalid Code Frame file."); - } - - // Version - int version = stream.ReadInt(); - - // Switch version - switch (version) - { - case 1: - { - // Read root node - Root = loadNode1(stream); - - break; - } - - case 2: - { - // Read date - Date = stream.ReadDateTime(); - - // Read root node - Root = loadNode1(stream); - - break; - } - - case 3: - { - // Read date - Date = stream.ReadDateTime(); - - // Read root node - Root = loadNode3(stream); - - break; - } - - case 4: - { - // Read date - Date = stream.ReadDateTime(); - - // Read root node - Root = loadNode4(stream); - - break; - } - - default: - throw new FileLoadException("Unknown Code Frame file version."); - } - - // Ending char - if(stream.ReadByte() != 99) - { - throw new FileLoadException("Code Frame file. is corrupted"); - } - } - - /// - /// Save to the file - /// - /// File path - public void Save(string path) - { - using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read)) - { - Save(fs); - } - } - - /// - /// Save to the stream - /// - /// Stream to write to - private void Save(Stream stream) - { - // Header - stream.Write(1032); - - // Version - stream.Write(4); - - // Date - stream.Write(Date); - - // Write root node - saveNode4(stream, Root); - - // Ending char - stream.WriteByte(99); - } - - #region Version 1 and 2 - - private void saveNode1(Stream stream, CodeFrameNode node) - { - // Save node data - stream.Write(node.FilesCount); - stream.Write(node.LinesOfCode[0]); - stream.Write(node.LinesOfCode[1]); - stream.WriteUTF8(node.ShortName, 13); - stream.Write(node.SizeOnDisk); - stream.Write(node.Children.Length); - - // Save all child nodes - for (int i = 0; i < node.Children.Length; i++) - { - saveNode1(stream, node.Children[i]); - } - } - - private CodeFrameNode loadNode1(Stream stream) - { - // Load node data - int files = stream.ReadInt(); - long[] lines = - { - stream.ReadLong(), - stream.ReadLong(), - 0, - 0 - }; - string name = stream.ReadStringUTF8(13); - long size = stream.ReadLong(); - int childrenCount = stream.ReadInt(); - - // Load all child nodes - CodeFrameNode[] children = new CodeFrameNode[childrenCount]; - for (int i = 0; i < childrenCount; i++) - { - children[i] = loadNode1(stream); - } - - // Create node - return new CodeFrameNode(name, files, lines, size, children); - } - - #endregion - - #region Version 3 - - private void saveNode3(Stream stream, CodeFrameNode node) - { - // Save node data - stream.Write(node.FilesCount); - stream.Write(node.LinesOfCode[0]); - stream.Write(node.LinesOfCode[1]); - stream.Write(node.LinesOfCode[2]); - stream.WriteUTF8(node.ShortName, 13); - stream.Write(node.SizeOnDisk); - stream.Write(node.Children.Length); - - // Save all child nodes - for (int i = 0; i < node.Children.Length; i++) - { - saveNode3(stream, node.Children[i]); - } - } - - private CodeFrameNode loadNode3(Stream stream) - { - // Load node data - int files = stream.ReadInt(); - long[] lines = - { - stream.ReadLong(), - stream.ReadLong(), - stream.ReadLong(), - 0, - }; - string name = stream.ReadStringUTF8(13); - long size = stream.ReadLong(); - int childrenCount = stream.ReadInt(); - - // Load all child nodes - CodeFrameNode[] children = new CodeFrameNode[childrenCount]; - for (int i = 0; i < childrenCount; i++) - { - children[i] = loadNode3(stream); - } - - // Create node - return new CodeFrameNode(name, files, lines, size, children); - } - - #endregion - - #region Version 4 - - private void saveNode4(Stream stream, CodeFrameNode node) - { - // Save node data - stream.Write(node.FilesCount); - stream.Write(node.LinesOfCode[0]); - stream.Write(node.LinesOfCode[1]); - stream.Write(node.LinesOfCode[2]); - stream.Write(node.LinesOfCode[3]); - stream.WriteUTF8(node.ShortName, 13); - stream.Write(node.SizeOnDisk); - stream.Write(node.Children.Length); - - // Save all child nodes - for (int i = 0; i < node.Children.Length; i++) - { - saveNode3(stream, node.Children[i]); - } - } - - private CodeFrameNode loadNode4(Stream stream) - { - // Load node data - int files = stream.ReadInt(); - long[] lines = - { - stream.ReadLong(), - stream.ReadLong(), - stream.ReadLong(), - stream.ReadLong() - }; - string name = stream.ReadStringUTF8(13); - long size = stream.ReadLong(); - int childrenCount = stream.ReadInt(); - - // Load all child nodes - CodeFrameNode[] children = new CodeFrameNode[childrenCount]; - for (int i = 0; i < childrenCount; i++) - { - children[i] = loadNode3(stream); - } - - // Create node - return new CodeFrameNode(name, files, lines, size, children); - } - - #endregion - - /// - /// Clean all data - /// - public void Dispose() - { - // Dispose root - if (Root != null) - { - Root.Dispose(); - Root = null; - } - } - } -} diff --git a/Source/Tools/Flax.Stats/CodeFrameNode.cs b/Source/Tools/Flax.Stats/CodeFrameNode.cs deleted file mode 100644 index 6f053262d..000000000 --- a/Source/Tools/Flax.Stats/CodeFrameNode.cs +++ /dev/null @@ -1,308 +0,0 @@ -// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved. - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Windows.Forms; - -namespace Flax.Stats -{ - /// - /// Single code frame data - /// - public sealed class CodeFrameNode : IDisposable - { - private static string[] ignoredFolders = new[] - { - ".vs", - ".git", - "obj", - "bin", - "packages", - "thirdparty", - "3rdparty", - "flaxdeps", - "platforms", - "flaxapi", - }; - - /// - /// Array with all child nodes - /// - public CodeFrameNode[] Children; - - /// - /// Amount of lines of code - /// - public long[] LinesOfCode; - - /// - /// Size of the node on the hard drive - /// - public long SizeOnDisk; - - /// - /// Amount of files - /// - public int FilesCount; - - /// - /// Short directory name - /// - public string ShortName; - - /// - /// Gets total amount of lines of code in that node and all child nodes - /// - public long TotalLinesOfCode - { - get - { - long result = 0; - for (int i = 0; i < (int)Languages.Max; i++) - { - result += LinesOfCode[i]; - } - for (int i = 0; i < Children.Length; i++) - { - result += Children[i].TotalLinesOfCode; - } - return result; - } - } - - /// - /// Gets total amount of memory used by that node and all child nodes - /// - public long TotalSizeOnDisk - { - get - { - long result = SizeOnDisk; - for (int i = 0; i < Children.Length; i++) - { - result += Children[i].TotalSizeOnDisk; - } - return result; - } - } - - /// - /// Gets total amount of files used by that node and all child nodes - /// - public long TotalFiles - { - get - { - long result = FilesCount; - for (int i = 0; i < Children.Length; i++) - { - result += Children[i].TotalFiles; - } - return result; - } - } - - /// - /// Gets code frame node with given index - /// - /// Code frame node index - /// Code frame node - public CodeFrameNode this[int index] - { - get { return Children[index]; } - } - - /// - /// Gets code frame node with given name - /// - /// Code frame node index - /// Code frame node - public CodeFrameNode this[string name] - { - get - { - for (int i = 0; i < Children.Length; i++) - if (Children[i].ShortName == name) - return Children[i]; - return null; - } - } - - /// - /// Init - /// - /// Directory name - /// Amount of files - /// Lines of code - /// Size on disk - /// Child nodes - public CodeFrameNode(string name, int filesCnt, long[] lines, long size, CodeFrameNode[] children) - { - if(lines == null || lines.Length != (int)Languages.Max) - throw new InvalidDataException(); - - ShortName = name; - FilesCount = filesCnt; - Children = children; - LinesOfCode = lines; - SizeOnDisk = size; - } - - /// - /// Gets total amount of lines of code per language - /// - /// Language - /// Result amount of lines - public long GetTotalLinesOfCode(Languages language) - { - long result = 0; - result += LinesOfCode[(int)language]; - for (int i = 0; i < Children.Length; i++) - { - result += Children[i].GetTotalLinesOfCode(language); - } - return result; - } - - /// - /// Capture data from the folder - /// - /// Folder path to capture - /// Created code frame of null if cannot create that - public static CodeFrameNode Capture(DirectoryInfo folder) - { - // Get all files from that folder - FileInfo[] files; - try - { - files = folder.GetFiles("*.*"); - } - catch (UnauthorizedAccessException) - { - return null; - } - catch (Exception exception) - { - MessageBox.Show(exception.Message); - return null; - } - - // Count data - long[] lines = new long[(int)Languages.Max]; - for (int i = 0; i < (int)Languages.Max; i++) - { - lines[i] = 0; - } - long size = 0; - for (int i = 0; i < files.Length; i++) - { - // Count files size - size += files[i].Length; - - // Get file type index - int index = -1; - switch (files[i].Extension) - { - // C++ - case ".h": - case ".cpp": - case ".cxx": - case ".hpp": - case ".hxx": - case ".c": - index = (int)Languages.Cpp; - break; - - // C# - case ".cs": - index = (int)Languages.CSharp; - break; - - // HLSL - case ".hlsl": - case ".shader": - index = (int)Languages.Hlsl; - break; - } - if (index == -1) - continue; - - // Count lines in the source file - long ll = 1; - using (StreamReader streamReader = new StreamReader(files[i].FullName)) - { - while (streamReader.ReadLine() != null) - { - ll++; - } - } - lines[index] += ll; - } - - // Get all directories - DirectoryInfo[] directories = folder.GetDirectories(); - if (directories.Length == 0 && files.Length == 0) - { - // Empty folder - return null; - } - - // Process child nodes - List children = new List(directories.Length); - for (int i = 0; i < directories.Length; i++) - { - // Validate name - if(ignoredFolders.Contains(directories[i].Name.ToLower())) - continue; - - var child = Capture(directories[i]); - if (child != null) - { - children.Add(child); - } - } - - // Create node - return new CodeFrameNode(folder.Name, files.Length, lines, size, children.ToArray()); - } - - public void CleanupDirectories() - { - var child = Children.ToList(); - child.RemoveAll(e => ignoredFolders.Contains(e.ShortName.ToLower())); - Children = child.ToArray(); - - foreach (var a in Children) - { - a.CleanupDirectories(); - } - } - - /// - /// Clean all data - /// - public void Dispose() - { - if (Children != null) - { - // Clear - for (int i = 0; i < Children.Length; i++) - { - Children[i].Dispose(); - } - Children = null; - } - } - - /// - /// To string - /// - /// String - public override string ToString() - { - return ShortName; - } - } -} diff --git a/Source/Tools/Flax.Stats/Flax.Stats.Build.cs b/Source/Tools/Flax.Stats/Flax.Stats.Build.cs deleted file mode 100644 index 9028ce71f..000000000 --- a/Source/Tools/Flax.Stats/Flax.Stats.Build.cs +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved. - -using Flax.Build; - -/// -/// Flax.Stats tool project build configuration. -/// -public class FlaxStatsTarget : Target -{ - /// - public FlaxStatsTarget() - { - Name = ProjectName = OutputName = "Flax.Stats"; - } - - /// - public override void Init() - { - base.Init(); - - Type = TargetType.DotNet; - OutputType = TargetOutputType.Library; - Platforms = new[] - { - TargetPlatform.Windows, - TargetPlatform.Linux, - TargetPlatform.Mac, - }; - Configurations = new[] - { - TargetConfiguration.Debug, - TargetConfiguration.Release, - }; - CustomExternalProjectFilePath = System.IO.Path.Combine(FolderPath, "Flax.Stats.csproj"); - } -} diff --git a/Source/Tools/Flax.Stats/Flax.Stats.csproj b/Source/Tools/Flax.Stats/Flax.Stats.csproj deleted file mode 100644 index d5049841b..000000000 --- a/Source/Tools/Flax.Stats/Flax.Stats.csproj +++ /dev/null @@ -1,71 +0,0 @@ - - - - - Debug - AnyCPU - {E9B47E88-802C-45E4-BFF4-F05A6F991BC9} - WinExe - Properties - Flax.Stats - Flax.Stats - v4.5.2 - 7.3 - 512 - true - - - - AnyCPU - true - full - false - false - ..\..\..\Binaries\Tools\ - ..\..\..\Binaries\Tools\Flax.Stats.xml - ..\..\..\Cache\Intermediate\Flax.Stats\Debug - DEBUG;TRACE - prompt - 1 - true - - - AnyCPU - pdbonly - true - false - ..\..\..\Binaries\Tools\ - ..\..\..\Binaries\Tools\Flax.Stats.xml - ..\..\..\Cache\Intermediate\Flax.Stats\Release - TRACE - prompt - 4 - true - - - - - - - - - - - - - Form - - - Form1.cs - - - - - - - - - - - - \ No newline at end of file diff --git a/Source/Tools/Flax.Stats/Form1.Designer.cs b/Source/Tools/Flax.Stats/Form1.Designer.cs deleted file mode 100644 index cf57fc9a4..000000000 --- a/Source/Tools/Flax.Stats/Form1.Designer.cs +++ /dev/null @@ -1,73 +0,0 @@ -namespace Flax.Stats -{ - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); - System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); - System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series(); - this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart(); - ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit(); - this.SuspendLayout(); - // - // chart1 - // - chartArea1.Name = "ChartArea1"; - this.chart1.ChartAreas.Add(chartArea1); - this.chart1.Dock = System.Windows.Forms.DockStyle.Fill; - legend1.Name = "Legend1"; - this.chart1.Legends.Add(legend1); - this.chart1.Location = new System.Drawing.Point(0, 0); - this.chart1.Name = "chart1"; - series1.ChartArea = "ChartArea1"; - series1.Legend = "Legend1"; - series1.Name = "TotalLines"; - this.chart1.Series.Add(series1); - this.chart1.Size = new System.Drawing.Size(932, 508); - this.chart1.TabIndex = 0; - this.chart1.Text = "chart1"; - // - // Form1 - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(932, 508); - this.Controls.Add(this.chart1); - this.Name = "Form1"; - this.Text = "Form1"; - ((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit(); - this.ResumeLayout(false); - - } - - #endregion - - private System.Windows.Forms.DataVisualization.Charting.Chart chart1; - } -} - diff --git a/Source/Tools/Flax.Stats/Form1.cs b/Source/Tools/Flax.Stats/Form1.cs deleted file mode 100644 index 35dccaa25..000000000 --- a/Source/Tools/Flax.Stats/Form1.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Windows.Forms; -using System.Windows.Forms.DataVisualization.Charting; - -namespace Flax.Stats -{ - internal partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - - public void SetSourceCode(List codeFrames, List apiCodeFrames) - { - var set = chart1.Series["TotalLines"]; - set.ChartType = SeriesChartType.Line; - var firstApiFrame = apiCodeFrames.Count > 0 ? apiCodeFrames[0].Date : DateTime.MaxValue; - - for (int i = 0; i < codeFrames.Count; i++) - { - var frame = codeFrames[i]; - var root = frame.Root; - long total = 0; - - // All frames before 2016-08-05 have Source folder named to Celelej in a project dir - if (frame.Date < new DateTime(2016, 8, 5)) - { - var sourceDir = root["Celelej"]; - total = sourceDir.TotalLinesOfCode; - } - else - { - var sourceDir = root["Source"]; - - // Check if frame is from Source - if (sourceDir != null) - { - total = sourceDir.TotalLinesOfCode + root["Development"].TotalLinesOfCode + - root["Tools"].TotalLinesOfCode; - } - - // Check if there was SourceAPI frame at that frame - /*if (frame.Date >= firstApiFrame) - { - var apiFrame = apiCodeFrames.Find(e => Math.Abs((e.Date - frame.Date).TotalMinutes) < 2); - if (apiFrame != null) - total += apiFrame.Root.TotalLinesOfCode; - }*/ - } - - set.Points.AddXY(codeFrames[i].Date, total); - } - } - } -} diff --git a/Source/Tools/Flax.Stats/Languages.cs b/Source/Tools/Flax.Stats/Languages.cs deleted file mode 100644 index 5127fffca..000000000 --- a/Source/Tools/Flax.Stats/Languages.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved. - -namespace Flax.Stats -{ - /// - /// Array with all source code languages - /// - public enum Languages : byte - { - /// - /// C++ - /// - Cpp = 0, - - /// - /// C# - /// - CSharp = 1, - - /// - /// Hlsl - /// - Hlsl = 2, - - /// - /// Amount of languages - /// - Max = 4 - } -} diff --git a/Source/Tools/Flax.Stats/Program.cs b/Source/Tools/Flax.Stats/Program.cs deleted file mode 100644 index 305d64522..000000000 --- a/Source/Tools/Flax.Stats/Program.cs +++ /dev/null @@ -1,190 +0,0 @@ -// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved. - -using System; -using System.Collections.Generic; -using System.IO; -using System.Windows.Forms; - -namespace Flax.Stats -{ - internal static class Program - { - private const string ProjectRoot = @"C:\Flax\"; // TODO: could we detect it? - - private struct StatsTarget - { - public string SourceFolder; - public string StatsFolder; - - public StatsTarget(string source, string stats) - { - SourceFolder = ProjectRoot + source; - StatsFolder = ProjectRoot + @"Source\" + stats; - - if (!Directory.Exists(SourceFolder)) - Directory.CreateDirectory(SourceFolder); - if (!Directory.Exists(StatsFolder)) - Directory.CreateDirectory(StatsFolder); - } - } - - private static StatsTarget Source = new StatsTarget("Source", @"Development\CodeStats"); - private static StatsTarget SourceAPI = new StatsTarget("Source\\FlaxAPI", @"Development\CodeStatsAPI"); - - private static string formatNum(long num) - { - return num.ToString("# ### ### ##0"); - } - - private static string getLangStatsText(out long totalLines, params CodeFrame[] frames) - { - long linesCpp = 0, linesCSharp = 0, linesHlsl = 0; - - for (int i = 0; i < frames.Length; i++) - { - var root = frames[i].Root; - - linesCpp += root.GetTotalLinesOfCode(Languages.Cpp); - linesCSharp += root.GetTotalLinesOfCode(Languages.CSharp); - linesHlsl += root.GetTotalLinesOfCode(Languages.Hlsl); - } - - totalLines = linesCpp + linesCSharp + linesHlsl; - - return string.Format( - @"C++: {0} -C#: {1} -HLSL: {2}", - formatNum(linesCpp), - formatNum(linesCSharp), - formatNum(linesHlsl) - ); - } - - private static void saveStatsInfo(CodeFrame source, CodeFrame sourceApi) - { - long totalLines; - - string sourceStats = getLangStatsText(out totalLines, source); - string sourceApiStats = getLangStatsText(out totalLines, sourceApi); - string totalStats = getLangStatsText(out totalLines, source, sourceApi); - - string path = Path.Combine(ProjectRoot, "Source\\Development", "Code Stats Summary.txt"); - File.WriteAllText(path, - string.Format( - @"Source: -{0} - -SourceAPI: -{1} - -Total: -{2} - -Total lines of code: {3} -", - sourceStats, - sourceApiStats, - totalStats, - formatNum(totalLines) - )); - } - - public static int CompareFrames(CodeFrame x, CodeFrame y) - { - return x.Date.CompareTo(y.Date); - } - - private static void Peek() - { - // Peek code frames - Environment.CurrentDirectory = Source.SourceFolder; - CodeFrame sourceFrame = CodeFrame.Capture(Source.SourceFolder); - CodeFrame sourceApiFrame = CodeFrame.Capture(SourceAPI.SourceFolder); - - // Save frames - var filename = "Stats_" + DateTime.Now.ToFilenameString() + ".dat"; - sourceFrame.Save(Path.Combine(Source.StatsFolder, filename)); - sourceApiFrame.Save(Path.Combine(SourceAPI.StatsFolder, filename)); - - // Update stats - saveStatsInfo(sourceFrame, sourceApiFrame); - } - - private static void Clear() - { - } - - private static void Show() - { - // Load all code frames - const string filesFilter = "Stats_*.dat"; - string[] files = Directory.GetFiles(Source.StatsFolder, filesFilter); - string[] filesApi = Directory.GetFiles(SourceAPI.StatsFolder, filesFilter); - // - List sourceCodeFrames = new List(files.Length); - List sourceApiCodeFrames = new List(filesApi.Length); - // - for (int i = 0; i < files.Length; i++) - sourceCodeFrames.Add(CodeFrame.Load(files[i])); - for (int i = 0; i < filesApi.Length; i++) - sourceApiCodeFrames.Add(CodeFrame.Load(filesApi[i])); - - // Sort frames - sourceCodeFrames.Sort(CompareFrames); - sourceApiCodeFrames.Sort(CompareFrames); - - // Show window - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - Form1 f = new Form1(); - f.SetSourceCode(sourceCodeFrames, sourceApiCodeFrames); - Application.Run(f); - - // Clean data - for (int i = 0; i < sourceCodeFrames.Count; i++) - sourceCodeFrames[i].Dispose(); - for (int i = 0; i < sourceApiCodeFrames.Count; i++) - sourceApiCodeFrames[i].Dispose(); - } - - /// - /// The main entry point for the application - /// - [STAThread] - private static void Main(string[] args) - { - // Parse input arguments - TaskType task = TaskType.Show; - foreach (var s in args) - { - switch (s) - { - case "peek": - task = TaskType.Peek; - break; - case "clear": - task = TaskType.Clear; - break; - default: - MessageBox.Show("Unknown argument: " + s); - break; - } - } - - // Switch task - switch (task) - { - case TaskType.Peek: - Peek(); - break; - case TaskType.Clear: - Clear(); - break; - default: - Show(); - break; - } - } - } -} diff --git a/Source/Tools/Flax.Stats/Properties/AssemblyInfo.cs b/Source/Tools/Flax.Stats/Properties/AssemblyInfo.cs deleted file mode 100644 index b96bf3f48..000000000 --- a/Source/Tools/Flax.Stats/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("Flax.Stats")] -[assembly: AssemblyDescription("Code metrics tool")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Flax.Stats")] -[assembly: AssemblyCopyright("Copyright © 2015-2017 Wojciech Figat")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] -[assembly: Guid("e9b47e88-802c-45e4-bff4-f05a6f991bc9")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Source/Tools/Flax.Stats/TaskType.cs b/Source/Tools/Flax.Stats/TaskType.cs deleted file mode 100644 index d1f5e2842..000000000 --- a/Source/Tools/Flax.Stats/TaskType.cs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved. - -namespace Flax.Stats -{ - /// - /// Code statistics app task types - /// - internal enum TaskType - { - /// - /// By default just show code statistics - /// - Show = 0, - - /// - /// Peek code stats to the database - /// - Peek, - - /// - /// Clear whole code statistics - /// - Clear, - } -} diff --git a/Source/Tools/Flax.Stats/Tools.cs b/Source/Tools/Flax.Stats/Tools.cs deleted file mode 100644 index f1fc8a6d0..000000000 --- a/Source/Tools/Flax.Stats/Tools.cs +++ /dev/null @@ -1,683 +0,0 @@ -// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved. - -using System; -using System.IO; -using System.Text; - -namespace Flax.Stats -{ - /// - /// Contains some useful functions - /// - public static class Tools - { - /// - /// Converts size of the file (in bytes) to the best fitting string - /// - /// Size of the file in bytes - /// The best fitting string of the file size - public static string BytesToText(long bytes) - { - string[] s = { "B", "KB", "MB", "GB", "TB" }; - int i = 0; - float dblSByte = bytes; - for (; (int)(bytes / 1024.0f) > 0; i++, bytes /= 1024) - dblSByte = bytes / 1024.0f; - return string.Format("{0:0.00} {1}", dblSByte, s[i]); - } - - /// - /// Returns date and time as 'good' for filenames string - /// - /// Date and Time - public static string ToFilenameString(this DateTime dt) - { - StringBuilder sb = new StringBuilder(); - sb.Append(dt.ToShortDateString().Replace(' ', '_').Replace('-', '_').Replace('/', '_').Replace('\\', '_')); - sb.Append('_'); - sb.Append(dt.ToLongTimeString().Replace(':', '_').Replace(' ', '_')); - return sb.ToString(); - } - - #region Direct Write - - /// - /// Write new line to the stream - /// - /// Stream - public static void WriteLine(this Stream fs) - { - fs.WriteByte((byte)'\n'); - } - - /// - /// Write text to the stream without '\0' char - /// - /// File stream - /// Data to write - public static void WriteText(this Stream fs, string data) - { - // Write all bytes - for (int i = 0; i < data.Length; i++) - { - // Write single byte - fs.WriteByte((byte)data[i]); - } - } - - /// - /// Write char to the stream - /// - /// File stream - /// Data to write - public static void Write(this Stream fs, char data) - { - // Write single byte - fs.WriteByte((byte)data); - } - - /// - /// Write string in UTF-8 encoding to the stream - /// - /// File stream - /// Data to write - public static void WriteUTF8(this Stream fs, string data) - { - // Check if string is null or empty - if (string.IsNullOrEmpty(data)) - { - // Write 0 - fs.Write(0); - } - else - { - // Get bytes - byte[] bytes = Encoding.UTF8.GetBytes(data); - - // Write length - fs.Write(bytes.Length); - - // Write all bytes - fs.Write(bytes, 0, bytes.Length); - } - } - - /// - /// Write string in UTF-8 encoding to the stream and offset data - /// - /// File stream - /// Data to write - /// Offset to apply when writing data - public static void WriteUTF8(this Stream fs, string data, byte offset) - { - // Check if string is null or empty - if (string.IsNullOrEmpty(data)) - { - // Write 0 - fs.Write(0); - } - else - { - // Get bytes - byte[] bytes = Encoding.UTF8.GetBytes(data); - - // Write length - int len = bytes.Length; - fs.Write(len); - - // Offset data - for (int i = 0; i < len; i++) - { - bytes[i] += offset; - } - - // Write all bytes - fs.Write(bytes, 0, len); - } - } - - /// - /// Write bool to the stream - /// - /// File stream - /// Value to write - public static void Write(this Stream fs, bool value) - { - // Write single byte - fs.WriteByte((value) ? (byte)1 : (byte)0); - } - - /// - /// Write short to the stream - /// - /// File stream - /// Value to write - public static void Write(this Stream fs, short value) - { - // Convert to bytes - byte[] bytes = BitConverter.GetBytes(value); - - // Write bytes - fs.Write(bytes, 0, 2); - } - - /// - /// Write ushort to the stream - /// - /// File stream - /// Value to write - public static void Write(this Stream fs, ushort value) - { - // Convert to bytes - byte[] bytes = BitConverter.GetBytes(value); - - // Write bytes - fs.Write(bytes, 0, 2); - } - - /// - /// Write int to the stream - /// - /// File stream - /// Value to write - public static void Write(this Stream fs, int value) - { - // Convert to bytes - byte[] bytes = BitConverter.GetBytes(value); - - // Write bytes - fs.Write(bytes, 0, 4); - } - - /// - /// Write uint to the stream - /// - /// File stream - /// Value to write - public static void Write(this Stream fs, uint value) - { - // Convert to bytes - byte[] bytes = BitConverter.GetBytes(value); - - // Write bytes - fs.Write(bytes, 0, 4); - } - - /// - /// Write long to the stream - /// - /// File stream - /// Value to write - public static void Write(this Stream fs, long value) - { - // Convert to bytes - byte[] bytes = BitConverter.GetBytes(value); - - // Write bytes - fs.Write(bytes, 0, 8); - } - - /// - /// Write float to the stream - /// - /// File stream - /// Value to write - public static void Write(this Stream fs, float value) - { - // Convert to bytes - byte[] bytes = BitConverter.GetBytes(value); - - // Write bytes - fs.Write(bytes, 0, 4); - } - - /// - /// Write float array to the stream - /// - /// File stream - /// Value to write - public static void Write(this Stream fs, float[] val) - { - // Write all floats - for (int i = 0; i < val.Length; i++) - { - // Convert to bytes - byte[] bytes = BitConverter.GetBytes(val[i]); - - // Write bytes - fs.Write(bytes, 0, 4); - } - } - - /// - /// Write double to the stream - /// - /// File stream - /// Value to write - public static void Write(this Stream fs, double val) - { - // Convert to bytes - byte[] bytes = BitConverter.GetBytes(val); - - // Write bytes - fs.Write(bytes, 0, 8); - } - - /// - /// Write DateTime to the stream - /// - /// File stream - /// Value to write - public static void Write(this Stream fs, DateTime val) - { - // Convert to bytes - byte[] bytes = BitConverter.GetBytes(val.ToBinary()); - - // Write bytes - fs.Write(bytes, 0, 8); - } - - /// - /// Write Guid to the stream - /// - /// File stream - /// Value to write - public static void Write(this Stream fs, Guid val) - { - // Convert to bytes - byte[] bytes = val.ToByteArray(); - - // Write bytes - fs.Write(bytes, 0, 16); - } - - /// - /// Write array of Guids to the stream - /// - /// File stream - /// Value to write - public static void Write(this Stream fs, Guid[] val) - { - // Check size - if (val == null || val.Length < 1) - { - // No Guids - fs.Write(0); - } - else - { - // Write length - fs.Write(val.Length); - - // Write all Guids - for (int i = 0; i < val.Length; i++) - { - // Convert to bytes - byte[] bytes = val[i].ToByteArray(); - - // Write bytes - fs.Write(bytes, 0, 16); - } - } - } - - /// - /// Write TimeSpan to the stream - /// - /// File stream - /// Value to write - public static void Write(this Stream fs, TimeSpan val) - { - // Convert to bytes - byte[] bytes = BitConverter.GetBytes(val.Ticks); - - // Write bytes - fs.Write(bytes, 0, 8); - } - - #endregion - - #region Direct Read - - /// - /// Read string from the file - /// - /// File stream - /// Length of the text - /// String - public static string ReadText(this Stream fs, int length) - { - // Read all bytes - string val = string.Empty; - while (fs.CanRead && length > 0) - { - // Read byte - int b = fs.ReadByte(); - - // Validate - if (b > 0) - { - // Add char to string - val += (char)b; - } - else - { - break; - } - length--; - } - - // Return value - return val; - } - - /// - /// Read string(UTF-8) from the file - /// - /// File stream - /// String - public static string ReadStringUTF8(this Stream fs) - { - // Read length - int len = fs.ReadInt(); - - // Check if no string - if (len == 0) - { - // Empty string - return string.Empty; - } - else - { - // Read all bytes - byte[] bytes = new byte[len]; - fs.Read(bytes, 0, bytes.Length); - - // Convert - return Encoding.UTF8.GetString(bytes); - } - } - - /// - /// Read string(UTF-8) from the file and restore offset - /// - /// File stream - /// Offset to restore - /// String - public static string ReadStringUTF8(this Stream fs, byte offset) - { - // Read length - int len = fs.ReadInt(); - - // Check if no string - if (len <= 0) - { - // Empty string - return string.Empty; - } - else - { - // Read all bytes - byte[] bytes = new byte[len]; - fs.Read(bytes, 0, bytes.Length); - - // Restore offset - for (int i = 0; i < len; i++) - { - bytes[i] -= offset; - } - - // Convert - return Encoding.UTF8.GetString(bytes); - } - } - - /// - /// Read bool from the file - /// - /// File stream - /// bool - public static bool ReadBool(this Stream fs) - { - // Read byte - return fs.ReadByte() == 1; - } - - /// - /// Read short from the file - /// - /// File stream - /// short - public static short ReadShort(this Stream fs) - { - // Read 2 bytes - byte[] bytes = new byte[2]; - fs.Read(bytes, 0, 2); - - // Return bytes converted - return BitConverter.ToInt16(bytes, 0); - } - - /// - /// Read ushort from the file - /// - /// File stream - /// ushort - public static ushort ReadUShort(this Stream fs) - { - // Read 2 bytes - byte[] bytes = new byte[2]; - fs.Read(bytes, 0, 2); - - // Return bytes converted - return BitConverter.ToUInt16(bytes, 0); - } - - /// - /// Read int from the file - /// - /// File stream - /// int - public static int ReadInt(this Stream fs) - { - // Read 4 bytes - byte[] bytes = new byte[4]; - fs.Read(bytes, 0, 4); - - // Return bytes converted - return BitConverter.ToInt32(bytes, 0); - } - - /// - /// Read uint from the file - /// - /// File stream - /// uint - public static uint ReadUInt(this Stream fs) - { - // Read 4 bytes - byte[] bytes = new byte[4]; - fs.Read(bytes, 0, 4); - - // Return bytes converted - return BitConverter.ToUInt32(bytes, 0); - } - - /// - /// Read ulong from the file - /// - /// File stream - /// ulong - public static ulong ReadULong(this Stream fs) - { - // Read 8 bytes - byte[] bytes = new byte[8]; - fs.Read(bytes, 0, 8); - - // Return bytes converted - return BitConverter.ToUInt64(bytes, 0); - } - - /// - /// Read long from the file - /// - /// File stream - /// long - public static long ReadLong(this Stream fs) - { - // Read 8 bytes - byte[] bytes = new byte[8]; - fs.Read(bytes, 0, 8); - - // Return bytes converted - return BitConverter.ToInt64(bytes, 0); - } - - /// - /// Read float from the file - /// - /// File stream - /// float - public static unsafe float ReadFloat(this Stream fs) - { - // Read 4 bytes - byte[] bytes = new byte[4]; - fs.Read(bytes, 0, 4); - - // Convert into float - fixed (byte* p = bytes) - { - return *((float*)p); - } - } - - /// - /// Read array of floats from the file - /// - /// File stream - /// Array size - /// float array - public static unsafe float[] ReadFloats(this Stream fs, uint size) - { - // Create arrays - float[] val = new float[size]; - byte[] bytes = new byte[4]; - - // Read all floats - for (int i = 0; i < size; i++) - { - // Read 4 bytes - fs.Read(bytes, 0, 4); - - // Convert into float - fixed (byte* p = bytes) - { - val[i] = *((float*)p); - } - } - - // Return - return val; - } - - /// - /// Read double from the file - /// - /// File stream - /// double - public static double ReadDouble(this Stream fs) - { - // Read 8 bytes - byte[] bytes = new byte[8]; - fs.Read(bytes, 0, 8); - - // Return bytes converted - return BitConverter.ToDouble(bytes, 0); - } - - /// - /// Read DateTime from the file - /// - /// File stream - /// DateTime - public static DateTime ReadDateTime(this Stream fs) - { - // Read 8 bytes - byte[] bytes = new byte[8]; - fs.Read(bytes, 0, 8); - - // Return bytes converted - return DateTime.FromBinary(BitConverter.ToInt64(bytes, 0)); - } - - /// - /// Read Guid from the file - /// - /// File stream - /// Guid - public static Guid ReadGuid(this Stream fs) - { - // Read 16 bytes - byte[] bytes = new byte[16]; - fs.Read(bytes, 0, 16); - - // Return created Guid - return new Guid(bytes); - } - - /// - /// Read array of Guids from the file - /// - /// File stream - /// Guids - public static Guid[] ReadGuids(this Stream fs) - { - // Read size - int len = fs.ReadInt(); - - // Check if can read more - Guid[] res; - if (len > 0) - { - // Create array - res = new Guid[len]; - - // Read all - for (int i = 0; i < len; i++) - { - // Read 16 bytes - byte[] bytes = new byte[16]; - fs.Read(bytes, 0, 16); - - // Create Guid - res[i] = new Guid(bytes); - } - } - else - { - // No Guids - res = new Guid[0]; - } - - // Return - return res; - } - - /// - /// Read TimeSpan from the file - /// - /// File stream - /// TimeSpan - public static TimeSpan ReadTimeSpan(this Stream fs) - { - // Read 8 bytes - byte[] bytes = new byte[8]; - fs.Read(bytes, 0, 8); - - // Return bytes converted - return new TimeSpan(BitConverter.ToInt64(bytes, 0)); - } - - #endregion - } -}