/// <summary>Loads the ES3File as a raw byte array.</summary> public byte[] LoadRawBytes() { if (cache.Count == 0) { return(new byte[0]); } using (var ms = new System.IO.MemoryStream()) { var memorySettings = (ES3Settings)settings.Clone(); memorySettings.location = ES3.Location.InternalMS; using (var baseWriter = ES3Writer.Create(ES3Stream.CreateStream(ms, memorySettings, ES3FileMode.Write), memorySettings, true, false)) { foreach (var kvp in cache) { baseWriter.Write(kvp.Key, kvp.Value.type.type, kvp.Value.bytes); } baseWriter.Save(false); } return(ms.ToArray()); } }
public void Save(ES3Settings settings, bool append) { using (var writer = new StreamWriter(ES3Stream.CreateStream(settings, append ? ES3FileMode.Append : ES3FileMode.Write))) { // If data already exists and we're appending, we need to prepend a newline. if (append && ES3.FileExists(settings)) { writer.Write(NEWLINE_CHAR); } var array = ToArray(); for (int row = 0; row < rows; row++) { if (row != 0) { writer.Write(NEWLINE_CHAR); } for (int col = 0; col < cols; col++) { if (col != 0) { writer.Write(COMMA_CHAR); } ES3Debug.Log("Writing cell (" + col + "," + row + ") to file with value " + array[col, row]); writer.Write(Escape(array[col, row])); } } } if (!append) { ES3IO.CommitBackup(settings); } }
public void Save(ES3Settings settings, bool append) { using (var writer = new StreamWriter(ES3Stream.CreateStream(settings, append ? ES3FileMode.Append : ES3FileMode.Write))) { var array = ToArray(); for (int row = 0; row < rows; row++) { if (row != 0) { writer.Write('\n'); } for (int col = 0; col < cols; col++) { if (col != 0) { writer.Write(','); } writer.Write(Escape(array [col, row])); } } } ES3IO.CommitBackup(settings); }
public void Load(ES3Settings settings) { Load(ES3Stream.CreateStream(settings, ES3FileMode.Read), settings); }
public void Load(ES3Settings settings) { using (var reader = new StreamReader(ES3Stream.CreateStream(settings, ES3FileMode.Read))) { int c_int; char c; string value = ""; int col = 0; int row = 0; // Read until the end of the stream. while (true) { c_int = reader.Read(); c = (char)c_int; if (c == QUOTE_CHAR) { while (true) { c = (char)reader.Read(); if (c == QUOTE_CHAR) { // If this quote isn't escaped by another, it is the last quote, so we should stop parsing this value. if (((char)reader.Peek()) != QUOTE_CHAR) { break; } else { c = (char)reader.Read(); } } value += c; } } // If this is the end of a column, row, or the stream, add the value to the spreadsheet. else if (c == COMMA_CHAR || c == NEWLINE_CHAR || c_int == -1) { SetCell(col, row, value); value = ""; if (c == COMMA_CHAR) { col++; } else if (c == NEWLINE_CHAR) { col = 0; row++; } else { break; } } else { value += c; } } } }
/// <summary>Creates or overwrites a file with the specified raw bytes.</summary> /// <param name="bytes">The bytes we want to store.</param> /// <param name="settings">The settings we want to use to override the default settings.</param> public static void SaveRaw(byte[] bytes, ES3Settings settings) { using (var stream = ES3Stream.CreateStream(settings, ES3FileMode.Write)) stream.Write(bytes, 0, bytes.Length); }