diff options
author | emkael <emkael@tlen.pl> | 2018-04-10 02:19:58 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2018-04-10 02:19:58 +0200 |
commit | 0581c8593e8e1b8f9b3c505b0c0da51f82f93c0d (patch) | |
tree | 294722d931808e8a10a0e68b7d95a98d589a97cc /src/PBNFile.cs | |
parent | 211428ebea89e08111354e6956e075967ee4f4af (diff) |
Renaming files to suit Python convention
Diffstat (limited to 'src/PBNFile.cs')
-rw-r--r-- | src/PBNFile.cs | 75 |
1 files changed, 0 insertions, 75 deletions
diff --git a/src/PBNFile.cs b/src/PBNFile.cs deleted file mode 100644 index b26f84c..0000000 --- a/src/PBNFile.cs +++ /dev/null @@ -1,75 +0,0 @@ -using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.IO;
-
-namespace BCDD
-{
- class PBNFile
- {
- public List<PBNBoard> Boards;
-
- private String filename;
- private String tmpFileName;
-
- StreamWriter outputFile;
-
- public PBNFile(String filename)
- {
- this.filename = filename;
- this.Boards = new List<PBNBoard>();
- String[] contents = File.ReadAllLines(this.filename).Select(l => l.Trim()).ToArray();
- List<String> lines = new List<String>();
- foreach (String line in contents)
- {
- if (line.Length == 0)
- {
- if (lines.Count > 0)
- {
- this.Boards.Add(new PBNBoard(lines));
- lines = new List<String>();
- }
- }
- else
- {
- lines.Add(line);
- }
- }
- if (lines.Count > 0)
- {
- this.Boards.Add(new PBNBoard(lines));
- }
- if (!this.Boards[0].HasField("Event"))
- {
- this.Boards[0].WriteEvent("");
- }
- }
-
- public void WriteBoard(PBNBoard board)
- {
- if (this.outputFile == null)
- {
- this.tmpFileName = Path.GetTempFileName();
- this.outputFile = new StreamWriter(new FileStream(this.tmpFileName, FileMode.Create), Encoding.UTF8);
- }
- foreach (PBNField field in board.Fields)
- {
- this.outputFile.WriteLine(field.RawField);
- }
- this.outputFile.WriteLine();
- }
-
- public void Save()
- {
- if (this.outputFile == null)
- {
- throw new IOException("No boards written to PBN file, unable to save it.");
- }
- this.outputFile.Flush();
- this.outputFile.Close();
- File.Delete(this.filename);
- File.Move(this.tmpFileName, this.filename);
- }
- }
-}
|