Skip to content

Features/advanced project options #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion ZXBStudio/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,21 @@
<Setter Property="Height" Value="32"></Setter>
<Setter Property="MaxWidth" Value="140"></Setter>
</Style>
<Style Selector="TextBox.dialogfw">
<Setter Property="Margin" Value="5"></Setter>
<Setter Property="CornerRadius" Value="5"></Setter>
<Setter Property="Height" Value="32"></Setter>
</Style>
<Style Selector="TextBox.dialogfwh">
<Setter Property="Margin" Value="5"></Setter>
<Setter Property="CornerRadius" Value="5"></Setter>
</Style>
<Style Selector="Button.dialog">
<Setter Property="Margin" Value="5"></Setter>
<Setter Property="CornerRadius" Value="5"></Setter>
</Style>
<Style Selector="ComboBox.dialog">
<Setter Property="Margin" Value="0"></Setter>
<Setter Property="Margin" Value="5"></Setter>
<Setter Property="CornerRadius" Value="5"></Setter>
<Setter Property="Height" Value="32"></Setter>
<Setter Property="Padding" Value="5"></Setter>
Expand Down
141 changes: 134 additions & 7 deletions ZXBStudio/BuildSystem/ZXProjectBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using ZXBasicStudio.Classes;
using ZXBasicStudio.Controls;
using ZXBasicStudio.Dialogs;
using ZXBasicStudio.DocumentModel.Classes;
using ZXBasicStudio.IntegratedDocumentTypes.CodeDocuments.Basic;
Expand Down Expand Up @@ -51,6 +53,22 @@ public class ZXProjectBuilder
settings = project.GetProjectSettings();
mainFile = project.GetMainFile();

// Prebuild
if (settings.PreBuild)
{
OutputLogWritter.WriteLine($"PreBuild: {settings.PreBuildValue}");
if (!ExecuteFile(settings.PreBuildValue, new string[]
{
project.ProjectPath,
Path.GetFileName(mainFile)
},
project.ProjectPath,
OutputLogWritter))
{
return null;
}
}

if (mainFile == null)
{
OutputLogWritter.WriteLine("Cannot find main file, check that it exists and if there are more than one that is specified in the build settings.");
Expand All @@ -60,14 +78,19 @@ public class ZXProjectBuilder
if (!PreBuild(false, project.ProjectPath, OutputLogWritter))
return null;

var args = settings.GetSettings();

Process? proc = null;
var startTime = DateTime.Now;
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 });
var args = settings.GetSettings();
if (settings.CustomCompiler)
{
OutputLogWritter.WriteLine("Custom compiler settings");
args = settings.CustomCompilerValue;
}
OutputLogWritter.WriteLine($"zxbc \"{mainFile}\" {args}");
proc = Process.Start(new ProcessStartInfo(Path.GetFullPath(ZXOptions.Current.ZxbcPath), $"\"{mainFile}\" " + args) { WorkingDirectory = project.ProjectPath, RedirectStandardError = true, CreateNoWindow = true });

string logOutput;

Expand All @@ -84,6 +107,22 @@ public class ZXProjectBuilder

string binFile = Path.Combine(project.ProjectPath, Path.GetFileNameWithoutExtension(mainFile) + ".bin");

// Postbuild
if (settings.PostBuild)
{
OutputLogWritter.WriteLine($"PostBuild: {settings.PostBuildValue}");
if (!ExecuteFile(settings.PostBuildValue, new string[]
{
project.ProjectPath,
Path.GetFileName(binFile)
},
project.ProjectPath,
OutputLogWritter))
{
return null;
}
}

byte[] binary = File.ReadAllBytes(binFile);

Cleanup(project.ProjectPath, binFile);
Expand Down Expand Up @@ -309,6 +348,22 @@ private static void CheckNextCreator()
settings = project.GetProjectSettings();
mainFile = project.GetMainFile();

// Prebuild
if (settings.PreBuild)
{
OutputLogWritter.WriteLine($"PreBuild: {settings.PreBuildValue}");
if (!ExecuteFile(settings.PreBuildValue, new string[]
{
project.ProjectPath,
Path.GetFileName(mainFile)
},
project.ProjectPath,
OutputLogWritter))
{
return null;
}
}

