Exemple #1
0
        public void CanAddAndRemoveNewEntryInKeyValuePairFile2()
        {
            KeyValuePair <string, string> newEntry = new KeyValuePair <string, string>("UnitTestKey", string.Empty);

            KeyValuePairFile tempFile = new KeyValuePairFile(string.Concat(Constants.TestData.DBPATH, Path.DirectorySeparatorChar, Constants.TestData.TEMPFILENAME_PREFIX, Constants.TestData.KEYVALUEPAIR_FILENAME));
            {// ADD ENTRY
                Assert.IsFalse(tempFile.KeyValuePairs.Contains(newEntry));
                tempFile.Add(newEntry.Key);
                Assert.IsTrue(tempFile.KeyValuePairs.Contains(newEntry));
            }
            {// COMMIT
                KeyValuePairFile tempFile2 = new KeyValuePairFile(string.Concat(Constants.TestData.DBPATH, Path.DirectorySeparatorChar, Constants.TestData.TEMPFILENAME_PREFIX, Constants.TestData.KEYVALUEPAIR_FILENAME));
                Assert.IsFalse(tempFile2.KeyValuePairs.Contains(newEntry));
                tempFile.Commit();
                Assert.IsTrue(tempFile.KeyValuePairs.Contains(newEntry));
                KeyValuePairFile tempFile3 = new KeyValuePairFile(string.Concat(Constants.TestData.DBPATH, Path.DirectorySeparatorChar, Constants.TestData.TEMPFILENAME_PREFIX, Constants.TestData.KEYVALUEPAIR_FILENAME));
                Assert.IsTrue(tempFile3.KeyValuePairs.Contains(newEntry));
            }
            {// REMOVE ENTRY
                KeyValuePairFile tempFile4 = new KeyValuePairFile(string.Concat(Constants.TestData.DBPATH, Path.DirectorySeparatorChar, Constants.TestData.TEMPFILENAME_PREFIX, Constants.TestData.KEYVALUEPAIR_FILENAME));
                Assert.IsTrue(tempFile4.KeyValuePairs.Contains(newEntry));
                tempFile4.Remove(newEntry.Key);
                Assert.IsFalse(tempFile4.KeyValuePairs.Contains(newEntry));
                KeyValuePairFile tempFile5 = new KeyValuePairFile(string.Concat(Constants.TestData.DBPATH, Path.DirectorySeparatorChar, Constants.TestData.TEMPFILENAME_PREFIX, Constants.TestData.KEYVALUEPAIR_FILENAME));
                Assert.IsTrue(tempFile5.KeyValuePairs.Contains(newEntry));
                tempFile4.Commit();
                KeyValuePairFile tempFile6 = new KeyValuePairFile(string.Concat(Constants.TestData.DBPATH, Path.DirectorySeparatorChar, Constants.TestData.TEMPFILENAME_PREFIX, Constants.TestData.KEYVALUEPAIR_FILENAME));
                Assert.IsFalse(tempFile6.KeyValuePairs.Contains(newEntry));
            }
        }
Exemple #2
0
        public void SaveInfo()
        {
            var infoPath = System.IO.Path.Combine(Path, "info.txt");
            var kvpFile  = new KeyValuePairFile(infoPath);

            kvpFile.Set("title", Title);
            kvpFile.Set("version", Version);
            kvpFile.Set("game_version", MinimumGameVersion);
            kvpFile.Set("author", Author);
            kvpFile.Set("author_twitter", AuthorTwitter);
            kvpFile.Set("autoload", AutoLoad);
            if (SteamWorkshopID.HasValue)
            {
                kvpFile.Set("steam_workshop_id", SteamWorkshopID.Value.ToString());
            }
            else
            {
                kvpFile.Remove("steam_workshop_id");
            }
            if (SteamUserID.HasValue)
            {
                kvpFile.Set("steam_user_id", SteamUserID.Value.ToString());
            }
            else
            {
                kvpFile.Remove("steam_user_id");
            }
            kvpFile.SaveIfModified();
        }
Exemple #3
0
        public Settings()
        {
            var settingsPath = Path.Combine(App.SavePath, "settings.txt");

            m_kvp            = new KeyValuePairFile(settingsPath);
            m_cachedKeyBinds = new Dictionary <Bind, Key>();
            EnsureDefaults();
            m_kvp.SaveIfModified();
        }
Exemple #4
0
        public void KeyValuePairLine6Matches()
        {
            string           expectedLine = "\"A sixth= key\"=\"A sixth val=ue\"";
            KeyValuePairFile file         = new KeyValuePairFile(string.Concat(Constants.TestData.DBFILEPATHS[1]));

            Assert.AreEqual(expectedLine, file.Data[5]);
            string expectedKey = "A sixth= key";

            Assert.AreEqual(expectedKey, file.KeyValuePairs[4].Key);
            string expectedValue = "A sixth val=ue";

            Assert.AreEqual(expectedValue, file.KeyValuePairs[4].Value);
        }
