Renamed some variables,

changed some access-types to protected/readonly
Made Resharper a bit happier
This commit is contained in:
glax 2023-05-20 01:06:00 +02:00
parent 2550beb621
commit 9d104b25f8
5 changed files with 15 additions and 17 deletions

View File

@ -78,15 +78,15 @@ public static class Tranga_Cli
string? query = Console.ReadLine(); string? query = Console.ReadLine();
while (query is null || query.Length < 1) while (query is null || query.Length < 1)
query = Console.ReadLine(); query = Console.ReadLine();
PrintTasks(taskManager.GetAllTasks().Where(task => PrintTasks(taskManager.GetAllTasks().Where(qTask =>
((Publication)task.publication!).sortName.ToLower() ((Publication)qTask.publication!).sortName.ToLower()
.Contains(query, StringComparison.OrdinalIgnoreCase)).ToArray()); .Contains(query, StringComparison.OrdinalIgnoreCase)).ToArray());
Console.WriteLine("Press any key."); Console.WriteLine("Press any key.");
Console.ReadKey(); Console.ReadKey();
menu = 0; menu = 0;
break; break;
case 6: case 6:
PrintTasks(taskManager.GetAllTasks().Where(task => task.isBeingExecuted).ToArray()); PrintTasks(taskManager.GetAllTasks().Where(eTask => eTask.isBeingExecuted).ToArray());
Console.WriteLine("Press any key."); Console.WriteLine("Press any key.");
Console.ReadKey(); Console.ReadKey();
menu = 0; menu = 0;
@ -315,7 +315,7 @@ public static class Tranga_Cli
selected = Console.ReadLine(); selected = Console.ReadLine();
int start = 0; int start = 0;
int end = 0; int end;
if (selected == "a") if (selected == "a")
end = chapters.Length - 1; end = chapters.Length - 1;
else if (selected.Contains('-')) else if (selected.Contains('-'))

View File

@ -68,7 +68,7 @@ public abstract class Connector
File.WriteAllText(seriesInfoPath,publication.GetSeriesInfoJson()); File.WriteAllText(seriesInfoPath,publication.GetSeriesInfoJson());
} }
public static string CreateComicInfo(Publication publication, Chapter chapter) protected static string CreateComicInfo(Publication publication, Chapter chapter)
{ {
XElement comicInfo = new XElement("ComicInfo", XElement comicInfo = new XElement("ComicInfo",
new XElement("Tags", string.Join(',',publication.tags)), new XElement("Tags", string.Join(',',publication.tags)),
@ -118,7 +118,7 @@ public abstract class Connector
foreach (string imageUrl in imageUrls) foreach (string imageUrl in imageUrls)
{ {
string[] split = imageUrl.Split('.'); string[] split = imageUrl.Split('.');
string extension = split[split.Length - 1]; string extension = split[^1];
DownloadImage(imageUrl, Path.Join(tempFolder, $"{chapter++}.{extension}"), downloadClient); DownloadImage(imageUrl, Path.Join(tempFolder, $"{chapter++}.{extension}"), downloadClient);
} }

View File

@ -224,13 +224,13 @@ public class MangaDex : Connector
if (result is null) if (result is null)
return; return;
string fileName = result!["data"]!["attributes"]!["fileName"]!.GetValue<string>(); string fileName = result["data"]!["attributes"]!["fileName"]!.GetValue<string>();
string coverUrl = $"https://uploads.mangadex.org/covers/{publication.downloadUrl}/{fileName}"; string coverUrl = $"https://uploads.mangadex.org/covers/{publication.downloadUrl}/{fileName}";
//Get file-extension (jpg, png) //Get file-extension (jpg, png)
string[] split = coverUrl.Split('.'); string[] split = coverUrl.Split('.');
string extension = split[split.Length - 1]; string extension = split[^1];
string outFolderPath = Path.Join(downloadLocation, publication.folderName); string outFolderPath = Path.Join(downloadLocation, publication.folderName);
Directory.CreateDirectory(outFolderPath); Directory.CreateDirectory(outFolderPath);

View File

@ -5,7 +5,7 @@ namespace Tranga;
/// <summary> /// <summary>
/// Contains information on a Publication (Manga) /// Contains information on a Publication (Manga)
/// </summary> /// </summary>
public struct Publication public readonly struct Publication
{ {
public string sortName { get; } public string sortName { get; }
[JsonIgnore]public string[,] altTitles { get; } [JsonIgnore]public string[,] altTitles { get; }

View File

@ -12,8 +12,7 @@ public class TaskManager
private readonly Dictionary<Publication, List<Chapter>> _chapterCollection; private readonly Dictionary<Publication, List<Chapter>> _chapterCollection;
private readonly HashSet<TrangaTask> _allTasks; private readonly HashSet<TrangaTask> _allTasks;
private bool _continueRunning = true; private bool _continueRunning = true;
private readonly Connector[] connectors; private readonly Connector[] _connectors;
private readonly string folderPath;
/// <summary> /// <summary>
/// ///
@ -21,8 +20,7 @@ public class TaskManager
/// <param name="folderPath">Local path to save data (Manga) to</param> /// <param name="folderPath">Local path to save data (Manga) to</param>
public TaskManager(string folderPath) public TaskManager(string folderPath)
{ {
this.folderPath = folderPath; this._connectors = new Connector[]{ new MangaDex(folderPath) };
this.connectors = new Connector[]{ new MangaDex(folderPath) };
_chapterCollection = new(); _chapterCollection = new();
_allTasks = ImportTasks(Directory.GetCurrentDirectory()); _allTasks = ImportTasks(Directory.GetCurrentDirectory());
Thread taskChecker = new(TaskCheckerThread); Thread taskChecker = new(TaskCheckerThread);
@ -36,7 +34,7 @@ public class TaskManager
foreach (TrangaTask task in _allTasks) foreach (TrangaTask task in _allTasks)
{ {
if(task.ShouldExecute()) if(task.ShouldExecute())
TaskExecutor.Execute(this.connectors, task, this._chapterCollection); TaskExecutor.Execute(this._connectors, task, this._chapterCollection);
} }
Thread.Sleep(1000); Thread.Sleep(1000);
} }
@ -53,7 +51,7 @@ public class TaskManager
Task t = new Task(() => Task t = new Task(() =>
{ {
TaskExecutor.Execute(this.connectors, task, this._chapterCollection); TaskExecutor.Execute(this._connectors, task, this._chapterCollection);
}); });
t.Start(); t.Start();
} }
@ -71,7 +69,7 @@ public class TaskManager
string language = "") string language = "")
{ {
//Get appropriate Connector from available Connectors for TrangaTask //Get appropriate Connector from available Connectors for TrangaTask
Connector? connector = connectors.FirstOrDefault(c => c.name == connectorName); Connector? connector = _connectors.FirstOrDefault(c => c.name == connectorName);
if (connector is null) if (connector is null)
throw new ArgumentException($"Connector {connectorName} is not a known connector."); throw new ArgumentException($"Connector {connectorName} is not a known connector.");
@ -108,7 +106,7 @@ public class TaskManager
/// <returns>All available Connectors</returns> /// <returns>All available Connectors</returns>
public Dictionary<string, Connector> GetAvailableConnectors() public Dictionary<string, Connector> GetAvailableConnectors()
{ {
return this.connectors.ToDictionary(connector => connector.name, connector => connector); return this._connectors.ToDictionary(connector => connector.name, connector => connector);
} }
/// <summary> /// <summary>