public void GetsInternalAvcCorrectly() { //Arrange var json = new JObject(); json["spec_version"] = 1; json["identifier"] = "DogeCoinFlag"; json["version"] = "1.0.0"; json["download"] = "https://awesomemod.example/AwesomeMod.zip"; var sut = new ModuleService(); // Act var result = sut.GetInternalAvc(CkanModule.FromJson(json.ToString()), TestData.DogeCoinFlagAvcZip()); // Assert Assert.That(result, Is.Not.Null, "ModuleService should get an internal AVC file." ); Assert.That(result.version, Is.EqualTo(new ModuleVersion("1.1.0.0")), "ModuleService should get correct version from the internal AVC file." ); Assert.That(result.ksp_version, Is.EqualTo(GameVersion.Parse("0.24.2")), "ModuleService should get correct ksp_version from the internal AVC file." ); Assert.That(result.ksp_version_min, Is.EqualTo(GameVersion.Parse("0.24.0")), "ModuleService should get correct ksp_version_min from the internal AVC file." ); Assert.That(result.ksp_version_max, Is.EqualTo(GameVersion.Parse("0.24.2")), "ModuleService should get correct ksp_version_max from the internal AVC file." ); }
public void FakeInstance_ValidArgumentsWithDLCs_ManagerHasValidInstance() { string name = "testname"; GameVersion mhVersion = GameVersion.Parse("1.1.0"); GameVersion bgVersion = GameVersion.Parse("1.0.0"); string tempdir = TestData.NewTempDir(); GameVersion version = GameVersion.Parse("1.7.1"); Dictionary <CKAN.DLC.IDlcDetector, GameVersion> dlcs = new Dictionary <CKAN.DLC.IDlcDetector, GameVersion>() { { new CKAN.DLC.MakingHistoryDlcDetector(), mhVersion }, { new CKAN.DLC.BreakingGroundDlcDetector(), bgVersion } }; manager.FakeInstance(new KerbalSpaceProgram(), name, tempdir, version, dlcs); CKAN.GameInstance newKSP = new CKAN.GameInstance(new KerbalSpaceProgram(), tempdir, name, new NullUser()); CKAN.DLC.MakingHistoryDlcDetector mhDetector = new CKAN.DLC.MakingHistoryDlcDetector(); CKAN.DLC.BreakingGroundDlcDetector bgDetector = new CKAN.DLC.BreakingGroundDlcDetector(); Assert.IsTrue(manager.HasInstance(name)); Assert.IsTrue(mhDetector.IsInstalled(newKSP, out string _, out UnmanagedModuleVersion detectedMhVersion)); Assert.IsTrue(bgDetector.IsInstalled(newKSP, out string _, out UnmanagedModuleVersion detectedBgVersion)); Assert.IsTrue(detectedMhVersion == new UnmanagedModuleVersion(mhVersion.ToString())); Assert.IsTrue(detectedBgVersion == new UnmanagedModuleVersion(bgVersion.ToString())); // Tidy up. CKAN.RegistryManager.Instance(newKSP).ReleaseLock(); System.IO.Directory.Delete(tempdir, true); }
public void CompatibleModules_PastAndFutureCompatibility_ReturnsCurrentOnly() { // Arrange CkanModule modFor161 = CkanModule.FromJson(@"{ ""identifier"": ""TypicalMod"", ""version"": ""0.9.0"", ""download"": ""https://kerbalstuff.com/mod/269/Dogecoin%20Flag/download/1.01"", ""ksp_version"": ""1.6.1"" }"); CkanModule modFor173 = CkanModule.FromJson(@"{ ""identifier"": ""TypicalMod"", ""version"": ""1.0.0"", ""download"": ""https://kerbalstuff.com/mod/269/Dogecoin%20Flag/download/1.01"", ""ksp_version"": ""1.7.3"" }"); CkanModule modFor181 = CkanModule.FromJson(@"{ ""identifier"": ""TypicalMod"", ""version"": ""1.1.0"", ""download"": ""https://kerbalstuff.com/mod/269/Dogecoin%20Flag/download/1.01"", ""ksp_version"": ""1.8.1"" }"); registry.AddAvailable(modFor161); registry.AddAvailable(modFor173); registry.AddAvailable(modFor181); // Act GameVersionCriteria v173 = new GameVersionCriteria(GameVersion.Parse("1.7.3")); List <CkanModule> compat = registry.CompatibleModules(v173).ToList(); // Assert Assert.IsFalse(compat.Contains(modFor161)); Assert.IsTrue(compat.Contains(modFor173)); Assert.IsFalse(compat.Contains(modFor181)); }
public void VersionComparison(string ver1, string ver2) { var v1 = GameVersion.Parse(ver1); var v2 = GameVersion.Parse(ver2); Assert.True(v1.CompareTo(v2) < 0); }
private void AddVersionToListButton_Click(object sender, EventArgs e) { if (AddVersionToListTextBox.Text.Length == 0) { return; } if (AddVersionToListTextBox.Text.ToLower() == "any") { MessageBox.Show( Properties.Resources.CompatibleGameVersionsDialogInvalidFormat, Properties.Resources.CompatibleGameVersionsDialogErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error ); return; } try { var version = GameVersion.Parse(AddVersionToListTextBox.Text); SelectedVersionsCheckedListBox.Items.Insert(0, version); } catch (FormatException) { MessageBox.Show( Properties.Resources.CompatibleGameVersionsDialogInvalidFormat, Properties.Resources.CompatibleGameVersionsDialogErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error ); } }
public void VersionEquality(string ver1, string ver2) { var v1 = GameVersion.Parse(ver1); var v2 = GameVersion.Parse(ver2); Assert.Equal(v1, v2); }
public CkanModule GeneratorRandomModule( GameVersion ksp_version = null, List <RelationshipDescriptor> conflicts = null, List <RelationshipDescriptor> depends = null, List <RelationshipDescriptor> suggests = null, List <String> provides = null, string identifier = null, ModuleVersion version = null) { var mod = new CkanModule { name = Generator.Next().ToString(CultureInfo.InvariantCulture), @abstract = Generator.Next().ToString(CultureInfo.InvariantCulture), identifier = identifier ?? Generator.Next().ToString(CultureInfo.InvariantCulture), spec_version = new ModuleVersion(1.ToString(CultureInfo.InvariantCulture)), ksp_version = ksp_version ?? GameVersion.Parse("0." + Generator.Next()), version = version ?? new ModuleVersion(Generator.Next().ToString(CultureInfo.InvariantCulture)) }; mod.ksp_version_max = mod.ksp_version_min = null; mod.conflicts = conflicts; mod.depends = depends; mod.suggests = suggests; mod.provides = provides; return(mod); }
public void ParseWorksCorrectly(string s, GameVersion version) { // Act var result = GameVersion.Parse(s); // Assert Assert.AreEqual(version, result); Assert.AreEqual(s, result.ToString()); }
public void ParseThrowsExceptionOnInvalidParameter(string s) { // Act // ReSharper disable once ObjectCreationAsStatement TestDelegate act = () => GameVersion.Parse(s); // Assert Assert.That(act, Throws.Exception); }
public void MissingPatch_VersionOnlyHasMajorMinor() { var converter = new JsonAvcToGameVersion(); string json = @"{""MAJOR"":1, ""MINOR"":5}"; var reader = new JsonTextReader(new StringReader(json)); var result = (GameVersion)converter.ReadJson(reader, null, null, null); Assert.That(result, Is.EqualTo(GameVersion.Parse("1.5"))); }
public void TestStrictGameComparator(String modVersion, String gameVersion, bool expectedResult) { var comparator = new CKAN.StrictGameComparator(); // We're going to tweak compatibly of the mod gameMod.ksp_version = GameVersion.Parse(modVersion); // Now test! Assert.AreEqual(expectedResult, comparator.Compatible(new GameVersionCriteria(GameVersion.Parse(gameVersion)), gameMod)); }
public GameVersion this[string buildId] { get { EnsureBuildMap(); string version; return(_jBuilds.Builds.TryGetValue(buildId, out version) ? GameVersion.Parse(version) : null); } }
public void GenerallySafeLax(Type type, bool expected) { var comparator = (CKAN.IGameComparator)Activator.CreateInstance(type); // We're going to tweak compatibly to mark the mod as being for 1.0.3 gameMod.ksp_version = gameMod.ksp_version_min = gameMod.ksp_version_max = GameVersion.Parse("1.0.3"); // Now test! Assert.AreEqual(expected, comparator.Compatible(new GameVersionCriteria(gameVersion), gameMod)); }
public void TestStrictGameComparatorMinMax(String modMinVersion, String modMaxVersion, String gameVersion, bool expectedResult) { var comparator = new CKAN.StrictGameComparator(); gameMod.ksp_version = null; gameMod.ksp_version_min = modMinVersion == null ? null : GameVersion.Parse(modMinVersion); gameMod.ksp_version_max = modMaxVersion == null ? null : GameVersion.Parse(modMaxVersion); // Now test! Assert.AreEqual(expectedResult, comparator.Compatible(new GameVersionCriteria(GameVersion.Parse(gameVersion)), gameMod)); }
public void TotallyCompatible(Type type, bool expected) { var comparator = (CKAN.IGameComparator)Activator.CreateInstance(type); // Mark the mod as being for 1.0.4 gameMod.ksp_version = gameMod.ksp_version_min = gameMod.ksp_version_max = GameVersion.Parse("1.0.4"); // Now test! Assert.AreEqual(expected, comparator.Compatible(new GameVersionCriteria(gameVersion), gameMod)); }
public void Test_That_Parsing_Versions_Works(string versionString, int versionMajor, int versionMinor, int?versionPatch = null) { var versionParsed = GameVersion.Parse(versionString); Assert.Equal(versionMajor, versionParsed.Major); Assert.Equal(versionMinor, versionParsed.Minor); if (versionPatch != null) { Assert.Equal(versionPatch, versionParsed.Patch); } }
public async Task Test_That_RunesApi_Works() { var runes = await _client.GetRunesAsync(GameVersion.Parse("10.9.1")); Assert.Equal(5, runes.Count); Assert.Contains(runes, rune => rune.Key == "Domination" && rune.Slots.Count == 4); Assert.Contains(runes, rune => rune.Key == "Inspiration" && rune.Slots.Count == 4); Assert.Contains(runes, rune => rune.Key == "Precision" && rune.Slots.Count == 4); Assert.Contains(runes, rune => rune.Key == "Resolve" && rune.Slots.Count == 4); Assert.Contains(runes, rune => rune.Key == "Sorcery" && rune.Slots.Count == 4); }
public void FakeInstance_InvalidVersion_ThrowsBadGameVersionKraken() { string name = "testname"; string tempdir = TestData.NewTempDir(); GameVersion version = GameVersion.Parse("1.1.99"); Assert.Throws <BadGameVersionKraken>(() => manager.FakeInstance(new KerbalSpaceProgram(), name, tempdir, version)); Assert.IsFalse(manager.HasInstance(name)); // Tidy up. System.IO.Directory.Delete(tempdir, true); }
public override object ReadJson( JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer ) { if (reader.Value == null) { return(null); } string raw_version = reader.Value.ToString(); return(GameVersion.Parse(ExpandVersionIfNeeded(raw_version))); }
private async Task <GameVersion?> InternalFetchLatestVersionAsync(CancellationToken token) { ThrowIfDisposed(); var data = await MakeRequestAsync <string[]>($"api/versions.json", token).ConfigureAwait(false); if (data is null) { return(null); } return(_latestVersion = GameVersion.Parse(data[0])); }
private static DalamudStartInfo GetStartInfo(string?arg, Process process) { DalamudStartInfo startInfo; if (arg != default) { startInfo = JsonConvert.DeserializeObject <DalamudStartInfo>(Encoding.UTF8.GetString(Convert.FromBase64String(arg))); } else { var ffxivDir = Path.GetDirectoryName(process.MainModule.FileName); var appDataDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); var xivlauncherDir = Path.Combine(appDataDir, "XIVLauncher"); var gameVerStr = File.ReadAllText(Path.Combine(ffxivDir, "ffxivgame.ver")); var gameVer = GameVersion.Parse(gameVerStr); startInfo = new DalamudStartInfo { WorkingDirectory = null, ConfigurationPath = Path.Combine(xivlauncherDir, "dalamudConfig.json"), PluginDirectory = Path.Combine(xivlauncherDir, "installedPlugins"), DefaultPluginDirectory = Path.Combine(xivlauncherDir, "devPlugins"), AssetDirectory = Path.Combine(xivlauncherDir, "dalamudAssets", "dev"), GameVersion = gameVer, Language = ClientLanguage.English, OptOutMbCollection = false, }; Log.Debug( "Creating a new StartInfo with:\n" + $" WorkingDirectory: {startInfo.WorkingDirectory}\n" + $" ConfigurationPath: {startInfo.ConfigurationPath}\n" + $" PluginDirectory: {startInfo.PluginDirectory}\n" + $" DefaultPluginDirectory: {startInfo.DefaultPluginDirectory}\n" + $" AssetDirectory: {startInfo.AssetDirectory}\n" + $" GameVersion: {startInfo.GameVersion}\n" + $" Language: {startInfo.Language}\n" + $" OptOutMbCollection: {startInfo.OptOutMbCollection}"); Log.Information("A Dalamud start info was not found in the program arguments. One has been generated for you."); Log.Information("Copy the following contents into the program arguments:"); var startInfoJson = Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(startInfo))); Log.Information(startInfoJson); } return(startInfo); }
public void FakeInstance_InNotEmptyFolder_ThrowsBadInstallLocationKraken() { string name = "testname"; string tempdir = TestData.NewTempDir(); GameVersion version = GameVersion.Parse("1.5.1"); System.IO.File.Create(System.IO.Path.Combine(tempdir, "shouldntbehere.txt")).Close(); Assert.Throws <BadInstallLocationKraken>(() => manager.FakeInstance(new KerbalSpaceProgram(), name, tempdir, version)); Assert.IsFalse(manager.HasInstance(name)); // Tidy up. System.IO.Directory.Delete(tempdir, true); }
private bool TryFieldsToModule(out string error, out Control badField) { if (!Identifier.ValidIdentifierPattern.IsMatch(IdentifierTextBox.Text)) { error = Properties.Resources.EditModpackBadIdentifier; badField = IdentifierTextBox; return(false); } if (string.IsNullOrEmpty(NameTextBox.Text)) { error = Properties.Resources.EditModpackBadName; badField = NameTextBox; return(false); } if (string.IsNullOrEmpty(VersionTextBox.Text)) { error = Properties.Resources.EditModpackBadVersion; badField = VersionTextBox; return(false); } if (!string.IsNullOrEmpty(GameVersionMinComboBox.Text) && !string.IsNullOrEmpty(GameVersionMaxComboBox.Text) && GameVersion.Parse(GameVersionMinComboBox.Text) > GameVersion.Parse(GameVersionMaxComboBox.Text)) { error = Properties.Resources.EditModpackBadGameVersions; badField = GameVersionMinComboBox; return(false); } error = null; badField = null; module.identifier = IdentifierTextBox.Text; module.name = NameTextBox.Text; module.@abstract = AbstractTextBox.Text; module.author = AuthorTextBox.Text .Split(',').Select(a => a.Trim()).ToList(); module.version = new ModuleVersion(VersionTextBox.Text); module.license = new List <License>() { new License(LicenseComboBox.Text) }; module.ksp_version_min = string.IsNullOrEmpty(GameVersionMinComboBox.Text) ? null : GameVersion.Parse(GameVersionMinComboBox.Text); module.ksp_version_max = string.IsNullOrEmpty(GameVersionMaxComboBox.Text) ? null : GameVersion.Parse(GameVersionMaxComboBox.Text); return(true); }
private void LoadCompatibleVersions() { String path = CompatibleGameVersionsFile(); if (File.Exists(path)) { CompatibleGameVersions compatibleGameVersions = JsonConvert.DeserializeObject <CompatibleGameVersions>(File.ReadAllText(path)); _compatibleVersions = compatibleGameVersions.Versions .Select(v => GameVersion.Parse(v)).ToList(); // Get version without throwing exceptions for null GameVersion mainVer = null; GameVersion.TryParse(compatibleGameVersions.GameVersionWhenWritten, out mainVer); GameVersionWhenCompatibleVersionsWereStored = mainVer; } }
public void Constructor_WithRegistryThatHasRequiredModuleRemoved_Throws() { var list = new List <string>(); var mod = generator.GeneratorRandomModule(); mod.ksp_version = GameVersion.Parse("0.10"); list.Add(mod.identifier); registry.AddAvailable(mod); registry.RemoveAvailable(mod); Assert.Throws <ModuleNotFoundKraken>(() => new RelationshipResolver( list, null, options, registry, null)); }
public void Test_That_Versions_Compare_Properly() { var lVersion = GameVersion.Parse("1.2.3"); var rVersion = GameVersion.Parse("3.2.1"); Assert.True(rVersion > lVersion, $"{rVersion} should be higher than {lVersion}"); Assert.True(rVersion >= lVersion, $"{rVersion} should be higher than or equal to {lVersion}"); Assert.Equal(1, rVersion.CompareTo(lVersion)); Assert.False(rVersion == lVersion, $"{rVersion} should not be equal to {lVersion}"); Assert.False(rVersion < lVersion, $"{rVersion} should not be lower than {lVersion}"); Assert.False(rVersion <= lVersion, $"{rVersion} should not be lower than or equal to {lVersion}"); Assert.Equal(-1, lVersion.CompareTo(rVersion)); Assert.True(rVersion > null, $"{rVersion} should be higher than null"); Assert.False(rVersion == null, $"{rVersion} should not be equal to null"); Assert.False(rVersion < null, $"{rVersion} should not be lower than null"); Assert.True(null < rVersion, $"null should be lower than {rVersion}"); Assert.False(null == rVersion, $"null should not be equal to {rVersion}"); Assert.False(null > rVersion, $"null should not be higher than {rVersion}"); var version = GameVersion.Parse("1.33.7"); var same = GameVersion.Parse("1.33.7"); Assert.True(version == same, $"{version} should be equal to {same}"); Assert.True(version >= same, $"{version} should be higher than or equal to {same}"); Assert.True(version <= same, $"{version} should be lower than or equal to {same}"); Assert.False(version > same, $"{version} should not be higher than {same}"); Assert.False(version < same, $"{version} should not be lower than {same}"); Assert.Equal(0, version.CompareTo(same)); Assert.Equal(0, same.CompareTo(version)); GameVersion @null = null; Assert.True(@null == null, "@null should be equal to null"); Assert.True(@null >= null, "@null should be higher than or equal to null"); Assert.True(@null <= null, "@null should be lower than or equal to null"); Assert.False(@null > null, "@null should not be higher than null"); Assert.False(@null < null, "@null should not be lower than null"); Assert.True(null == @null, "null should be equal to @null"); Assert.True(null >= @null, "null should be higher than or equal to @null"); Assert.True(null <= @null, "null should be lower than or equal to @null"); Assert.False(null > @null, "null should not be higher than @null"); Assert.False(null < @null, "null should not be lower than @null"); }
public bool TryGetVersion(string directory, out GameVersion result) { var readmePath = Path.Combine(directory, "readme.txt"); if (File.Exists(readmePath)) { var match = File .ReadAllLines(readmePath) .Select(i => VersionPattern.Match(i)) .FirstOrDefault(i => i.Success); if (match != null) { result = GameVersion.Parse(match.Groups["version"].Value); return(true); } } result = default(GameVersion); return(false); }
public override object ReadJson( JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer ) { if (reader.TokenType == JsonToken.StartArray) { return(JArray.Load(reader) .Values <string>() .Select(v => GameVersion.Parse(Regex.Replace(v, @"-.*$", ""))) .ToArray()); } else { if (reader.Value == null) { return(null); } string raw_version = reader.Value.ToString(); return(GameVersion.Parse(Regex.Replace(raw_version, @"-.*$", ""))); } }
public void FakeInstance_DlcsWithWrongBaseVersion_ThrowsWrongGameVersionKraken(string baseVersion) { string name = "testname"; GameVersion mhVersion = GameVersion.Parse("1.1.0"); GameVersion bgVersion = GameVersion.Parse("1.0.0"); string tempdir = TestData.NewTempDir(); GameVersion version = GameVersion.Parse(baseVersion); Dictionary <CKAN.DLC.IDlcDetector, GameVersion> dlcs = new Dictionary <CKAN.DLC.IDlcDetector, GameVersion>() { { new CKAN.DLC.MakingHistoryDlcDetector(), mhVersion }, { new CKAN.DLC.BreakingGroundDlcDetector(), bgVersion } }; Assert.Throws <WrongGameVersionKraken>(() => manager.FakeInstance(new KerbalSpaceProgram(), name, tempdir, version, dlcs)); Assert.IsFalse(manager.HasInstance(name)); // Tidy up. System.IO.Directory.Delete(tempdir, true); }
private bool VersionsNeedManualReview(Metadata metadata, out string reason) { JObject json = metadata.Json(); var minStr = json["ksp_version_min"] ?? json["ksp_version"]; var maxStr = json["ksp_version_max"] ?? json["ksp_version"]; var minVer = minStr == null ? GameVersion.Any : GameVersion.Parse((string)minStr); var maxVer = maxStr == null ? GameVersion.Any : GameVersion.Parse((string)maxStr); if (currentRelease.IntersectWith(new GameVersionRange(minVer, maxVer)) == null) { var game = new KerbalSpaceProgram(); reason = $"Hard-coded game versions not compatible with current release: {GameVersionRange.VersionSpan(game, minVer, maxVer)}\r\nPlease check that they match the forum thread."; return(true); } else { // Compatible with latest release, no manual review needed reason = ""; return(false); } }