From e6d380dc4141438fd10fce0c4945727c6bf52425 Mon Sep 17 00:00:00 2001 From: Hendrik Mennen Date: Sun, 12 Nov 2023 22:58:24 +0100 Subject: [PATCH] create pcf --- .../UniversalFpgaProjectCompileViewModel.cs | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/OneWare.UniversalFpgaProjectSystem/ViewModels/UniversalFpgaProjectCompileViewModel.cs b/src/OneWare.UniversalFpgaProjectSystem/ViewModels/UniversalFpgaProjectCompileViewModel.cs index f4480216..061b99aa 100644 --- a/src/OneWare.UniversalFpgaProjectSystem/ViewModels/UniversalFpgaProjectCompileViewModel.cs +++ b/src/OneWare.UniversalFpgaProjectSystem/ViewModels/UniversalFpgaProjectCompileViewModel.cs @@ -51,6 +51,41 @@ public UniversalFpgaProjectCompileViewModel(FpgaService fpgaService, NodeProvide public async Task SaveAsync(FlexibleWindow window) { - + CreatePcf(); + } + + private string RemoveLine(string file, string find) + { + var startIndex = file.IndexOf(find, StringComparison.Ordinal); + while (startIndex > -1) + { + var endIndex = file.IndexOf('\n', startIndex); + if (endIndex == -1) endIndex = file.Length - 1; + file = file.Remove(startIndex, endIndex - startIndex + 1); + startIndex = file.IndexOf(find, startIndex, StringComparison.Ordinal); + } + + return file; + } + + private void CreatePcf() + { + if (SelectedFpga == null) return; + var pcfPath = Path.Combine(_project.FullPath, "project.pcf"); + + var pcf = ""; + if (File.Exists(pcfPath)) + { + var existingPcf = File.ReadAllText(pcfPath); + existingPcf = RemoveLine(existingPcf, "set_io"); + pcf = existingPcf.Trim() + "\n"; + } + + foreach (var conn in SelectedFpga.Pins.Where(x => x.Value.Connection is not null)) + { + pcf += $"set_io {conn.Value.Connection!.Name} {conn.Value.Name}\n"; + } + + File.WriteAllText(pcfPath, pcf); } } \ No newline at end of file