Compare commits

...

6 Commits

7 changed files with 28 additions and 20 deletions

View File

@ -1,6 +1,6 @@
namespace Logging;
public class LogMessage
public readonly struct LogMessage
{
public DateTime logTime { get; }
public string caller { get; }

View File

@ -6,7 +6,6 @@ public class MemoryLogger : LoggerBase
{
private readonly SortedList<DateTime, LogMessage> _logMessages = new();
private int _lastLogMessageIndex = 0;
private bool _lockLogMessages = false;
public MemoryLogger(Encoding? encoding = null) : base(encoding)
{
@ -15,12 +14,9 @@ public class MemoryLogger : LoggerBase
protected override void Write(LogMessage value)
{
if (!_lockLogMessages)
lock (_logMessages)
{
_lockLogMessages = true;
while(!_logMessages.TryAdd(DateTime.Now, value))
Thread.Sleep(10);
_lockLogMessages = false;
_logMessages.Add(DateTime.Now, value);
}
}
@ -41,11 +37,9 @@ public class MemoryLogger : LoggerBase
for (int retIndex = 0; retIndex < ret.Length; retIndex++)
{
if (!_lockLogMessages)
lock (_logMessages)
{
_lockLogMessages = true;
ret[retIndex] = _logMessages.GetValueAtIndex(_logMessages.Count - retLength + retIndex).ToString();
_lockLogMessages = false;
}
}
@ -63,11 +57,9 @@ public class MemoryLogger : LoggerBase
{
try
{
if (!_lockLogMessages)
lock(_logMessages)
{
_lockLogMessages = true;
ret.Add(_logMessages.GetValueAtIndex(_lastLogMessageIndex + retIndex).ToString());
_lockLogMessages = false;
}
}
catch (NullReferenceException e)//Called when LogMessage has not finished writing

View File

@ -24,7 +24,7 @@ public class DownloadChapter : Job
public override string ToString()
{
return $"DownloadChapter {id} {chapter}";
return $"{id} Chapter: {chapter}";
}
protected override IEnumerable<Job> ExecuteReturnSubTasksInternal()

View File

@ -28,7 +28,7 @@ public class DownloadNewChapters : Job
public override string ToString()
{
return $"DownloadChapter {id} {manga}";
return $"{id} Manga: {manga}";
}
protected override IEnumerable<Job> ExecuteReturnSubTasksInternal()

View File

@ -18,7 +18,7 @@ public class Mangaworld: MangaConnector
public override Manga[] GetManga(string publicationTitle = "")
{
Log($"Searching Publications. Term=\"{publicationTitle}\"");
string sanitizedTitle = string.Join('_', Regex.Matches(publicationTitle, "[A-z]*").Where(str => str.Length > 0)).ToLower();
string sanitizedTitle = string.Join(' ', Regex.Matches(publicationTitle, "[A-z]*").Where(str => str.Length > 0)).ToLower();
string requestUrl = $"https://www.mangaworld.bz/archive?keyword={sanitizedTitle}";
DownloadClient.RequestResult requestResult =
downloadClient.MakeRequest(requestUrl, 1);
@ -34,6 +34,9 @@ public class Mangaworld: MangaConnector
private Manga[] ParsePublicationsFromHtml(HtmlDocument document)
{
if (!document.DocumentNode.SelectSingleNode("//div[@class='comics-grid']").ChildNodes
.Any(node => node.HasClass("entry")))
return Array.Empty<Manga>();
List<string> urls = document.DocumentNode
.SelectNodes(
@ -134,8 +137,8 @@ public class Mangaworld: MangaConnector
foreach (HtmlNode volNode in document.DocumentNode.SelectNodes(
"//div[contains(concat(' ',normalize-space(@class),' '),'chapters-wrapper')]//div[contains(concat(' ',normalize-space(@class),' '),'volume-element')]"))
{
string volume = volNode.SelectSingleNode("//p[contains(concat(' ',normalize-space(@class),' '),'volume-name')]").InnerText.Split(' ')[^1];
foreach (HtmlNode chNode in volNode.SelectNodes("//div[contains(concat(' ',normalize-space(@class),' '),'volume-chapters')]/div[@class='chapter']"))
string volume = volNode.SelectNodes("div").First(node => node.HasClass("volume")).SelectSingleNode("p").InnerText.Split(' ')[^1];
foreach (HtmlNode chNode in volNode.SelectNodes("div").First(node => node.HasClass("volume-chapters")).SelectNodes("div"))
{
string number = chNode.SelectSingleNode("a").SelectSingleNode("span").InnerText.Split(" ")[^1];
string url = chNode.SelectSingleNode("a").GetAttributeValue("href", "");

View File

@ -13,6 +13,8 @@ public partial class Tranga : GlobalBase
public Tranga(Logger? logger, TrangaSettings settings) : base(logger, settings)
{
Log("\n\n _______ \n|_ _|.----..---.-..-----..-----..---.-.\n | | | _|| _ || || _ || _ |\n |___| |__| |___._||__|__||___ ||___._|\n |_____| \n\n");
Log(settings.ToString());
keepRunning = true;
_connectors = new HashSet<MangaConnector>()
{

View File

@ -23,13 +23,13 @@ public class TrangaSettings
string lockFilePath = $"{settingsFilePath}.lock";
if (File.Exists(settingsFilePath) && !File.Exists(lockFilePath))
{//Load from settings file
FileStream lockFile = File.Create(lockFilePath,0, FileOptions.DeleteOnClose);
FileStream lockFile = File.Create(lockFilePath,0, FileOptions.DeleteOnClose); //lock settingsfile
string settingsStr = File.ReadAllText(settingsFilePath);
TrangaSettings settings = JsonConvert.DeserializeObject<TrangaSettings>(settingsStr)!;
this.downloadLocation = downloadLocation ?? settings.downloadLocation;
this.workingDirectory = workingDirectory ?? settings.workingDirectory;
this.apiPortNumber = apiPortNumber ?? settings.apiPortNumber;
lockFile.Close();
lockFile.Close(); //unlock settingsfile
}
else if(!File.Exists(settingsFilePath))
{//No settings file exists
@ -132,4 +132,15 @@ public class TrangaSettings
{
return Path.Join(this.coverImageCache, manga.coverFileNameInCache);
}
public override string ToString()
{
return $"TrangaSettings:\n" +
$"\tDownloadLocation: {downloadLocation}\n" +
$"\tworkingDirectory: {workingDirectory}\n" +
$"\tjobsFolderPath: {jobsFolderPath}\n" +
$"\tsettingsFilePath: {settingsFilePath}\n" +
$"\t\tnotificationConnectors: {notificationConnectorsFilePath}\n" +
$"\t\tlibraryConnectors: {libraryConnectorsFilePath}\n";
}
}