Ejemplo n.º 1
0
        /// <summary>
        ///     Opens the file store in the specified directory.
        /// </summary>
        /// <param name="cacheDirectory">The directory containing the index and data files.</param>
        /// <param name="readOnly">No empty cache will be initialized if only reading, and writing will be disallowed.</param>
        /// <exception cref="FileDoesNotExistException">If any of the main_file_cache.* files could not be found.</exception>
        public FileStore(string cacheDirectory, bool readOnly = true)
        {
            this.CacheDirectory = PathExtensions.FixDirectory(cacheDirectory);
            this.ReadOnly       = readOnly;

            if (!this.ReadOnly)
            {
                Directory.CreateDirectory(this.CacheDirectory);
            }

            var fileAccess = this.ReadOnly ? FileAccess.Read : FileAccess.ReadWrite;

            var dataFilePath = Path.Combine(this.CacheDirectory, "main_file_cache.dat2");

            if (this.ReadOnly && !File.Exists(dataFilePath))
            {
                throw new FileNotFoundException("Cache data file does not exist.");
            }

            this._dataStream = File.Open(dataFilePath, FileMode.OpenOrCreate, fileAccess);

            // Load in existing index files
            for (var indexId = 0; indexId <= 255; indexId++)
            {
                var indexFile = Path.Combine(this.CacheDirectory, "main_file_cache.idx" + indexId);

                if (!File.Exists(indexFile))
                {
                    continue;
                }

                this._indexStreams.Add((Index)indexId, File.Open(indexFile, FileMode.Open, fileAccess));
            }
        }
        /// <summary>
        /// Creates an interface on the cache stored in the given directory.
        /// </summary>
        /// <param name="cacheDirectory"></param>
        /// <param name="readOnly"></param>
        public JavaClientCache(string?cacheDirectory = null, bool readOnly = true) : base(new RuneTek5CacheFileDecoder())
        {
            this.CacheDirectory = PathExtensions.FixDirectory(cacheDirectory ?? JavaClientCache.DefaultCacheDirectory);
            this.ReadOnly       = readOnly;

            // Create the cache directory if writing is allowed.
            if (!this.ReadOnly)
            {
                Directory.CreateDirectory(this.CacheDirectory);
            }

            this.OpenStreams();
        }
Ejemplo n.º 3
0
        public NxtClientCache(string?cacheDirectory = null, bool readOnly = true) : base(new RuneTek7CacheFileDecoder())
        {
            // Configure SQLite provider for NXT operations.
            SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_sqlite3());

            this.CacheDirectory = PathExtensions.FixDirectory(cacheDirectory ?? NxtClientCache.DefaultCacheDirectory);
            this.ReadOnly       = readOnly;

            // Create the cache directory if writing is allowed.
            if (!this.ReadOnly)
            {
                Directory.CreateDirectory(this.CacheDirectory);
            }

            this.OpenConnections();
        }
 public FlatFileCache(string baseDirectory)
 {
     this.BaseDirectory = PathExtensions.FixDirectory(baseDirectory);
 }
Ejemplo n.º 5
0
 /// <summary>
 ///     Opens the file store in the specified directory.
 /// </summary>
 public FileStore(IFileSystem fileSystem)
 {
     this.CacheDirectory = PathExtensions.FixDirectory(fileSystem.CachePath);
     this.ReadOnly       = true;
 }