mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-14 18:57:39 -07:00
Added NzbDrone.Update, refactored some common wrappers to NzbDrone.Common
This commit is contained in:
parent
7563527eac
commit
fb0b505bf4
42 changed files with 1316 additions and 97 deletions
71
NzbDrone.Update/NzbDrone.Update.csproj
Normal file
71
NzbDrone.Update/NzbDrone.Update.csproj
Normal file
|
@ -0,0 +1,71 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{4CCC53CD-8D5E-4CC4-97D2-5C9312AC2BD7}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>NzbDrone.Update</RootNamespace>
|
||||
<AssemblyName>NzbDrone.Update</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="NLog">
|
||||
<HintPath>..\packages\NLog.2.0.0.2000\lib\net40\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Providers\DiskProvider.cs" />
|
||||
<Compile Include="Providers\UpdateProvider.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\NzbDrone.Common\NzbDrone.Common.csproj">
|
||||
<Project>{F2BE0FDF-6E47-4827-A420-DD4EF82407F8}</Project>
|
||||
<Name>NzbDrone.Common</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
15
NzbDrone.Update/Program.cs
Normal file
15
NzbDrone.Update/Program.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace NzbDrone.Update
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
36
NzbDrone.Update/Properties/AssemblyInfo.cs
Normal file
36
NzbDrone.Update/Properties/AssemblyInfo.cs
Normal file
|
@ -0,0 +1,36 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("NzbDrone.Update")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Microsoft")]
|
||||
[assembly: AssemblyProduct("NzbDrone.Update")]
|
||||
[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("e4560a3d-8053-4d57-a260-bfe52f4cc357")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
87
NzbDrone.Update/Providers/DiskProvider.cs
Normal file
87
NzbDrone.Update/Providers/DiskProvider.cs
Normal file
|
@ -0,0 +1,87 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
|
||||
namespace NzbDrone.Update.Providers
|
||||
{
|
||||
public class DiskProvider
|
||||
{
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public virtual bool FolderExists(string path)
|
||||
{
|
||||
return Directory.Exists(path);
|
||||
}
|
||||
|
||||
public virtual bool FileExists(string path)
|
||||
{
|
||||
return File.Exists(path);
|
||||
}
|
||||
|
||||
public virtual string[] GetDirectories(string path)
|
||||
{
|
||||
return Directory.GetDirectories(path);
|
||||
}
|
||||
|
||||
public virtual string[] GetFiles(string path, SearchOption searchOption)
|
||||
{
|
||||
return Directory.GetFiles(path, "*.*", searchOption);
|
||||
}
|
||||
|
||||
public virtual long GetDirectorySize(string path)
|
||||
{
|
||||
return GetFiles(path, SearchOption.AllDirectories).Sum(e => new FileInfo(e).Length);
|
||||
}
|
||||
|
||||
public virtual long GetSize(string path)
|
||||
{
|
||||
var fi = new FileInfo(path);
|
||||
return fi.Length;
|
||||
//return new FileInfo(path).Length;
|
||||
}
|
||||
|
||||
public virtual String CreateDirectory(string path)
|
||||
{
|
||||
return Directory.CreateDirectory(path).FullName;
|
||||
}
|
||||
|
||||
public virtual void DeleteFile(string path)
|
||||
{
|
||||
File.Delete(path);
|
||||
}
|
||||
|
||||
public virtual void MoveFile(string sourcePath, string destinationPath)
|
||||
{
|
||||
File.Move(sourcePath, destinationPath);
|
||||
}
|
||||
|
||||
public virtual void DeleteFolder(string path, bool recursive)
|
||||
{
|
||||
Directory.Delete(path, recursive);
|
||||
}
|
||||
|
||||
public virtual DateTime DirectoryDateCreated(string path)
|
||||
{
|
||||
return Directory.GetCreationTime(path);
|
||||
}
|
||||
|
||||
public virtual IEnumerable<FileInfo> GetFileInfos(string path, string pattern, SearchOption searchOption)
|
||||
{
|
||||
return new DirectoryInfo(path).GetFiles(pattern, searchOption);
|
||||
}
|
||||
|
||||
public virtual void MoveDirectory(string source, string destination)
|
||||
{
|
||||
Directory.Move(source, destination);
|
||||
}
|
||||
|
||||
public virtual void InheritFolderPermissions(string filename)
|
||||
{
|
||||
var fs = File.GetAccessControl(filename);
|
||||
fs.SetAccessRuleProtection(false, false);
|
||||
File.SetAccessControl(filename, fs);
|
||||
}
|
||||
}
|
||||
}
|
56
NzbDrone.Update/Providers/UpdateProvider.cs
Normal file
56
NzbDrone.Update/Providers/UpdateProvider.cs
Normal file
|
@ -0,0 +1,56 @@
|
|||
using System.IO;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
|
||||
namespace NzbDrone.Update.Providers
|
||||
{
|
||||
public class UpdateProvider
|
||||
{
|
||||
private readonly DiskProvider _diskProvider;
|
||||
private readonly EnviromentProvider _enviromentProvider;
|
||||
private readonly ConsoleProvider _consoleProvider;
|
||||
private readonly ServiceProvider _serviceProvider;
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public UpdateProvider(DiskProvider diskProvider, EnviromentProvider enviromentProvider, ConsoleProvider consoleProvider,
|
||||
ServiceProvider serviceProvider)
|
||||
{
|
||||
_diskProvider = diskProvider;
|
||||
_enviromentProvider = enviromentProvider;
|
||||
_consoleProvider = consoleProvider;
|
||||
_serviceProvider = serviceProvider;
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
var sandboxFolder = Path.Combine(_enviromentProvider.StartUpPath, "nzbdrone_update");
|
||||
Logger.Info("Looking for update package at {0}", sandboxFolder);
|
||||
|
||||
Logger.Info("Verifying Update Folder");
|
||||
if (!_diskProvider.FolderExists(sandboxFolder))
|
||||
{
|
||||
Logger.Error("Update folder doesn't exist {0}", sandboxFolder);
|
||||
_consoleProvider.UpdateFolderDoestExist(sandboxFolder);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_serviceProvider.ServiceExist(ServiceProvider.NzbDroneServiceName))
|
||||
{
|
||||
_serviceProvider.Stop(ServiceProvider.NzbDroneServiceName);
|
||||
}
|
||||
|
||||
//Stop NzbDrone Process
|
||||
|
||||
//Create backup of current folder
|
||||
|
||||
//Copy update folder on top of the existing folder
|
||||
|
||||
//Happy: Start Service, Process?
|
||||
//Happy: Cleanup
|
||||
|
||||
//Sad: delete fucked up folder
|
||||
//Sad: restore backup
|
||||
//Sad: start service, process
|
||||
}
|
||||
}
|
||||
}
|
4
NzbDrone.Update/packages.config
Normal file
4
NzbDrone.Update/packages.config
Normal file
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="NLog" version="2.0.0.2000" />
|
||||
</packages>
|
Loading…
Add table
Add a link
Reference in a new issue