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