diff --git a/NzbDrone.Common/EnvironmentInfo/StartupArguments.cs b/NzbDrone.Common/EnvironmentInfo/StartupArguments.cs index 4dbb07546..9075d64e0 100644 --- a/NzbDrone.Common/EnvironmentInfo/StartupArguments.cs +++ b/NzbDrone.Common/EnvironmentInfo/StartupArguments.cs @@ -17,6 +17,14 @@ public class StartupArguments : IStartupArguments public const string UNINSTALL_SERVICE = "u"; public const string HELP = "?"; + static StartupArguments() + { + if (RuntimeInfo.IsProduction) + { + Instance = new StartupArguments(""); + } + } + public StartupArguments(params string[] args) { Flags = new HashSet(); diff --git a/NzbDrone.Console/ConsoleAlerts.cs b/NzbDrone.Console/ConsoleAlerts.cs new file mode 100644 index 000000000..4d623fc8e --- /dev/null +++ b/NzbDrone.Console/ConsoleAlerts.cs @@ -0,0 +1,15 @@ +using NzbDrone.Host; + +namespace NzbDrone.Console +{ + public class ConsoleAlerts : IUserAlert + { + public void Alert(string message) + { + System.Console.WriteLine(); + System.Console.WriteLine(message); + System.Console.WriteLine("Press enter to continue"); + System.Console.ReadLine(); + } + } +} \ No newline at end of file diff --git a/NzbDrone.Console/ConsoleApp.cs b/NzbDrone.Console/ConsoleApp.cs index 7d2e4c7dc..36bf92f65 100644 --- a/NzbDrone.Console/ConsoleApp.cs +++ b/NzbDrone.Console/ConsoleApp.cs @@ -1,5 +1,6 @@ using System; using NzbDrone.Common.EnvironmentInfo; +using NzbDrone.Host; namespace NzbDrone.Console { @@ -9,13 +10,15 @@ public static void Main(string[] args) { try { - Host.Bootstrap.Start(new StartupArguments(args)); + Bootstrap.Start(new StartupArguments(args), new ConsoleAlerts()); + } + catch (TerminateApplicationException) + { } catch (Exception e) { System.Console.WriteLine(e.ToString()); } - System.Console.WriteLine("Press enter to exit..."); System.Console.ReadLine(); } diff --git a/NzbDrone.Console/NzbDrone.Console.csproj b/NzbDrone.Console/NzbDrone.Console.csproj index 0510fb9cd..eeffbaff2 100644 --- a/NzbDrone.Console/NzbDrone.Console.csproj +++ b/NzbDrone.Console/NzbDrone.Console.csproj @@ -83,6 +83,10 @@ False ..\packages\Newtonsoft.Json.5.0.6\lib\net40\Newtonsoft.Json.dll + + False + ..\packages\NLog.2.0.1.2\lib\net40\NLog.dll + False ..\packages\Owin.1.0\lib\net40\Owin.dll @@ -94,6 +98,7 @@ Properties\SharedAssemblyInfo.cs + diff --git a/NzbDrone.Console/packages.config b/NzbDrone.Console/packages.config index e66a55717..d9496d8b2 100644 --- a/NzbDrone.Console/packages.config +++ b/NzbDrone.Console/packages.config @@ -5,5 +5,6 @@ + \ No newline at end of file diff --git a/NzbDrone.Host/Bootstrap.cs b/NzbDrone.Host/Bootstrap.cs index 225900e8a..e4b592fd1 100644 --- a/NzbDrone.Host/Bootstrap.cs +++ b/NzbDrone.Host/Bootstrap.cs @@ -1,6 +1,4 @@ -using System; -using System.Diagnostics; -using System.Reflection; +using System.Reflection; using NLog; using NzbDrone.Common.Composition; using NzbDrone.Common.EnvironmentInfo; @@ -12,54 +10,27 @@ namespace NzbDrone.Host { public static class Bootstrap { - public static IContainer Start(StartupArguments args) + public static IContainer Start(StartupArguments args, IUserAlert userAlert) { var logger = LogManager.GetLogger("AppMain"); - try + GlobalExceptionHandlers.Register(); + IgnoreCertErrorPolicy.Register(); + + logger.Info("Starting NzbDrone Console. Version {0}", Assembly.GetExecutingAssembly().GetName().Version); + + + if (!PlatformValidation.IsValidate(userAlert)) { - GlobalExceptionHandlers.Register(); - IgnoreCertErrorPolicy.Register(); - - logger.Info("Starting NzbDrone Console. Version {0}", Assembly.GetExecutingAssembly().GetName().Version); - - //Check if full version .NET is installed. - try - { - Assembly.Load("System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"); - } - catch (Exception) - { - logger.Error("It looks like you don't have full version of .NET Framework installed. Press any key and you will be directed to the download page."); - Console.Read(); - - try - { - Process.Start("http://www.microsoft.com/download/en/details.aspx?id=17851"); - } - catch (Exception e) - { - logger.Warn("Oops. can't start default browser. Please visit http://www.microsoft.com/download/en/details.aspx?id=17851 to download .NET Framework 4."); - Console.ReadLine(); - } - - return null; - } - - var container = MainAppContainerBuilder.BuildContainer(args); - - DbFactory.RegisterDatabase(container); - container.Resolve().Route(); - - - - return container; - } - catch (Exception e) - { - logger.FatalException("Epic Fail " + e.Message, e); - throw; + throw new TerminateApplicationException(); } + + var container = MainAppContainerBuilder.BuildContainer(args); + + DbFactory.RegisterDatabase(container); + container.Resolve().Route(); + + return container; } } } \ No newline at end of file diff --git a/NzbDrone.Host/IUserAlert.cs b/NzbDrone.Host/IUserAlert.cs new file mode 100644 index 000000000..04db62985 --- /dev/null +++ b/NzbDrone.Host/IUserAlert.cs @@ -0,0 +1,7 @@ +namespace NzbDrone.Host +{ + public interface IUserAlert + { + void Alert(string message); + } +} \ No newline at end of file diff --git a/NzbDrone.Host/NzbDrone.Host.csproj b/NzbDrone.Host/NzbDrone.Host.csproj index 4258ef460..3cdf5cf62 100644 --- a/NzbDrone.Host/NzbDrone.Host.csproj +++ b/NzbDrone.Host/NzbDrone.Host.csproj @@ -121,6 +121,8 @@ + + @@ -132,6 +134,7 @@ + diff --git a/NzbDrone.Host/PlatformValidation.cs b/NzbDrone.Host/PlatformValidation.cs new file mode 100644 index 000000000..978a579ae --- /dev/null +++ b/NzbDrone.Host/PlatformValidation.cs @@ -0,0 +1,55 @@ +using System; +using System.Diagnostics; +using System.Reflection; +using NLog; +using NzbDrone.Common.EnvironmentInfo; + +namespace NzbDrone.Host +{ + public static class PlatformValidation + { + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + public static bool IsValidate(IUserAlert userAlert) + { + if (OsInfo.IsMono) + { + return true; + } + + if (!IsAssemblyAvailable("System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")) + { + userAlert.Alert("It looks like you don't have full version of .NET Framework installed. You will now be directed the download page."); + + try + { + Process.Start("http://www.microsoft.com/en-ca/download/details.aspx?id=30653"); + } + catch (Exception e) + { + userAlert.Alert("Oops. can't start default browser. Please visit http://www.microsoft.com/en-ca/download/details.aspx?id=30653 to download .NET Framework 4.5."); + } + + return false; + } + + return true; + } + + + private static bool IsAssemblyAvailable(string assemblyString) + { + try + { + Assembly.Load(assemblyString); + return true; + } + catch (Exception e) + { + Logger.Warn("Couldn't load {0}", e.Message); + return false; + } + + } + } +} \ No newline at end of file diff --git a/NzbDrone.Host/TerminateApplicationException.cs b/NzbDrone.Host/TerminateApplicationException.cs new file mode 100644 index 000000000..04464bea3 --- /dev/null +++ b/NzbDrone.Host/TerminateApplicationException.cs @@ -0,0 +1,8 @@ +using System; + +namespace NzbDrone.Host +{ + public class TerminateApplicationException : ApplicationException + { + } +} \ No newline at end of file diff --git a/NzbDrone.Update.Test/ProgramFixture.cs b/NzbDrone.Update.Test/ProgramFixture.cs index f7d976308..2a955e7f6 100644 --- a/NzbDrone.Update.Test/ProgramFixture.cs +++ b/NzbDrone.Update.Test/ProgramFixture.cs @@ -9,7 +9,7 @@ namespace NzbDrone.Update.Test { [TestFixture] - public class ProgramFixture : TestBase + public class ProgramFixture : TestBase { diff --git a/NzbDrone.Update/NzbDrone.Update.csproj b/NzbDrone.Update/NzbDrone.Update.csproj index eee3a4550..c2d12c5c4 100644 --- a/NzbDrone.Update/NzbDrone.Update.csproj +++ b/NzbDrone.Update/NzbDrone.Update.csproj @@ -52,7 +52,7 @@ Properties\SharedAssemblyInfo.cs - + diff --git a/NzbDrone.Update/Program.cs b/NzbDrone.Update/Program.cs index b46e8ee7b..11a56b85d 100644 --- a/NzbDrone.Update/Program.cs +++ b/NzbDrone.Update/Program.cs @@ -10,7 +10,7 @@ namespace NzbDrone.Update { - public class Program + public class UpdateApp { private readonly IInstallUpdateService _installUpdateService; private readonly IProcessProvider _processProvider; @@ -18,7 +18,7 @@ public class Program private static readonly Logger logger = LogManager.GetCurrentClassLogger(); - public Program(IInstallUpdateService installUpdateService, IProcessProvider processProvider) + public UpdateApp(IInstallUpdateService installUpdateService, IProcessProvider processProvider) { _installUpdateService = installUpdateService; _processProvider = processProvider; @@ -38,7 +38,7 @@ public static void Main(string[] args) _container = UpdateContainerBuilder.Build(); logger.Info("Updating NzbDrone to version {0}", BuildInfo.Version); - _container.Resolve().Start(args); + _container.Resolve().Start(args); } catch (Exception e) { diff --git a/NzbDrone/MessageBoxUserAlert.cs b/NzbDrone/MessageBoxUserAlert.cs new file mode 100644 index 000000000..1b5686864 --- /dev/null +++ b/NzbDrone/MessageBoxUserAlert.cs @@ -0,0 +1,13 @@ +using System.Windows.Forms; +using NzbDrone.Host; + +namespace NzbDrone +{ + public class MessageBoxUserAlert : IUserAlert + { + public void Alert(string message) + { + MessageBox.Show(text: message, buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Warning, caption: "NzbDrone"); + } + } +} \ No newline at end of file diff --git a/NzbDrone/NzbDrone.csproj b/NzbDrone/NzbDrone.csproj index 9b276ad11..67868aa0c 100644 --- a/NzbDrone/NzbDrone.csproj +++ b/NzbDrone/NzbDrone.csproj @@ -96,6 +96,7 @@ Properties\SharedAssemblyInfo.cs + True True diff --git a/NzbDrone/WindowsApp.cs b/NzbDrone/WindowsApp.cs index bf3bf25fa..0ded14d61 100644 --- a/NzbDrone/WindowsApp.cs +++ b/NzbDrone/WindowsApp.cs @@ -1,6 +1,7 @@ using System; using System.Windows.Forms; using NzbDrone.Common.EnvironmentInfo; +using NzbDrone.Host; using NzbDrone.SysTray; namespace NzbDrone @@ -11,10 +12,13 @@ public static void Main(string[] args) { try { - var container = Host.Bootstrap.Start(new StartupArguments(args)); + var container = Bootstrap.Start(new StartupArguments(args), new MessageBoxUserAlert()); container.Register(); container.Resolve().Start(); } + catch (TerminateApplicationException) + { + } catch (Exception e) { var message = string.Format("{0}: {1}", e.GetType().Name, e.Message);