mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-07-07 14:52:52 +01:00
update file system methods
This commit is contained in:
@@ -7,6 +7,7 @@ using SharpCompress.Reader;
|
||||
using SharpCompress.Reader.Zip;
|
||||
using System;
|
||||
using System.IO;
|
||||
using MediaBrowser.Common.IO;
|
||||
|
||||
namespace MediaBrowser.Common.Implementations.Archiving
|
||||
{
|
||||
@@ -15,7 +16,14 @@ namespace MediaBrowser.Common.Implementations.Archiving
|
||||
/// </summary>
|
||||
public class ZipClient : IZipClient
|
||||
{
|
||||
/// <summary>
|
||||
private IFileSystem _fileSystem;
|
||||
|
||||
public ZipClient(IFileSystem fileSystem)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extracts all.
|
||||
/// </summary>
|
||||
/// <param name="sourceFile">The source file.</param>
|
||||
@@ -23,7 +31,7 @@ namespace MediaBrowser.Common.Implementations.Archiving
|
||||
/// <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))
|
||||
using (var fileStream = _fileSystem.OpenRead(sourceFile))
|
||||
{
|
||||
ExtractAll(fileStream, targetPath, overwriteExistingFiles);
|
||||
}
|
||||
@@ -73,7 +81,7 @@ namespace MediaBrowser.Common.Implementations.Archiving
|
||||
/// <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))
|
||||
using (var fileStream = _fileSystem.OpenRead(sourceFile))
|
||||
{
|
||||
ExtractAllFrom7z(fileStream, targetPath, overwriteExistingFiles);
|
||||
}
|
||||
@@ -112,7 +120,7 @@ namespace MediaBrowser.Common.Implementations.Archiving
|
||||
/// <param name="overwriteExistingFiles">if set to <c>true</c> [overwrite existing files].</param>
|
||||
public void ExtractAllFromTar(string sourceFile, string targetPath, bool overwriteExistingFiles)
|
||||
{
|
||||
using (var fileStream = File.OpenRead(sourceFile))
|
||||
using (var fileStream = _fileSystem.OpenRead(sourceFile))
|
||||
{
|
||||
ExtractAllFromTar(fileStream, targetPath, overwriteExistingFiles);
|
||||
}
|
||||
@@ -150,7 +158,7 @@ namespace MediaBrowser.Common.Implementations.Archiving
|
||||
/// <param name="overwriteExistingFiles">if set to <c>true</c> [overwrite existing files].</param>
|
||||
public void ExtractAllFromRar(string sourceFile, string targetPath, bool overwriteExistingFiles)
|
||||
{
|
||||
using (var fileStream = File.OpenRead(sourceFile))
|
||||
using (var fileStream = _fileSystem.OpenRead(sourceFile))
|
||||
{
|
||||
ExtractAllFromRar(fileStream, targetPath, overwriteExistingFiles);
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ namespace MediaBrowser.Common.Implementations
|
||||
/// <summary>
|
||||
/// The _XML serializer
|
||||
/// </summary>
|
||||
protected readonly IXmlSerializer XmlSerializer = new XmlSerializer();
|
||||
protected readonly IXmlSerializer XmlSerializer;
|
||||
|
||||
/// <summary>
|
||||
/// Gets assemblies that failed to load
|
||||
@@ -180,7 +180,7 @@ namespace MediaBrowser.Common.Implementations
|
||||
{
|
||||
if (_deviceId == null)
|
||||
{
|
||||
_deviceId = new DeviceId(ApplicationPaths, LogManager.GetLogger("SystemId"));
|
||||
_deviceId = new DeviceId(ApplicationPaths, LogManager.GetLogger("SystemId"), FileSystemManager);
|
||||
}
|
||||
|
||||
return _deviceId.Value;
|
||||
@@ -199,6 +199,7 @@ namespace MediaBrowser.Common.Implementations
|
||||
ILogManager logManager,
|
||||
IFileSystem fileSystem)
|
||||
{
|
||||
XmlSerializer = new MediaBrowser.Common.Implementations.Serialization.XmlSerializer (fileSystem);
|
||||
FailedAssemblies = new List<string>();
|
||||
|
||||
ApplicationPaths = applicationPaths;
|
||||
@@ -473,7 +474,7 @@ namespace MediaBrowser.Common.Implementations
|
||||
InstallationManager = new InstallationManager(Logger, this, ApplicationPaths, HttpClient, JsonSerializer, SecurityManager, ConfigurationManager, FileSystemManager);
|
||||
RegisterSingleInstance(InstallationManager);
|
||||
|
||||
ZipClient = new ZipClient();
|
||||
ZipClient = new ZipClient(FileSystemManager);
|
||||
RegisterSingleInstance(ZipClient);
|
||||
|
||||
IsoManager = new IsoManager();
|
||||
@@ -650,7 +651,7 @@ namespace MediaBrowser.Common.Implementations
|
||||
{
|
||||
try
|
||||
{
|
||||
return Assembly.Load(File.ReadAllBytes((file)));
|
||||
return Assembly.Load(FileSystemManager.ReadAllBytes((file)));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace MediaBrowser.Common.Implementations
|
||||
{
|
||||
_dataDirectory = Path.Combine(ProgramDataPath, "data");
|
||||
|
||||
Directory.CreateDirectory(_dataDirectory);
|
||||
FileSystem.CreateDirectory(_dataDirectory);
|
||||
}
|
||||
|
||||
return _dataDirectory;
|
||||
@@ -152,7 +152,7 @@ namespace MediaBrowser.Common.Implementations
|
||||
{
|
||||
_cachePath = Path.Combine(ProgramDataPath, "cache");
|
||||
|
||||
Directory.CreateDirectory(_cachePath);
|
||||
FileSystem.CreateDirectory(_cachePath);
|
||||
}
|
||||
|
||||
return _cachePath;
|
||||
|
||||
@@ -121,7 +121,7 @@ namespace MediaBrowser.Common.Implementations.Configuration
|
||||
{
|
||||
var path = CommonApplicationPaths.SystemConfigurationFilePath;
|
||||
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
||||
FileSystem.CreateDirectory(Path.GetDirectoryName(path));
|
||||
|
||||
lock (_configurationSyncLock)
|
||||
{
|
||||
@@ -276,7 +276,7 @@ namespace MediaBrowser.Common.Implementations.Configuration
|
||||
_configurations.AddOrUpdate(key, configuration, (k, v) => configuration);
|
||||
|
||||
var path = GetConfigurationFile(key);
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
||||
FileSystem.CreateDirectory(Path.GetDirectoryName(path));
|
||||
|
||||
lock (_configurationSyncLock)
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using MediaBrowser.Common.IO;
|
||||
|
||||
namespace MediaBrowser.Common.Implementations.Configuration
|
||||
{
|
||||
@@ -18,7 +19,7 @@ namespace MediaBrowser.Common.Implementations.Configuration
|
||||
/// <param name="path">The path.</param>
|
||||
/// <param name="xmlSerializer">The XML serializer.</param>
|
||||
/// <returns>System.Object.</returns>
|
||||
public static object GetXmlConfiguration(Type type, string path, IXmlSerializer xmlSerializer)
|
||||
public static object GetXmlConfiguration(Type type, string path, IXmlSerializer xmlSerializer, IFileSystem fileSystem)
|
||||
{
|
||||
object configuration;
|
||||
|
||||
@@ -27,7 +28,7 @@ namespace MediaBrowser.Common.Implementations.Configuration
|
||||
// Use try/catch to avoid the extra file system lookup using File.Exists
|
||||
try
|
||||
{
|
||||
buffer = File.ReadAllBytes(path);
|
||||
buffer = fileSystem.ReadAllBytes(path);
|
||||
|
||||
configuration = xmlSerializer.DeserializeFromBytes(type, buffer);
|
||||
}
|
||||
@@ -46,10 +47,10 @@ namespace MediaBrowser.Common.Implementations.Configuration
|
||||
// If the file didn't exist before, or if something has changed, re-save
|
||||
if (buffer == null || !buffer.SequenceEqual(newBytes))
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
||||
fileSystem.CreateDirectory(Path.GetDirectoryName(path));
|
||||
|
||||
// Save it after load in case we got new items
|
||||
File.WriteAllBytes(path, newBytes);
|
||||
fileSystem.WriteAllBytes(path, newBytes);
|
||||
}
|
||||
|
||||
return configuration;
|
||||
|
||||
@@ -3,13 +3,15 @@ using MediaBrowser.Model.Logging;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using MediaBrowser.Common.IO;
|
||||
|
||||
namespace MediaBrowser.Common.Implementations.Devices
|
||||
{
|
||||
public class DeviceId
|
||||
{
|
||||
private readonly IApplicationPaths _appPaths;
|
||||
private readonly ILogger _logger;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IFileSystem _fileSystem;
|
||||
|
||||
private readonly object _syncLock = new object();
|
||||
|
||||
@@ -24,7 +26,7 @@ namespace MediaBrowser.Common.Implementations.Devices
|
||||
{
|
||||
lock (_syncLock)
|
||||
{
|
||||
var value = File.ReadAllText(CachePath, Encoding.UTF8);
|
||||
var value = _fileSystem.ReadAllText(CachePath, Encoding.UTF8);
|
||||
|
||||
Guid guid;
|
||||
if (Guid.TryParse(value, out guid))
|
||||
@@ -55,11 +57,11 @@ namespace MediaBrowser.Common.Implementations.Devices
|
||||
{
|
||||
var path = CachePath;
|
||||
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
||||
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
|
||||
|
||||
lock (_syncLock)
|
||||
{
|
||||
File.WriteAllText(path, id, Encoding.UTF8);
|
||||
_fileSystem.WriteAllText(path, id, Encoding.UTF8);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -88,10 +90,15 @@ namespace MediaBrowser.Common.Implementations.Devices
|
||||
|
||||
private string _id;
|
||||
|
||||
public DeviceId(IApplicationPaths appPaths, ILogger logger)
|
||||
public DeviceId(IApplicationPaths appPaths, ILogger logger, IFileSystem fileSystem)
|
||||
{
|
||||
if (fileSystem == null) {
|
||||
throw new ArgumentNullException ("fileSystem");
|
||||
}
|
||||
|
||||
_appPaths = appPaths;
|
||||
_logger = logger;
|
||||
_fileSystem = fileSystem;
|
||||
}
|
||||
|
||||
public string Value
|
||||
|
||||
@@ -355,7 +355,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
|
||||
|
||||
private async Task CacheResponse(HttpResponseInfo response, string responseCachePath)
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(responseCachePath));
|
||||
_fileSystem.CreateDirectory(Path.GetDirectoryName(responseCachePath));
|
||||
|
||||
using (var responseStream = response.Content)
|
||||
{
|
||||
@@ -599,7 +599,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
|
||||
{
|
||||
ValidateParams(options);
|
||||
|
||||
Directory.CreateDirectory(_appPaths.TempDirectory);
|
||||
_fileSystem.CreateDirectory(_appPaths.TempDirectory);
|
||||
|
||||
var tempFile = Path.Combine(_appPaths.TempDirectory, Guid.NewGuid() + ".tmp");
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ using MediaBrowser.Model.Logging;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace MediaBrowser.Common.Implementations.IO
|
||||
{
|
||||
@@ -75,7 +77,7 @@ namespace MediaBrowser.Common.Implementations.IO
|
||||
|
||||
if (string.Equals(Path.GetExtension(filename), ".mblink", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var path = File.ReadAllText(filename);
|
||||
var path = ReadAllText(filename);
|
||||
|
||||
return NormalizePath(path);
|
||||
}
|
||||
@@ -105,7 +107,7 @@ namespace MediaBrowser.Common.Implementations.IO
|
||||
throw new ArgumentNullException("target");
|
||||
}
|
||||
|
||||
File.WriteAllText(shortcutPath, target);
|
||||
_fileSystem.WriteAllText(shortcutPath, target);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -230,7 +232,7 @@ namespace MediaBrowser.Common.Implementations.IO
|
||||
/// <param name="share">The share.</param>
|
||||
/// <param name="isAsync">if set to <c>true</c> [is asynchronous].</param>
|
||||
/// <returns>FileStream.</returns>
|
||||
public FileStream GetFileStream(string path, FileMode mode, FileAccess access, FileShare share, bool isAsync = false)
|
||||
public Stream GetFileStream(string path, FileMode mode, FileAccess access, FileShare share, bool isAsync = false)
|
||||
{
|
||||
if (_supportsAsyncFileStreams && isAsync)
|
||||
{
|
||||
@@ -264,11 +266,11 @@ namespace MediaBrowser.Common.Implementations.IO
|
||||
RemoveHiddenAttribute(file1);
|
||||
RemoveHiddenAttribute(file2);
|
||||
|
||||
File.Copy(file1, temp1, true);
|
||||
File.Copy(file2, temp2, true);
|
||||
CopyFile(file1, temp1, true);
|
||||
CopyFile(file2, temp2, true);
|
||||
|
||||
File.Copy(temp1, file2, true);
|
||||
File.Copy(temp2, file1, true);
|
||||
CopyFile(temp1, file2, true);
|
||||
CopyFile(temp2, file1, true);
|
||||
|
||||
DeleteFile(temp1);
|
||||
DeleteFile(temp2);
|
||||
@@ -410,24 +412,42 @@ namespace MediaBrowser.Common.Implementations.IO
|
||||
//return Path.IsPathRooted(path);
|
||||
}
|
||||
|
||||
public void DeleteFile(string path, bool sendToRecycleBin)
|
||||
public void DeleteFile(string path)
|
||||
{
|
||||
File.Delete(path);
|
||||
}
|
||||
|
||||
public void DeleteDirectory(string path, bool recursive, bool sendToRecycleBin)
|
||||
{
|
||||
Directory.Delete(path, recursive);
|
||||
}
|
||||
|
||||
public void DeleteFile(string path)
|
||||
{
|
||||
DeleteFile(path, false);
|
||||
}
|
||||
|
||||
public void DeleteDirectory(string path, bool recursive)
|
||||
{
|
||||
DeleteDirectory(path, recursive, false);
|
||||
}
|
||||
Directory.Delete(path, recursive);
|
||||
}
|
||||
|
||||
public void CreateDirectory(string path)
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
|
||||
public IEnumerable<DirectoryInfo> GetDirectories(string path, bool recursive = false)
|
||||
{
|
||||
var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
|
||||
|
||||
return new DirectoryInfo (path).EnumerateDirectories("*", searchOption);
|
||||
}
|
||||
|
||||
public IEnumerable<FileInfo> GetFiles(string path, bool recursive = false)
|
||||
{
|
||||
var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
|
||||
|
||||
return new DirectoryInfo (path).EnumerateFiles("*", searchOption);
|
||||
}
|
||||
|
||||
public IEnumerable<FileSystemInfo> GetFileSystemEntries(string path, bool recursive = false)
|
||||
{
|
||||
var directoryInfo = new DirectoryInfo (path);
|
||||
var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
|
||||
|
||||
return directoryInfo.EnumerateDirectories("*", searchOption)
|
||||
.Concat<FileSystemInfo>(directoryInfo.EnumerateFiles("*", searchOption));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,7 +208,7 @@ namespace MediaBrowser.Common.Implementations.Logging
|
||||
{
|
||||
LogFilePath = Path.Combine(LogDirectory, LogFilePrefix + "-" + decimal.Round(DateTime.Now.Ticks / 10000000) + ".txt");
|
||||
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(LogFilePath));
|
||||
_fileSystem.CreateDirectory(Path.GetDirectoryName(LogFilePath));
|
||||
|
||||
AddFileTarget(LogFilePath, level);
|
||||
|
||||
|
||||
@@ -154,7 +154,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
|
||||
_lastExecutionResult = value;
|
||||
|
||||
var path = GetHistoryFilePath();
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
||||
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
|
||||
|
||||
lock (_lastExecutionResultSyncLock)
|
||||
{
|
||||
@@ -552,7 +552,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
|
||||
{
|
||||
var path = GetConfigurationFilePath();
|
||||
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
||||
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
|
||||
|
||||
JsonSerializer.SerializeToFile(triggers.Select(ScheduledTaskHelpers.GetTriggerInfo), path);
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks
|
||||
/// <param name="progress">The progress.</param>
|
||||
private void DeleteCacheFilesFromDirectory(CancellationToken cancellationToken, string directory, DateTime minDateModified, IProgress<double> progress)
|
||||
{
|
||||
var filesToDelete = new DirectoryInfo(directory).EnumerateFiles("*", SearchOption.AllDirectories)
|
||||
var filesToDelete = _fileSystem.GetFiles(directory, true)
|
||||
.Where(f => _fileSystem.GetLastWriteTimeUtc(f) < minDateModified)
|
||||
.ToList();
|
||||
|
||||
@@ -120,14 +120,14 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks
|
||||
progress.Report(100);
|
||||
}
|
||||
|
||||
private static void DeleteEmptyFolders(string parent)
|
||||
private void DeleteEmptyFolders(string parent)
|
||||
{
|
||||
foreach (var directory in Directory.GetDirectories(parent))
|
||||
{
|
||||
DeleteEmptyFolders(directory);
|
||||
if (!Directory.EnumerateFileSystemEntries(directory).Any())
|
||||
{
|
||||
Directory.Delete(directory, false);
|
||||
_fileSystem.DeleteDirectory(directory, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks
|
||||
// Delete log files more than n days old
|
||||
var minDateModified = DateTime.UtcNow.AddDays(-(ConfigurationManager.CommonConfiguration.LogFileRetentionDays));
|
||||
|
||||
var filesToDelete = new DirectoryInfo(ConfigurationManager.CommonApplicationPaths.LogDirectoryPath).EnumerateFileSystemInfos("*", SearchOption.AllDirectories)
|
||||
var filesToDelete = _fileSystem.GetFiles(ConfigurationManager.CommonApplicationPaths.LogDirectoryPath, true)
|
||||
.Where(f => _fileSystem.GetLastWriteTimeUtc(f) < minDateModified)
|
||||
.ToList();
|
||||
|
||||
|
||||
@@ -99,15 +99,15 @@ namespace MediaBrowser.Common.Implementations.Security
|
||||
{
|
||||
try
|
||||
{
|
||||
contents = File.ReadAllLines(licenseFile);
|
||||
contents = _fileSystem.ReadAllLines(licenseFile);
|
||||
}
|
||||
catch (DirectoryNotFoundException)
|
||||
{
|
||||
(File.Create(licenseFile)).Close();
|
||||
(_fileSystem.CreateFile(licenseFile)).Close();
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
(File.Create(licenseFile)).Close();
|
||||
(_fileSystem.CreateFile(licenseFile)).Close();
|
||||
}
|
||||
}
|
||||
if (contents != null && contents.Length > 0)
|
||||
@@ -150,8 +150,8 @@ namespace MediaBrowser.Common.Implementations.Security
|
||||
}
|
||||
|
||||
var licenseFile = Filename;
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(licenseFile));
|
||||
lock (_fileLock) File.WriteAllLines(licenseFile, lines);
|
||||
_fileSystem.CreateDirectory(Path.GetDirectoryName(licenseFile));
|
||||
lock (_fileLock) _fileSystem.WriteAllLines(licenseFile, lines);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace MediaBrowser.Common.Implementations.Serialization
|
||||
throw new ArgumentNullException("file");
|
||||
}
|
||||
|
||||
using (Stream stream = File.Open(file, FileMode.Create))
|
||||
using (Stream stream = _fileSystem.GetFileStream(file, FileMode.Create, FileAccess.Write, FileShare.Read))
|
||||
{
|
||||
SerializeToStream(obj, stream);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using MediaBrowser.Common.IO;
|
||||
|
||||
namespace MediaBrowser.Common.Implementations.Serialization
|
||||
{
|
||||
@@ -11,6 +12,13 @@ namespace MediaBrowser.Common.Implementations.Serialization
|
||||
/// </summary>
|
||||
public class XmlSerializer : IXmlSerializer
|
||||
{
|
||||
private IFileSystem _fileSystem;
|
||||
|
||||
public XmlSerializer(IFileSystem fileSystem)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
}
|
||||
|
||||
// Need to cache these
|
||||
// http://dotnetcodebox.blogspot.com/2013/01/xmlserializer-class-may-result-in.html
|
||||
private readonly ConcurrentDictionary<string, System.Xml.Serialization.XmlSerializer> _serializers =
|
||||
@@ -83,7 +91,7 @@ namespace MediaBrowser.Common.Implementations.Serialization
|
||||
/// <returns>System.Object.</returns>
|
||||
public object DeserializeFromFile(Type type, string file)
|
||||
{
|
||||
using (var stream = File.OpenRead(file))
|
||||
using (var stream = _fileSystem.OpenRead(file))
|
||||
{
|
||||
return DeserializeFromStream(type, stream);
|
||||
}
|
||||
|
||||
@@ -553,7 +553,7 @@ namespace MediaBrowser.Common.Implementations.Updates
|
||||
if (packageChecksum != Guid.Empty) // support for legacy uploads for now
|
||||
{
|
||||
using (var crypto = new MD5CryptoServiceProvider())
|
||||
using (var stream = new BufferedStream(File.OpenRead(tempFile), 100000))
|
||||
using (var stream = new BufferedStream(_fileSystem.OpenRead(tempFile), 100000))
|
||||
{
|
||||
var check = Guid.Parse(BitConverter.ToString(crypto.ComputeHash(stream)).Replace("-", String.Empty));
|
||||
if (check != packageChecksum)
|
||||
@@ -568,12 +568,12 @@ namespace MediaBrowser.Common.Implementations.Updates
|
||||
// Success - move it to the real target
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(target));
|
||||
File.Copy(tempFile, target, true);
|
||||
_fileSystem.CreateDirectory(Path.GetDirectoryName(target));
|
||||
_fileSystem.CopyFile(tempFile, target, true);
|
||||
//If it is an archive - write out a version file so we know what it is
|
||||
if (isArchive)
|
||||
{
|
||||
File.WriteAllText(target + ".ver", package.versionStr);
|
||||
_fileSystem.WriteAllText(target + ".ver", package.versionStr);
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
|
||||
Reference in New Issue
Block a user