if (mainFile == null)
{
OutputLogWritter.WriteLine("Cannot find main file, check that it exists and if there are more than one that is specified in the build settings.");
Expand All @@ -329,6 +384,11 @@ private static void CheckNextCreator()
string logOutput;

var args = settings.GetDebugSettings();
if (settings.CustomCompiler)
{
OutputLogWritter.WriteLine("Custom compiler settings");
args = settings.CustomCompilerValue;
}

OutputLogWritter.WriteLine("Building map files...");

Expand All @@ -339,7 +399,6 @@ private static void CheckNextCreator()

OutputLogWritter.WriteLine("Building program map...");

// TODO: DUEFECTU 2023.05.17: Bug for long path
var codeFile = files.FirstOrDefault(f => f.AbsolutePath == Path.GetFullPath(mainFile));
if (codeFile == null)
{
Expand All @@ -349,10 +408,10 @@ private static void CheckNextCreator()
}

cmd = $"\"{Path.Combine(codeFile.Directory, codeFile.TempFileName)}\" -M MEMORY_MAP " + args;
OutputLogWritter.WriteLine("zxbc "+cmd);
OutputLogWritter.WriteLine("zxbc " + cmd);
var proc = Process.Start(
new ProcessStartInfo(
Path.GetFullPath(ZXOptions.Current.ZxbcPath),cmd)
Path.GetFullPath(ZXOptions.Current.ZxbcPath), cmd)
{ WorkingDirectory = project.ProjectPath, RedirectStandardError = true, CreateNoWindow = true });

OutputProcessLog(OutputLogWritter, proc, out logOutput);
Expand Down Expand Up @@ -692,5 +751,73 @@ private static bool PostBuild(bool debug, string path, ZXProgram CompiledProgram

return true;
}


public static bool ExecuteFile(string preBuildValue, string[] parameters, string workingPath, TextWriter outLog)
{
try
{
var proc = Process.Start(
new ProcessStartInfo(
preBuildValue,
parameters)
{
WorkingDirectory = workingPath,
RedirectStandardError = true,
RedirectStandardOutput = true,
CreateNoWindow = true
});

string logOutput = "";
ProcessRedirect(proc, outLog);

var ecode = proc.ExitCode;

if (ecode != 0)
{
Cleanup(workingPath);
outLog.WriteLine("Error building program, aborting...");
return false;
}
return true;
}
catch (Exception ex)
{
outLog.WriteLine("ERROR executing file: " + ex.Message);
return false;
}
}


private static void ProcessRedirect(Process proc, TextWriter outLog)
{
try
{
while (!proc.HasExited)
{
if (!proc.StandardOutput.EndOfStream)
{
string? line = proc.StandardOutput.ReadLine();
outLog.WriteLine(line);
}
if (!proc.StandardError.EndOfStream)
{
string? line = proc.StandardError.ReadLine();
outLog.WriteLine(line);
}
}
while (!proc.StandardOutput.EndOfStream)
{
string? line = proc.StandardOutput.ReadLine();
outLog.WriteLine(line);
}
while (!proc.StandardError.EndOfStream)
{
string? line = proc.StandardError.ReadLine();
outLog.WriteLine(line);
}
}
catch { }
}
}
}
16 changes: 16 additions & 0 deletions ZXBStudio/Classes/ZXBuildSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ public class ZXBuildSettings
public bool Strict { get; set; }
public bool Headerless { get; set; }
public bool NextMode { get; set; }

public bool PreBuild { get; set; }
public string PreBuildValue { get; set; }
public bool CustomCompiler { get; set; }
public string CustomCompilerValue { get; set; }
public bool PostBuild { get; set; }
public string PostBuildValue { get; set; }
public bool ExternalEmulator { get; set; }
public string ExternalEmuladorValue { get; set; }