Exemple #5
0
        public void KeyValuePairLine4Matches()
        {
            string           expectedLine = "\"A fourth\" ke\"y\"=\"A fourth value\"\"";
            KeyValuePairFile file         = new KeyValuePairFile(string.Concat(Constants.TestData.DBFILEPATHS[1]));

            Assert.AreEqual(expectedLine, file.Data[3]);
            string expectedKey = "A fourth\" ke\"y";

            Assert.AreEqual(expectedKey, file.KeyValuePairs[3].Key);
            string expectedValue = "A fourth value\"";

            Assert.AreEqual(expectedValue, file.KeyValuePairs[3].Value);
        }
Exemple #6
0
        public void KeyValuePairLine3Matches()
        {
            string           expectedLine = "A third key=A third value";
            KeyValuePairFile file         = new KeyValuePairFile(string.Concat(Constants.TestData.DBFILEPATHS[1]));

            Assert.AreEqual(expectedLine, file.Data[2]);
            string expectedKey = "A third key";

            Assert.AreEqual(expectedKey, file.KeyValuePairs[2].Key);
            string expectedValue = "A third value";

            Assert.AreEqual(expectedValue, file.KeyValuePairs[2].Value);
        }
Exemple #7
0
        public void KeyValuePairLine5Matches()
        {
            string           expectedLine = "A fifth= key=A fifth= value";
            KeyValuePairFile file         = new KeyValuePairFile(string.Concat(Constants.TestData.DBFILEPATHS[1]));

            Assert.AreEqual(expectedLine, file.Data[4]);
            foreach (KeyValuePair <string, string> kvPair in file.KeyValuePairs)
            {
                if (kvPair.Key.Contains("fifth"))
                {
                    Assert.Fail("The key value pair should not be added");
                }
            }
        }
Exemple #8
0
        public void CanIdentifyListFileWhenEntriesAreUrlsWithParameters()
        {
            Db db = new Db(Constants.TestData.DBPATH);

            KeyValuePairFile keyValuePairFile = db.GetKeyValuePairFile(Constants.TestData.DBFILEPATHS[4].Replace(".txt", ""));

            Assert.IsNull(keyValuePairFile);

            ListFile listFile = db.GetListFile(Constants.TestData.DBFILEPATHS[4].Replace(".txt", ""));

            Assert.IsNotNull(listFile);
            Assert.IsNotNull(listFile.Data);
            Assert.IsTrue(listFile.Data.Count == 1);
        }
        private void CreateLevel()
        {
            // Determine where to create the new level
            var assetsPath = m_mod != null?Path.Combine(m_mod.Path, "assets") : Path.Combine(App.AssetPath, "main");

            var shortCampaignTitle = AssetPath.GetFileNameWithoutExtension(m_campaign.Path);

            int i = 1;
            var levelAssetPath = "levels/" + shortCampaignTitle + "/" + i + ".level";

            while (File.Exists(Path.Combine(assetsPath, levelAssetPath)))
            {
                levelAssetPath = "levels/" + shortCampaignTitle + "/" + i + ".level";
                ++i;
            }

            // Add the level to the campaign
            var newCampaign = m_campaign.Copy();

            newCampaign.Levels.Add(levelAssetPath);

            // Save the campaign
            var fullCampaignPath = Path.Combine(assetsPath, m_campaign.Path);

            newCampaign.Save(fullCampaignPath);

            // Create the Level
            var fullLevelPath = Path.Combine(assetsPath, levelAssetPath);

            Directory.CreateDirectory(Path.GetDirectoryName(fullLevelPath));
            File.Copy(Path.Combine(App.AssetPath, "base/levels/template.level"), fullLevelPath);

            // Modify the ID
            {
                var kvp = new KeyValuePairFile(fullLevelPath);
                kvp.Set("id", MathUtils.GenerateLevelID(levelAssetPath));
                kvp.Save();
            }

            // Reload and edit the level
            Assets.Reload(levelAssetPath);
            Assets.Reload(m_campaign.Path);

            EditLevel(m_campaign.Levels.Count - 1);
        }
Exemple #10
0
        public Progress(INetwork network, string fileName)
        {
            m_network = network;

            // Load KVP and check for tampering
            m_kvp         = new KeyValuePairFile(m_network.LocalUser.RemoteSaveStore, fileName);
            m_kvp.Comment = "Game progress. NOTE: Tampering with this file will disable achievements";
            var tamperCode = ComputeTamperCode();

            if (m_kvp.GetInteger("tamper_code", 0) != tamperCode)
            {
                App.Log("Error: progress.txt has been tampered with! Setting used_cheats to true");
                m_kvp.Set("used_cheats", true);
                tamperCode = ComputeTamperCode();
            }
            m_kvp.Set("tamper_code", tamperCode);
            m_kvp.SaveIfModified();

            if (m_network != null && !App.Demo)
            {
                // Send stat and achivement updates to the network
                foreach (Statistic stat in Enum.GetValues(typeof(Statistic)))
                {
                    int value = GetStatistic(stat);
                    stat.UnlockLinkedAchievements(this, value, value);
                    if (!UsedCheats && m_network.SupportsStatistics)
                    {
                        m_network.LocalUser.SetStatistic(stat.GetID(), value);
                    }
                }
                foreach (Achievement achievement in Enum.GetValues(typeof(Achievement)))
                {
                    if (IsAchievementUnlocked(achievement))
                    {
                        if (!UsedCheats && m_network.SupportsAchievements)
                        {
                            m_network.LocalUser.UnlockAchievement(achievement.GetID());
                        }
                    }
                }
            }
        }