-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8047d46
Showing
16 changed files
with
738 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.30907.101 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Adv-FolderSize", "Adv-FolderSize\Adv-FolderSize.csproj", "{50E3AA47-DCF6-4C5B-969D-9D1744B13A9D}" | ||
EndProject | ||
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FolderAnalysisFSLib", "FolderAnalysisFSLib\FolderAnalysisFSLib.fsproj", "{BA6F8578-098B-438E-A2ED-630267396879}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{50E3AA47-DCF6-4C5B-969D-9D1744B13A9D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{50E3AA47-DCF6-4C5B-969D-9D1744B13A9D}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{50E3AA47-DCF6-4C5B-969D-9D1744B13A9D}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{50E3AA47-DCF6-4C5B-969D-9D1744B13A9D}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{BA6F8578-098B-438E-A2ED-630267396879}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{BA6F8578-098B-438E-A2ED-630267396879}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{BA6F8578-098B-438E-A2ED-630267396879}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{BA6F8578-098B-438E-A2ED-630267396879}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {38342B4B-018B-4E83-9286-0458B30F2D79} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net5.0</TargetFramework> | ||
<RootNamespace>Adv_FolderSize</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="TriggerLib" Version="1.1.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\FolderAnalysisFSLib\FolderAnalysisFSLib.fsproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Adv_FolderSize | ||
{ | ||
public record ArgSet | ||
{ | ||
// empty -> arg without key | ||
public string Key { get; init; } = ""; | ||
|
||
// null -> value is required | ||
// not null -> value is optional | ||
// empty -> arg without value | ||
public string Default { get; init; } = ""; | ||
} | ||
|
||
public static class Args | ||
{ | ||
public static string[] Interprete(ArgSet[] argsets, string args, bool remainder = false) | ||
{ | ||
var values = new List<string>(); | ||
var leftargs = new List<string>(); | ||
|
||
if (remainder) | ||
leftargs.Add(args); | ||
else if (args != "") | ||
leftargs.AddRange(args.Split(' ')); | ||
|
||
foreach (var argset in argsets) | ||
{ | ||
var key = argset.Key.ToUpper(); | ||
var defaultvalue = argset.Default; | ||
|
||
var matchedarg = leftargs.Find(arg => arg.ToUpper().StartsWith(key)); | ||
|
||
if (matchedarg != null) | ||
{ | ||
var matchedvalue = matchedarg[key.Length..]; | ||
if ((defaultvalue == "" && matchedvalue != "") // empty -> arg without value | ||
|| (defaultvalue == null && matchedvalue == "")) // null -> value is required | ||
return null; | ||
values.Add(matchedvalue); | ||
leftargs.Remove(matchedarg); | ||
} | ||
else if (defaultvalue == null) // null -> value is required | ||
{ | ||
return null; | ||
} | ||
else | ||
{ | ||
values.Add(defaultvalue); | ||
} | ||
} | ||
|
||
// Check the unregistered case | ||
if (leftargs.Count == 0) | ||
return values.ToArray(); | ||
else | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
|
||
namespace Adv_FolderSize | ||
{ | ||
public static class ColorConsole | ||
{ | ||
public static void Write(string contents, ConsoleColor color, bool asline = true) | ||
{ | ||
var curcolor = Console.ForegroundColor; | ||
Console.ForegroundColor = color; | ||
if (asline) | ||
Console.WriteLine(contents); | ||
else | ||
Console.Write(contents); | ||
Console.ForegroundColor = curcolor; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using FolderAnalysisFSLib; | ||
|
||
namespace Adv_FolderSize | ||
{ | ||
public class FolderAnalysis | ||
{ | ||
private readonly FolderAnalysisBase _fABase; | ||
private readonly List<string> _selectableTree = new List<string>(); | ||
private readonly List<string> _selectableList = new List<string>(); | ||
|
||
public FolderAnalysis(string path) | ||
=> _fABase = new FolderAnalysisBase(path); | ||
|
||
public async Task StartAnalysisAsync() | ||
=> await Task.Run(() => _fABase.StartAnalysis()); | ||
|
||
public bool RedirectTo(int idx) | ||
{ | ||
if (idx >= 0 && idx < _selectableTree.Count) | ||
return _fABase.RedirectTo(_selectableTree[idx]); | ||
else | ||
return false; | ||
} | ||
|
||
public bool Back() | ||
=> _fABase.Back(); | ||
|
||
public string GetListElemPath(int idx) | ||
{ | ||
if (idx >= 0 && idx < _selectableList.Count) | ||
return _selectableList[idx]; | ||
else | ||
return null; | ||
} | ||
|
||
public string GetTreeDirPath(int idx) | ||
{ | ||
if (idx >= 0 && idx < _selectableTree.Count) | ||
return _selectableTree[idx]; | ||
else | ||
return null; | ||
} | ||
|
||
private static string SizeBar(long stand, long size, int length) | ||
{ | ||
if (stand != 0) | ||
return "■".Repeat((int)(size * length / stand)); | ||
else | ||
return ""; | ||
} | ||
|
||
|
||
private static string DirAbbrevName(string path) | ||
=> Path.DirectorySeparatorChar + Path.GetFileName(path); | ||
|
||
public void PrintDirTree(string measure, int depthLimt, int dirExpLimt, int fileExpLimt) | ||
{ | ||
// Length = 4 | ||
var diridx = "│ "; | ||
var sym = "├── "; | ||
var tabidx = " "; | ||
|
||
var printline = _fABase.GetPrintableTree(depthLimt, dirExpLimt, fileExpLimt); | ||
|
||
_selectableTree.Clear(); | ||
var idxcount = -1; | ||
var dirtopsize = _fABase.GetDirList(top: true, 1); | ||
var filetopsize = _fABase.GetFileList(top: true, 1); | ||
var dirsizestand = dirtopsize.Length != 0 ? dirtopsize[0].Item2 : 0; | ||
var filesizestand = filetopsize.Length != 0 ? filetopsize[0].Item2 : 0; | ||
|
||
foreach (var item in printline) | ||
{ | ||
var type = item.Item1; | ||
var name = item.Item2; | ||
var size = item.Item3; | ||
var depth = item.Item4; | ||
|
||
switch (type) | ||
{ | ||
case "F": | ||
Console.WriteLine( | ||
$"{SizeBar(filesizestand, size, 16),16} {ByteMeasure.byteToString(measure, size),10} " + | ||
$"{tabidx.Repeat(depth)}{sym}{name}"); | ||
break; | ||
case "D": | ||
ColorConsole.Write( | ||
$"{SizeBar(dirsizestand, size, 16),16} {ByteMeasure.byteToString(measure, size),10} " | ||
, ConsoleColor.Cyan, asline: false); | ||
Console.Write($"{diridx.Repeat(depth)}{sym}"); | ||
|
||
var print = ""; | ||
if (idxcount == -1) | ||
{ | ||
print = name; | ||
idxcount++; | ||
} | ||
else if (depth == 1) | ||
{ | ||
_selectableTree.Add(name); | ||
print = $"[{idxcount}] {DirAbbrevName(name)}"; | ||
idxcount++; | ||
} | ||
else | ||
{ | ||
print = DirAbbrevName(name); | ||
} | ||
ColorConsole.Write(print, ConsoleColor.Cyan); | ||
break; | ||
case "FH": | ||
Console.Write($"{"",16} {"",-10} {tabidx.Repeat(depth)}{sym}"); | ||
ColorConsole.Write($"... {name} files are hided", ConsoleColor.Yellow); | ||
break; | ||
case "DH": | ||
Console.Write($"{"",16} {"",-10} {tabidx.Repeat(depth + 1)}{sym}"); | ||
ColorConsole.Write($"... {name} directories are hided", ConsoleColor.Yellow); | ||
break; | ||
case "DF": | ||
Console.Write($"{"",16} {"",-10} {tabidx.Repeat(depth + 1)}{sym}"); | ||
ColorConsole.Write($"... {name} directories above this directory are folded", ConsoleColor.Yellow); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
} | ||
|
||
public void PrintDirList(string measure = "AUTO", int num = 10) | ||
{ | ||
_selectableList.Clear(); | ||
var idxcount = 0; | ||
|
||
var dirlist = _fABase.GetDirList(top: true, num); | ||
var dirsizestand = dirlist.Length != 0 ? dirlist[0].Item2 : 0; | ||
|
||
foreach (var item in dirlist) | ||
{ | ||
var name = item.Item1; | ||
var size = item.Item2; | ||
ColorConsole.Write( | ||
$"{SizeBar(dirsizestand, size, 16),16} {ByteMeasure.byteToString(measure, size),10} " + | ||
$"[{idxcount}] {name}" | ||
, ConsoleColor.Cyan); | ||
|
||
_selectableList.Add(name); | ||
idxcount++; | ||
} | ||
} | ||
|
||
public void PrintFileList(string measure = "AUTO", int num = 10) | ||
{ | ||
_selectableList.Clear(); | ||
var idxcount = 0; | ||
|
||
var filelist = _fABase.GetFileList(top: true, num); | ||
var filesizestand = filelist.Length != 0 ? filelist[0].Item2 : 0; | ||
|
||
foreach (var item in filelist) | ||
{ | ||
var name = item.Item1; | ||
var size = item.Item2; | ||
Console.WriteLine( | ||
$"{SizeBar(filesizestand, size, 16),16} {ByteMeasure.byteToString(measure, size),10} " + | ||
$"[{idxcount}] {name}"); | ||
|
||
_selectableList.Add(name); | ||
idxcount++; | ||
} | ||
} | ||
} | ||
} |
Binary file not shown.
Oops, something went wrong.