Visual Studio Reformat: Emby.IsoMounting

This commit is contained in:
Erwin de Haan 2019-01-13 20:17:15 +01:00
parent 009c95d972
commit 25a428373c
3 changed files with 71 additions and 34 deletions

View file

@ -1,12 +1,12 @@
using System; using System;
using System.IO; using System.IO;
using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MediaBrowser.Model.Diagnostics; using MediaBrowser.Model.Diagnostics;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using Microsoft.Extensions.Logging;
using MediaBrowser.Model.System; using MediaBrowser.Model.System;
using System.Runtime.InteropServices; using Microsoft.Extensions.Logging;
namespace IsoMounter namespace IsoMounter
{ {
@ -87,9 +87,12 @@ namespace IsoMounter
UmountCommand UmountCommand
); );
if (!string.IsNullOrEmpty(SudoCommand) && !string.IsNullOrEmpty(MountCommand) && !string.IsNullOrEmpty(UmountCommand)) { if (!string.IsNullOrEmpty(SudoCommand) && !string.IsNullOrEmpty(MountCommand) && !string.IsNullOrEmpty(UmountCommand))
{
ExecutablesAvailable = true; ExecutablesAvailable = true;
} else { }
else
{
ExecutablesAvailable = false; ExecutablesAvailable = false;
} }
@ -99,18 +102,23 @@ namespace IsoMounter
#region Interface Implementation for IIsoMounter #region Interface Implementation for IIsoMounter
public bool IsInstalled { public bool IsInstalled
get { {
get
{
return true; return true;
} }
} }
public string Name { public string Name
{
get { return "LinuxMount"; } get { return "LinuxMount"; }
} }
public bool RequiresInstallation { public bool RequiresInstallation
get { {
get
{
return false; return false;
} }
} }
@ -148,10 +156,12 @@ namespace IsoMounter
public Task<IIsoMount> Mount(string isoPath, CancellationToken cancellationToken) public Task<IIsoMount> Mount(string isoPath, CancellationToken cancellationToken)
{ {
if (MountISO(isoPath, out LinuxMount mountedISO)) { if (MountISO(isoPath, out LinuxMount mountedISO))
{
return Task.FromResult<IIsoMount>(mountedISO); return Task.FromResult<IIsoMount>(mountedISO);
} }
else { else
{
throw new IOException(string.Format( throw new IOException(string.Format(
"An error occurred trying to mount image [$0].", "An error occurred trying to mount image [$0].",
isoPath isoPath
@ -180,7 +190,8 @@ namespace IsoMounter
protected virtual void Dispose(bool disposing) protected virtual void Dispose(bool disposing)
{ {
if (disposed) { if (disposed)
{
return; return;
} }
@ -190,7 +201,8 @@ namespace IsoMounter
disposing.ToString() disposing.ToString()
); );
if (disposing) { if (disposing)
{
// //
// Free managed objects here. // Free managed objects here.
@ -217,7 +229,8 @@ namespace IsoMounter
{ {
string path = test.Trim(); string path = test.Trim();
if (!string.IsNullOrEmpty(path) && FileSystem.FileExists(path = Path.Combine(path, name))) { if (!string.IsNullOrEmpty(path) && FileSystem.FileExists(path = Path.Combine(path, name)))
{
return FileSystem.GetFullPath(path); return FileSystem.GetFullPath(path);
} }
} }
@ -247,7 +260,8 @@ namespace IsoMounter
bool processFailed = false; bool processFailed = false;
var process = ProcessFactory.Create( var process = ProcessFactory.Create(
new ProcessOptions { new ProcessOptions
{
CreateNoWindow = true, CreateNoWindow = true,
RedirectStandardOutput = true, RedirectStandardOutput = true,
RedirectStandardError = true, RedirectStandardError = true,
@ -285,9 +299,12 @@ namespace IsoMounter
_logger.LogDebug(ex, "[{Name}] Unhandled exception executing command.", Name); _logger.LogDebug(ex, "[{Name}] Unhandled exception executing command.", Name);
} }
if (!processFailed && process.ExitCode == 0) { if (!processFailed && process.ExitCode == 0)
{
return true; return true;
} else { }
else
{
return false; return false;
} }
@ -300,7 +317,8 @@ namespace IsoMounter
string cmdFilename; string cmdFilename;
string mountPoint = Path.Combine(MountPointRoot, Guid.NewGuid().ToString()); string mountPoint = Path.Combine(MountPointRoot, Guid.NewGuid().ToString());
if (!string.IsNullOrEmpty(isoPath)) { if (!string.IsNullOrEmpty(isoPath))
{
_logger.LogInformation( _logger.LogInformation(
"[{Name}] Attempting to mount [{Path}].", "[{Name}] Attempting to mount [{Path}].",
@ -314,7 +332,9 @@ namespace IsoMounter
mountPoint mountPoint
); );
} else { }
else
{
throw new ArgumentNullException(nameof(isoPath)); throw new ArgumentNullException(nameof(isoPath));
@ -333,10 +353,13 @@ namespace IsoMounter
throw new IOException("Unable to create mount point for " + isoPath); throw new IOException("Unable to create mount point for " + isoPath);
} }
if (GetUID() == 0) { if (GetUID() == 0)
{
cmdFilename = MountCommand; cmdFilename = MountCommand;
cmdArguments = string.Format("\"{0}\" \"{1}\"", isoPath, mountPoint); cmdArguments = string.Format("\"{0}\" \"{1}\"", isoPath, mountPoint);
} else { }
else
{
cmdFilename = SudoCommand; cmdFilename = SudoCommand;
cmdArguments = string.Format("\"{0}\" \"{1}\" \"{2}\"", MountCommand, isoPath, mountPoint); cmdArguments = string.Format("\"{0}\" \"{1}\" \"{2}\"", MountCommand, isoPath, mountPoint);
} }
@ -348,7 +371,8 @@ namespace IsoMounter
cmdArguments cmdArguments
); );
if (ExecuteCommand(cmdFilename, cmdArguments)) { if (ExecuteCommand(cmdFilename, cmdArguments))
{
_logger.LogInformation( _logger.LogInformation(
"[{0}] ISO mount completed successfully.", "[{0}] ISO mount completed successfully.",
@ -357,7 +381,9 @@ namespace IsoMounter
mountedISO = new LinuxMount(this, isoPath, mountPoint); mountedISO = new LinuxMount(this, isoPath, mountPoint);
} else { }
else
{
_logger.LogInformation( _logger.LogInformation(
"[{0}] ISO mount completed with errors.", "[{0}] ISO mount completed with errors.",
@ -387,7 +413,8 @@ namespace IsoMounter
string cmdArguments; string cmdArguments;
string cmdFilename; string cmdFilename;
if (mount != null) { if (mount != null)
{
_logger.LogInformation( _logger.LogInformation(
"[{0}] Attempting to unmount ISO [{1}] mounted on [{2}].", "[{0}] Attempting to unmount ISO [{1}] mounted on [{2}].",
@ -396,16 +423,21 @@ namespace IsoMounter
mount.MountedPath mount.MountedPath
); );
} else { }
else
{
throw new ArgumentNullException(nameof(mount)); throw new ArgumentNullException(nameof(mount));
} }
if (GetUID() == 0) { if (GetUID() == 0)
{
cmdFilename = UmountCommand; cmdFilename = UmountCommand;
cmdArguments = string.Format("\"{0}\"", mount.MountedPath); cmdArguments = string.Format("\"{0}\"", mount.MountedPath);
} else { }
else
{
cmdFilename = SudoCommand; cmdFilename = SudoCommand;
cmdArguments = string.Format("\"{0}\" \"{1}\"", UmountCommand, mount.MountedPath); cmdArguments = string.Format("\"{0}\" \"{1}\"", UmountCommand, mount.MountedPath);
} }
@ -417,14 +449,17 @@ namespace IsoMounter
cmdArguments cmdArguments
); );
if (ExecuteCommand(cmdFilename, cmdArguments)) { if (ExecuteCommand(cmdFilename, cmdArguments))
{
_logger.LogInformation( _logger.LogInformation(
"[{0}] ISO unmount completed successfully.", "[{0}] ISO unmount completed successfully.",
Name Name
); );
} else { }
else
{
_logger.LogInformation( _logger.LogInformation(
"[{0}] ISO unmount completed with errors.", "[{0}] ISO unmount completed with errors.",

View file

@ -45,11 +45,13 @@ namespace IsoMounter
protected virtual void Dispose(bool disposing) protected virtual void Dispose(bool disposing)
{ {
if (disposed) { if (disposed)
{
return; return;
} }
if (disposing) { if (disposing)
{
// //
// Free managed objects here. // Free managed objects here.

View file

@ -1,8 +1,8 @@
using MediaBrowser.Common.Configuration; using System;
using IsoMounter.Configuration;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Plugins; using MediaBrowser.Common.Plugins;
using MediaBrowser.Model.Serialization; using MediaBrowser.Model.Serialization;
using System;
using IsoMounter.Configuration;
namespace IsoMounter namespace IsoMounter
{ {