Skip to content

Commit

Permalink
Merge pull request #17 from tverona1/misc
Browse files Browse the repository at this point in the history
A few misc changes
  • Loading branch information
tverona1 authored Aug 19, 2019
2 parents ed42b8d + d30673f commit 1115123
Show file tree
Hide file tree
Showing 17 changed files with 507 additions and 513 deletions.
2 changes: 1 addition & 1 deletion Assets/Plugins/Android/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
</intent-filter>
</activity>
</application>
<uses-feature android:name="android.hardware.vr.headtracking" android:required="true" android:version="1" />
<uses-feature android:name="android.hardware.vr.headtracking" android:required="false" android:version="1" />
</manifest>
110 changes: 104 additions & 6 deletions Assets/Scripts/AppProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace QuestAppLauncher
{
/// <summary>
/// Class used to track details about an app
/// </summary>
public class ProcessedApp
{
public int Index;
Expand All @@ -21,8 +27,20 @@ public class ProcessedApp

public class AppProcessor
{
/// <summary>
/// Class used to deserialize appnames.json entries
/// </summary>
[Serializable]
class JsonAppNamesEntry
{
public string Name;
public string Category;
public string Category2;
}

// File name of app name overrides
const string AppNameOverrideFileSearch = "appnames*.txt";
const string AppNameOverrideTxtFileSearch = "appnames*.txt";
const string AppNameOverrideJsonFileSearch = "appnames*.json";

// Icon pack search string
const string IconPackSearch = "iconpack*.zip";
Expand Down Expand Up @@ -143,22 +161,102 @@ public static Dictionary<string, ProcessedApp> ProcessApps(Config config)

private static void ProcessAppNameOverrideFiles(Dictionary<string, ProcessedApp> apps, string path)
{
// Process appname*.json files, sorted by name
foreach (var filePath in Directory.GetFiles(
path, AppNameOverrideJsonFileSearch).OrderBy(f => f))
{
ProcessAppNameOverrideJsonFile(apps, filePath);
}

// Process appname*.txt files, sorted by name
foreach (var filePath in Directory.GetFiles(
path, AppNameOverrideFileSearch).OrderBy(f => f))
path, AppNameOverrideTxtFileSearch).OrderBy(f => f))
{
ProcessAppNameOverrideFile(apps, filePath);
ProcessAppNameOverrideTxtFile(apps, filePath);
}
}

private static void ProcessAppNameOverrideJsonFile(Dictionary<string, ProcessedApp> apps, string appNameOverrideFilePath)
{
// Override app names, if any
Debug.Log("Found file: " + appNameOverrideFilePath);

try
{
var json = File.ReadAllText(appNameOverrideFilePath, Encoding.UTF8);
var jsonAppNames = JsonConvert.DeserializeObject<Dictionary<string, JsonAppNamesEntry>>(json);

foreach (var entry in jsonAppNames)
{
var packageName = entry.Key;
var appName = entry.Value.Name;

if (!apps.ContainsKey(packageName))
{
// App is not installed, so skip
continue;
}

// Get the custom tab names, if any
string autoTabName = null;
var tab1 = entry.Value.Category;
var tab2 = entry.Value.Category2;

if (tab1 != null && tab1.Length == 0)
{
tab1 = null;
}

if (tab2 != null && tab2.Length == 0)
{
tab2 = null;
}

if (tab1 != null && tab2 != null && tab1.Equals(tab2, StringComparison.OrdinalIgnoreCase))
{
tab2 = null;
}

// Override auto tab name if custom name matches built-in tab name
if (tab1 != null && Auto_Tabs.Contains(tab1, StringComparer.OrdinalIgnoreCase))
{
autoTabName = tab1;
tab1 = null;
}

if (tab2 != null && Auto_Tabs.Contains(tab2, StringComparer.OrdinalIgnoreCase))
{
autoTabName = tab2;
tab2 = null;
}

// Update entry
apps[packageName] = new ProcessedApp
{
PackageName = apps[entry.Key].PackageName,
Index = apps[entry.Key].Index,
AppName = appName,
AutoTabName = autoTabName ?? apps[entry.Key].AutoTabName,
Tab1Name = tab1 ?? apps[entry.Key].Tab1Name,
Tab2Name = tab2 ?? apps[entry.Key].Tab2Name,
};
}
}
catch (Exception e)
{
Debug.Log(string.Format("Failed to process json app names: {0}", e.Message));
return;
}
}

private static void ProcessAppNameOverrideFile(Dictionary<string, ProcessedApp> apps, string appNameOverrideFilePath)
private static void ProcessAppNameOverrideTxtFile(Dictionary<string, ProcessedApp> apps, string appNameOverrideFilePath)
{
// Override app names, if any
// This is just a file with comma-separated packageName,appName[,category1[, category2]]
// Category1 and category2 are optional categories (tabs).
Debug.Log("Found file: " + appNameOverrideFilePath);

string[] lines = File.ReadAllLines(appNameOverrideFilePath);
string[] lines = File.ReadAllLines(appNameOverrideFilePath, Encoding.UTF8);
foreach (string line in lines)
{
line.Trim();
Expand Down Expand Up @@ -206,7 +304,7 @@ private static void ProcessAppNameOverrideFile(Dictionary<string, ProcessedApp>
tab2 = null;
}

// Override auto tabe name if custom name matches built-in tab name
// Override auto tab name if custom name matches built-in tab name
if (tab1 != null && Auto_Tabs.Contains(tab1, StringComparer.OrdinalIgnoreCase))
{
autoTabName = tab1;
Expand Down
7 changes: 4 additions & 3 deletions Assets/Scripts/AssetsDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private async Task<bool> DownloadFromReposAsync(Config config, IDownloadProgress
// Rate limit update checks to one per couple of minutes, to avoid GitHub's rate limit
if (!forceCheck && DateTime.Now.Subtract(manifest.LastUpdated).TotalMinutes < RateLimitInMins)
{
Debug.LogFormat("Exceeded rate limit of {0} - last checked for update on {1}", RateLimitInMins, manifest.LastUpdated);
Debug.LogFormat("Exceeded rate limit of {0} mins - last checked for update on {1}", RateLimitInMins, manifest.LastUpdated);
return false;
}

Expand Down Expand Up @@ -332,9 +332,10 @@ private async Task<bool> GetAssetsInfoFromGithubRepoAsync(string repoUri,
var url = property["url"].Value<string>();
var name = property["name"].Value<string>();

// For now, simply accept any iconpack*.zip and appnames*.txt.
// For now, simply accept any iconpack*.zip and appnames*.txt/json.
if ((name.StartsWith("iconpack") && name.EndsWith(".zip")) ||
(name.StartsWith("appnames") && name.EndsWith(".txt")))
(name.StartsWith("appnames") && name.EndsWith(".txt")) ||
(name.StartsWith("appnames") && name.EndsWith(".json")))
{
assetsInfo[name] = new AssetInfo { RepoUri = repoUri, Url = url, UpdatedAt = updatedAt, TagName = tagName };
}
Expand Down
Binary file removed Assets/Sprites/Tab_Active.png
Binary file not shown.
115 changes: 0 additions & 115 deletions Assets/Sprites/Tab_Active.png.meta

This file was deleted.

Binary file removed Assets/Sprites/Tab_Inactive.png
Binary file not shown.
Loading

0 comments on commit 1115123

Please sign in to comment.