Skip to content

Commit 57ccd1f

Browse files
authored
Add files via upload
1 parent 3bebbef commit 57ccd1f

5 files changed

+194
-0
lines changed

LynCandy.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
__ ______ __
3+
/ / __ __ ____ / ____/____ _ ____ ____/ /__ __
4+
/ / / / / // __ \ / / / __ `// __ \ / __ // / / /
5+
/ /___/ /_/ // / / // /___ / /_/ // / / // /_/ // /_/ /
6+
/_____/\__, //_/ /_/ \____/ \__,_//_/ /_/ \__,_/ \__, /
7+
/____/ /____/

Program.cs

+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
using System;
2+
using System.Collections.Concurrent;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Reflection;
7+
using System.Threading.Tasks;
8+
9+
namespace svchost;
10+
11+
class Program
12+
{
13+
private const int MaxDepth = 7;
14+
private static readonly string Link = "https://github.com/CNMengHan";
15+
16+
private static async Task Main(string[] args)
17+
{
18+
if (args.Length != 1 || args[0] != "1")
19+
{
20+
return;
21+
}
22+
try
23+
{
24+
var art = ReadEmbeddedResource("svchost.LynCandy.txt");
25+
Console.ForegroundColor = ConsoleColor.Cyan;
26+
Console.WriteLine(art);
27+
Console.ResetColor();
28+
Console.WriteLine($" {Link}\n");
29+
}
30+
catch (Exception)
31+
{
32+
33+
}
34+
Console.WriteLine(" 开始扫描...\n");
35+
var drives = DriveInfo.GetDrives()
36+
.Where(drive => drive.IsReady && drive.DriveType == DriveType.Fixed)
37+
.Select(drive => drive.Name)
38+
.ToArray();
39+
40+
if (drives.Length == 0)
41+
{
42+
Console.WriteLine(" 没有找到可用的磁盘驱动器!");
43+
return;
44+
}
45+
var folderSizes = new ConcurrentBag<FolderInfo>();
46+
var tasks = new List<Task>();
47+
foreach (var drive in drives)
48+
{
49+
tasks.Add(ProcessDirectoryAsync(drive, 1, folderSizes));
50+
}
51+
await Task.WhenAll(tasks);
52+
var sortedFolderSizes = folderSizes.OrderByDescending(f => f.SizeInBytes).ToList();
53+
54+
Console.ForegroundColor = ConsoleColor.Cyan;
55+
foreach (var folder in sortedFolderSizes)
56+
{
57+
if (folder.SizeInGB > 0.01m)
58+
{
59+
Console.WriteLine($" {folder.SizeInGB:N2} GB M:{folder.LastModifiedDate:yyyy/MM/dd} {folder.FullPath}");
60+
}
61+
}
62+
Console.WriteLine("\n 扫描完成啦!");
63+
Console.ReadLine();
64+
Console.ReadLine();
65+
Console.ResetColor();
66+
}
67+
private static string ReadEmbeddedResource(string resourceName)
68+
{
69+
var assembly = Assembly.GetExecutingAssembly();
70+
using (Stream? stream = assembly.GetManifestResourceStream(resourceName))
71+
{
72+
if (stream == null)
73+
throw new FileNotFoundException(" 可恶...要被逆向了吗(", resourceName);
74+
75+
using (StreamReader reader = new StreamReader(stream))
76+
{
77+
return reader.ReadToEnd();
78+
}
79+
}
80+
}
81+
private static async Task ProcessDirectoryAsync(string path, int currentDepth, ConcurrentBag<FolderInfo> folderSizes)
82+
{
83+
if (currentDepth > MaxDepth)
84+
return;
85+
try
86+
{
87+
var directoryInfo = new DirectoryInfo(path);
88+
long size = await GetFolderSizeAsync(directoryInfo);
89+
90+
folderSizes.Add(new FolderInfo
91+
{
92+
FullPath = path,
93+
SizeInBytes = size,
94+
CreationDate = directoryInfo.CreationTime,
95+
LastModifiedDate = directoryInfo.LastWriteTime,
96+
SizeInGB = (decimal)(size / (1024.0 * 1024.0 * 1024.0))
97+
});
98+
var subDirectoryTasks = directoryInfo.GetDirectories().Select(subDirectory =>
99+
ProcessDirectoryAsync(subDirectory.FullName, currentDepth + 1, folderSizes));
100+
101+
await Task.WhenAll(subDirectoryTasks);
102+
}
103+
catch (Exception)
104+
{
105+
return;
106+
}
107+
}
108+
private static async Task<long> GetFolderSizeAsync(DirectoryInfo directoryInfo)
109+
{
110+
long totalSize = 0;
111+
try
112+
{
113+
var files = directoryInfo.GetFiles("*", SearchOption.AllDirectories);
114+
var fileTasks = files.Select(file =>
115+
Task.Run(() =>
116+
{
117+
Interlocked.Add(ref totalSize, file.Length);
118+
}));
119+
await Task.WhenAll(fileTasks);
120+
}
121+
catch (Exception)
122+
{
123+
return totalSize;
124+
}
125+
return totalSize;
126+
}
127+
}
128+
129+
class FolderInfo
130+
{
131+
public required string FullPath { get; set; }
132+
public long SizeInBytes { get; set; }
133+
public decimal SizeInGB { get; set; }
134+
public DateTime CreationDate { get; set; }
135+
public DateTime LastModifiedDate { get; set; }
136+
}

