Skip to content

Commit 29657f1

Browse files
authored
added to GitHub
1 parent 6d638ff commit 29657f1

File tree

4 files changed

+110
-0
lines changed

4 files changed

+110
-0
lines changed

Unget/Unget.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}") = "Unget", "Unget\Unget.csproj", "{A262F683-AEE5-4680-AEC6-EFA2D126762C}"
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+
{A262F683-AEE5-4680-AEC6-EFA2D126762C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
12+
{A262F683-AEE5-4680-AEC6-EFA2D126762C}.Debug|Any CPU.Build.0 = Debug|Any CPU
13+
{A262F683-AEE5-4680-AEC6-EFA2D126762C}.Release|Any CPU.ActiveCfg = Release|Any CPU
14+
{A262F683-AEE5-4680-AEC6-EFA2D126762C}.Release|Any CPU.Build.0 = Release|Any CPU
15+
EndGlobalSection
16+
EndGlobal

Unget/Unget/NuGetPaths.cs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Runtime.InteropServices;
4+
5+
namespace Unget
6+
{
7+
public static class NuGetPaths
8+
{
9+
public static readonly Dictionary<OSPlatform, string> NuGetCachePaths = new Dictionary<OSPlatform, string>()
10+
{
11+
{OSPlatform.Windows, Environment.ExpandEnvironmentVariables("%UserProfile%\\.nuget\\packages")},
12+
{OSPlatform.Linux, "~/.nuget/packages"},
13+
{OSPlatform.OSX, "~/.nuget/packages"}
14+
};
15+
16+
public static string GetNugetCachePathByPlatform()
17+
{
18+
return (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
19+
? NuGetCachePaths[OSPlatform.Windows]
20+
: (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
21+
? NuGetCachePaths[OSPlatform.Linux]
22+
: ((RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
23+
? NuGetCachePaths[OSPlatform.OSX]
24+
: null)));
25+
}
26+
}
27+
}

Unget/Unget/Program.cs

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Runtime.CompilerServices;
6+
using System.Runtime.InteropServices;
7+
using System.Threading;
8+
using System.Threading.Tasks;
9+
10+
namespace Unget
11+
{
12+
class Program
13+
{
14+
static void Main(string[] args)
15+
{
16+
try
17+
{
18+
Console.WriteLine("unget - NuGet Cache Cleaner\n");
19+
20+
string[] dirs
21+
= Directory.GetDirectories(NuGetPaths.GetNugetCachePathByPlatform(),
22+
"*.*", SearchOption.TopDirectoryOnly);
23+
24+
int revomalDirCount = 0;
25+
26+
Parallel.For(0, dirs.Length, i =>
27+
{
28+
List<string> cachedDirs
29+
= Directory.GetDirectories(dirs[i], "*.*", SearchOption.TopDirectoryOnly).ToList();
30+
31+
if (cachedDirs.Count > 1)
32+
{
33+
Interlocked.Add(ref revomalDirCount, cachedDirs.Count - 1);
34+
cachedDirs.Sort();
35+
36+
for (int j = 0; j < cachedDirs.Count - 1; j++)
37+
{
38+
try
39+
{
40+
Directory.Delete(cachedDirs[j], true);
41+
Console.WriteLine($"[DEL] {cachedDirs[j]}");
42+
}
43+
catch (Exception exception)
44+
{
45+
Console.WriteLine($"\n[ERR] {cachedDirs[j]}\n{exception}\n");
46+
}
47+
}
48+
}
49+
});
50+
51+
Console.WriteLine($"\nTotal {revomalDirCount} folder(s) are deleted from cache.");
52+
53+
Console.ReadKey(false);
54+
}
55+
catch (Exception exception)
56+
{
57+
Console.WriteLine(exception);
58+
}
59+
}
60+
}
61+
}

Unget/Unget/Unget.csproj

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>netcoreapp2.1</TargetFramework>
5+
</PropertyGroup>
6+
</Project>

0 commit comments

Comments
 (0)