diff options
author | emkael <emkael@tlen.pl> | 2016-05-25 13:28:25 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2016-05-25 13:28:25 +0200 |
commit | d76442512fd4314fcedbdc28a611f676ab70ce2b (patch) | |
tree | 21b01a4ed029cb8b7d844edb7f546926b140d1e4 /PBNFile.cs | |
parent | e385b66ad2c83bf989f9cbe1fb2f2e995e6a0ece (diff) |
* project directory structure
Diffstat (limited to 'PBNFile.cs')
-rw-r--r-- | PBNFile.cs | 71 |
1 files changed, 0 insertions, 71 deletions
diff --git a/PBNFile.cs b/PBNFile.cs deleted file mode 100644 index 5526623..0000000 --- a/PBNFile.cs +++ /dev/null @@ -1,71 +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));
- }
- }
-
- 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);
- }
- }
-}
|