Skip to content
Permalink
Browse files

Discord overlay, show autoupdate status in credits, firefox fixes.

  • Loading branch information
noahc3 committed Aug 24, 2019
1 parent 4d1e362 commit e40785e4665529738417b2d0263c322b3ee46dff
@@ -57,14 +57,14 @@ public class v1 : ControllerBase {
} else if (!Program.validChannels.Contains(channel)) {
Response.StatusCode = Http.StatusCodes.Status401Unauthorized;
return new ObjectResult("Invalid channel");
} else if (!Directory.Exists((Program.Files + "/" + packageset).AsPath())) {
} else if (!Directory.Exists((Program.FilesPath + "/" + packageset).AsPath())) {
Response.StatusCode = Http.StatusCodes.Status400BadRequest;
return new ObjectResult("Invalid packageset");
} else if (System.IO.File.Exists((Program.Files + "/" + packageset + "/.PRIVILEGED.FLAG").AsPath()) && !Program.IsUuidPriveleged(uuid)) {
} else if (System.IO.File.Exists((Program.FilesPath + "/" + packageset + "/.PRIVILEGED.FLAG").AsPath()) && !Program.IsUuidPriveleged(uuid)) {
Response.StatusCode = Http.StatusCodes.Status401Unauthorized;
return new ObjectResult("You do not have access to that packageset");
} else {
string tempdir = (Program.Temp + "/" + uuid).AsPath();
string tempdir = (Program.TempPath + "/" + uuid).AsPath();
try {
Program.uuidLocks.Add(uuid);

@@ -79,14 +79,14 @@ public class v1 : ControllerBase {
return new ObjectResult("hackerman");
}

if (Directory.Exists((Program.Files + "/" + packageset + "/" + k + "/" + channel).AsPath())) {
foreach (string f in EnumerateAllFiles((Program.Files + "/" + packageset + "/" + k + "/" + channel).AsPath())) {
if (Directory.Exists((Program.FilesPath + "/" + packageset + "/" + k + "/" + channel).AsPath())) {
foreach (string f in EnumerateAllFiles((Program.FilesPath + "/" + packageset + "/" + k + "/" + channel).AsPath())) {
if (client == "hbswitch") {
if (f.StartsWith((Program.Files + "/" + packageset + "/" + k + "/" + channel + "/sd").AsPath())) {
files[f.Replace((Program.Files + "/" + packageset + "/" + k + "/" + channel + "/sd").AsPath(), "")] = f;
if (f.StartsWith((Program.FilesPath + "/" + packageset + "/" + k + "/" + channel + "/sd").AsPath())) {
files[f.Replace((Program.FilesPath + "/" + packageset + "/" + k + "/" + channel + "/sd").AsPath(), "")] = f;
}
} else {
files[f.Replace((Program.Files + "/" + packageset + "/" + k + "/" + channel).AsPath(), "")] = f;
files[f.Replace((Program.FilesPath + "/" + packageset + "/" + k + "/" + channel).AsPath(), "")] = f;
}
}

@@ -140,9 +140,9 @@ public class v1 : ControllerBase {

[HttpGet("fetch/manifest/{uuid}/{packageset}")]
public ActionResult FetchManifest(string uuid, string packageset) {
if (!Directory.Exists((Program.Files + "/" + packageset).AsPath())) {
if (!Directory.Exists((Program.FilesPath + "/" + packageset).AsPath())) {
return new ObjectResult(packageset);
} else if (System.IO.File.Exists((Program.Files + "/" + packageset + "/.PRIVILEGED.FLAG").AsPath()) && !Program.IsUuidPriveleged(uuid)) {
} else if (System.IO.File.Exists((Program.FilesPath + "/" + packageset + "/.PRIVILEGED.FLAG").AsPath()) && !Program.IsUuidPriveleged(uuid)) {
Response.StatusCode = Http.StatusCodes.Status401Unauthorized;
return new ObjectResult("You do not have access to that packageset");
}
@@ -178,7 +178,7 @@ public class v1 : ControllerBase {
public ActionResult GetLatestAppDownload() {
string zipname = "sdsetup-switch.nro";
Response.Headers["Content-Disposition"] = "filename=" + zipname;
return new FileStreamResult(new FileStream((Program.Config + "/sdsetup-switch.nro").AsPath(), FileMode.Open, FileAccess.Read, FileShare.ReadWrite), "application/octet-stream");
return new FileStreamResult(new FileStream((Program.ConfigPath + "/sdsetup-switch.nro").AsPath(), FileMode.Open, FileAccess.Read, FileShare.ReadWrite), "application/octet-stream");
}

[HttpGet("set/latestpackageset/{uuid}/{packageset}")]
@@ -188,7 +188,7 @@ public class v1 : ControllerBase {
return new ObjectResult("UUID not priveleged");
}
Program.latestPackageset = packageset;
System.IO.File.WriteAllText(Program.Config + "/latestpackageset.txt", packageset);
System.IO.File.WriteAllText(Program.ConfigPath + "/latestpackageset.txt", packageset);
return new ObjectResult("Success");
}

@@ -227,7 +227,7 @@ public class v1 : ControllerBase {

public static Stream ZipFromFilestreams(OrderedDictionary files, string uuid) {

DeletingFileStream outputMemStream = new DeletingFileStream((Program.Temp + "/" + Guid.NewGuid().ToString().Replace("-", "").ToLower()).AsPath(), FileMode.Create, uuid);
DeletingFileStream outputMemStream = new DeletingFileStream((Program.TempPath + "/" + Guid.NewGuid().ToString().Replace("-", "").ToLower()).AsPath(), FileMode.Create, uuid);
ZipOutputStream zipStream = new ZipOutputStream(outputMemStream);

zipStream.SetLevel(3); //0-9, 9 being the highest level of compression
@@ -26,9 +26,9 @@ public class Program {
private static string ip;
private static int httpPort;

public static string Temp;
public static string Files;
public static string Config;
public static string TempPath;
public static string FilesPath;
public static string ConfigPath;

public static string[] validChannels;
public static List<string> uuidLocks = new List<string>();
@@ -60,16 +60,16 @@ public class Program {

ReloadEverything();

Console.WriteLine(Config);
Console.WriteLine(ConfigPath);

string[] hostConf = File.ReadAllLines((Config + "/host.txt").AsPath());
string[] hostConf = File.ReadAllLines((ConfigPath + "/host.txt").AsPath());
ip = hostConf[0];
httpPort = Convert.ToInt32(hostConf[1]);

string[] certInfo = File.ReadAllLines((Config + "/https.txt").AsPath());

privelegedUUID = Guid.NewGuid().ToString().Replace("-", "").ToLower();



IWebHost host = CreateWebHostBuilder(args).Build();
host.Run();
}
@@ -108,40 +108,40 @@ public class Program {
//use temporary variables so if anything goes wrong, values wont be out of sync.
Dictionary<string, string> _Manifests = new Dictionary<string, string>();

string _Temp = (AppContext.BaseDirectory + "/temp").AsPath();
string _Files = (AppContext.BaseDirectory + "/files").AsPath();
string _Config = (AppContext.BaseDirectory + "/config").AsPath();
string _TempPath = (AppContext.BaseDirectory + "/temp").AsPath();
string _FilesPath = (AppContext.BaseDirectory + "/files").AsPath();
string _ConfigPath = (AppContext.BaseDirectory + "/config").AsPath();

if (!Directory.Exists(_Temp)) Directory.CreateDirectory(_Temp);
if (!Directory.Exists(_Files)) Directory.CreateDirectory(_Files);
if (!Directory.Exists(_Config)) Directory.CreateDirectory(_Config);
if (!File.Exists((_Config + "/latestpackageset.txt").AsPath())) File.WriteAllText((_Config + "/latestpackageset.txt").AsPath(), "default");
if (!File.Exists((_Config + "/latestappversion.txt").AsPath())) File.WriteAllText((_Config + "/latestappversion.txt").AsPath(), "NO VERSION");
if (!File.Exists((_Config + "/validchannels.txt").AsPath())) File.WriteAllLines((_Config + "/validchannels.txt").AsPath(), new string[] { "latest", "nightly" });
if (!Directory.Exists(_TempPath)) Directory.CreateDirectory(_TempPath);
if (!Directory.Exists(_FilesPath)) Directory.CreateDirectory(_FilesPath);
if (!Directory.Exists(_ConfigPath)) Directory.CreateDirectory(_ConfigPath);
if (!File.Exists((_ConfigPath + "/latestpackageset.txt").AsPath())) File.WriteAllText((_ConfigPath + "/latestpackageset.txt").AsPath(), "default");
if (!File.Exists((_ConfigPath + "/latestappversion.txt").AsPath())) File.WriteAllText((_ConfigPath + "/latestappversion.txt").AsPath(), "NO VERSION");
if (!File.Exists((_ConfigPath + "/validchannels.txt").AsPath())) File.WriteAllLines((_ConfigPath + "/validchannels.txt").AsPath(), new string[] { "latest", "nightly" });

foreach(string n in Directory.EnumerateDirectories(_Files)) {
foreach(string n in Directory.EnumerateDirectories(_FilesPath)) {
string k = n.Split(Path.DirectorySeparatorChar).Last();
if (!File.Exists((_Files + "/" + k + "/manifest6.json").AsPath())) File.WriteAllText(_Files + "/" + k + "/manifest6.json", "{}");
if (!File.Exists((_FilesPath + "/" + k + "/manifest6.json").AsPath())) File.WriteAllText(_FilesPath + "/" + k + "/manifest6.json", "{}");
}

string _latestPackageset = File.ReadAllText((_Config + "/latestpackageset.txt").AsPath());
string _latestAppVersion = File.ReadAllText((_Config + "/latestappversion.txt").AsPath());
string[] _validChannels = File.ReadAllLines((_Config + "/validchannels.txt").AsPath());
string _latestPackageset = File.ReadAllText((_ConfigPath + "/latestpackageset.txt").AsPath());
string _latestAppVersion = File.ReadAllText((_ConfigPath + "/latestappversion.txt").AsPath());
string[] _validChannels = File.ReadAllLines((_ConfigPath + "/validchannels.txt").AsPath());

//look away
foreach (string n in Directory.EnumerateDirectories(_Files)) {
foreach (string n in Directory.EnumerateDirectories(_FilesPath)) {
string k = n.Split(Path.DirectorySeparatorChar).Last();
Manifest m = JsonConvert.DeserializeObject<Manifest>(File.ReadAllText((_Files + "/" + k + "/manifest6.json").AsPath()));
foreach (string c in Directory.EnumerateDirectories((_Files + "/" + k).AsPath()).OrderBy(filename => filename)) {
Manifest m = JsonConvert.DeserializeObject<Manifest>(File.ReadAllText((_FilesPath + "/" + k + "/manifest6.json").AsPath()));
foreach (string c in Directory.EnumerateDirectories((_FilesPath + "/" + k).AsPath()).OrderBy(filename => filename)) {
string f = c.Split(Path.DirectorySeparatorChar).Last();
Package p = JsonConvert.DeserializeObject<Package>(File.ReadAllText((_Files + "/" + k + "/" + f + "/info.json").AsPath()));
Package p = JsonConvert.DeserializeObject<Package>(File.ReadAllText((_FilesPath + "/" + k + "/" + f + "/info.json").AsPath()));
m.Platforms[p.Platform].PackageSections[p.Section].Categories[p.Category].Subcategories[p.Subcategory].Packages[p.ID] = p;
}
_Manifests[k] = JsonConvert.SerializeObject(m, Formatting.Indented);
}

//this must be set before GetPackageListInLatestPackageset() is called
Files = _Files;
FilesPath = _FilesPath;

//DownloadStats _dlStats;

@@ -171,8 +171,8 @@ public class Program {
//dlStatsSaveTimer.Start();

//update the real variables
Temp = _Temp;
Config = _Config;
TempPath = _TempPath;
ConfigPath = _ConfigPath;
latestPackageset = _latestPackageset;
latestAppVersion = _latestAppVersion;
validChannels = _validChannels;
@@ -189,9 +189,9 @@ public class Program {
}

public static bool OverridePrivilegedUuid() {
if (File.Exists((Config + "/uuidoverride.txt").AsPath())) {
privelegedUUID = File.ReadAllText((Config + "/uuidoverride.txt").AsPath());
File.Delete((Config + "/uuidoverride.txt").AsPath());
if (File.Exists((ConfigPath + "/uuidoverride.txt").AsPath())) {
privelegedUUID = File.ReadAllText((ConfigPath + "/uuidoverride.txt").AsPath());
File.Delete((ConfigPath + "/uuidoverride.txt").AsPath());
return true;
}
return false;
@@ -19,7 +19,7 @@ public class U {
public static List<string> GetPackageList(string packageset) {
List<string> packages = new List<string>();

foreach (string k in Directory.EnumerateDirectories((Program.Files + "/" + packageset).AsPath())) {
foreach (string k in Directory.EnumerateDirectories((Program.FilesPath + "/" + packageset).AsPath())) {
packages.Add(k.Split(Path.DirectorySeparatorChar).Last());
}

@@ -29,7 +29,10 @@
<BSNavItem><BSNavLink Href="https://github.com/noahc3/SDSetup/issues">Issues</BSNavLink></BSNavItem>
</BSNav>
<BSNav IsList="true" IsNavbar="true" Class="my-2 my-lg-0">
<BSNavItem><BSNavLink Href="https://github.com/noahc3/SDSetup/"><span class="iconify" data-icon="bytesize:github" data-inline="false" data-width="2rem" data-height="2rem"></span></BSNavLink></BSNavItem>
<BSNavItem><BSNavLink Href="https://discord.teamatlasnx.com"><span class="iconify" style="max-width:2rem;max-height:2rem" data-icon="simple-icons:discord" data-inline="false" data-width="2rem" data-height="2rem"></span></BSNavLink></BSNavItem>
</BSNav>
<BSNav IsList="true" IsNavbar="true" Class="my-2 my-lg-0">
<BSNavItem><BSNavLink Href="https://github.com/noahc3/SDSetup/"><span class="iconify" style="max-width:2rem;max-height:2rem" data-icon="bytesize:github" data-inline="false" data-width="2rem" data-height="2rem"></span></BSNavLink></BSNavItem>
</BSNav>
</BSCollapse>
</BSNavbar>
@@ -135,7 +135,6 @@
static bool barMode = true;

protected override void OnInitialized() {
Console.WriteLine("yote");
string a = UriHelper.GetAbsoluteUri().Split('?')[1];
if (a.Contains('#')) a = a.Split('#')[0];
G.consoleId = a;
@@ -22,16 +22,24 @@
<BSTableHeadCell scope="col">Authors</BSTableHeadCell>
<BSTableHeadCell scope="col">Version</BSTableHeadCell>
<BSTableHeadCell scope="col">Source</BSTableHeadCell>
<BSTableHeadCell scope="col">Auto Updates</BSTableHeadCell>
</BSTableRow>
</BSTableHead>
<tbody>
@foreach (Package p in G.packages[plat.ID].Values) {
if (String.IsNullOrEmpty(p.Authors) || !p.Visible) { continue; }
if (String.IsNullOrEmpty(p.Authors) || !p.Visible || !p.ShowsInCredits) { continue; }
<BSTableRow>
<BSTableHeadCell scope="row">@p.Name</BSTableHeadCell>
<BSTableCell>@p.Authors</BSTableCell>
<BSTableCell>@p.Versions[G.channel]</BSTableCell>
<BSTableCell>@if (@p.Source.Contains("https://") || p.Source.Contains("http://")) {<a href="@p.Source">@p.Source</a>} else {@p.Source}</BSTableCell>
<BSTableCell style="text-align:center">
@if (p.AutoUpdateType > 0) {
<span style="color:#00ff90"></span>
} else {
<span style="color:#c83030"></span>
}
</BSTableCell>
</BSTableRow>
}

@@ -70,6 +70,15 @@
</div>
}

if (discordBadge) {
<a href="https://discord.teamatlasnx.com" style="color:#fff" target="_blank">
<div class="discord-overlay">
<div class="discord-text"><span class="iconify" style="margin-right:0.3rem;max-width:2rem;max-height:2rem;" data-icon="simple-icons:discord" data-inline="false" data-width="2rem" data-height="2rem"></span>Need help? Join us on Discord!</div>
<a href="javascript:void(0);" style="max-width:1.5rem;max-height:1.5rem;position:absolute;right:3px;top:3px;color:#fff" @onclick="hideDiscordOverlay"><span class="iconify" data-icon="fe:close" data-inline="false" data-width="1.5rem" data-height="1.5rem"></span></a>
</div>
</a>
}

} else if (!loadFailed) {
<div class="ui active dimmer" style="height:100vh;width:100vw;position:absolute;margin:0;top:0;left:0;right:0;bottom:0">
<div class="ui massive text loader">Loading</div>
@@ -94,6 +103,7 @@
public static Action ForceUiRefresh;
private static bool ResetWarnState = false;

private static bool discordBadge = false;
private static bool loadFailed = false;
public static bool downloadFailed = false;
public static bool rateLimited = false;
@@ -112,6 +122,16 @@
if (String.IsNullOrWhiteSpace(theme)) theme = "flatly";
await BootstrapCSS.SetBootstrapCSS(theme, "4.3.1");

string discordClosed = localStorage.GetItem("discord-overlay");
if (!String.IsNullOrWhiteSpace(discordClosed)) {
if (DateTime.UtcNow.Subtract(DateTime.Parse(discordClosed)).TotalDays > 7) {
localStorage.RemoveItem("discord-overlay");
discordBadge = true;
}
} else {
discordBadge = true;
}

if (ForceUiRefresh == null) {
ForceUiRefresh = new Action(() => StateHasChanged());
}
@@ -186,6 +206,11 @@
StateHasChanged();
}

private void hideDiscordOverlay() {
discordBadge = false;
localStorage.SetItem("discord-overlay", DateTime.UtcNow.ToString());
}

//[JSInvokable]
//public static void BrowserNotCompatible(int val) {
// Console.WriteLine("Browser Compat Response: " + val);
@@ -334,3 +334,39 @@ a.nav-item.nav-link.active {
background-color: #c82323 !important;
}

.discord-overlay {
max-width: 500px;
max-height: 100px;
min-width: 280px;
width: 280px;
height: 3rem;
background-color: #7289DA;
border-radius: 0.25rem;
}

.discord-text {
position:absolute;
top:50%;
left:50%;
transform: translate(-50%, -50%);
width:100%;
text-align:center;
}


@media only screen and (min-width: 769px) {
.discord-overlay {
position: fixed;
right: 20px;
bottom: 20px;
}
}

@media only screen and (max-width: 768px) {
.discord-overlay {
position: fixed;
bottom: 5px;
left: 50%;
transform: translate(-50%, -50%);
}
}

0 comments on commit e40785e

Please sign in to comment.
You can’t perform that action at this time.