1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2024-12-29 02:55:38 +00:00
Lidarr/NzbDrone.Common/EnvironmentInfo/AppFolderInfo.cs

76 lines
2.3 KiB
C#
Raw Normal View History

using System;
using System.IO;
using System.Reflection;
using System.Security.AccessControl;
using System.Security.Principal;
using NLog;
2013-08-31 01:42:30 +00:00
using NzbDrone.Common.Instrumentation;
namespace NzbDrone.Common.EnvironmentInfo
{
public interface IAppFolderInfo
{
string AppDataFolder { get; }
string TempFolder { get; }
string StartUpFolder { get; }
}
public class AppFolderInfo : IAppFolderInfo
{
private readonly IDiskProvider _diskProvider;
2013-07-09 00:47:28 +00:00
private readonly Logger _logger;
2013-06-19 21:08:56 +00:00
private readonly Environment.SpecialFolder DATA_SPECIAL_FOLDER = Environment.SpecialFolder.CommonApplicationData;
public AppFolderInfo(IDiskProvider diskProvider, IStartupArguments startupArguments)
2013-07-27 04:53:05 +00:00
{
_diskProvider = diskProvider;
2013-06-19 21:08:56 +00:00
2013-07-27 04:53:05 +00:00
if (OsInfo.IsLinux)
{
DATA_SPECIAL_FOLDER = Environment.SpecialFolder.ApplicationData;
}
2013-06-19 21:08:56 +00:00
2013-08-31 01:42:30 +00:00
_logger = NzbDroneLogger.GetLogger(this);
if (startupArguments.Args.ContainsKey(StartupArguments.APPDATA))
{
AppDataFolder = startupArguments.Args[StartupArguments.APPDATA];
}
else
{
AppDataFolder = Path.Combine(Environment.GetFolderPath(DATA_SPECIAL_FOLDER, Environment.SpecialFolderOption.None), "NzbDrone");
}
_diskProvider.EnsureFolder(AppDataFolder);
StartUpFolder = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName;
TempFolder = Path.GetTempPath();
2013-07-27 04:53:05 +00:00
diskProvider.EnsureFolder(AppDataFolder);
2013-07-26 06:55:15 +00:00
if (!OsInfo.IsLinux)
{
SetPermissions();
}
}
private void SetPermissions()
{
try
{
_diskProvider.SetPermissions(AppDataFolder, WellKnownSidType.WorldSid, FileSystemRights.FullControl, AccessControlType.Allow);
}
catch (Exception ex)
{
2013-07-09 00:47:28 +00:00
_logger.WarnException("Coudn't set app folder permission", ex);
}
}
public string AppDataFolder { get; private set; }
public string StartUpFolder { get; private set; }
public String TempFolder { get; private set; }
}
}