diff --git a/JMMServer/AniDB_API/Commands/AniDBHTTPCommand_GetFullAnime.cs b/JMMServer/AniDB_API/Commands/AniDBHTTPCommand_GetFullAnime.cs index cd0ae4804..072f35241 100644 --- a/JMMServer/AniDB_API/Commands/AniDBHTTPCommand_GetFullAnime.cs +++ b/JMMServer/AniDB_API/Commands/AniDBHTTPCommand_GetFullAnime.cs @@ -4,11 +4,14 @@ using System.Xml; using JMMServer; using JMMServer.Providers.Azure; +using NLog; namespace AniDBAPI.Commands { public class AniDBHTTPCommand_GetFullAnime : AniDBHTTPCommand, IAniDBHTTPCommand { + private static Logger logger = LogManager.GetCurrentClassLogger(); + private int animeID; public int AnimeID @@ -146,19 +149,34 @@ private XmlDocument LoadAnimeHTTPFromFile(int animeID) private void WriteAnimeHTTPToFile(int animeID, string xml) { - string filePath = ServerSettings.AnimeXmlDirectory; + try + { + string filePath = ServerSettings.AnimeXmlDirectory; + if (!Directory.Exists(filePath)) + Directory.CreateDirectory(filePath); - if (!Directory.Exists(filePath)) - Directory.CreateDirectory(filePath); + string fileName = $"AnimeDoc_{animeID}.xml"; + string fileNameWithPath = Path.Combine(filePath, fileName); - string fileName = string.Format("AnimeDoc_{0}.xml", animeID); - string fileNameWithPath = Path.Combine(filePath, fileName); + // First check to make sure we not rights issue + if (!Utils.IsDirectoryWritable(filePath)) + Utils.GrantAccess(filePath); - StreamWriter sw; - sw = File.CreateText(fileNameWithPath); - sw.Write(xml); - sw.Close(); + // Check again and only if write-able we create it + if (Utils.IsDirectoryWritable(filePath)) + { + StreamWriter sw; + sw = File.CreateText(fileNameWithPath); + sw.Write(xml); + sw.Close(); + } + + } + catch (Exception ex) + { + logger.Error($"Error occurred during WriteAnimeHTTPToFile(): {ex}"); + } } public virtual enHelperActivityType Process() diff --git a/JMMServer/ServerSettings.cs b/JMMServer/ServerSettings.cs index 449e49ad1..0656dee03 100644 --- a/JMMServer/ServerSettings.cs +++ b/JMMServer/ServerSettings.cs @@ -2202,32 +2202,30 @@ public static void DebugSettingsToLog() System.Reflection.Assembly a = System.Reflection.Assembly.GetExecutingAssembly(); try { - if (a != null) - { - logger.Info(string.Format("JMM Server Version: v{0}", Utils.GetApplicationVersion(a))); - } + if(Utils.GetApplicationVersion(a) != null) + logger.Info($"JMM Server Version: v{Utils.GetApplicationVersion(a)}"); } catch (Exception ex) { - // oopps, can't create file - logger.Warn("Error in log: {0}", ex.ToString()); + logger.Warn("Error in log (server version lookup): {0}", ex.ToString()); } try { - logger.Info(string.Format("Database Version: {0}", DatabaseFactory.Instance.GetDatabaseVersion())); + if(DatabaseFactory.Instance != null) + logger.Info($"Database Version: {DatabaseFactory.Instance.GetDatabaseVersion()}"); } catch (Exception ex) { // oopps, can't create file - logger.Warn("Error in log: {0}", ex.Message); + logger.Warn("Error in log (database version lookup: {0}", ex.Message); } - logger.Info(string.Format("Operating System: {0}", Utils.GetOSInfo())); + logger.Info($"Operating System: {Utils.GetOSInfo()}"); string screenSize = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width.ToString() + "x" + System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height.ToString(); - logger.Info(string.Format("Screen Size: {0}", screenSize)); + logger.Info($"Screen Size: {screenSize}"); try @@ -2242,9 +2240,8 @@ public static void DebugSettingsToLog() if (File.Exists(mediaInfoPath)) { FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(mediaInfoPath); - mediaInfoVersion = string.Format("MediaInfo DLL {0}.{1}.{2}.{3} ({4})", fvi.FileMajorPart, - fvi.FileMinorPart, - fvi.FileBuildPart, fvi.FilePrivatePart, mediaInfoPath); + mediaInfoVersion = + $"MediaInfo DLL {fvi.FileMajorPart}.{fvi.FileMinorPart}.{fvi.FileBuildPart}.{fvi.FilePrivatePart} ({mediaInfoPath})"; } logger.Info(mediaInfoVersion); @@ -2259,8 +2256,9 @@ public static void DebugSettingsToLog() hasherInfoVersion = string.Format("Hasher DLL found at {0}", fullHasherexepath); logger.Info(hasherInfoVersion); } - catch + catch (Exception ex) { + logger.Error("Error in log (hasher / info): {0}", ex.Message); } logger.Info("-------------------------------------------------------");