Esempio n. 1
0
 private PcdbFile(string path, PcdbGameVersion gameVersion)
 {
     FileName = path;
     database = new SQLiteDatabase(FileName);
     database.BeginTransaction();
     {
         database.ExecuteNonQuery(new[] {"PRAGMA encoding = 'UTF-8'", "PRAGMA foreign_keys = ON"});
         switch (gameVersion)
         {
         case PcdbGameVersion.Unknown:
             database.RollBackTransaction();
             database.Close();
             throw new NotSupportedException("Unknown game version.");
         case PcdbGameVersion.SHOC:
             database.RollBackTransaction();
             database.Close();
             throw new NotSupportedException("S.T.A.L.K.E.R.: Shadow of Chernobyl is not supported.");
         case PcdbGameVersion.CS:
             database.ExecuteNonQuery(new[]
             {
                 "CREATE TABLE DBVERSION (VERSION INTEGER UNSIGNED NOT NULL)",
                 "INSERT INTO DBVERSION VALUES ('" + (int)SupportedRevision + "')",
                 "CREATE TABLE DBTYPE (TYPEID TINYINT UNSIGNED NOT NULL)",
                 "INSERT INTO DBTYPE VALUES ('2')",
                 "CREATE TABLE HASHES (HASH CHAR(32) NOT NULL PRIMARY KEY, INFO TINYTEXT NULL)",
                 "CREATE TABLE NAMES (HASH CHAR(32) NOT NULL, NAME TINYTEXT NOT NULL, " +
                     "DATEINFO TIMESTAMP NULL, FOREIGN KEY (HASH) REFERENCES HASHES(HASH), " +
                     "PRIMARY KEY (HASH, NAME))",
                 "CREATE TABLE IPS (HASH CHAR(32) NOT NULL, IP TINYTEXT NOT NULL, " +
                     "DATEINFO TIMESTAMP NULL, FOREIGN KEY (HASH) REFERENCES HASHES(HASH), " +
                     "PRIMARY KEY (HASH, IP))"
             });
             break;
         case PcdbGameVersion.COP:
             database.ExecuteNonQuery(new[]
             {
                 "CREATE TABLE DBVERSION (VERSION INTEGER UNSIGNED NOT NULL)",
                 "INSERT INTO DBVERSION VALUES ('" + (int)SupportedRevision + "')",
                 "CREATE TABLE DBTYPE (TYPEID TINYINT UNSIGNED NOT NULL)",
                 "INSERT INTO DBTYPE VALUES ('3')",
                 "CREATE TABLE HASHES (HASH CHAR(32) NOT NULL PRIMARY KEY, INFO TINYTEXT NULL)",
                 "CREATE TABLE NAMES (HASH CHAR(32) NOT NULL, NAME TINYTEXT NOT NULL, " +
                     "DATEINFO TIMESTAMP NULL, FOREIGN KEY (HASH) REFERENCES HASHES(HASH), " +
                     "PRIMARY KEY (HASH, NAME))",
                 "CREATE TABLE IPS (HASH CHAR(32) NOT NULL, IP TINYTEXT NOT NULL, " +
                     "DATEINFO TIMESTAMP NULL, FOREIGN KEY (HASH) REFERENCES HASHES(HASH), " +
                     "PRIMARY KEY (HASH, IP))",
                 "CREATE TABLE GSIDS (HASH CHAR(32) NOT NULL, GSID INT UNSIGNED NOT NULL, " +
                     "DATEINFO TIMESTAMP NULL, FOREIGN KEY (HASH) REFERENCES HASHES(HASH), " +
                     "PRIMARY KEY (HASH, GSID))"
             });
             break;
         }
     }
     database.CommitTransaction();
     database.Close();
     Revision = (int)SupportedRevision;
 }