-
-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
292 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace CKAN.Extensions | ||
{ | ||
public static class DictionaryExtensions | ||
{ | ||
|
||
public static V GetOrDefault<K, V>(this Dictionary<K, V> dict, K key) | ||
{ | ||
V val = default(V); | ||
if (key != null) | ||
{ | ||
dict.TryGetValue(key, out val); | ||
} | ||
return val; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace CKAN | ||
{ | ||
public class ModuleTag | ||
{ | ||
public string Name; | ||
public bool Visible; | ||
public HashSet<string> Modules; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using System; | ||
using System.Linq; | ||
using System.IO; | ||
using System.Collections.Generic; | ||
using Newtonsoft.Json; | ||
|
||
namespace CKAN | ||
{ | ||
public class ModuleTagList | ||
{ | ||
[JsonIgnore] | ||
public Dictionary<string, ModuleTag> Tags = new Dictionary<string, ModuleTag>(); | ||
|
||
[JsonIgnore] | ||
public HashSet<string> Untagged = new HashSet<string>(); | ||
|
||
[JsonProperty("hidden_tags")] | ||
public HashSet<string> HiddenTags = new HashSet<string>(); | ||
|
||
public static readonly string DefaultPath = Path.Combine( | ||
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), | ||
"CKAN", | ||
"tags.json" | ||
); | ||
|
||
public void BuildTagIndexFor(AvailableModule am) | ||
{ | ||
bool tagged = false; | ||
foreach (CkanModule m in am.AllAvailable()) | ||
{ | ||
if (m.Tags != null) | ||
{ | ||
tagged = true; | ||
foreach (string tagName in m.Tags) | ||
{ | ||
ModuleTag tag = null; | ||
if (Tags.TryGetValue(tagName, out tag)) | ||
tag.Modules.Add(m.identifier); | ||
else | ||
Tags.Add(tagName, new ModuleTag() | ||
{ | ||
Name = tagName, | ||
Visible = !HiddenTags.Contains(tagName), | ||
Modules = new HashSet<string>() { m.identifier }, | ||
}); | ||
} | ||
} | ||
} | ||
if (!tagged) | ||
{ | ||
Untagged.Add(am.AllAvailable().First().identifier); | ||
} | ||
} | ||
|
||
public static ModuleTagList Load(string path) | ||
{ | ||
try | ||
{ | ||
return JsonConvert.DeserializeObject<ModuleTagList>(File.ReadAllText(path)); | ||
} | ||
catch (FileNotFoundException ex) | ||
{ | ||
return null; | ||
} | ||
} | ||
|
||
public bool Save(string path) | ||
{ | ||
try | ||
{ | ||
File.WriteAllText(path, JsonConvert.SerializeObject(this, Formatting.Indented)); | ||
return true; | ||
} | ||
catch | ||
{ | ||
return false; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.