Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:Nez.Persistence.Binary.FileDataStore"/> class. If <paramref name="persistentDataPath"/>
        /// is null, it will use Utils.GetStorageRoot().
        /// </summary>
        /// <param name="persistentDataPath">Persistent data path.</param>
        /// <param name="fileFormat">File format.</param>
        public FileDataStore(string persistentDataPath = null, FileFormat fileFormat = FileFormat.Binary)
        {
            persistentDataPath = persistentDataPath ?? Utils.GetStorageRoot();

            // ensure directory exists
            Directory.CreateDirectory(persistentDataPath);
            _persistentDataPath = persistentDataPath;
            _fileFormat         = fileFormat;
            if (_fileFormat == FileFormat.Binary)
            {
                // if we are binary, cache our reader/writer since they are reuseable
                _writer = new ReuseableBinaryWriter();
                _reader = new ReuseableBinaryReader();
            }
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:Nez.Persistence.Binary.FileDataStore"/> class. If <paramref name="persistentDataPath"/>
        /// is null, it will use Utils.GetStorageRoot().
        /// </summary>
        /// <param name="persistentDataPath">Persistent data path.</param>
        /// <param name="fileFormat">File format.</param>
        public FileDataStore(string persistentDataPath, FileFormat fileFormat = FileFormat.Binary)
        {
            if (persistentDataPath == null)
            {
                var exeName = Path.GetFileNameWithoutExtension(AppDomain.CurrentDomain.FriendlyName).Replace(".vshost", "");
                persistentDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), exeName);
            }

            // ensure directory exists
            Directory.CreateDirectory(persistentDataPath);
            _persistentDataPath = persistentDataPath;
            _fileFormat         = fileFormat;
            if (_fileFormat == FileFormat.Binary)
            {
                // if we are binary, cache our reader/writer since they are reuseable
                _writer = new ReuseableBinaryWriter();
                _reader = new ReuseableBinaryReader();
            }
        }