2013-07-05 07:43:28 +03:00
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
using System.Reflection;
|
2013-07-05 09:30:45 +03:00
|
|
|
using System.Security.AccessControl;
|
|
|
|
using NLog;
|
2013-07-05 07:43:28 +03:00
|
|
|
|
|
|
|
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 03:47:28 +03:00
|
|
|
private readonly Logger _logger;
|
2013-06-20 00:08:56 +03:00
|
|
|
private readonly Environment.SpecialFolder DATA_SPECIAL_FOLDER = Environment.SpecialFolder.CommonApplicationData;
|
2013-07-26 09:48:35 +03:00
|
|
|
|
2013-07-05 07:43:28 +03:00
|
|
|
|
2013-07-27 07:53:05 +03:00
|
|
|
public AppFolderInfo(IDiskProvider diskProvider)
|
|
|
|
{
|
|
|
|
_diskProvider = diskProvider;
|
2013-06-20 00:08:56 +03:00
|
|
|
|
2013-07-27 07:53:05 +03:00
|
|
|
if (OsInfo.IsLinux)
|
|
|
|
{
|
|
|
|
DATA_SPECIAL_FOLDER = Environment.SpecialFolder.ApplicationData;
|
|
|
|
}
|
2013-06-20 00:08:56 +03:00
|
|
|
|
2013-07-27 07:53:05 +03:00
|
|
|
_logger = LogManager.GetCurrentClassLogger();
|
2013-07-05 07:43:28 +03:00
|
|
|
|
2013-07-27 07:53:05 +03:00
|
|
|
AppDataFolder = Path.Combine(Environment.GetFolderPath(DATA_SPECIAL_FOLDER, Environment.SpecialFolderOption.Create), "NzbDrone");
|
2013-07-26 09:48:35 +03:00
|
|
|
StartUpFolder = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName;
|
|
|
|
TempFolder = Path.GetTempPath();
|
2013-07-05 07:43:28 +03:00
|
|
|
|
2013-07-27 07:53:05 +03:00
|
|
|
diskProvider.EnsureFolder(AppDataFolder);
|
|
|
|
|
2013-07-26 09:55:15 +03:00
|
|
|
if (!OsInfo.IsLinux)
|
|
|
|
{
|
|
|
|
SetPermissions();
|
|
|
|
}
|
2013-07-05 07:43:28 +03:00
|
|
|
}
|
|
|
|
|
2013-07-05 09:30:45 +03:00
|
|
|
private void SetPermissions()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
_diskProvider.SetPermissions(AppDataFolder, "Everyone", FileSystemRights.FullControl, AccessControlType.Allow);
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2013-07-09 03:47:28 +03:00
|
|
|
_logger.WarnException("Coudn't set app folder permission", ex);
|
2013-07-05 09:30:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-05 07:43:28 +03:00
|
|
|
public string AppDataFolder { get; private set; }
|
|
|
|
|
|
|
|
public string StartUpFolder { get; private set; }
|
|
|
|
|
|
|
|
public String TempFolder { get; private set; }
|
|
|
|
}
|
|
|
|
}
|