2
0

Compare commits

..

No commits in common. "6d723b6355c84d39ea4f454a7ce05315bbebd42c" and "63b493fa9ce4d858a8577584a3ae8959e124275d" have entirely different histories.

4 changed files with 10 additions and 13 deletions

View File

@ -49,8 +49,6 @@ internal sealed class TrangaCli : Command<TrangaCli.Settings>
if(settings.workingDirectory is not null) if(settings.workingDirectory is not null)
TrangaSettings.LoadFromWorkingDirectory(settings.workingDirectory); TrangaSettings.LoadFromWorkingDirectory(settings.workingDirectory);
else
TrangaSettings.CreateOrUpdate();
if(settings.downloadLocation is not null) if(settings.downloadLocation is not null)
TrangaSettings.CreateOrUpdate(downloadDirectory: settings.downloadLocation); TrangaSettings.CreateOrUpdate(downloadDirectory: settings.downloadLocation);

View File

@ -198,7 +198,7 @@ public class Server : GlobalBase
SendResponse(HttpStatusCode.OK, response, _parent.jobBoss.jobs.Where(jjob => jjob is DownloadNewChapters).OrderBy(jjob => ((DownloadNewChapters)jjob).manga.sortName)); SendResponse(HttpStatusCode.OK, response, _parent.jobBoss.jobs.Where(jjob => jjob is DownloadNewChapters).OrderBy(jjob => ((DownloadNewChapters)jjob).manga.sortName));
break; break;
case "Settings": case "Settings":
SendResponse(HttpStatusCode.OK, response, TrangaSettings.AsJObject()); SendResponse(HttpStatusCode.OK, response, TrangaSettings.Serialize());
break; break;
case "Settings/userAgent": case "Settings/userAgent":
SendResponse(HttpStatusCode.OK, response, TrangaSettings.userAgent); SendResponse(HttpStatusCode.OK, response, TrangaSettings.userAgent);

View File

@ -41,8 +41,6 @@ public partial class Tranga : GlobalBase
if (wdp) if (wdp)
TrangaSettings.LoadFromWorkingDirectory(workingDirectoryPath![0]); TrangaSettings.LoadFromWorkingDirectory(workingDirectoryPath![0]);
else
TrangaSettings.CreateOrUpdate();
if(dlp) if(dlp)
TrangaSettings.CreateOrUpdate(downloadDirectory: downloadLocationPath![0]); TrangaSettings.CreateOrUpdate(downloadDirectory: downloadLocationPath![0]);

View File

@ -37,9 +37,14 @@ public static class TrangaSettings
public static void LoadFromWorkingDirectory(string directory) public static void LoadFromWorkingDirectory(string directory)
{ {
TrangaSettings.workingDirectory = directory; TrangaSettings.workingDirectory = directory;
if(File.Exists(settingsFilePath)) if (!File.Exists(settingsFilePath))
{
return;
}
else
{
Deserialize(File.ReadAllText(settingsFilePath)); Deserialize(File.ReadAllText(settingsFilePath));
else return; }
Directory.CreateDirectory(downloadLocation); Directory.CreateDirectory(downloadLocation);
Directory.CreateDirectory(workingDirectory); Directory.CreateDirectory(workingDirectory);
@ -48,8 +53,6 @@ public static class TrangaSettings
public static void CreateOrUpdate(string? downloadDirectory = null, string? pWorkingDirectory = null, int? pApiPortNumber = null, string? pUserAgent = null, bool? pAprilFoolsMode = null) public static void CreateOrUpdate(string? downloadDirectory = null, string? pWorkingDirectory = null, int? pApiPortNumber = null, string? pUserAgent = null, bool? pAprilFoolsMode = null)
{ {
if(pWorkingDirectory is null && File.Exists(settingsFilePath))
LoadFromWorkingDirectory(workingDirectory);
TrangaSettings.downloadLocation = downloadDirectory ?? TrangaSettings.downloadLocation; TrangaSettings.downloadLocation = downloadDirectory ?? TrangaSettings.downloadLocation;
TrangaSettings.workingDirectory = pWorkingDirectory ?? TrangaSettings.workingDirectory; TrangaSettings.workingDirectory = pWorkingDirectory ?? TrangaSettings.workingDirectory;
TrangaSettings.apiPortNumber = pApiPortNumber ?? TrangaSettings.apiPortNumber; TrangaSettings.apiPortNumber = pApiPortNumber ?? TrangaSettings.apiPortNumber;
@ -151,7 +154,7 @@ public static class TrangaSettings
File.WriteAllText(settingsFilePath, Serialize()); File.WriteAllText(settingsFilePath, Serialize());
} }
public static JObject AsJObject() public static string Serialize()
{ {
JObject jobj = new JObject(); JObject jobj = new JObject();
jobj.Add("downloadLocation", JToken.FromObject(TrangaSettings.downloadLocation)); jobj.Add("downloadLocation", JToken.FromObject(TrangaSettings.downloadLocation));
@ -161,11 +164,9 @@ public static class TrangaSettings
jobj.Add("aprilFoolsMode", JToken.FromObject(TrangaSettings.aprilFoolsMode)); jobj.Add("aprilFoolsMode", JToken.FromObject(TrangaSettings.aprilFoolsMode));
jobj.Add("version", JToken.FromObject(TrangaSettings.version)); jobj.Add("version", JToken.FromObject(TrangaSettings.version));
jobj.Add("requestLimits", JToken.FromObject(TrangaSettings.requestLimits)); jobj.Add("requestLimits", JToken.FromObject(TrangaSettings.requestLimits));
return jobj; return jobj.ToString();
} }
public static string Serialize() => AsJObject().ToString();
public static void Deserialize(string serialized) public static void Deserialize(string serialized)
{ {
JObject jobj = JObject.Parse(serialized); JObject jobj = JObject.Parse(serialized);