From fe5a9232c84cea113336005b3c7cbd7fe77a2d80 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 24 Sep 2013 20:54:51 -0400 Subject: moved a few things for mono --- .../Archiving/ZipClient.cs | 87 ++++++++++++++++++++++ .../BaseApplicationHost.cs | 59 ++++++++------- .../MediaBrowser.Common.Implementations.csproj | 4 + .../packages.config | 1 + 4 files changed, 121 insertions(+), 30 deletions(-) create mode 100644 MediaBrowser.Common.Implementations/Archiving/ZipClient.cs (limited to 'MediaBrowser.Common.Implementations') 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 +{ + /// + /// Class DotNetZipClient + /// + public class ZipClient : IZipClient + { + /// + /// Extracts all. + /// + /// The source file. + /// The target path. + /// if set to true [overwrite existing files]. + public void ExtractAll(string sourceFile, string targetPath, bool overwriteExistingFiles) + { + using (var fileStream = File.OpenRead(sourceFile)) + { + ExtractAll(fileStream, targetPath, overwriteExistingFiles); + } + } + + /// + /// Extracts all. + /// + /// The source. + /// The target path. + /// if set to true [overwrite existing files]. + 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); + } + } + + /// + /// Extracts all from7z. + /// + /// The source file. + /// The target path. + /// if set to true [overwrite existing files]. + public void ExtractAllFrom7z(string sourceFile, string targetPath, bool overwriteExistingFiles) + { + using (var fileStream = File.OpenRead(sourceFile)) + { + ExtractAllFrom7z(fileStream, targetPath, overwriteExistingFiles); + } + } + + /// + /// Extracts all from7z. + /// + /// The source. + /// The target path. + /// if set to true [overwrite existing files]. + 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; @@ -149,6 +151,12 @@ namespace MediaBrowser.Common.Implementations /// The installation manager. protected IInstallationManager InstallationManager { get; set; } + /// + /// Gets or sets the zip client. + /// + /// The zip client. + protected IZipClient ZipClient { get; set; } + /// /// Initializes a new instance of the class. /// @@ -202,12 +210,27 @@ namespace MediaBrowser.Common.Implementations { Resolve().AddTasks(GetExports(false)); - Task.Run(() => ConfigureAutoRunAtStartup()); + Task.Run(() => ConfigureAutorun()); ConfigurationManager.ConfigurationUpdated += OnConfigurationUpdated; }); } + /// + /// Configures the autorun. + /// + private void ConfigureAutorun() + { + try + { + ConfigureAutoRunAtStartup(ConfigurationManager.CommonConfiguration.RunAtStartup); + } + catch (Exception ex) + { + Logger.ErrorException("Error configuring autorun", ex); + } + } + /// /// Gets the composable part assemblies. /// @@ -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); }); } @@ -453,11 +479,6 @@ namespace MediaBrowser.Common.Implementations } } - /// - /// Defines the full path to our shortcut in the start menu - /// - protected abstract string ProductShortcutPath { get; } - /// /// Handles the ConfigurationUpdated event of the ConfigurationManager control. /// @@ -466,32 +487,10 @@ namespace MediaBrowser.Common.Implementations /// protected virtual void OnConfigurationUpdated(object sender, EventArgs e) { - ConfigureAutoRunAtStartup(); + ConfigureAutorun(); } - /// - /// Configures the auto run at startup. - /// - 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); /// /// 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 @@ Always + + ..\packages\sharpcompress.0.10.1.3\lib\net40\SharpCompress.dll + @@ -58,6 +61,7 @@ Properties\SharedVersion.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 @@ + \ No newline at end of file -- cgit v1.2.3