Add NUS checking (#2)

* Add NUS checking

* Remove obsolete variable
This commit is contained in:
Michael 2022-03-19 21:58:35 -05:00 committed by GitHub
parent 5778ea5bfc
commit 642771463a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 75 additions and 27 deletions

3
.gitignore vendored
View file

@ -1,3 +1,4 @@
/.vs /.vs
/bin /bin
/obj /obj
/Log.cs

View file

@ -35,7 +35,6 @@ namespace libWiiSharp
public class NusClient : IDisposable public class NusClient : IDisposable
{ {
private const string nusUrl = "http://ccs.cdn.wup.shop.nintendo.net/ccs/download/";
#pragma warning disable SYSLIB0014 // Type or member is obsolete #pragma warning disable SYSLIB0014 // Type or member is obsolete
private readonly WebClient wcNus = new WebClient(); private readonly WebClient wcNus = new WebClient();
#pragma warning restore SYSLIB0014 // Type or member is obsolete #pragma warning restore SYSLIB0014 // Type or member is obsolete
@ -148,11 +147,7 @@ namespace libWiiSharp
contentId = num.ToString("x8"); contentId = num.ToString("x8");
FireDebug("Downloading Content (Content ID: {0}) of Title {1} v{2}...", contentId, titleId, string.IsNullOrEmpty(titleVersion) ? "[Latest]" : titleVersion); FireDebug("Downloading Content (Content ID: {0}) of Title {1} v{2}...", contentId, titleId, string.IsNullOrEmpty(titleVersion) ? "[Latest]" : titleVersion);
FireDebug(" Checking for Internet connection..."); FireDebug(" Checking for Internet connection...");
if (!PrivCheckInet()) string nusUrl = PrivNUSUp();
{
FireDebug(" Connection not found...");
throw new Exception("You're not connected to the internet!");
}
FireProgress(0); FireProgress(0);
string str1 = "tmd" + (string.IsNullOrEmpty(titleVersion) ? string.Empty : "." + titleVersion); string str1 = "tmd" + (string.IsNullOrEmpty(titleVersion) ? string.Empty : "." + titleVersion);
string str2 = string.Format("{0}{1}/", nusUrl, titleId); string str2 = string.Format("{0}{1}/", nusUrl, titleId);
@ -215,10 +210,7 @@ namespace libWiiSharp
private Ticket PrivDownloadTicket(string titleId) private Ticket PrivDownloadTicket(string titleId)
{ {
if (!PrivCheckInet()) string nusUrl = PrivNUSUp();
{
throw new Exception("You're not connected to the internet!");
}
string titleUrl = string.Format("{0}{1}/", nusUrl, titleId); string titleUrl = string.Format("{0}{1}/", nusUrl, titleId);
byte[] tikArray = wcNus.DownloadData(titleUrl + "cetk"); byte[] tikArray = wcNus.DownloadData(titleUrl + "cetk");
@ -228,10 +220,7 @@ namespace libWiiSharp
private TMD PrivDownloadTmd(string titleId, string titleVersion) private TMD PrivDownloadTmd(string titleId, string titleVersion)
{ {
if (!PrivCheckInet()) string nusUrl = PrivNUSUp();
{
throw new Exception("You're not connected to the internet!");
}
return TMD.Load(wcNus.DownloadData(string.Format("{0}{1}/", nusUrl, titleId) + ("tmd" + (string.IsNullOrEmpty(titleVersion) ? string.Empty : "." + titleVersion)))); return TMD.Load(wcNus.DownloadData(string.Format("{0}{1}/", nusUrl, titleId) + ("tmd" + (string.IsNullOrEmpty(titleVersion) ? string.Empty : "." + titleVersion))));
} }
@ -248,6 +237,8 @@ namespace libWiiSharp
FireDebug(" No store types were defined..."); FireDebug(" No store types were defined...");
throw new Exception("You must at least define one store type!"); throw new Exception("You must at least define one store type!");
} }
FireDebug(" Checking for Internet connection...");
string nusUrl = PrivNUSUp();
string str1 = string.Format("{0}{1}/", nusUrl, titleId); string str1 = string.Format("{0}{1}/", nusUrl, titleId);
bool flag1 = false; bool flag1 = false;
bool flag2 = false; bool flag2 = false;
@ -285,12 +276,6 @@ namespace libWiiSharp
flag1 = true; flag1 = true;
flag3 = false; flag3 = false;
} }
FireDebug(" Checking for Internet connection...");
if (!PrivCheckInet())
{
FireDebug(" Connection not found...");
throw new Exception("You're not connected to the internet!");
}
if (outputDir[outputDir.Length - 1] != Path.DirectorySeparatorChar) if (outputDir[outputDir.Length - 1] != Path.DirectorySeparatorChar)
{ {
outputDir += Path.DirectorySeparatorChar.ToString(); outputDir += Path.DirectorySeparatorChar.ToString();
@ -495,6 +480,74 @@ namespace libWiiSharp
return buffer; return buffer;
} }
private string PrivNUSUp()
{
if (!PrivCheckInet())
{
FireDebug(" Connection not found...");
throw new Exception("You're not connected to the internet!");
}
const string WiiEndpoint = "http://nus.cdn.shop.wii.com/ccs/download/";
const string WiiUEndpoint = "http://ccs.cdn.wup.shop.nintendo.net/ccs/download/";
const string DSiEndpoint = "http://nus.cdn.t.shop.nintendowifi.net/ccs/download/";
const string RC24Endpoint = "http://ccs.cdn.sho.rc24.xyz/ccs/download/";
// Wii Endpoint
try
{
wcNus.DownloadData(WiiEndpoint);
} catch (WebException e)
{
if (e.Message.Split('(')[1].Split(')')[0] == "401")
{
return WiiEndpoint;
}
}
// WiiU Endpoint
try
{
wcNus.DownloadData(WiiUEndpoint);
}
catch (WebException e)
{
if (e.Message.Split('(')[1].Split(')')[0] == "401")
{
return WiiUEndpoint;
}
}
// DSi Endpoint
try
{
wcNus.DownloadData(DSiEndpoint);
}
catch (WebException e)
{
if (e.Message.Split('(')[1].Split(')')[0] == "401")
{
return DSiEndpoint;
}
}
// RC24 Endpoint
try
{
wcNus.DownloadData(RC24Endpoint);
}
catch (WebException e)
{
if (e.Message.Split('(')[1].Split(')')[0] == "401")
{
return RC24Endpoint;
}
}
throw new Exception("Unable to verify any online NUS server!");
}
private bool PrivCheckInet() private bool PrivCheckInet()
{ {
try try

View file

@ -9,12 +9,6 @@
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets> <ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
<Nullable>annotations</Nullable> <Nullable>annotations</Nullable>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<RegisterForComInterop>true</RegisterForComInterop>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<RegisterForComInterop>false</RegisterForComInterop>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<Content Include=".gitignore" /> <Content Include=".gitignore" />
</ItemGroup> </ItemGroup>