2013-07-05 04:43:28 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Reflection;
|
2013-07-05 06:30:45 +00:00
|
|
|
|
using System.Security.AccessControl;
|
|
|
|
|
using NLog;
|
2013-07-05 04:43:28 +00: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;
|
|
|
|
|
|
|
|
|
|
public AppFolderInfo(IDiskProvider diskProvider)
|
|
|
|
|
{
|
|
|
|
|
_diskProvider = diskProvider;
|
|
|
|
|
AppDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData, Environment.SpecialFolderOption.DoNotVerify), "NzbDrone");
|
|
|
|
|
StartUpFolder = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName;
|
|
|
|
|
TempFolder = Path.GetTempPath();
|
|
|
|
|
|
|
|
|
|
if (!_diskProvider.FolderExists(AppDataFolder))
|
|
|
|
|
{
|
2013-07-05 06:30:45 +00:00
|
|
|
|
MigrateFromAppData();
|
2013-07-05 04:43:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-05 06:30:45 +00:00
|
|
|
|
SetPermissions();
|
|
|
|
|
}
|
2013-07-05 04:43:28 +00:00
|
|
|
|
|
2013-07-05 06:30:45 +00:00
|
|
|
|
private void MigrateFromAppData()
|
2013-07-05 04:43:28 +00:00
|
|
|
|
{
|
|
|
|
|
var oldAppDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.DoNotVerify), "NzbDrone");
|
|
|
|
|
|
|
|
|
|
if (_diskProvider.FolderExists(oldAppDataFolder))
|
|
|
|
|
{
|
|
|
|
|
_diskProvider.MoveFolder(oldAppDataFolder, AppDataFolder);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_diskProvider.CreateFolder(AppDataFolder);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-05 06:30:45 +00:00
|
|
|
|
private void SetPermissions()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_diskProvider.SetPermissions(AppDataFolder, "Everyone", FileSystemRights.FullControl, AccessControlType.Allow);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
//Todo: Add logging
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-05 04:43:28 +00:00
|
|
|
|
public string AppDataFolder { get; private set; }
|
|
|
|
|
|
|
|
|
|
public string StartUpFolder { get; private set; }
|
|
|
|
|
|
|
|
|
|
public String TempFolder { get; private set; }
|
|
|
|
|
}
|
|
|
|
|
}
|