From 1c74aa3b43a78c2925c9ab7ff511c74a5b429468 Mon Sep 17 00:00:00 2001 From: Duefectu Date: Thu, 11 Jan 2024 01:22:22 +0100 Subject: [PATCH] Python is no longer required for compiling to Next --- ZXBStudio/BuildSystem/ZXProjectBuilder.cs | 30 +++++++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/ZXBStudio/BuildSystem/ZXProjectBuilder.cs b/ZXBStudio/BuildSystem/ZXProjectBuilder.cs index f3d874d..32d8b8b 100644 --- a/ZXBStudio/BuildSystem/ZXProjectBuilder.cs +++ b/ZXBStudio/BuildSystem/ZXProjectBuilder.cs @@ -66,7 +66,7 @@ public class ZXProjectBuilder OutputLogWritter.WriteLine("Project path: " + project.ProjectPath); OutputLogWritter.WriteLine("Building program " + mainFile); OutputLogWritter.WriteLine("Building starts at " + startTime); - + var proc = Process.Start(new ProcessStartInfo(Path.GetFullPath(ZXOptions.Current.ZxbcPath), $"\"{mainFile}\" " + args) { WorkingDirectory = project.ProjectPath, RedirectStandardError = true, CreateNoWindow = true }); string logOutput; @@ -131,6 +131,7 @@ private static bool BuildNexFile(byte[] binary, ZXBuildSettings settings, ZXProj // Create .bin file { + outputLogWritter.WriteLine("Creating .bin file..."); binFile = Path.Combine(project.ProjectPath, Path.GetFileNameWithoutExtension(settings.MainFile) + ".bin"); if (File.Exists(binFile)) { @@ -161,9 +162,9 @@ private static bool BuildNexFile(byte[] binary, ZXBuildSettings settings, ZXProj // Main file { int[] nextBank16K = { 255, 5, 2, 0 }; - int bank = org/16384; - int offset = org-(bank * 16384); - if(bank<0 || bank > 3) + int bank = org / 16384; + int offset = org - (bank * 16384); + if (bank < 0 || bank > 3) { outputLogWritter.WriteLine("Error: Invalid ORG direction, must be >0 and <65535"); return false; @@ -210,7 +211,8 @@ private static bool BuildNexFile(byte[] binary, ZXBuildSettings settings, ZXProj Process process = new Process(); if (Environment.OSVersion.Platform == PlatformID.Win32NT) { - process.StartInfo.FileName = "python"; + CheckNextCreator(); + process.StartInfo.FileName = Path.Combine(Path.GetDirectoryName(ZXOptions.Current.ZxbcPath), "python", "python.exe"); process.StartInfo.Arguments = string.Format("{0} nex.cfg {1}", Path.Combine(Path.GetDirectoryName(ZXOptions.Current.ZxbcPath), "tools", "nextcreator.py"), Path.GetFileNameWithoutExtension(settings.MainFile) + ".nex"); @@ -228,12 +230,17 @@ private static bool BuildNexFile(byte[] binary, ZXBuildSettings settings, ZXProj process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardOutput = true; } + outputLogWritter.WriteLine(string.Format("{0} {1}", + process.StartInfo.FileName, + process.StartInfo.Arguments)); process.Start(); process.WaitForExit(); if (!File.Exists(nexFile)) { outputLogWritter.WriteLine("Error building .nex file"); + outputLogWritter.WriteLine(process.StartInfo.WorkingDirectory); + using (StreamReader reader = process.StandardOutput) { string output = reader.ReadToEnd(); @@ -256,6 +263,19 @@ private static bool BuildNexFile(byte[] binary, ZXBuildSettings settings, ZXProj } + private static void CheckNextCreator() + { + var fNCexe = Path.Combine(Path.GetDirectoryName(ZXOptions.Current.ZxbcPath), "tools", "nextcreator.exe"); + if (File.Exists(fNCexe)) + { + return; + } + + File.Copy(ZXOptions.Current.ZxbcPath, fNCexe); + return; + } + + public static ZXProgram? BuildDebug(TextWriter OutputLogWritter) { try