/// <summary> /// Loads database form file to mempry. /// </summary> /// <param name="fileName">File name of database</param> /// <param name="wellKnownTypes">Dictionary of types, are contained in database (from outside libraries)</param> /// <returns></returns> /// <remarks> /// You need to register all outside types, will saved into database. /// For this you need to pass dictionary of these types. /// </remarks> public static DB Load(string fileName, Dictionary<int, Type> wellKnownTypes) { foreach (var pair in wellKnownTypes) Register(pair.Key, pair.Value); var result = new DB(); if (File.Exists(fileName)) using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read)) using (var zip = new GZipStream(fs, CompressionMode.Decompress, false)) using (var br = new BinaryReader(zip, Encoding.UTF8)) try { br.ReadByte();//version result.Audios.Load(br); } catch (EndOfStreamException) {/*end of stream*/} return result; }
private void LoadDatabase() { Database = DB.Load(DatabasePath, Factory.GetKnownTypes()); }