2022-06-03 01:35:01 -05:00
|
|
|
using System;
|
2023-04-28 18:53:00 -05:00
|
|
|
using System.Diagnostics;
|
2022-06-03 01:24:53 -05:00
|
|
|
using System.IO;
|
2023-04-28 18:53:00 -05:00
|
|
|
using System.Linq;
|
2022-06-03 01:24:53 -05:00
|
|
|
using System.Threading;
|
|
|
|
|
|
|
|
|
|
namespace ZuneHost
|
|
|
|
|
{
|
|
|
|
|
internal class Program
|
|
|
|
|
{
|
2022-07-13 18:03:35 -05:00
|
|
|
static DirectoryInfo _zuneProgramDir;
|
2022-06-03 01:24:53 -05:00
|
|
|
|
2022-06-03 02:23:11 -05:00
|
|
|
[STAThread]
|
|
|
|
|
static int Main(string[] args)
|
2022-06-03 01:24:53 -05:00
|
|
|
{
|
2022-06-03 02:23:11 -05:00
|
|
|
string strArgs = string.Join(" ", args);
|
2022-06-03 01:24:53 -05:00
|
|
|
|
2023-04-28 18:53:00 -05:00
|
|
|
#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))
|
2022-06-03 01:24:53 -05:00
|
|
|
{
|
2023-04-28 18:53:00 -05:00
|
|
|
// 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)
|
2022-06-03 01:24:53 -05:00
|
|
|
{
|
2023-04-28 18:53:00 -05:00
|
|
|
foreach (var info in _zuneProgramDir.GetFileSystemInfos())
|
2022-06-03 02:23:11 -05:00
|
|
|
{
|
2023-04-28 18:53:00 -05:00
|
|
|
if (info is DirectoryInfo dirInfo)
|
2022-07-13 18:03:35 -05:00
|
|
|
{
|
2023-04-28 18:53:00 -05:00
|
|
|
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);
|
|
|
|
|
}
|
2022-07-13 18:03:35 -05:00
|
|
|
}
|
2022-06-03 02:23:11 -05:00
|
|
|
}
|
2022-06-03 01:24:53 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("Starting Zune...");
|
|
|
|
|
|
2023-04-28 18:53:00 -05:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return Microsoft.Zune.Shell.ZuneApplication.Launch(strArgs, IntPtr.Zero);
|
|
|
|
|
}
|
|
|
|
|
catch (FileNotFoundException ex)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(ex.FileName);
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
Debugger.Launch();
|
|
|
|
|
Debugger.Break();
|
|
|
|
|
|
|
|
|
|
throw;
|
|
|
|
|
}
|
2022-06-03 02:23:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void CopyAll(DirectoryInfo source, DirectoryInfo target)
|
|
|
|
|
{
|
|
|
|
|
// Check if the target directory exists
|
|
|
|
|
if (Directory.Exists(target.FullName) == false)
|
2022-06-03 01:24:53 -05:00
|
|
|
{
|
2022-06-03 02:23:11 -05:00
|
|
|
Directory.CreateDirectory(target.FullName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Copy all the files into the new directory
|
|
|
|
|
foreach (FileInfo fi in source.GetFiles())
|
|
|
|
|
{
|
|
|
|
|
fi.CopyTo(Path.Combine(target.ToString(), fi.Name), true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Copy all the sub directories using recursion
|
|
|
|
|
foreach (DirectoryInfo diSourceDir in source.GetDirectories())
|
|
|
|
|
{
|
|
|
|
|
DirectoryInfo nextTargetDir = target.CreateSubdirectory(diSourceDir.Name);
|
|
|
|
|
CopyAll(diSourceDir, nextTargetDir);
|
|
|
|
|
}
|
2022-06-03 01:24:53 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|