-
Notifications
You must be signed in to change notification settings - Fork 40
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
Showing
6 changed files
with
117 additions
and
92 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
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,99 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
|
||
namespace GeneralUpdate.Common; | ||
|
||
public class BlackListManager | ||
{ | ||
private readonly static object _lockObject = new object(); | ||
|
||
private static BlackListManager _instance; | ||
|
||
private static readonly List<string> _blackFileFormats = | ||
[ | ||
".patch", | ||
".7z", | ||
".zip", | ||
".rar", | ||
".tar", | ||
".json" | ||
]; | ||
|
||
private static readonly List<string> _blackFiles = ["Newtonsoft.Json.dll"]; | ||
|
||
private BlackListManager() | ||
{ | ||
} | ||
|
||
public static BlackListManager Instance | ||
{ | ||
get | ||
{ | ||
if (_instance == null) | ||
{ | ||
lock (_lockObject) | ||
{ | ||
if (_instance == null) | ||
{ | ||
_instance = new BlackListManager(); | ||
} | ||
} | ||
} | ||
|
||
return _instance; | ||
} | ||
} | ||
|
||
public IReadOnlyList<string> BlackFileFormats => _blackFileFormats.AsReadOnly(); | ||
public IReadOnlyList<string> BlackFiles => _blackFiles.AsReadOnly(); | ||
|
||
public void AddBlackFileFormats(List<string> formats) | ||
{ | ||
foreach (var format in formats) | ||
{ | ||
AddBlackFileFormat(format); | ||
} | ||
} | ||
|
||
public void AddBlackFileFormat(string format) | ||
{ | ||
if (!_blackFileFormats.Contains(format)) | ||
{ | ||
_blackFileFormats.Add(format); | ||
} | ||
} | ||
|
||
public void RemoveBlackFileFormat(string format) | ||
{ | ||
_blackFileFormats.Remove(format); | ||
} | ||
|
||
public void AddBlackFiles(List<string> fileNames) | ||
{ | ||
foreach (var fileName in fileNames) | ||
{ | ||
AddBlackFile(fileName); | ||
} | ||
} | ||
|
||
public void AddBlackFile(string fileName) | ||
{ | ||
if (!_blackFiles.Contains(fileName)) | ||
{ | ||
_blackFiles.Add(fileName); | ||
} | ||
} | ||
|
||
public void RemoveBlackFile(string fileName) | ||
{ | ||
_blackFiles.Remove(fileName); | ||
} | ||
|
||
public bool IsBlacklisted(string relativeFilePath) | ||
{ | ||
var fileName = Path.GetFileName(relativeFilePath); | ||
var fileExtension = Path.GetExtension(relativeFilePath); | ||
|
||
return _blackFiles.Contains(fileName) || _blackFileFormats.Contains(fileExtension); | ||
} | ||
} |
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
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
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
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