Skip to content

Commit

Permalink
create pcf
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikMennen committed Nov 12, 2023
1 parent d95514e commit e6d380d
Showing 1 changed file with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit e6d380d

Please sign in to comment.