public string GetSettings()
{
List<string> settings = new List<string>();
Expand Down Expand Up @@ -69,6 +80,11 @@ public string GetSettings()
if (Strict)
settings.Add("--strict");

if (Headerless)
{
settings.Add("--headerless");
}

if (NextMode)
{
settings.Add("--zxnext");
Expand Down
6 changes: 4 additions & 2 deletions ZXBStudio/Classes/ZXLogTextWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ namespace ZXBasicStudio.Classes
{
public class ZXLogTextWriter : TextWriter
{
TextBlock target;
//TextBlock target;
TextBox target;
ScrollViewer scroll;

public ZXLogTextWriter(TextBlock Target, ScrollViewer Scroller)
//public ZXLogTextWriter(TextBlock Target, ScrollViewer Scroller)
public ZXLogTextWriter(TextBox Target, ScrollViewer Scroller)
{
this.target = Target;
this.scroll = Scroller;
Expand Down
45 changes: 26 additions & 19 deletions ZXBStudio/Controls/ZXOutputLog.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,31 @@
xmlns:svg="using:Avalonia.Svg.Skia"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="ZXBasicStudio.Controls.ZXOutputLog">
<UserControl.ContextMenu>
<ContextMenu Placement="Pointer">
<MenuItem Header="Clear output window" Name="mnuClearOutputWindow" />
<MenuItem Header="Copy to clipboard" Name="mnuCopyToClipboard" />
</ContextMenu>
</UserControl.ContextMenu>
<Grid RowDefinitions="auto,*">
<Grid ColumnDefinitions="1*" DataContext=".ZXMemoryView">
<StackPanel Grid.Row="0" Spacing="2" Orientation="Horizontal" Margin="2" HorizontalAlignment="Left">
<Button Width="30" Foreground="Black" Classes="toolbar" Name="btnClearOutputWindow" ToolTip.Tip="Clear output window"><svg:Svg Path="/Svg/eraser-solid.svg"></svg:Svg></Button>
<Button Width="30" Foreground="Black" Classes="toolbar" Name="btnCopyToClipboard" ToolTip.Tip="Copy output log to clipboard"><svg:Svg Path="/Svg/copy-solid.svg"></svg:Svg></Button>
</StackPanel>
</Grid>
<Grid Grid.Row="1">
<ScrollViewer HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="#FF202020" Name="scrOutput"
VerticalScrollBarVisibility="Auto">
<TextBlock TextWrapping="Wrap" Foreground="White" Name="tbOutput" Padding="10"></TextBlock>
</ScrollViewer>
</Grid>
<UserControl.ContextMenu>
<ContextMenu Placement="Pointer">
<MenuItem Header="Clear output window" Name="mnuClearOutputWindow" />
<MenuItem Header="Copy to clipboard" Name="mnuCopyToClipboard" />
</ContextMenu>
</UserControl.ContextMenu>
<Grid RowDefinitions="auto,*">
<Grid ColumnDefinitions="1*" DataContext=".ZXMemoryView">
<StackPanel Grid.Row="0" Spacing="2" Orientation="Horizontal" Margin="2" HorizontalAlignment="Left">
<Button Width="30" Foreground="Black" Classes="toolbar" Name="btnClearOutputWindow" ToolTip.Tip="Clear output window">
<svg:Svg Path="/Svg/eraser-solid.svg"></svg:Svg>
</Button>
<Button Width="30" Foreground="Black" Classes="toolbar" Name="btnCopyToClipboard" ToolTip.Tip="Copy output log to clipboard">
<svg:Svg Path="/Svg/copy-solid.svg"></svg:Svg>
</Button>
</StackPanel>
</Grid>
<Grid Grid.Row="1">
<ScrollViewer HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="#FF202020" Name="scrOutput"
VerticalScrollBarVisibility="Auto">
<!--
<TextBlock TextWrapping="Wrap" Foreground="White" Name="tbOutput" Padding="10" IsVisible="False"/>
-->
<TextBox TextWrapping="Wrap" AcceptsReturn="True" Foreground="White" Name="tbOutput" Padding="10" IsReadOnly="True"/>
</ScrollViewer>
</Grid>
</Grid>
</UserControl>
4 changes: 2 additions & 2 deletions ZXBStudio/Dialogs/ZXAboutDialog.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public ZXAboutDialog()
{
InitializeComponent();

txtBuild.Text = "1.6.0-beta3";
txtDate.Text = "2025-05-13";
txtBuild.Text = "1.6.0-beta4";
txtDate.Text = "2025-05-21";

btnClose.Click += BtnClose_Click;

Expand Down
Loading