Skip to content

Commit

Permalink
removed stable/unstable
Browse files Browse the repository at this point in the history
  • Loading branch information
Rynchodon committed Mar 23, 2017
1 parent ec9c78f commit dade9d1
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 115 deletions.
2 changes: 1 addition & 1 deletion Injector/CommandLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private static SortedDictionary<OptionName, Option> 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"));
Expand Down
2 changes: 1 addition & 1 deletion Injector/Properties/VersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
33 changes: 0 additions & 33 deletions Loader/BuildTest.cs

This file was deleted.

11 changes: 3 additions & 8 deletions Loader/GitHubClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions Loader/LoadArms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,36 +100,37 @@ public static void RunInSEProcess()
/// <param name="files">Paths to files to include in the mod.</param>
/// <param name="author">The author of GitHub repository</param>
/// <param name="repo">The name of the GitHub repository</param>
/// <param name="allBuilds">If true, version will be stable and unstable. If false, version will match the current SE build.</param>
/// <param name="allBuilds">If true and seVersion is zero, the mod will be considered compatible with all Space Engineers versions.</param>
/// <param name="basedir">Files will be orgainzed relative to this directory.</param>
/// <param name="oAuthToken">Personal access token for GitHub, it may also be set as an environment variable.</param>
/// <param name="publish">If true, publish a release to GitHub</param>
/// <param name="versionString">The version of the release. If it is null, the highest version number from any file is used.</param>
/// <param name="seVersion">Version of Space Engineers the mod was compiled against.</param>
/// <param name="seVersion">Version of Space Engineers the mod was compiled against. 0 - get version from SpaceEngineersGame, unless allBuilds is true.</param>
public static void AddLocallyCompiledMod(IEnumerable<string> 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)
new LoadArms(false);

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
{
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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();

Expand Down
1 change: 0 additions & 1 deletion Loader/Loader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
<Compile Include="..\Injector\Properties\VersionInfo.cs">
<Link>Properties\VersionInfo.cs</Link>
</Compile>
<Compile Include="BuildTest.cs" />
<Compile Include="DownloadProgress.cs" />
<Compile Include="GitChecks.cs" />
<Compile Include="GitHubClient.cs" />
Expand Down
4 changes: 0 additions & 4 deletions Loader/ModInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.ComponentModel;
using System.IO;
using System.Runtime.Serialization;

Expand Down Expand Up @@ -68,9 +67,6 @@ internal class ModVersion : ModName
/// <summary>The version of the mod.</summary>
[DataMember]
public Version version;
/// <summary>The version of Space Engineers the mod was compiled against.</summary>
[DataMember]
public int seVersion;
/// <summary>Allows version to be greater than latest release.</summary>
[DataMember]
public bool locallyCompiled;
Expand Down
20 changes: 3 additions & 17 deletions Loader/Release.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Reflection;
using System.Runtime.Serialization;
using System.Text;
using System.Text.RegularExpressions;

namespace Rynchodon.Loader
{
Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions Loader/ReleaseCreater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
68 changes: 28 additions & 40 deletions Loader/Version.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,20 @@ namespace Rynchodon.Loader
[DataContract]
public struct Version : IComparable<Version>
{
private const string stableTag = "-stable", unstableTag = "-unstable";

[DataMember]
public int Major, Minor, Build, Revision;
/// <summary>Space Engineers version the mod was compiled with. If the value is 0, the mod is considered compatible with all Space Engineers versions.</summary>
[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;
}

/// <summary>
Expand All @@ -44,8 +30,7 @@ public Version(FileVersionInfo info, bool allBuilds)
/// <param name="versionString">The string to create the version from.</param>
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);
Expand All @@ -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);
}
}

/// <summary>
/// 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.
/// </summary>
/// <param name="other">The version to compare this version against.</param>
/// <returns>A positive value, zero, or a negative value indicating that this version is preferred over, is equal to, or defers to other.</returns>
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;
Expand All @@ -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;

Expand All @@ -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;
}

}
}

0 comments on commit dade9d1

Please sign in to comment.