diff --git a/Lz77.cs b/Lz77.cs
index b3b69a4..8156976 100644
--- a/Lz77.cs
+++ b/Lz77.cs
@@ -27,26 +27,45 @@ namespace libWiiSharp
//private const int F = 18;
//private const int threshold = 2;
private static readonly uint lz77Magic = 1280980791;
- //private readonly int[] leftSon = new int[4097];
- //private readonly int[] rightSon = new int[4353];
- //private readonly int[] dad = new int[4097];
+ private readonly int[] leftSon = new int[4097];
+ private readonly int[] rightSon = new int[4353];
+ private readonly int[] dad = new int[4097];
private readonly ushort[] textBuffer = new ushort[4113];
- //private int matchPosition;
- //private int matchLength;
+ private int matchPosition;
+ private int matchLength;
+ ///
+ /// Lz77 Magic.
+ ///
public static uint Lz77Magic => lz77Magic;
+ #region Public Functions
+ ///
+ /// Checks whether a file is Lz77 compressed or not.
+ ///
+ ///
+ ///
public static bool IsLz77Compressed(string file)
{
return IsLz77Compressed(File.ReadAllBytes(file));
}
+ ///
+ /// Checks whether a file is Lz77 compressed or not.
+ ///
+ ///
+ ///
public static bool IsLz77Compressed(byte[] file)
{
Headers.HeaderType headerType = Headers.DetectHeader(file);
return (int)Shared.Swap(BitConverter.ToUInt32(file, (int)headerType)) == (int)lz77Magic;
}
+ ///
+ /// Checks whether a file is Lz77 compressed or not.
+ ///
+ ///
+ ///
public static bool IsLz77Compressed(Stream file)
{
Headers.HeaderType headerType = Headers.DetectHeader(file);
@@ -56,12 +75,17 @@ namespace libWiiSharp
return (int)Shared.Swap(BitConverter.ToUInt32(buffer, 0)) == (int)lz77Magic;
}
+ ///
+ /// Compresses a file using the Lz77 algorithm.
+ ///
+ ///
+ ///
public void Compress(string inFile, string outFile)
{
Stream stream = null;
using (FileStream fileStream = new FileStream(inFile, FileMode.Open))
{
- stream = Compress(fileStream);
+ stream = PrivCompress(fileStream);
}
byte[] buffer = new byte[stream.Length];
@@ -77,22 +101,37 @@ namespace libWiiSharp
}
}
+ ///
+ /// Compresses the byte array using the Lz77 algorithm.
+ ///
+ ///
+ ///
public byte[] Compress(byte[] file)
{
- return ((MemoryStream)Compress(new MemoryStream(file))).ToArray();
+ return ((MemoryStream)PrivCompress(new MemoryStream(file))).ToArray();
}
+ ///
+ /// Compresses the stream using the Lz77 algorithm.
+ ///
+ ///
+ ///
public Stream Compress(Stream file)
{
- return Compress(file);
+ return PrivCompress(file);
}
+ ///
+ /// Decompresses a file using the Lz77 algorithm.
+ ///
+ ///
+ ///
public void Decompress(string inFile, string outFile)
{
Stream stream = null;
using (FileStream fileStream = new FileStream(inFile, FileMode.Open))
{
- stream = Decompress(fileStream);
+ stream = PrivDecompress(fileStream);
}
byte[] buffer = new byte[stream.Length];
@@ -108,6 +147,11 @@ namespace libWiiSharp
}
}
+ ///
+ /// Decompresses the byte array using the Lz77 algorithm.
+ ///
+ ///
+ ///
public byte[] Decompress(byte[] file)
{
return ((MemoryStream)PrivDecompress(new MemoryStream(file))).ToArray();
@@ -117,7 +161,9 @@ namespace libWiiSharp
{
return PrivDecompress(file);
}
+ #endregion
+ #region Private Functions
private Stream PrivDecompress(Stream inFile)
{
if (!IsLz77Compressed(inFile))
@@ -224,7 +270,7 @@ namespace libWiiSharp
label_24:
return memoryStream;
}
- /*
+
private Stream PrivCompress(Stream inFile)
{
if (Lz77.IsLz77Compressed(inFile))
@@ -415,6 +461,6 @@ namespace libWiiSharp
this.leftSon[this.dad[p]] = index;
this.dad[p] = 4096;
}
- */
+ #endregion
}
}
diff --git a/NusClient.cs b/NusClient.cs
index e708f88..7c612d3 100644
--- a/NusClient.cs
+++ b/NusClient.cs
@@ -25,6 +25,14 @@ using System.Security.Cryptography;
namespace libWiiSharp
{
+ public enum StoreType
+ {
+ EncryptedContent,
+ DecryptedContent,
+ WAD,
+ All,
+ }
+
public class NusClient : IDisposable
{
private const string nusUrl = "http://nus.cdn.shop.wii.com/ccs/download/";
@@ -33,12 +41,18 @@ namespace libWiiSharp
private bool continueWithoutTicket;
private bool isDisposed;
+ ///
+ /// If true, existing local files will be used.
+ ///
public bool UseLocalFiles
{
get => useLocalFiles;
set => useLocalFiles = value;
}
+ ///
+ /// If true, the download will be continued even if no ticket for the title is avaiable (WAD packaging and decryption are disabled).
+ ///
public bool ContinueWithoutTicket
{
get => continueWithoutTicket;
@@ -165,11 +179,19 @@ namespace libWiiSharp
FireDebug(" Content ID {0} wasn't found in TMD...", (object)contentId);
throw new Exception("Content ID wasn't found in the TMD!");
}
- if (!File.Exists("cetk"))
+ if (!File.Exists("cetk") && !continueWithoutTicket)
{
FireDebug(" Downloading Ticket...");
- //byte[] tikArray = wcNus.DownloadData(str2 + "cetk");
Console.WriteLine("Downloading");
+ try
+ {
+ byte[] tikArray = wcNus.DownloadData(str2 + "cetk");
+ }
+ catch(Exception ex)
+ {
+ FireDebug(" Downloading Ticket Failed...");
+ throw new Exception("CETK Doesn't Exist and Downloading Ticket Failed:\n" + ex.Message);
+ }
}
Console.WriteLine("Continuing");
FireDebug("Parsing Ticket...");
@@ -257,6 +279,12 @@ namespace libWiiSharp
break;
}
}
+ if (ContinueWithoutTicket == true)
+ {
+ flag2 = false;
+ flag1 = true;
+ flag3 = false;
+ }
FireDebug(" Checking for Internet connection...");
if (!CheckInet())
{
@@ -317,7 +345,8 @@ namespace libWiiSharp
FireDebug(" -> {0} Contents", (object)tmd.NumOfContents);
FireDebug(" Parsing Ticket...");
- Ticket tik = Ticket.Load(outputDir + "cetk");
+ Ticket tik = null;
+ if (!continueWithoutTicket) { tik = Ticket.Load(outputDir + "cetk"); }
string[] strArray1 = new string[tmd.NumOfContents];
uint contentId;
for (int index1 = 0; index1 < tmd.NumOfContents; ++index1)
@@ -427,7 +456,10 @@ namespace libWiiSharp
{
FireDebug(" Deleting TMD and Ticket...");
File.Delete(outputDir + str2);
- File.Delete(outputDir + "cetk");
+ if (ContinueWithoutTicket == false)
+ {
+ File.Delete(outputDir + "cetk");
+ }
}
FireDebug("Downloading Title {0} v{1} Finished...", titleId, string.IsNullOrEmpty(titleVersion) ? "[Latest]" : titleVersion);
FireProgress(100);
diff --git a/StoreType.cs b/StoreType.cs
deleted file mode 100644
index 759fea8..0000000
--- a/StoreType.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-/* This file is part of libWiiSharp
- * Copyright (C) 2009 Leathl
- * Copyright (C) 2020 - 2021 Github Contributors
- *
- * libWiiSharp is free software: you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as published
- * by the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * libWiiSharp is distributed in the hope that it will be
- * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-namespace libWiiSharp
-{
- public enum StoreType
- {
- EncryptedContent,
- DecryptedContent,
- WAD,
- All,
- }
-}
diff --git a/libWiiSharp.csproj b/libWiiSharp.csproj
index fbb6901..7a1b29d 100644
--- a/libWiiSharp.csproj
+++ b/libWiiSharp.csproj
@@ -60,7 +60,6 @@
-