From e472dde145e23a8a4d67c0b9f677316273902c7b Mon Sep 17 00:00:00 2001 From: Yoshi Askharoun Date: Wed, 13 Jul 2022 18:03:35 -0500 Subject: [PATCH] Updated hosts to prevent crash when Zune is not installed --- ZuneHost/Program.cs | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/ZuneHost/Program.cs b/ZuneHost/Program.cs index 75d604b..887aca7 100644 --- a/ZuneHost/Program.cs +++ b/ZuneHost/Program.cs @@ -6,34 +6,35 @@ namespace ZuneHost { internal class Program { - static string _zuneProgramFolder; + static DirectoryInfo _zuneProgramDir; [STAThread] static int Main(string[] args) { - Console.WriteLine("Creating splash window..."); - string strArgs = string.Join(" ", args); // Make sure that ZuneDBApi can find all the Zune native libraries Console.WriteLine("Copying Zune files..."); - _zuneProgramFolder = Path.Combine( + _zuneProgramDir = new(Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), - "Zune"); - foreach (var info in new DirectoryInfo(_zuneProgramFolder).GetFileSystemInfos()) + "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); + } } } }