forked from nopSolutions/nopCommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
111 lines (95 loc) · 4.05 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace ClearPluginAssemblies
{
public class Program
{
protected const string FILES_TO_DELETE = "dotnet-bundle.exe;Nop.Web.pdb;Nop.Web.exe;Nop.Web.exe.config";
protected static void Clear(string paths, IList<string> fileNames, bool saveLocalesFolders)
{
foreach (var pluginPath in paths.Split(';'))
{
try
{
var pluginDirectoryInfo = new DirectoryInfo(pluginPath);
var allDirectoryInfo = new List<DirectoryInfo> { pluginDirectoryInfo };
if (!saveLocalesFolders)
allDirectoryInfo.AddRange(pluginDirectoryInfo.GetDirectories());
foreach (var directoryInfo in allDirectoryInfo)
{
foreach (var fileName in fileNames)
{
//delete dll file if it exists in current path
var dllfilePath = Path.Combine(directoryInfo.FullName, fileName + ".dll");
if (File.Exists(dllfilePath))
File.Delete(dllfilePath);
//delete pdb file if it exists in current path
var pdbfilePath = Path.Combine(directoryInfo.FullName, fileName + ".pdb");
if (File.Exists(pdbfilePath))
File.Delete(pdbfilePath);
}
foreach (var fileName in FILES_TO_DELETE.Split(';'))
{
//delete file if it exists in current path
var pdbfilePath = Path.Combine(directoryInfo.FullName, fileName);
if (File.Exists(pdbfilePath))
File.Delete(pdbfilePath);
}
if (!directoryInfo.GetFiles().Any() && !directoryInfo.GetDirectories().Any() && !saveLocalesFolders)
directoryInfo.Delete(true);
}
}
catch
{
//do nothing
}
}
}
private static void Main(string[] args)
{
var paths = string.Empty;
var outputPath = string.Empty;
var basePluginPath = string.Empty;
var saveLocalesFolders = true;
var settings = args.FirstOrDefault(a => a.Contains("|")) ?? string.Empty;
if(string.IsNullOrEmpty(settings))
return;
foreach (var arg in settings.Split('|'))
{
var data = arg.Split("=").Select(p => p.Trim()).ToList();
var name = data[0];
var value = data.Count > 1 ? data[1] : string.Empty;
switch (name)
{
case "Paths":
paths = value;
break;
case "OutputPath":
outputPath = value;
break;
case "PluginPath":
basePluginPath = value;
break;
case "SaveLocalesFolders":
bool.TryParse(value, out saveLocalesFolders);
break;
}
}
if(!Directory.Exists(outputPath))
return;
var di = new DirectoryInfo(outputPath);
var fileNames = di.GetFiles("*.dll", SearchOption.AllDirectories).Select(fi => fi.Name.Replace(fi.Extension, "")).ToList();
if (string.IsNullOrEmpty(paths) || !fileNames.Any())
{
return;
}
if (!string.IsNullOrEmpty(basePluginPath))
{
paths = basePluginPath;
}
Clear(paths, fileNames, saveLocalesFolders);
}
}
}