Skip to content

Commit

Permalink
Merge pull request #423 from Pioooooo/temperalBlacklist
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0ade authored Apr 16, 2022
2 parents fec4700 + 9ab563c commit afac984
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
4 changes: 1 addition & 3 deletions Celeste.Mod.mm/Mod/Everest/Everest.Content.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,7 @@ protected override void Crawl() {
for (int i = 0; i < files.Length; i++) {
string file = files[i];
string name = file.Substring(Path.Length + 1);
if (!file.EndsWith(".bin") || Everest.Loader._Blacklist.Contains(name))
continue;
if (Everest.Loader._Whitelist != null && !Everest.Loader._Whitelist.Contains(name))
if (!file.EndsWith(".bin") || !Everest.Loader.ShouldLoadFile(name))
continue;
Add("Maps/" + file.Substring(Path.Length + 1), new MapBinsInModsModAsset(this, file));
}
Expand Down
27 changes: 21 additions & 6 deletions Celeste.Mod.mm/Mod/Everest/Everest.Loader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ public static class Loader {
/// </summary>
public static ReadOnlyCollection<string> Blacklist => _Blacklist?.AsReadOnly();

/// <summary>
/// The path to the Everest /Mods/temporaryblacklist.txt file.
/// </summary>
public static string PathTemporaryBlacklist { get; internal set; }
internal static string NameTemporaryBlacklist;
internal static List<string> _TemporaryBlacklist;
/// <summary>
/// The currently loaded mod whitelist.
/// </summary>
public static ReadOnlyCollection<string> TemporaryBlacklist => _TemporaryBlacklist?.AsReadOnly();
/// <summary>
/// The path to the Everest /Mods/whitelist.txt file.
/// </summary>
Expand Down Expand Up @@ -109,6 +119,9 @@ public static class Loader {

public static bool AutoLoadNewMods { get; internal set; }

public static bool ShouldLoadFile(string file)
=> !Blacklist.Contains(file) && (TemporaryBlacklist == null || !TemporaryBlacklist.Contains(file)) && (Whitelist == null || Whitelist.Contains(file));

internal static void LoadAuto() {
Directory.CreateDirectory(PathMods = Path.Combine(PathEverest, "Mods"));
Directory.CreateDirectory(PathCache = Path.Combine(PathMods, "Cache"));
Expand All @@ -123,6 +136,12 @@ internal static void LoadAuto() {
writer.WriteLine("SomeMod.zip");
}
}
if (!string.IsNullOrEmpty(NameTemporaryBlacklist)) {
PathTemporaryBlacklist = Path.Combine(PathMods, NameTemporaryBlacklist);
if (File.Exists(PathTemporaryBlacklist)) {
_TemporaryBlacklist = File.ReadAllLines(PathTemporaryBlacklist).Select(l => (l.StartsWith("#") ? "" : l).Trim()).ToList();
}
}

if (!string.IsNullOrEmpty(NameWhitelist)) {
PathWhitelist = Path.Combine(PathMods, NameWhitelist);
Expand Down Expand Up @@ -161,19 +180,15 @@ internal static void LoadAuto() {
string[] files = Directory.GetFiles(PathMods);
for (int i = 0; i < files.Length; i++) {
string file = Path.GetFileName(files[i]);
if (!file.EndsWith(".zip") || _Blacklist.Contains(file))
continue;
if (_Whitelist != null && !_Whitelist.Contains(file))
if (!file.EndsWith(".zip") || !ShouldLoadFile(file))
continue;
LoadZip(Path.Combine(PathMods, file));
}

files = Directory.GetDirectories(PathMods);
for (int i = 0; i < files.Length; i++) {
string file = Path.GetFileName(files[i]);
if (file == "Cache" || _Blacklist.Contains(file))
continue;
if (_Whitelist != null && !_Whitelist.Contains(file))
if (file == "Cache" || !ShouldLoadFile(file))
continue;
LoadDir(Path.Combine(PathMods, file));
}
Expand Down
3 changes: 3 additions & 0 deletions Celeste.Mod.mm/Mod/Everest/Everest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ internal static void ParseArgs(string[] args) {
else if (arg == "--whitelist" && queue.Count >= 1)
Loader.NameWhitelist = queue.Dequeue();

else if (arg == "--blacklist" && queue.Count >= 1)
Loader.NameTemporaryBlacklist = queue.Dequeue();

}
}

Expand Down
4 changes: 1 addition & 3 deletions Celeste.Mod.mm/Mod/UI/OuiDependencyDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,7 @@ private void downloadAllDependencies() {
LogLine(string.Format(Dialog.Get("DEPENDENCYDOWNLOADER_MOD_UNBLACKLIST"), modFilename));

// remove the mod from the loaded blacklist
while (Everest.Loader._Blacklist.Contains(modFilename)) {
Everest.Loader._Blacklist.Remove(modFilename);
}
Everest.Loader._Blacklist.RemoveAll(item => item == modFilename);

// hot load the mod
if (modFilename.EndsWith(".zip")) {
Expand Down
8 changes: 4 additions & 4 deletions Celeste.Mod.mm/Mod/UI/OuiModToggler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ protected override void addOptionsToMenu(TextMenu menu) {
// remove the "loading..." message
menu.Remove(loading);
// if there is a whitelist, warn the user that it will break those settings.
if (Everest.Loader.Whitelist != null) {
// if there is a whitelist or temporary blacklist, warn the user that it will break those settings.
if (Everest.Loader.Whitelist != null || Everest.Loader.TemporaryBlacklist != null) {
menu.Add(restartMessage1 = new TextMenuExt.SubHeaderExt(Dialog.Clean("MODOPTIONS_MODTOGGLE_WHITELISTWARN")) { TextColor = Color.OrangeRed });
}
Expand All @@ -202,7 +202,7 @@ protected override void addOptionsToMenu(TextMenu menu) {
menu.Add(new TextMenuExt.SubHeaderExt(Dialog.Clean("MODOPTIONS_MODTOGGLE_MESSAGE_3")) { HeightExtra = 20f, TextColor = Color.Goldenrod });
// reduce spacing between the whitelist warning and the blacklist overwrite warning
if (Everest.Loader.Whitelist != null) {
if (Everest.Loader.Whitelist != null || Everest.Loader.TemporaryBlacklist != null) {
restartMessage1.HeightExtra = 30f;
}
Expand Down Expand Up @@ -315,7 +315,7 @@ protected override void addOptionsToMenu(TextMenu menu) {
private void addFileToMenu(TextMenu menu, string file) {
TextMenu.OnOff option;

bool enabled = !Everest.Loader._Blacklist.Contains(file);
bool enabled = !Everest.Loader.Blacklist.Contains(file);
menu.Add(option = (TextMenu.OnOff) new TextMenu.OnOff(file.Length > 40 ? file.Substring(0, 40) + "..." : file, enabled)
.Change(b => {
if (b) {
Expand Down

0 comments on commit afac984

Please sign in to comment.