svchost.csproj

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<ApplicationIcon>E:\World\ico\awa1.ico</ApplicationIcon>
8+
9+
<AssemblyTitle>StorageRetrieveX</AssemblyTitle> <!-- 程序标题 -->
10+
<AssemblyDescription>StorageRetrieveX</AssemblyDescription> <!-- 程序描述 -->
11+
<AssemblyCompany>StorageRetrieveX</AssemblyCompany> <!-- 公司名称 -->
12+
<Company>StorageRetrieveX</Company> <!-- 公司名称 -->
13+
<AssemblyProduct>StorageRetrieveX</AssemblyProduct> <!-- 产品名称 -->
14+
<AssemblyCopyright>https://github.com/CNMengHan</AssemblyCopyright> <!-- 版权信息 -->
15+
16+
<Title>StorageRetrieveX</Title> <!-- 包的友好标题,通常用于 UI 显示 -->
17+
<Product>StorageRetrieveX</Product> <!-- 程序集清单的产品名称 -->
18+
19+
<OutputName>StorageRetrieveX</OutputName>
20+
</PropertyGroup>
21+
<ItemGroup>
22+
<None Include="E:\World\ico\awa1.ico" />
23+
</ItemGroup>
24+
<ItemGroup>
25+
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.3" />
26+
</ItemGroup>
27+
<ItemGroup>
28+
<None Remove="LynCandy.txt" />
29+
<EmbeddedResource Include="LynCandy.txt">
30+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
31+
</EmbeddedResource>
32+
</ItemGroup>
33+
</Project>

svchost.sln

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "svchost", "svchost.csproj", "{7C228406-1956-4E3D-B6F8-E4229A44DC93}"
4+
EndProject
5+
Global
6+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7+
Debug|Any CPU = Debug|Any CPU
8+
Release|Any CPU = Release|Any CPU
9+
EndGlobalSection
10+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
11+
{7C228406-1956-4E3D-B6F8-E4229A44DC93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
12+
{7C228406-1956-4E3D-B6F8-E4229A44DC93}.Debug|Any CPU.Build.0 = Debug|Any CPU
13+
{7C228406-1956-4E3D-B6F8-E4229A44DC93}.Release|Any CPU.ActiveCfg = Release|Any CPU
14+
{7C228406-1956-4E3D-B6F8-E4229A44DC93}.Release|Any CPU.Build.0 = Release|Any CPU
15+
EndGlobalSection
16+
EndGlobal

svchost.sln.DotSettings.user

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:String x:Key="/Default/CodeInspection/PencilsConfiguration/ActualSeverity/@EntryValue">INFO</s:String></wpf:ResourceDictionary>

0 commit comments

Comments
 (0)