private static void Install() { try { if (Quiet.quiet > 1) { Console.WriteLine("Installing Sharpii..."); } if (Quiet.quiet > 1) { Console.WriteLine("Adding Variables"); } Environment.SetEnvironmentVariable("PATH", Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Machine) + ";" + Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\\Sharpii\\", EnvironmentVariableTarget.Machine); if (Quiet.quiet > 1) { Console.WriteLine("Creating Directory"); } if (Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\\Sharpii\\")) { DeleteDir.DeleteDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\\Sharpii\\"); } Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\\Sharpii\\"); if (Quiet.quiet > 1) { Console.WriteLine("Copying Files"); } File.Copy(Application.ExecutablePath, Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\\Sharpii\\Sharpii.exe"); if (File.Exists(Path.GetDirectoryName(Application.ExecutablePath) + "\\libWiiSharp.dll")) { File.Copy(Path.GetDirectoryName(Application.ExecutablePath) + "\\libWiiSharp.dll", Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\\Sharpii\\libWiiSharp.dll"); } if (File.Exists(Path.GetDirectoryName(Application.ExecutablePath) + "\\WadInstaller.dll")) { File.Copy(Path.GetDirectoryName(Application.ExecutablePath) + "\\WadInstaller.dll", Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\\Sharpii\\WadInstaller.dll"); } if (Quiet.quiet > 1) { Console.WriteLine("Sharpii was successfully installed to: {0}", Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\\Sharpii\\"); Console.WriteLine("You can now use Sharpii in any directory!"); Console.WriteLine("\nNOTE: You may need to restart your computer for this to take effect"); } return; } catch (Exception ex) { Console.WriteLine("An unknown error occured, please try again\n\nERROR DETAILS: {0}", ex.Message); return; } }
private static void WadIosNamingStuff(bool wad, string temp, string id, string version, string ios, bool NoOut, string output, string realout) { if (wad == true) { if (!File.Exists(temp + "\\" + id + "v" + version + ".wad")) { Console.WriteLine("ERROR: Can't find WAD"); return; } if (ios != "" && NoOut == true) { int index = realout.LastIndexOf("\\") > realout.LastIndexOf("/") ? realout.LastIndexOf("\\") : realout.LastIndexOf("/"); if (File.Exists(realout.Substring(0, index + 1) + ios)) { File.Delete(realout.Substring(0, index + 1) + ios); } File.Move(temp + "\\" + id + "v" + version + ".wad", realout.Substring(0, index + 1) + ios); } else if (ios == "" && NoOut == true) { if (File.Exists(realout + ".wad")) { File.Delete(realout + ".wad"); } File.Move(temp + "\\" + id + "v" + version + ".wad", realout + ".wad"); } else { if (File.Exists(realout)) { File.Delete(realout); } File.Move(temp + "\\" + id + "v" + version + ".wad", realout); } DeleteDir.DeleteDirectory(temp); } else if (ios != "") { if (output.Substring(output.Length - 1, 1) == "\\" || output.Substring(output.Length - 1, 1) == "/") { output = output.Substring(output.Length - 1, 1); } if (File.Exists(output + "\\" + id + "v" + version + ".wad")) { if (File.Exists(output + "\\" + ios)) { File.Delete(output + "\\" + ios); } File.Move(output + "\\" + id + "v" + version + ".wad", output + "\\" + ios); } } }
static void Main(string[] args) { if (args.Length < 1) { help(); Environment.Exit(0); } if (!File.Exists(Path.GetDirectoryName(Application.ExecutablePath) + "\\libWiiSharp.dll")) { Console.WriteLine("ERROR: libWiiSharp.dll not found"); Console.WriteLine("\n\nAttemp to download? [Y/N]"); Console.Write("\n>>"); string ans = Console.ReadLine(); if (ans.ToUpper() == "Y") { try { Console.Write("\nGrabbing libWiiSharp.dll..."); WebClient DLlibWiiSharp = new WebClient(); DLlibWiiSharp.DownloadFile("https://github.com/mogzol/sharpii/raw/master/Sharpii/libWiiSharp.dll", Path.GetDirectoryName(Application.ExecutablePath) + "\\libWiiSharp.dll"); Console.Write("Done!\n"); } catch (Exception ex) { Console.WriteLine("An error occured: {0}", ex.Message); Environment.Exit(0); } } else { Environment.Exit(0); } } for (int i = 1; i < args.Length; i++) { switch (args[i].ToUpper()) { case "-QUIET": Quiet.quiet = 1; break; case "-Q": Quiet.quiet = 1; break; case "-LOTS": Quiet.quiet = 3; break; } } string Function = args[0].ToUpper(); bool gotSomewhere = false; if (Function == "-H" || Function == "-HELP" || Function == "H" || Function == "HELP") { help(); gotSomewhere = true; } if (Function == "BNS") { BNS_Stuff.BNS(args); gotSomewhere = true; } if (Function == "WAD") { WAD_Stuff.WAD(args); gotSomewhere = true; } if (Function == "TPL") { TPL_Stuff.TPL(args); gotSomewhere = true; } if (Function == "U8") { U8_Stuff.U8(args); gotSomewhere = true; } if (Function == "IOS") { IOS_Stuff.IOS(args); gotSomewhere = true; } if (Function == "NUS" || Function == "NUSD") { NUS_Stuff.NUS(args); gotSomewhere = true; } if (Function == "SENDDOL" || Function == "SENDOL") { HBC_Stuff.SendDol(args); gotSomewhere = true; } if (Function == "SENDWAD") { bool cont = HBC_Stuff.SendWad_Check(args); if (cont == true) { HBC_Stuff.SendWad(args); } gotSomewhere = true; } if (Function == "INSTALL") { Install(); gotSomewhere = true; } if (Function == "UNINSTALL") { Uninstall(); gotSomewhere = true; } if (Function == "WHICH CAME FIRST" || Function == "WHICH CAME FIRST?" || (Function == "WHICH" && args[1].ToUpper() == "CAME" && args[2].Substring(0, 5).ToUpper() == "FIRST")) { InconspicuousNotEasterEggThingamajig(); gotSomewhere = true; } if (gotSomewhere == false) { //If tuser gets here, they entered something wrong Console.WriteLine("ERROR: The argument {0} is invalid", args[0]); } string temp = Path.GetTempPath() + "Sharpii.tmp"; if (Directory.Exists(temp) == true) { DeleteDir.DeleteDirectory(temp); } Environment.Exit(0); }
public static void NUS(string[] args) { if (args.Length < 2) { NUS_help(); return; } if (args[1].ToUpper() == "-H" || args[1].ToUpper() == "-HELP") { NUS_help(); return; } //Set up variables string id = ""; string content = ""; string version = ""; int intver = -1; string output = ""; bool local = false; List <StoreType> store = new List <StoreType>(); bool entered = false; bool wad = false; bool NoOut = false; string ios = ""; string temp = Path.GetTempPath() + "Sharpii.tmp"; //Get arguments for (int i = 1; i < args.Length; i++) { switch (args[i].ToUpper()) { case "-ALL": store.Add(StoreType.All); entered = true; break; case "-WAD": store.Add(StoreType.WAD); entered = true; break; case "-ENCRYPT": store.Add(StoreType.EncryptedContent); entered = true; break; case "-ENCRYPTED": store.Add(StoreType.EncryptedContent); entered = true; break; case "-DECRYPT": store.Add(StoreType.DecryptedContent); entered = true; break; case "-DECRYPTED": store.Add(StoreType.DecryptedContent); entered = true; break; case "-LOCAL": local = true; break; case "-V": if (i + 1 >= args.Length) { Console.WriteLine("ERROR: No version set"); return; } version = args[i + 1]; if (version.ToUpper() == "LATEST") { break; } if (!int.TryParse(version, out intver)) { Console.WriteLine("Invalid version {0}...", args[i + 1]); return; } if (intver < 0 || intver > 65535) { Console.WriteLine("Invalid version {0}...", version); return; } break; case "-VERSION": if (i + 1 >= args.Length) { Console.WriteLine("ERROR: No version set"); return; } version = args[i + 1]; if (version.ToUpper() == "LATEST") { break; } if (!int.TryParse(version, out intver)) { Console.WriteLine("Invalid version {0}...", args[i + 1]); return; } if (intver < 0 || intver > 65535) { Console.WriteLine("Invalid version {0}...", version); return; } break; case "-O": if (i + 1 >= args.Length) { Console.WriteLine("ERROR: No output set"); return; } output = args[i + 1]; break; case "-ID": if (i + 1 >= args.Length) { Console.WriteLine("ERROR: No ID specified"); return; } id = args[i + 1]; break; case "-IOS": if (i + 1 >= args.Length) { Console.WriteLine("ERROR: No IOS specified"); return; } id = "00000001000000" + Convert.ToInt32(args[i + 1]).ToString("X2"); break; case "-SINGLE": if (i + 1 >= args.Length) { Console.WriteLine("ERROR: No ID specified"); return; } content = args[i + 1]; break; case "-S": if (i + 1 >= args.Length) { Console.WriteLine("ERROR: No ID specified"); return; } content = args[i + 1]; break; } } //Error checking & stuff if (id == "") { Console.WriteLine("ERROR: No ID specified"); return; } if (version == "") { if (Quiet.quiet > 2) { Console.WriteLine("No version specified, using latest", version); } version = "LATEST"; } if (version.ToUpper() == "LATEST") { //Grab the TMD and get the latest version NusClient grabtmd = new NusClient(); TMD tmd = grabtmd.DownloadTMD(id, ""); version = tmd.TitleVersion.ToString(); if (Quiet.quiet > 2) { Console.WriteLine("Found latest version: v{0}", version); } } if (entered == false) //Will only be false if no store type argument was given { store.Add(StoreType.All); if (Quiet.quiet > 2) { Console.WriteLine("No store type specified, using all"); } } if (id.Length == 16 && Convert.ToInt32(id.Substring(14, 2), 16) >= 3 && Convert.ToInt32(id.Substring(14, 2), 16) <= 255 && id.Substring(0, 14) == "00000001000000") { ios = "IOS" + Convert.ToInt32(id.Substring(14, 2), 16) + "-64-" + version + ".wad"; } if ((((output.Length >= 4 && output.Substring(output.Length - 4, 4).ToUpper() == ".WAD") || output == "") && Array.IndexOf(store.ToArray(), StoreType.WAD) != -1 && store.ToArray().Length == 1) || (output == "" && ios != "" && Array.IndexOf(store.ToArray(), StoreType.WAD) != -1 && store.ToArray().Length == 1)) { wad = true; if (Directory.Exists(temp) == true) { DeleteDir.DeleteDirectory(temp); } Directory.CreateDirectory(temp); } if (output == "") { NoOut = true; output = ios == "" ? id + "v" + version : ios.Substring(0, ios.Length - 4); if (Quiet.quiet > 2) { Console.WriteLine("No output specified, using {0}", output); } } //Main part, catches random/unexpected exceptions try { NusClient nus = new NusClient(); if (local == true) { if (Quiet.quiet > 2) { Console.WriteLine("Using local files if present..."); } nus.UseLocalFiles = true; } if (content != "") { if (Quiet.quiet > 1) { Console.Write("Downloading content..."); } nus.DownloadSingleContent(id, version, content, output); if (Quiet.quiet > 1) { Console.Write("Done!\n"); } } else { if (Quiet.quiet > 1) { Console.Write("Downloading title..."); } string realout = output; if (wad == true) { output = temp; } nus.DownloadTitle(id, version, output, store.ToArray()); WadIosNamingStuff(wad, temp, id, version, ios, NoOut, output, realout); if (Quiet.quiet > 1) { Console.Write("Done!\n"); } } if (Quiet.quiet > 1) { Console.WriteLine("Operation completed succesfully!"); } } catch (Exception ex) { Console.WriteLine("An unknown error occured, please try again"); Console.WriteLine(""); Console.WriteLine("ERROR DETAILS: {0}", ex.Message); return; } return; }