From 6e6a965a04dae4c787fe9768b7187179b85e2607 Mon Sep 17 00:00:00 2001 From: Yoshi Askharoun Date: Fri, 28 Apr 2023 18:53:00 -0500 Subject: [PATCH] Make ZuneHost report errors on old systems --- ZuneHost.Wpf/ZuneHost.Wpf.csproj | 2 +- ZuneHost/App.config | 2 +- ZuneHost/Program.cs | 60 ++++++++++++++++++++++---------- ZuneHost/ZuneHost.csproj | 22 +++++++----- 4 files changed, 58 insertions(+), 28 deletions(-) diff --git a/ZuneHost.Wpf/ZuneHost.Wpf.csproj b/ZuneHost.Wpf/ZuneHost.Wpf.csproj index afe3822..f06fa0c 100644 --- a/ZuneHost.Wpf/ZuneHost.Wpf.csproj +++ b/ZuneHost.Wpf/ZuneHost.Wpf.csproj @@ -3,7 +3,7 @@ WinExe net6.0-windows10.0.22000;net40 - 11.0 + 11.0 true Assets\ZuneFluentGem.ico diff --git a/ZuneHost/App.config b/ZuneHost/App.config index 02eb0a8..38f9885 100644 --- a/ZuneHost/App.config +++ b/ZuneHost/App.config @@ -1,6 +1,6 @@  - + diff --git a/ZuneHost/Program.cs b/ZuneHost/Program.cs index 887aca7..ee40848 100644 --- a/ZuneHost/Program.cs +++ b/ZuneHost/Program.cs @@ -1,5 +1,7 @@ using System; +using System.Diagnostics; using System.IO; +using System.Linq; using System.Threading; namespace ZuneHost @@ -13,27 +15,34 @@ namespace ZuneHost { string strArgs = string.Join(" ", args); - // Make sure that ZuneDBApi can find all the Zune native libraries - Console.WriteLine("Copying Zune files..."); - _zuneProgramDir = new(Path.Combine( - Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), - "Zune")); - if (_zuneProgramDir.Exists) +#if NETFRAMEWORK + Console.WriteLine("Running legacy build on .NET Framework. If your OS supports .NET Core, please use OpenZune."); +#endif + + if (args.Contains("--copyFiles", StringComparer.InvariantCultureIgnoreCase)) { - foreach (var info in _zuneProgramDir.GetFileSystemInfos()) + // Make sure that ZuneDBApi can find all the Zune native libraries + Console.WriteLine("Copying Zune files..."); + _zuneProgramDir = new(Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), + "Zune")); + if (_zuneProgramDir.Exists) { - if (info is DirectoryInfo dirInfo) + foreach (var info in _zuneProgramDir.GetFileSystemInfos()) { - CopyAll(dirInfo, new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, dirInfo.Name))); - } - else if (info is FileInfo fileInfo) - { - string fileName = fileInfo.Name; - if (fileInfo.Extension == ".dll") + if (info is DirectoryInfo dirInfo) { - string targetPath = Path.Combine(Environment.CurrentDirectory, fileName); - if (!File.Exists(targetPath) || fileName == "ZuneDbApi.dll") - fileInfo.CopyTo(targetPath); + CopyAll(dirInfo, new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, dirInfo.Name))); + } + else if (info is FileInfo fileInfo) + { + string fileName = fileInfo.Name; + if (fileInfo.Extension == ".dll") + { + string targetPath = Path.Combine(Environment.CurrentDirectory, fileName); + if (!File.Exists(targetPath) || fileName == "ZuneDbApi.dll") + fileInfo.CopyTo(targetPath); + } } } } @@ -41,7 +50,22 @@ namespace ZuneHost Console.WriteLine("Starting Zune..."); - return Microsoft.Zune.Shell.ZuneApplication.Launch(strArgs, IntPtr.Zero); + try + { + return Microsoft.Zune.Shell.ZuneApplication.Launch(strArgs, IntPtr.Zero); + } + catch (FileNotFoundException ex) + { + Console.WriteLine(ex.FileName); + throw; + } + catch + { + Debugger.Launch(); + Debugger.Break(); + + throw; + } } public static void CopyAll(DirectoryInfo source, DirectoryInfo target) diff --git a/ZuneHost/ZuneHost.csproj b/ZuneHost/ZuneHost.csproj index 1b5b0af..9054fce 100644 --- a/ZuneHost/ZuneHost.csproj +++ b/ZuneHost/ZuneHost.csproj @@ -1,14 +1,20 @@  - - Exe - net6.0-windows10.0.22000;net6.0;net40 - AnyCPU;x64;x86;ARM32 + + Exe + net40;net6.0-windows10.0.22000;net6.0; + AnyCPU;x64;x86;ARM32 11.0 - + - - - + + + + + + + + +