aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common.Implementations
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2013-09-24 20:54:51 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2013-09-24 20:54:51 -0400
commitfe5a9232c84cea113336005b3c7cbd7fe77a2d80 (patch)
tree9fb1412f4a8ca4303ec276b6ab6e096f98eed58d /MediaBrowser.Common.Implementations
parent0ab379e271afe69372806ab0e24a874d3f085456 (diff)
moved a few things for mono
Diffstat (limited to 'MediaBrowser.Common.Implementations')
-rw-r--r--MediaBrowser.Common.Implementations/Archiving/ZipClient.cs87
-rw-r--r--MediaBrowser.Common.Implementations/BaseApplicationHost.cs59
-rw-r--r--MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj4
-rw-r--r--MediaBrowser.Common.Implementations/packages.config1
4 files changed, 121 insertions, 30 deletions
diff --git a/MediaBrowser.Common.Implementations/Archiving/ZipClient.cs b/MediaBrowser.Common.Implementations/Archiving/ZipClient.cs
new file mode 100644
index 000000000..39690eb07
--- /dev/null
+++ b/MediaBrowser.Common.Implementations/Archiving/ZipClient.cs
@@ -0,0 +1,87 @@
+using MediaBrowser.Model.IO;
+using SharpCompress.Archive.SevenZip;
+using SharpCompress.Common;
+using SharpCompress.Reader;
+using System.IO;
+
+namespace MediaBrowser.Common.Implementations.Archiving
+{
+ /// <summary>
+ /// Class DotNetZipClient
+ /// </summary>
+ public class ZipClient : IZipClient
+ {
+ /// <summary>
+ /// Extracts all.
+ /// </summary>
+ /// <param name="sourceFile">The source file.</param>
+ /// <param name="targetPath">The target path.</param>
+ /// <param name="overwriteExistingFiles">if set to <c>true</c> [overwrite existing files].</param>
+ public void ExtractAll(string sourceFile, string targetPath, bool overwriteExistingFiles)
+ {
+ using (var fileStream = File.OpenRead(sourceFile))
+ {
+ ExtractAll(fileStream, targetPath, overwriteExistingFiles);
+ }
+ }
+
+ /// <summary>
+ /// Extracts all.
+ /// </summary>
+ /// <param name="source">The source.</param>
+ /// <param name="targetPath">The target path.</param>
+ /// <param name="overwriteExistingFiles">if set to <c>true</c> [overwrite existing files].</param>
+ public void ExtractAll(Stream source, string targetPath, bool overwriteExistingFiles)
+ {
+ using (var reader = ReaderFactory.Open(source))
+ {
+ var options = ExtractOptions.ExtractFullPath;
+
+ if (overwriteExistingFiles)
+ {
+ options = options | ExtractOptions.Overwrite;
+ }
+
+ reader.WriteAllToDirectory(targetPath, options);
+ }
+ }
+
+ /// <summary>
+ /// Extracts all from7z.
+ /// </summary>
+ /// <param name="sourceFile">The source file.</param>
+ /// <param name="targetPath">The target path.</param>
+ /// <param name="overwriteExistingFiles">if set to <c>true</c> [overwrite existing files].</param>
+ public void ExtractAllFrom7z(string sourceFile, string targetPath, bool overwriteExistingFiles)
+ {
+ using (var fileStream = File.OpenRead(sourceFile))
+ {
+ ExtractAllFrom7z(fileStream, targetPath, overwriteExistingFiles);
+ }
+ }
+
+ /// <summary>
+ /// Extracts all from7z.
+ /// </summary>
+ /// <param name="source">The source.</param>
+ /// <param name="targetPath">The target path.</param>
+ /// <param name="overwriteExistingFiles">if set to <c>true</c> [overwrite existing files].</param>
+ public void ExtractAllFrom7z(Stream source, string targetPath, bool overwriteExistingFiles)
+ {
+ using (var archive = SevenZipArchive.Open(source))
+ {
+ using (var reader = archive.ExtractAllEntries())
+ {
+ var options = ExtractOptions.ExtractFullPath;
+
+ if (overwriteExistingFiles)
+ {
+ options = options | ExtractOptions.Overwrite;
+ }
+
+ reader.WriteAllToDirectory(targetPath, options);
+ }
+ }
+ }
+ }
+}
diff --git a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs
index c0ac6a4b3..0d96df9a2 100644
--- a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs
+++ b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs
@@ -1,5 +1,6 @@
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Events;
+using MediaBrowser.Common.Implementations.Archiving;
using MediaBrowser.Common.Implementations.NetworkManagement;
using MediaBrowser.Common.Implementations.ScheduledTasks;
using MediaBrowser.Common.Implementations.Security;
@@ -10,6 +11,7 @@ using MediaBrowser.Common.Plugins;
using MediaBrowser.Common.ScheduledTasks;
using MediaBrowser.Common.Security;
using MediaBrowser.Common.Updates;
+using MediaBrowser.Model.IO;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Updates;
@@ -150,6 +152,12 @@ namespace MediaBrowser.Common.Implementations
protected IInstallationManager InstallationManager { get; set; }
/// <summary>
+ /// Gets or sets the zip client.
+ /// </summary>
+ /// <value>The zip client.</value>
+ protected IZipClient ZipClient { get; set; }
+
+ /// <summary>
/// Initializes a new instance of the <see cref="BaseApplicationHost{TApplicationPathsType}"/> class.
/// </summary>
protected BaseApplicationHost(TApplicationPathsType applicationPaths, ILogManager logManager)
@@ -202,13 +210,28 @@ namespace MediaBrowser.Common.Implementations
{
Resolve<ITaskManager>().AddTasks(GetExports<IScheduledTask>(false));
- Task.Run(() => ConfigureAutoRunAtStartup());
+ Task.Run(() => ConfigureAutorun());
ConfigurationManager.ConfigurationUpdated += OnConfigurationUpdated;
});
}
/// <summary>
+ /// Configures the autorun.
+ /// </summary>
+ private void ConfigureAutorun()
+ {
+ try
+ {
+ ConfigureAutoRunAtStartup(ConfigurationManager.CommonConfiguration.RunAtStartup);
+ }
+ catch (Exception ex)
+ {
+ Logger.ErrorException("Error configuring autorun", ex);
+ }
+ }
+
+ /// <summary>
/// Gets the composable part assemblies.
/// </summary>
/// <returns>IEnumerable{Assembly}.</returns>
@@ -281,6 +304,9 @@ namespace MediaBrowser.Common.Implementations
InstallationManager = new InstallationManager(Logger, this, ApplicationPaths, HttpClient, JsonSerializer, SecurityManager, NetworkManager, ConfigurationManager);
RegisterSingleInstance(InstallationManager);
+
+ ZipClient = new ZipClient();
+ RegisterSingleInstance(ZipClient);
});
}
@@ -454,11 +480,6 @@ namespace MediaBrowser.Common.Implementations
}
/// <summary>
- /// Defines the full path to our shortcut in the start menu
- /// </summary>
- protected abstract string ProductShortcutPath { get; }
-
- /// <summary>
/// Handles the ConfigurationUpdated event of the ConfigurationManager control.
/// </summary>
/// <param name="sender">The source of the event.</param>
@@ -466,32 +487,10 @@ namespace MediaBrowser.Common.Implementations
/// <exception cref="System.NotImplementedException"></exception>
protected virtual void OnConfigurationUpdated(object sender, EventArgs e)
{
- ConfigureAutoRunAtStartup();
+ ConfigureAutorun();
}
- /// <summary>
- /// Configures the auto run at startup.
- /// </summary>
- private void ConfigureAutoRunAtStartup()
- {
- if (ConfigurationManager.CommonConfiguration.RunAtStartup)
- {
- //Copy our shortut into the startup folder for this user
- File.Copy(ProductShortcutPath, Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), Path.GetFileName(ProductShortcutPath) ?? "MBstartup.lnk"), true);
- }
- else
- {
- //Remove our shortcut from the startup folder for this user
- try
- {
- File.Delete(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), Path.GetFileName(ProductShortcutPath) ?? "MBstartup.lnk"));
- }
- catch (FileNotFoundException)
- {
- //This is okay - trying to remove it anyway
- }
- }
- }
+ protected abstract void ConfigureAutoRunAtStartup(bool autorun);
/// <summary>
/// Removes the plugin.
diff --git a/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj b/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj
index 79514b5cb..11da950f7 100644
--- a/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj
+++ b/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj
@@ -37,6 +37,9 @@
<RunPostBuildEvent>Always</RunPostBuildEvent>
</PropertyGroup>
<ItemGroup>
+ <Reference Include="SharpCompress">
+ <HintPath>..\packages\sharpcompress.0.10.1.3\lib\net40\SharpCompress.dll</HintPath>
+ </Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
@@ -58,6 +61,7 @@
<Compile Include="..\SharedVersion.cs">
<Link>Properties\SharedVersion.cs</Link>
</Compile>
+ <Compile Include="Archiving\ZipClient.cs" />
<Compile Include="BaseApplicationHost.cs" />
<Compile Include="BaseApplicationPaths.cs" />
<Compile Include="Configuration\BaseConfigurationManager.cs" />
diff --git a/MediaBrowser.Common.Implementations/packages.config b/MediaBrowser.Common.Implementations/packages.config
index 4be861cce..d03cb14e0 100644
--- a/MediaBrowser.Common.Implementations/packages.config
+++ b/MediaBrowser.Common.Implementations/packages.config
@@ -2,5 +2,6 @@
<packages>
<package id="NLog" version="2.0.1.2" targetFramework="net45" />
<package id="ServiceStack.Text" version="3.9.62" targetFramework="net45" />
+ <package id="sharpcompress" version="0.10.1.3" targetFramework="net45" />
<package id="SimpleInjector" version="2.3.5" targetFramework="net45" />
</packages> \ No newline at end of file