diff --git a/Injector/CommandLine.cs b/Injector/CommandLine.cs index bee19a2..818185e 100644 --- a/Injector/CommandLine.cs +++ b/Injector/CommandLine.cs @@ -90,7 +90,7 @@ private static SortedDictionary GetOptions() opts.Add(OptionName.repo, new Option(new string[] { "-r=", "--repo=", "--repository=" }, "the repository of the mod, required", typeof(string), false)); // optional - opts.Add(OptionName.allBuilds, new Option(new string[] { "--allBuilds" }, "If set, this version will be considered compatible with all SE builds")); + opts.Add(OptionName.allBuilds, new Option(new string[] { "--allBuilds" }, "If set and --seVersion is not set, the mod will be considered compatible with all Space Engineers versions.")); opts.Add(OptionName.basedir, new Option(new string[] { "--basedir=" }, "files will be organized relative to this directory, defaults to current working directory", typeof(string), defaultValue: Environment.CurrentDirectory)); opts.Add(OptionName.oAuthToken, new Option(new string[] { "--oAuthToken=" }, "personal access token used to log into GitHub, by default the value from the environment variable \"oAuthToken\" will be used", typeof(string))); opts.Add(OptionName.publish, new Option(new string[] { "-p", "--publish" }, "publish the mod to GitHub")); diff --git a/Injector/Properties/VersionInfo.cs b/Injector/Properties/VersionInfo.cs index da68084..df45f13 100644 --- a/Injector/Properties/VersionInfo.cs +++ b/Injector/Properties/VersionInfo.cs @@ -12,4 +12,4 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.5.4.0")] +[assembly: AssemblyVersion("0.5.5.0")] diff --git a/Loader/BuildTest.cs b/Loader/BuildTest.cs deleted file mode 100644 index 90e8e31..0000000 --- a/Loader/BuildTest.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Reflection; -using VRage.Game; - -namespace Rynchodon.Loader -{ - public static class BuildTest - { - - /// - /// Check that the current Space Engineers build is stable. - /// - /// True iff the current Space Engineers build is stable. - public static bool IsStable() - { - FieldInfo field = typeof(MyFinalBuildConstants).GetField("IS_STABLE"); - if (field == null) - throw new NullReferenceException("MyFinalBuildConstants does not have a field named IS_STABLE or it has unexpected binding"); - return (bool)field.GetValue(null); - } - - /// - /// Check that a version's build matches the current Space Engineers build. - /// - /// The version that may be compatible. - /// True iff the version is compatible with the current Space Engineers build. - public static bool MatchesCurrent(Version version) - { - return IsStable() ? version.StableBuild : version.UnstableBuild; - } - - } -} diff --git a/Loader/GitHubClient.cs b/Loader/GitHubClient.cs index e9739e2..bd05863 100644 --- a/Loader/GitHubClient.cs +++ b/Loader/GitHubClient.cs @@ -6,8 +6,6 @@ using System.Runtime.Serialization.Json; using System.Threading.Tasks; using System.Windows.Forms; -using SpaceEngineers.Game; -using VRage.Game; namespace Rynchodon.Loader { @@ -272,10 +270,7 @@ internal bool Update(ModInfo info, ModVersion current, string destinationDirecto continue; // skip if release was compiled with a newer version of SE - if (seVersion < rel.seVersion) - continue; - - if (!BuildTest.MatchesCurrent(rel.version)) + if (seVersion < rel.version.SeVersion) continue; if (mostRecent == null || mostRecent.version.CompareTo(rel.version) < 0) @@ -296,9 +291,9 @@ internal bool Update(ModInfo info, ModVersion current, string destinationDirecto Logger.WriteLine("Up-to-date: " + current.version); return false; } - if (relative < 0) // current version is newer than latest + if (relative < 0) // current version is newer than latest release { - if (current.locallyCompiled && BuildTest.MatchesCurrent(current.version)) + if (current.locallyCompiled) { Logger.WriteLine("Keeping locally compiled version: " + current.version); return false; diff --git a/Loader/LoadArms.cs b/Loader/LoadArms.cs index 5e211be..1639bce 100644 --- a/Loader/LoadArms.cs +++ b/Loader/LoadArms.cs @@ -100,12 +100,12 @@ public static void RunInSEProcess() /// Paths to files to include in the mod. /// The author of GitHub repository /// The name of the GitHub repository - /// If true, version will be stable and unstable. If false, version will match the current SE build. + /// If true and seVersion is zero, the mod will be considered compatible with all Space Engineers versions. /// Files will be orgainzed relative to this directory. /// Personal access token for GitHub, it may also be set as an environment variable. /// If true, publish a release to GitHub /// The version of the release. If it is null, the highest version number from any file is used. - /// Version of Space Engineers the mod was compiled against. + /// Version of Space Engineers the mod was compiled against. 0 - get version from SpaceEngineersGame, unless allBuilds is true. public static void AddLocallyCompiledMod(IEnumerable files, string author, string repo, bool allBuilds = false, string basedir = null, string oAuthToken = null, bool publish = false, string versionString = null, int seVersion = 0) { if (_instance == null) @@ -113,7 +113,11 @@ public static void AddLocallyCompiledMod(IEnumerable files, string autho ModName name = new ModName(author, repo); + if (seVersion < 1 && !allBuilds) + seVersion = GetCurrentSEVersion(); + Version version; + version.SeVersion = seVersion; if (versionString != null) version = new Version(versionString); else @@ -121,15 +125,12 @@ public static void AddLocallyCompiledMod(IEnumerable files, string autho version = new Version(); foreach (string file in files) { - Version fileVersion = new Version(FileVersionInfo.GetVersionInfo(file), allBuilds); + Version fileVersion = new Version(FileVersionInfo.GetVersionInfo(file), seVersion); if (version.CompareTo(fileVersion) < 0) version = fileVersion; } } - if (seVersion < 1) - seVersion = GetCurrentSEVersion(); - _instance.Load(); ModVersion modVersion = _instance.AddLocallyCompiled(name, version, seVersion, files, basedir); @@ -199,7 +200,7 @@ private LoadArms(bool start) Directory.CreateDirectory(_directory); Logger.logFile = _directory + (Game.IsDedicated ? "Load-ARMS Dedicated.log" : "Load-ARMS.log"); - Logger.WriteLine("Load-ARMS version: " + new Version(FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location), true)); + Logger.WriteLine("Load-ARMS version: " + new Version(FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location), 0)); if (start) _task = ParallelTasks.Parallel.StartBackground(Run); @@ -496,7 +497,6 @@ private ModVersion AddLocallyCompiled(ModName name, Version version, int seVersi _data.ModsCurrentVersions.Add(hashCode, current); } current.version = version; - current.seVersion = seVersion; Logger.WriteLine("mod: " + name.fullName + ", compiled version: " + current.version); current.EraseAllFiles(); diff --git a/Loader/Loader.csproj b/Loader/Loader.csproj index 13ab3b8..dc7a408 100644 --- a/Loader/Loader.csproj +++ b/Loader/Loader.csproj @@ -77,7 +77,6 @@ Properties\VersionInfo.cs - diff --git a/Loader/ModInfo.cs b/Loader/ModInfo.cs index 7e821c6..6b00383 100644 --- a/Loader/ModInfo.cs +++ b/Loader/ModInfo.cs @@ -1,5 +1,4 @@ using System; -using System.ComponentModel; using System.IO; using System.Runtime.Serialization; @@ -68,9 +67,6 @@ internal class ModVersion : ModName /// The version of the mod. [DataMember] public Version version; - /// The version of Space Engineers the mod was compiled against. - [DataMember] - public int seVersion; /// Allows version to be greater than latest release. [DataMember] public bool locallyCompiled; diff --git a/Loader/Release.cs b/Loader/Release.cs index fc894a3..1c81b60 100644 --- a/Loader/Release.cs +++ b/Loader/Release.cs @@ -4,7 +4,6 @@ using System.Reflection; using System.Runtime.Serialization; using System.Text; -using System.Text.RegularExpressions; namespace Rynchodon.Loader { @@ -44,33 +43,20 @@ public string tag_name get { return _tag_name; } set { - Match match = Regex.Match(value, @"-SE(\d+)"); - if (!match.Success) - seVersion = 0; - else - { - string group = match.Groups[1].Value; - seVersion = string.IsNullOrWhiteSpace(group) ? 0 : int.Parse(group); - } - - _tag_name = value; version = new Version(value); + _tag_name = value; } } [IgnoreDataMember] public Version version { get; private set; } - [IgnoreDataMember] - public int seVersion { get; private set; } - public CreateRelease() { } - public CreateRelease(Version modVersion, int seVersion, bool draft) + public CreateRelease(Version modVersion, bool draft) { this.version = modVersion; - this.seVersion = seVersion; - this.tag_name = modVersion.ToString() + "-SE" + seVersion; + this.tag_name = modVersion.ToString(); this.draft = draft; } diff --git a/Loader/ReleaseCreater.cs b/Loader/ReleaseCreater.cs index 116b24d..ecfb645 100644 --- a/Loader/ReleaseCreater.cs +++ b/Loader/ReleaseCreater.cs @@ -29,9 +29,9 @@ public static void Publish(ModVersion modVersion, string directory, string oAuth GitHubClient client = new GitHubClient(modVersion, oAuthToken); if (!client.HasOAuthToken) throw new ArgumentException("Need oAuthToken"); - + Input input = new Input(); - input.Release = new CreateRelease(modVersion.version, modVersion.seVersion, true); + input.Release = new CreateRelease(modVersion.version, true); string tag_name = input.Release.tag_name; string zipTempFile = PathExtensions.Combine(Path.GetTempPath(), Path.GetRandomFileName() + ".zip"); diff --git a/Loader/Version.cs b/Loader/Version.cs index df97443..008033a 100644 --- a/Loader/Version.cs +++ b/Loader/Version.cs @@ -8,34 +8,20 @@ namespace Rynchodon.Loader [DataContract] public struct Version : IComparable { - private const string stableTag = "-stable", unstableTag = "-unstable"; - [DataMember] public int Major, Minor, Build, Revision; + /// Space Engineers version the mod was compiled with. If the value is 0, the mod is considered compatible with all Space Engineers versions. [DataMember] - public bool StableBuild, UnstableBuild; + public int SeVersion; - public Version(FileVersionInfo info, bool allBuilds) + public Version(FileVersionInfo info, int seVersion) { Major = Math.Max(info.FileMajorPart, info.ProductMajorPart); Minor = Math.Max(info.FileMinorPart, info.ProductMinorPart); Build = Math.Max(info.FileBuildPart, info.ProductBuildPart); Revision = Math.Max(info.FilePrivatePart, info.ProductPrivatePart); - if (allBuilds) - { - StableBuild = UnstableBuild = true; - } - else if (BuildTest.IsStable()) - { - StableBuild = true; - UnstableBuild = false; - } - else - { - // SE version will be checked, so stable will only get the release once it catches up - StableBuild = UnstableBuild = true; - } + this.SeVersion = seVersion; } /// @@ -44,8 +30,7 @@ public Version(FileVersionInfo info, bool allBuilds) /// The string to create the version from. public Version(string versionString) { - Regex versionParts = new Regex(@"(\d+)\.(\d+)\.?(\d*)\.?(\d*)"); - Match match = versionParts.Match(versionString); + Match match = Regex.Match(versionString, @"(\d+)\.(\d+)\.?(\d*)\.?(\d*)"); if (!match.Success) throw new ArgumentException("Could not parse: " + versionString); @@ -59,16 +44,28 @@ public Version(string versionString) group = match.Groups[4].Value; this.Revision = string.IsNullOrWhiteSpace(group) ? 0 : int.Parse(group); - StableBuild = versionString.Contains(stableTag); - UnstableBuild = versionString.Contains(unstableTag); - - if (!StableBuild && !UnstableBuild) - StableBuild = UnstableBuild = true; + match = Regex.Match(versionString, @"-SE(\d+)"); + if (!match.Success) + SeVersion = 0; + else + { + group = match.Groups[1].Value; + SeVersion = string.IsNullOrWhiteSpace(group) ? 0 : int.Parse(group); + } } + /// + /// Compare a version to another to determine if it is more preferable. Versions are first compared by SE version, then by major, minor, build, and revision numbers. + /// + /// The version to compare this version against. + /// A positive value, zero, or a negative value indicating that this version is preferred over, is equal to, or defers to other. public int CompareTo(Version other) { - int diff = this.Major - other.Major; + int diff; + diff = this.SeVersion - other.SeVersion; + if (diff != 0) + return diff; + diff = this.Major - other.Major; if (diff != 0) return diff; diff = this.Minor - other.Minor; @@ -78,12 +75,6 @@ public int CompareTo(Version other) if (diff != 0) return diff; diff = this.Revision - other.Revision; - if (diff != 0) - return diff; - diff = this.StableBuild.CompareTo(other.StableBuild); - if (diff != 0) - return diff; - diff = this.UnstableBuild.CompareTo(other.UnstableBuild); if (diff != 0) return diff; @@ -92,14 +83,11 @@ public int CompareTo(Version other) public override string ToString() { - string result = "v" + Major + "." + Minor + "." + Build + "." + Revision; - if (StableBuild && UnstableBuild) - return result; - if (StableBuild) - result += stableTag; - if (UnstableBuild) - result += unstableTag; - return result; + string value = "v" + Major + "." + Minor + "." + Build + "." + Revision; + if (SeVersion > 0) + value += "-SE" + SeVersion; + return value; } + } }