Skip to content

Commit

Permalink
Add download_size field.
Browse files Browse the repository at this point in the history
For KerbalStuff, spec, and schema.

Closes #77.
  • Loading branch information
pjf committed Oct 19, 2014
1 parent 67dffce commit 9576a00
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CKAN.schema
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
"type" : "string",
"format" : "uri"
},
"download_size" : {
"description" : "The size of the download in bytes",
"type" : "integer"
},
"license" : {
"description" : "Machine readable license, or array of licenses",
"$ref" : "#/definitions/licenses"
Expand Down
3 changes: 3 additions & 0 deletions CKAN/CKAN/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public class Module
[JsonConverter(typeof(JsonSingleOrArrayConverter<string>))]
public List<string> author;

[JsonProperty("download_size")]
public long download_size;

[JsonProperty("comment")] public string comment;
[JsonProperty("conflicts")] public dynamic[] conflicts;
[JsonProperty("depends")] public dynamic[] depends;
Expand Down
17 changes: 16 additions & 1 deletion CKAN/KerbalStuff/KSMod.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;
using log4net;
using Newtonsoft.Json.Linq;

Expand Down Expand Up @@ -26,8 +27,12 @@ public override string ToString()
/// Takes a JObject and inflates it with KS metadata.
/// This will not overwrite fields that already exist.
/// </summary>
public void InflateMetadata(JObject metadata, KSVersion version)
public void InflateMetadata(JObject metadata, KSVersion version, string filename)
{

// Check how big our file is
long download_size = (new FileInfo (filename)).Length;

// Make sure resources exist.
if (metadata["resources"] == null)
{
Expand All @@ -47,6 +52,7 @@ public void InflateMetadata(JObject metadata, KSVersion version)
Inflate(metadata, "version", version.friendly_version.ToString());
Inflate(metadata, "download", Uri.EscapeUriString(version.download_path));
Inflate(metadata, "comment", "Generated by ks2ckan");
Inflate(metadata, "download_size", download_size);
Inflate((JObject) metadata["resources"], "homepage", website);
Inflate((JObject) metadata["resources"]["kerbalstuff"], "url", KSHome());
Inflate(metadata, "ksp_version", version.KSP_version.ToString());
Expand All @@ -70,5 +76,14 @@ internal static void Inflate(JObject metadata, string key, string value)
log.DebugFormat("Leaving {0} as {1}", key, metadata[key]);
}
}

internal static void Inflate(JObject metadata, string key, long value)
{
if (metadata[key] == null)
{
metadata[key] = value;
}
}

}
}
2 changes: 1 addition & 1 deletion CKAN/KerbalStuff/MainClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static int Main(string[] args)
if ((string) metadata[expand_token] == ks_expand_path)
{
log.InfoFormat("Inflating...");
ks.InflateMetadata(metadata, latest);
ks.InflateMetadata(metadata, latest, filename);
metadata.Remove(expand_token);
}

Expand Down
7 changes: 7 additions & 0 deletions Spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,13 @@ and the old name of the mod is listed in the `provides` field. This
allows for mods to be renamed without updating all other mods which
depend upon it.

##### download_size

If supplied, `download_size` is the number of bytes to expect when
downloading from the `download` URL. It is recommended this this field
only be generated by automated tools (where it is encouraged),
and not filled in by hand.

#### Extensions

Any field starting with `x_` (an x, followed by an underscore) is considered
Expand Down

0 comments on commit 9576a00

Please sign in to comment.