diff --git a/uppsrc/ide/UppHub.cpp b/uppsrc/ide/UppHub.cpp index 831c9b0f7..453106466 100644 --- a/uppsrc/ide/UppHub.cpp +++ b/uppsrc/ide/UppHub.cpp @@ -1,7 +1,5 @@ #include "ide.h" -// Todo: other folders in UppHub - struct UppHubNest : Moveable { int tier = -1; String name; @@ -22,14 +20,15 @@ struct UppHubDlg : WithUppHubLayout { bool loading_stopped; String last_package; - void Readme(); - void Load(int tier, const String& url, bool deep); - void Load(); - void Install(bool noprompt = false); - void Uninstall(bool noprompt = false); - void Reinstall(); - void Install(const Index& ii); - void SyncList(); + void Readme(); + Value LoadJson(const String& url); + void Load(int tier, const String& url); + void Load(); + void Install(bool noprompt = false); + void Uninstall(bool noprompt = false); + void Reinstall(); + void Install(const Index& ii); + void SyncList(); UppHubNest *Get(const String& name) { return upv.FindPtr(name); } UppHubNest *Current() { return Get(list.GetKey()); } @@ -104,13 +103,8 @@ void UppHubDlg::Readme() } } -void UppHubDlg::Load(int tier, const String& url, bool deep) +Value UppHubDlg::LoadJson(const String& url) { - if(loaded.Find(url) >= 0) - return; - loaded.Add(url); - - String s = LoadFile(url); if(IsNull(s)) { @@ -128,7 +122,7 @@ void UppHubDlg::Load(int tier, const String& url, bool deep) r.Execute(); if(loading_stopped) - return; + return ErrorValue(); s = r.GetContent(); } @@ -138,17 +132,36 @@ void UppHubDlg::Load(int tier, const String& url, bool deep) if(begin >= 0 && end >= 0) s = s.Mid(begin, end - begin); + + DDUMP(s); Value v = ParseJSON(s); if(v.IsError()) { s.Replace(""", "\""); s.Replace("&", "&"); + DDUMP(s); v = ParseJSON(s); + DDUMP(v); } + return v; +} + +void UppHubDlg::Load(int tier, const String& url) +{ + if(loaded.Find(url) >= 0) + return; + loaded.Add(url); + + Value v = LoadJson(url); + + DDUMP(v); try { String list_name = v["name"]; for(Value ns : v["nests"]) { + String url = ns["url"]; + if(url.GetCount()) + ns = LoadJson(url); String name = ns["name"]; UppHubNest& n = upv.GetAdd(name); n.name = name; @@ -170,16 +183,10 @@ void UppHubDlg::Load(int tier, const String& url, bool deep) Attr(n.readme, "readme"); n.list_name = list_name; } - if(deep) - for(Value l : v["links"]) { - if(loading_stopped) - break; - Load(tier + 1, l, true); - } - for(Value l : v["refs"]) { + for(Value l : v["links"]) { if(loading_stopped) break; - Load(tier + 1, l, false); + Load(tier + 1, l); } } catch(ValueTypeError) {} @@ -206,8 +213,7 @@ void UppHubDlg::Load() upv.Clear(); Load(0, Nvl(LoadFile(ConfigFile("upphub_root")), - "https://raw.githubusercontent.com/ultimatepp/ultimatepp/master/upphub.root"), - true); + "https://raw.githubusercontent.com/ultimatepp/ultimatepp/master/upphub.root")); SyncList();