-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor friend/ignore list loading/saving. Implement friend list fil…
…ter in OnlineListPanel.
- Loading branch information
1 parent
8548495
commit 27b5680
Showing
7 changed files
with
107 additions
and
121 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
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 was deleted.
Oops, something went wrong.
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,67 @@ | ||
using AutomaticTypeMapper; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace EndlessClient.Services | ||
{ | ||
[AutoMappedType] | ||
public class FriendIgnoreListService : IFriendIgnoreListService | ||
{ | ||
public IReadOnlyList<string> LoadList(string path) | ||
{ | ||
return Load(path); | ||
} | ||
|
||
public void SaveFriends(string path, IReadOnlyList<string> contents) | ||
{ | ||
Save(isIgnore: false, path, contents); | ||
} | ||
|
||
public void SaveIgnored(string path, IReadOnlyList<string> contents) | ||
{ | ||
Save(isIgnore: true, path, contents); | ||
} | ||
|
||
private static List<string> Load(string fileName) | ||
{ | ||
List<string> allLines; | ||
try | ||
{ | ||
allLines = new List<string>(File.ReadAllLines(fileName)); | ||
} | ||
catch (IOException) | ||
{ | ||
allLines = new List<string>(); | ||
} | ||
|
||
allLines.RemoveAll(s => s.StartsWith("#") || string.IsNullOrWhiteSpace(s)); | ||
|
||
return allLines.Select(Capitalize).Distinct().ToList(); | ||
} | ||
|
||
private static void Save(bool isIgnore, string fileName, IEnumerable<string> lines) | ||
{ | ||
using (var sw = new StreamWriter(fileName)) | ||
{ | ||
string friendOrIgnore = isIgnore ? "ignore" : "friend"; | ||
sw.WriteLine($"# Endless Online 0.28 [ {friendOrIgnore} list ]\n"); | ||
sw.WriteLine($"# List of {friendOrIgnore}{(isIgnore ? "d" : "")} characters, use a new line for each name\n\n"); | ||
|
||
foreach (string s in lines) | ||
sw.WriteLine(Capitalize(s)); | ||
} | ||
} | ||
|
||
private static string Capitalize(string input) => char.ToUpper(input[0]) + input.Substring(1).ToLower(); | ||
} | ||
|
||
public interface IFriendIgnoreListService | ||
{ | ||
IReadOnlyList<string> LoadList(string path); | ||
|
||
void SaveFriends(string path, IReadOnlyList<string> contents); | ||
|
||
void SaveIgnored(string path, IReadOnlyList<string> contents); | ||
} | ||
} |