Skip to content

Commit

Permalink
Merge pull request #83 from AlexanderDzhoganov/master
Browse files Browse the repository at this point in the history
A lot of work on GUI
  • Loading branch information
pjf committed Oct 18, 2014
2 parents a5c7062 + 0c31303 commit cfe317a
Show file tree
Hide file tree
Showing 39 changed files with 2,755 additions and 676 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ CKAN/*/bin
CKAN/*/obj
test-results
*.userprefs
*.csproj.user
TestResult.xml
StyleCop.Cache
ckan.exe
Expand Down
2 changes: 1 addition & 1 deletion CKAN.schema
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
},
"install_to" : {
"description" : "Where file should be installed to",
"enum" : [ "GameData", "Ships" ]
"enum" : [ "GameData", "Ships", "GameRoot", "Tutorial" ]
},
"license" : {
"description" : "A license.",
Expand Down
18 changes: 8 additions & 10 deletions CKAN/CKAN.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,29 @@ Global
{92442BD6-F533-4BB8-8E04-9D93A038035E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{92442BD6-F533-4BB8-8E04-9D93A038035E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{92442BD6-F533-4BB8-8E04-9D93A038035E}.Release|Any CPU.Build.0 = Release|Any CPU
{A79F9D54-315C-472B-928F-713A5860B2BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A79F9D54-315C-472B-928F-713A5860B2BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A79F9D54-315C-472B-928F-713A5860B2BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A79F9D54-315C-472B-928F-713A5860B2BE}.Release|Any CPU.Build.0 = Release|Any CPU
{E97D81F6-85E2-4F1F-906D-BE21766602E5}.Debug|Any CPU.ActiveCfg = Debug|x86
{E97D81F6-85E2-4F1F-906D-BE21766602E5}.Debug|Any CPU.Build.0 = Debug|x86
{E97D81F6-85E2-4F1F-906D-BE21766602E5}.Release|Any CPU.ActiveCfg = Release|x86
{E97D81F6-85E2-4F1F-906D-BE21766602E5}.Release|Any CPU.Build.0 = Release|x86
{A79F9D54-315C-472B-928F-713A5860B2BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A79F9D54-315C-472B-928F-713A5860B2BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A79F9D54-315C-472B-928F-713A5860B2BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A79F9D54-315C-472B-928F-713A5860B2BE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = CKAN\CKAN.csproj
Policies = $0
$0.TextStylePolicy = $1
$0.TextStylePolicy = $5
$1.FileWidth = 120
$1.TabsToSpaces = False
$1.inheritsSet = VisualStudio
$1.inheritsScope = text/plain
$0.DotNetNamingPolicy = $2
$2.DirectoryNamespaceAssociation = None
$2.ResourceNamePolicy = FileFormatDefault
$0.TextStylePolicy = $3
$3.inheritsSet = null
$3.scope = text/x-csharp
$0.CSharpFormattingPolicy = $4
Expand All @@ -52,7 +54,6 @@ Global
$4.inheritsSet = Mono
$4.inheritsScope = text/x-csharp
$4.scope = text/x-csharp
$0.TextStylePolicy = $5
$5.NoTabsAfterNonTabs = True
$5.inheritsSet = VisualStudio
$5.inheritsScope = text/plain
Expand All @@ -61,7 +62,4 @@ Global
$6.Text =
$6.IncludeInNewFiles = True
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
1 change: 1 addition & 0 deletions CKAN/CKAN/CKAN.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<Compile Include="ModuleInstaller.cs" />
<Compile Include="Net.cs" />
<Compile Include="AvailableModule.cs" />
<Compile Include="TransactionalFilesystem.cs" />
<Compile Include="User.cs" />
<Compile Include="RelationshipResolver.cs" />
<Compile Include="Types\Version.cs" />
Expand Down
11 changes: 11 additions & 0 deletions CKAN/CKAN/KSP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,17 @@ public static void Init() {
Directory.CreateDirectory (DownloadCacheDir ());
}

if (!Directory.Exists(FilesystemTransaction.TempPath))
{
Directory.CreateDirectory(FilesystemTransaction.TempPath);
}
else
{
var directory = new DirectoryInfo(FilesystemTransaction.TempPath);
foreach (System.IO.FileInfo file in directory.GetFiles()) file.Delete();
foreach (System.IO.DirectoryInfo subDirectory in directory.GetDirectories()) subDirectory.Delete(true);
}

// If we've got no game in the registry, then store this one.
// If we *do* have a game there, don't touch it.

Expand Down
47 changes: 43 additions & 4 deletions CKAN/CKAN/Module.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Schema;

namespace CKAN {

using System;
Expand Down Expand Up @@ -114,8 +117,6 @@ private void DeSerialisationFixes(StreamingContext like_i_could_care) {
// KSP version mixed with min/max.
throw new InvalidModuleAttributesException ("ksp_version mixed wtih ksp_version_(min|max)", this);
}


}

/// <summary>
Expand Down Expand Up @@ -154,12 +155,15 @@ public class BundledModule : Module {

public BundledModule(dynamic stanza) {
// For now, we just copy across the fields from our stanza.
version = stanza.version;
JValue jVersion = (JValue) stanza.version;
version = new Version((string)jVersion.Value);
identifier = stanza.identifier;
license = stanza.license;
}
}

public class CkanInvalidMetadataJson : Exception { }

public class CkanModule : Module {

private static string[] required_fields = {
Expand All @@ -185,6 +189,37 @@ public class CkanModule : Module {

private static readonly ILog log = LogManager.GetLogger (typeof(CkanModule));

private static JsonSchema metadata_schema = null;
private static string metadata_schema_path = "CKAN.schema";
private static bool metadata_schema_missing_warning_fired = false;

private static bool validate_json_against_schema(string json)
{
return true;
// due to Newtonsoft Json not supporting v4 of the standard, we can't actually do this :(

if (metadata_schema == null) {
string schema = "";

try {
schema = System.IO.File.ReadAllText(metadata_schema_path);
}
catch (Exception) {
if (!metadata_schema_missing_warning_fired) {
User.Error("Couldn't open metadata schema at \"{0}\", will not validate metadata files", metadata_schema_path);
metadata_schema_missing_warning_fired = true;
}

return true;
}

metadata_schema = JsonSchema.Parse(schema);
}

JObject obj = JObject.Parse(json);
return obj.IsValid(metadata_schema);
}

/// <summary> Generates a CKAN.Meta object given a filename</summary>
public static CkanModule from_file(string filename) {
string json = System.IO.File.ReadAllText (filename);
Expand All @@ -195,6 +230,11 @@ public static CkanModule from_file(string filename) {
/// Also validates that all required fields are present.
/// </summary>
public static CkanModule from_string(string json) {
if (!validate_json_against_schema(json))
{
throw new CkanInvalidMetadataJson();
}

CkanModule newModule = JsonConvert.DeserializeObject<CkanModule> (json);

// Check everything in the spec if defined.
Expand All @@ -211,7 +251,6 @@ public static CkanModule from_string(string json) {

// All good! Return module
return newModule;

}

/// <summary>
Expand Down
Loading

0 comments on commit cfe317a

Please sign in to comment.