コード例 #1
0
ファイル: ES3Reader.cs プロジェクト: NickBHaynes/GolfTally
    /// <summary>Creates a new ES3Reader and loads a file in storage into it.</summary>
    /// <param name="settings">The settings we want to use to override the default settings.</param>
    public static ES3Reader Create(ES3Settings settings)
    {
        Stream stream = ES3Stream.CreateStream(settings, ES3FileMode.Read);

        if (stream == null)
        {
            return(null);
        }

        // Get the baseWriter using the given Stream.
        if (settings.format == ES3.Format.JSON)
        {
            return(new ES3JSONReader(stream, settings));
        }
        return(null);
    }
コード例 #2
0
    internal static ES3Reader Create(Stream stream, ES3Settings settings)
    {
        stream = ES3Stream.CreateStream(stream, settings, ES3FileMode.Read);

        // Get the baseWriter using the given Stream.
        if (settings.format == ES3.Format.JSON)
        {
            return(new ES3JSONReader(stream, settings));
        }

        /*else if(settings.format == ES3.Format.XML)
        *       return new ES3XMLWriter(stream, settings);*/
        /*else // if(settings.format == ES3.Format.BSON)
         * return new  new ES3BSONWriter(stream, settings);*/

        return(null);
    }
コード例 #3
0
        private void Action_LoadFileFromSaveDataPath()
        {
            _isSaveDataPathValid = File.Exists(_saveDataPath);
            if (_isSaveDataPathValid.HasValue && _isSaveDataPathValid.Value)
            {
                ES3File file         = new ES3File(_saveDataPath, Default_ES3Settings);
                var     contentBytes = file.LoadRawBytes();

                using (MemoryStream stream = new MemoryStream(contentBytes))
                {
                    StreamReader reader = new StreamReader(ES3Stream.CreateStream(stream, Default_ES3Settings, ES3FileMode.Read));
                    SaveDataContent = reader.ReadToEnd();
                }
            }

            var obj = JsonConvert.DeserializeObject(SaveDataContent);

            SaveDataContent = JsonConvert.SerializeObject(obj, Formatting.Indented);
        }
コード例 #4
0
ファイル: ES3Reader.cs プロジェクト: frank731/topdown
    /// <summary>Creates a new ES3Reader and loads the bytes provided into it.</summary>
    /// <param name="settings">The settings we want to use to override the default settings.</param>
    public static ES3Reader Create(byte[] bytes, ES3Settings settings)
    {
        Stream stream = ES3Stream.CreateStream(new MemoryStream(bytes), settings, ES3FileMode.Read);

        if (stream == null)
        {
            return(null);
        }

        // Get the baseWriter using the given Stream.
        if (settings.format == ES3.Format.JSON)
        {
            return(new ES3JSONReader(stream, settings));
        }
        else if (settings.format == ES3.Format.Binary_Alpha)
        {
            return(new ES3BinaryReader(stream, settings));
        }
        return(null);
    }
コード例 #5
0
    /// <summary>Loads the default file as a byte array.</summary>
    /// <param name="settings">The settings we want to use to override the default settings.</param>
    public static byte[] LoadRawBytes(ES3Settings settings)
    {
        using (var stream = ES3Stream.CreateStream(settings, ES3FileMode.Read))
        {
            var bytes = new byte[stream.Length];
            stream.Read(bytes, 0, bytes.Length);
            return(bytes);
        }

        /*if(settings.location == Location.File)
         *      return ES3IO.ReadAllBytes(settings.FullPath);
         * else if(settings.location == Location.PlayerPrefs)
         *      return System.Convert.FromBase64String(PlayerPrefs.GetString(settings.FullPath));
         * else if(settings.location == Location.Resources)
         * {
         *      var textAsset = Resources.Load<TextAsset>(settings.FullPath);
         *      return textAsset.bytes;
         * }
         * return null;*/
    }
コード例 #6
0
    /// <summary>Creates a new ES3Reader and loads the bytes provided into it.</summary>
    /// <param name="settings">The settings we want to use to override the default settings.</param>
    public static ES3Reader Create(byte[] bytes, ES3Settings settings)
    {
        Stream stream = ES3Stream.CreateStream(new MemoryStream(bytes), settings, ES3FileMode.Read);

        if (stream == null)
        {
            return(null);
        }

        // Get the baseWriter using the given Stream.
        if (settings.format == ES3.Format.JSON)
        {
            return(new ES3JSONReader(stream, settings));
        }

        /*else if(settings.format == ES3.Format.XML)
        *       return new ES3XMLWriter(stream, settings);*/
        /*else // if(settings.format == ES3.Format.BSON)
         * return new  new ES3BSONWriter(stream, settings);*/

        return(null);
    }
コード例 #7
0
ファイル: ES3File.cs プロジェクト: wkdeo12/myshooting
    /// <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());
        }
    }
コード例 #8
0
    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);
        }
    }
コード例 #9
0
    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);
    }
コード例 #10
0
 public void Load(ES3Settings settings)
 {
     Load(ES3Stream.CreateStream(settings, ES3FileMode.Read), settings);
 }
コード例 #11
0
ファイル: ES3Spreadsheet.cs プロジェクト: erwinwu211/SYHX
    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;
                }
            }
        }
    }
コード例 #12
0
 /// <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);
 }