Skip to content

Commit

Permalink
Add SearchResultWithType to OculusDB and add OculusDB as fallback whe…
Browse files Browse the repository at this point in the history
…n requests to oculus fail in Oculus Downgrader
  • Loading branch information
ComputerElite committed Jan 2, 2024
1 parent 9dc2683 commit e0a26e9
Showing 1 changed file with 62 additions and 25 deletions.
87 changes: 62 additions & 25 deletions Oculus Downgrader/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
using QuestPatcher.Axml;
using OculusGraphQLApiLib.Folders;
using OculusDB.Database;
using OculusDB.Search;
using OculusGraphQLApiLib.GraphQL;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
Expand Down Expand Up @@ -1169,40 +1170,76 @@ public void StoreSearch(string autoterm = "")
string term = auto ? autoterm : ConsoleUiController.QuestionString("Search term: ");
Logger.Log("User entered " + term);
Console.ForegroundColor = ConsoleColor.White;
Logger.Log("Requesting results");
Console.WriteLine("Requesting results");
ViewerData<ContextualSearch> s = GraphQLClient.StoreSearch(term, config.headset);
Console.WriteLine();
Logger.Log("Results: ");
Console.WriteLine("Results: ");
Console.WriteLine();

Dictionary<string, string> nameIdRaw = new Dictionary<string, string>();
Dictionary<string, string> nameId = new Dictionary<string, string>();
foreach (CategorySearchResult c in s.data.viewer.contextual_search.all_category_results)

Logger.Log("Requesting results from Oculus");
Console.WriteLine("Requesting results from Oculus");
try
{
if (c.name == "APPS" || c.name == "CONCEPT")
ViewerData<ContextualSearch> s = GraphQLClient.StoreSearch(term, config.headset);
Console.WriteLine();
foreach (CategorySearchResult c in s.data.viewer.contextual_search.all_category_results)
{
foreach (TargetObject<EdgesPrimaryBinaryApplication> r in c.search_results.nodes)
if (c.name == "APPS" || c.name == "CONCEPT")
{
int increment = 0;
while (nameId.ContainsKey(r.target_object.display_name + (increment == 0 ? "" : " " + increment)))
foreach (TargetObject<EdgesPrimaryBinaryApplication> r in c.search_results.nodes)
{
increment++;
}
string name = r.target_object.display_name + (increment == 0 ? "" : " " + increment);
nameId.Add(name.ToLower(), r.target_object.id);
Logger.Log(" - " + name);
Console.WriteLine(" - " + name);
if (name.ToLower() == term.ToLower())
{
Logger.Log("Result is exact match. Auto selecting");
Console.WriteLine("Result is exact match. Auto selecting");
ShowVersions(r.target_object.id);
return;
if (!nameIdRaw.ContainsKey(r.target_object.id))
nameIdRaw.Add(r.target_object.id, r.target_object.display_name);
}

}
}
}
catch (Exception e)
{
Error("Couldn't get results from Oculus");
Logger.Log("Couldn't get results from Oculus: " + e);
}

try
{

Logger.Log("Requesting results from OculusDB");
Console.WriteLine("Requesting results from OculusDB");
SearchResultWithType<DBApplication> applications = JsonSerializer.Deserialize<SearchResultWithType<DBApplication>>(

Check failure on line 1206 in Oculus Downgrader/Program.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'SearchResultWithType<>' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 1206 in Oculus Downgrader/Program.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'SearchResultWithType<>' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 1206 in Oculus Downgrader/Program.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'SearchResultWithType<>' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 1206 in Oculus Downgrader/Program.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'SearchResultWithType<>' could not be found (are you missing a using directive or an assembly reference?)
new WebClient().DownloadString("https://oculusdb-rewrite.rui2015.me/api/v2/search?q=" + term));
foreach (DBApplication application in applications.results)
{
if (!nameIdRaw.ContainsKey(application.id))
nameIdRaw.Add(application.id, application.displayName);
}

} catch(Exception e)
{
Error("Couldn't get results from OculusDB");
Logger.Log("Couldn't get results from OculusDB: " + e);
}
Console.WriteLine();
Logger.Log("Results: ");
Console.WriteLine("Results: ");


foreach (KeyValuePair<string,string> pair in nameIdRaw)
{
int increment = 0;
while (nameId.ContainsKey(pair.Value + (increment == 0 ? "" : " " + increment)))
{
increment++;
}
string name = pair.Value + (increment == 0 ? "" : " " + increment);
nameId.Add(name.ToLower(), pair.Key);
Logger.Log(" - " + name);
Console.WriteLine(" - " + name);
if (name.ToLower() == term.ToLower())
{
Logger.Log("Result is exact match. Auto selecting");
Console.WriteLine("Result is exact match. Auto selecting");
ShowVersions(pair.Key);
return;
}
}
Logger.Log("Requesting cache results");
WebClient client = new WebClient();
client.Headers.Add("user-agent", updater.AppName + "/" + updater.version);
Expand Down

0 comments on commit e0a26e9

Please sign in to comment.