Пример #1
0
        public MainForm()
        {
            InitializeComponent();
            ViewerButton.Enabled = Utils.IsWindows();

            if (Utils.IsWindows())
            {
                try
                {
                    var pat = new KLST_PATTERN_MATCH {
                        DeviceID = @"USB\VID_057E&PID_3000"
                    };
                    var lst = new LstK(0, ref pat);
                    lst.MoveNext(out var dinfo);
                    USB = new UsbK(dinfo);
                }
                catch
                {
                }

                if (USB == null)
                {
                    ViewerButton.Enabled = false;
                }
            }

            var drive = Utils.DetectSDCardDrive();

            if (drive != null)
            {
                EntryManagerButton.Enabled = true;
                PluginButton.Enabled       = true;
                FoundDriveText.Text        = "Found SD card on drive \"" + drive.VolumeLabel + "\" (" + drive.Name + ")";
            }
        }
Пример #2
0
 public static void Main(string[] Args)
 {
     Initialize();
     Warn.LLogL("Make sure to open Goldtree after having opened Goldleaf on your console. Looking for connection...");
     try
     {
         var pat = new KLST_PATTERN_MATCH {
             DeviceID = @"USB\VID_057E&PID_3000"
         };
         var lst = new LstK(0, ref pat);
         lst.MoveNext(out var dinfo);
         USB = new UsbK(dinfo);
         Log.LogL("Connection was established.");
     }
     catch
     {
         Error.LLogL("Unable to find USB communication. Are you sure Goldleaf is open and plugged in?");
     }
     Console.WriteLine();
     while (true)
     {
         USB.CommandHandleLoop();
     }
     Error.LLogL("An error ocurred handling Goldleaf's latest command request.");
 }
Пример #3
0
        private void connect(bool re)
        {
            try
            {
                var pat = new KLST_PATTERN_MATCH {
                    DeviceID = @"USB\VID_057E&PID_3000"
                };
                var lst = new LstK(0, ref pat);
                lst.MoveNext(out var dinfo);
                this.USB = new UsbK(dinfo);
            }
            catch (Exception)
            {
                this.USB = null;
            }

            if (this.USB == null)
            {
                MessageBox.Show("No Switch running uLaunch detected!");
                disconnect();
            }
            else
            {
                if (!re)
                {
                    MessageBox.Show("Switch running uLaunch detected, continuing!");
                }
                miConn.IsEnabled    = false;
                miReConn.IsEnabled  = true;
                miDisConn.IsEnabled = true;
                USBThread           = new Thread(new ThreadStart(USBThreadMain));
                USBThread.Start();
            }
        }
Пример #4
0
        private static UsbK FindDevice()
        {
            var patternMatch = new KLST_PATTERN_MATCH {
                DeviceID = @"USB\VID_0955&PID_7321"
            };
            var deviceList = new LstK(0, ref patternMatch);

            deviceList.MoveNext(out var deviceInfo);
            return(new UsbK(deviceInfo));
        }
Пример #5
0
        public static void Refresh()
        {
            WMIDeviceInfo = null;
            Device        = null;
            DeviceWrapper = null;
            foreach (UsbDeviceInfo info in CreateUsbControllerDeviceInfos(GetUsbDevices()))
            {
                if (info.DeviceID.StartsWith($"USB\\VID_{VID}&PID_{PID}"))
                {
                    WMIDeviceInfo = info;
                    var patternMatch = new KLST_PATTERN_MATCH {
                        ClassGUID = WMIDeviceInfo.ClassGuid
                    };
                    var deviceList = new LstK(0, ref patternMatch);
                    deviceList.MoveNext(out KLST_DEVINFO_HANDLE deviceInfo);

                    Device = new UsbK(deviceInfo);
                    Device.SetAltInterface(0, false, 0);
                    DeviceWrapper = new UsbKWrapper(Device);
                    break;
                }
            }
        }
Пример #6
0
        public static void Scan()
        {
            WMIDeviceInfo = null;
            Device        = null;
            DeviceWrapper = null;
            foreach (UsbDeviceInfo info in AllUsbDevices)
            {
                if (info.DeviceID.StartsWith($"USB\\VID_{VID}&PID_{PID}"))
                {
                    WMIDeviceInfo = info;

                    if (!LibusbKInstalled)
                    {
                        MessageBoxResult result = MessageBox.Show("You have plugged in your console, but it lacks the libusbK driver. Want to install it? (You cannot inject anything until this is done)", "", MessageBoxButton.YesNo);
                        if (result == MessageBoxResult.Yes)
                        {
                            InstallDriver();
                        }
                        WMIDeviceInfo = AllUsbDevices.First(x => x.DeviceID == WMIDeviceInfo.DeviceID); // we need to refresh the info
                    }

                    if (LibusbKInstalled)
                    {
                        var patternMatch = new KLST_PATTERN_MATCH {
                            ClassGUID = WMIDeviceInfo.ClassGuid
                        };
                        var deviceList = new LstK(0, ref patternMatch);
                        deviceList.MoveNext(out KLST_DEVINFO_HANDLE deviceInfo);

                        Device = new UsbK(deviceInfo);
                        Device.SetAltInterface(0, false, 0);
                        DeviceWrapper = new UsbKWrapper(Device);
                    }
                    break;
                }
            }
        }
Пример #7
0
 public static void Main(string[] Args)
 {
     Initialize();
     Warn.LLogL("Make sure Goldleaf is already opened and the console is connected to this system via USB. Looking for connection...");
     try
     {
         var pat = new KLST_PATTERN_MATCH {
             DeviceID = @"USB\VID_057E&PID_3000"
         };
         var lst = new LstK(0, ref pat);
         lst.MoveNext(out var dinfo);
         USB = new UsbK(dinfo);
         Log.LogL("Connection with Goldleaf was established.");
     }
     catch
     {
         Error.LLogL("Unable to find connection. Have you installed libusbK drivers? Are you sure Goldleaf is open and the USB icon is shown there?");
     }
     Console.WriteLine();
     while (true)
     {
         USB.CommandHandleLoop();
     }
 }
Пример #8
0
        public ViewerMainForm()
        {
            InitializeComponent();
            InitializePictureBox(CaptureBox);

            try
            {
                var pat = new KLST_PATTERN_MATCH {
                    DeviceID = @"USB\VID_057E&PID_3000"
                };
                var lst = new LstK(0, ref pat);
                lst.MoveNext(out var dinfo);
                USB = new UsbK(dinfo);
            }
            catch
            {
            }

            Toolbox = new ToolboxForm(this);
            Toolbox.Show();

            USBThread = new Thread(new ThreadStart(USBThreadMain));
            USBThread.Start();
        }
Пример #9
0
        public static void Main(string[] Args)
        {
usbnsp:
            Console.Clear();
            Initialize();
            try
            {
                var pat = new KLST_PATTERN_MATCH {
                    DeviceID = @"USB\VID_057E&PID_3000"
                };
                var lst = new LstK(0, ref pat);
                lst.MoveNext(out var dinfo);
                USB = new UsbK(dinfo);
            }
            catch
            {
                Error.Log("No USB connection was found. Make sure you have Goldleaf open before running Goldtree.");
            }
            try
            {
                Command c = new Command(CommandId.ConnectionRequest);
                USB.Write(c);
                Log.Log("Attempting to connect to Goldleaf via USB...");
                Command rc = USB.Read();
                if (rc.MagicOk())
                {
                    if (rc.IsCommandId(CommandId.ConnectionResponse))
                    {
                        Log.Log("Connection was established with Goldleaf.");
                        Log.Log("Select the NSP to send to Goldleaf on the dialog.");
                        OpenFileDialog fd = new OpenFileDialog()
                        {
                            Title       = "Select NSP to send to Goldleaf via USB",
                            Filter      = "NSP / Nintendo Submission Package (*.nsp)|*.nsp",
                            Multiselect = false,
                        };
                        if (fd.ShowDialog() == DialogResult.OK)
                        {
                            string nsp     = fd.FileName;
                            string nspname = Path.GetFileName(nsp);
                            c = new Command(CommandId.NSPName);
                            USB.Write(c);
                            USB.Write((uint)nspname.Length);
                            USB.Write(nspname);
                            Log.Log("Selected NSP's name was sent to Goldleaf. Waiting for install approval from Goldleaf...");
                            Command rc2 = USB.Read();
                            if (rc2.MagicOk())
                            {
                                if (rc2.IsCommandId(CommandId.Start))
                                {
                                    Log.Log("Goldleaf is ready for the installation. Preparing everything...");
                                    try
                                    {
                                        FileStream    fs   = new FileStream(nsp, FileMode.Open);
                                        StreamStorage ist  = new StreamStorage(fs, true);
                                        Pfs           pnsp = new Pfs(ist);
                                        ist.Dispose();
                                        fs.Close();
                                        fs = new FileStream(nsp, FileMode.Open);
                                        uint filecount = (uint)pnsp.Files.Length;
                                        c = new Command(CommandId.NSPData);
                                        USB.Write(c);
                                        USB.Write(filecount);
                                        int tikidx  = -1;
                                        int certidx = -1;
                                        int tmpidx  = 0;
                                        foreach (var file in pnsp.Files)
                                        {
                                            ulong offset = (ulong)pnsp.HeaderSize + (ulong)file.Offset;
                                            ulong size   = (ulong)file.Size;
                                            uint  len    = (uint)file.Name.Length;
                                            USB.Write(len);
                                            USB.Write(file.Name);
                                            USB.Write(offset);
                                            USB.Write(size);
                                            if (Path.GetExtension(file.Name).Replace(".", "").ToLower() == "tik")
                                            {
                                                tikidx = tmpidx;
                                            }
                                            else if (Path.GetExtension(file.Name).Replace(".", "").ToLower() == "cert")
                                            {
                                                certidx = tmpidx;
                                            }
                                            tmpidx++;
                                        }
                                        BinaryReader br = new BinaryReader(fs);
                                        while (true)
                                        {
                                            Command ccmd = USB.Read();
                                            if (ccmd.MagicOk())
                                            {
                                                if (ccmd.IsCommandId(CommandId.NSPContent))
                                                {
                                                    USB.Read(out uint idx);
                                                    Log.Log("Sending content \'" + pnsp.Files[idx].Name + "\'... (" + (idx + 1) + " of " + pnsp.Files.Length + ")");
                                                    PfsFileEntry ent     = pnsp.Files[idx];
                                                    long         rsize   = 0x800000;
                                                    long         coffset = pnsp.HeaderSize + ent.Offset;
                                                    long         toread  = ent.Size;
                                                    long         tmpread = 1;
                                                    byte[]       bufb;
                                                    while ((tmpread > 0) && (toread > 0) && (coffset < (coffset + ent.Size)))
                                                    {
                                                        if (rsize >= ent.Size)
                                                        {
                                                            rsize = ent.Size;
                                                        }
                                                        int tor = (int)Math.Min(rsize, toread);
                                                        br.BaseStream.Position = coffset;
                                                        bufb    = br.ReadBytes(tor);
                                                        tmpread = bufb.Length;
                                                        USB.Write(bufb);
                                                        coffset += tmpread;
                                                        toread  -= tmpread;
                                                    }
                                                    Log.Log("Content was sent to Goldleaf.");
                                                }
                                                else if (ccmd.IsCommandId(CommandId.NSPTicket))
                                                {
                                                    Log.Log("Sending ticket file...");
                                                    PfsFileEntry tik = pnsp.Files[tikidx];
                                                    br.BaseStream.Seek(pnsp.HeaderSize + tik.Offset, SeekOrigin.Begin);
                                                    byte[] file = br.ReadBytes((int)tik.Size);
                                                    USB.Write(file);
                                                    Log.Log("Ticket was sent to Goldleaf.");
                                                }
                                                else if (ccmd.IsCommandId(CommandId.Finish))
                                                {
                                                    break;
                                                }
                                                else
                                                {
                                                    USB = null;
                                                    Error.Log("An invalid command was received. Are you sure Goldleaf is active?");
                                                }
                                            }
                                            else
                                            {
                                                USB = null;
                                                Error.Log("An invalid command was received. Are you sure Goldleaf is active?");
                                            }
                                        }
                                    }
                                    catch
                                    {
                                        Error.Log("An error ocurred opening the selected NSP. Are you sure it's a valid NSP?");
                                    }
                                }
                                else if (rc2.IsCommandId(CommandId.Finish))
                                {
                                    USB = null;
                                    Error.Log("Goldleaf has canceled the installation.");
                                }
                                else
                                {
                                    USB = null;
                                    Error.Log("An invalid command was received. Are you sure Goldleaf is active?");
                                }
                            }
                            else
                            {
                                USB = null;
                                Error.Log("An invalid command was received. Are you sure Goldleaf is active?");
                            }
                        }
                        else
                        {
                            Error.Log("The dialog was closed without selecting a NSP, or another error ocurred. Reopen Goldleaf and Goldtree and try again.");
                        }
                    }
                    else if (rc.IsCommandId(CommandId.Finish))
                    {
                        USB = null;
                        Error.Log("Goldleaf has canceled the installation.");
                    }
                    else
                    {
                        USB = null;
                        Error.Log("An invalid command was received. Are you sure Goldleaf is active?");
                    }
                }
                else
                {
                    USB = null;
                    Error.Log("An invalid command was received. Are you sure Goldleaf is active?");
                }
            }
            catch
            {
                Error.Log("An error ocurred selecting the NSP to be sent.");
            }
            Log.Log("The installation has finished. Press ENTER to close Goldtree, or any other key to start another USB installation.", true);
            ConsoleKeyInfo ki = Console.ReadKey();

            if (ki.Key == ConsoleKey.Enter)
            {
                if (USB != null)
                {
                    Command cmd = new Command(CommandId.Finish);
                    USB.Write(cmd);
                }
                Environment.Exit(0);
            }
            else
            {
                goto usbnsp;
            }
        }
Пример #10
0
        public bool ConfigureDevice(out WINUSB_PIPE_INFORMATION pipeInfo,
                                    out UsbK usb,
                                    out USB_INTERFACE_DESCRIPTOR interfaceDescriptor)
        {
            bool success;

            Console.WriteLine("Finding usb device by VID/PID.. ({0:X4}h / {1:X4}h)",
                              Vid,
                              Pid);

            // Use a patttern match to include only matching devices.
            // NOTE: You can use the '*' and '?' chars as wildcards for all chars or a single char (respectively).
            KLST_PATTERN_MATCH patternMatch = new KLST_PATTERN_MATCH();

            if (MI != -1)
            {
                patternMatch.DeviceID = String.Format("USB\\VID_{0:X4}&PID_{1:X4}&MI_{2:X2}*",
                                                      Vid,
                                                      Pid,
                                                      MI);
            }
            else
            {
                patternMatch.DeviceID = String.Format("USB\\VID_{0:X4}&PID_{1:X4}*",
                                                      Vid,
                                                      Pid);
            }

            LstK deviceList = new LstK(KLST_FLAG.NONE,
                                       ref patternMatch);
            KLST_DEVINFO_HANDLE deviceInfo;

            interfaceDescriptor = new USB_INTERFACE_DESCRIPTOR();
            pipeInfo            = new WINUSB_PIPE_INFORMATION();
            usb = null;

            // Iterate the devices looking for a matching alt-interface and endpoint id.
            while (deviceList.MoveNext(out deviceInfo))
            {
                // libusbK class contructors can throw exceptions; For instance, if the device is
                // using the WinUsb driver and already in-use by another application.
                Console.WriteLine("Opening usb device..");
                usb = new UsbK(deviceInfo);

                Console.WriteLine("Finding interface and endpoint by PipeId..");
                success = FindPipeAndInterface(usb,
                                               out interfaceDescriptor,
                                               out pipeInfo);
                if (success)
                {
                    break;
                }

                Console.WriteLine("PipeId {0:X2}h not found on this device.",
                                  PipeId);
                usb.Free();
                usb = null;
            }
            if (ReferenceEquals(usb,
                                null))
            {
                Console.WriteLine("Usb device not found: {0}",
                                  patternMatch.DeviceID);
                success = false;
                goto Done;
            }

            MI             = interfaceDescriptor.bInterfaceNumber;
            AltInterfaceId = interfaceDescriptor.bAlternateSetting;
            PipeId         = pipeInfo.PipeId;

            // Set interface alt setting.
            Console.WriteLine("Setting interface #{0} to bAlternateSetting #{1}..",
                              interfaceDescriptor.bInterfaceNumber,
                              interfaceDescriptor.bAlternateSetting);
            success = usb.SetAltInterface(interfaceDescriptor.bInterfaceNumber,
                                          false,
                                          interfaceDescriptor.bAlternateSetting);
            if (!success)
            {
                Console.WriteLine("SetAltInterface failed. ErrorCode={0:X8}h",
                                  Marshal.GetLastWin32Error());
                Console.WriteLine(interfaceDescriptor.ToString());
            }

Done:
            deviceList.Free();

            return(success);
        }
Пример #11
0
        public bool ConfigureDevice(out WINUSB_PIPE_INFORMATION pipeInfo,
                                    out UsbK usb,
                                    out USB_INTERFACE_DESCRIPTOR interfaceDescriptor)
        {
            bool success;
            Console.WriteLine("Finding usb device by VID/PID.. ({0:X4}h / {1:X4}h)",
                              Vid,
                              Pid);

            // Use a patttern match to include only matching devices.
            // NOTE: You can use the '*' and '?' chars as wildcards for all chars or a single char (respectively). 
            KLST_PATTERN_MATCH patternMatch = new KLST_PATTERN_MATCH();
            if (MI != -1)
                patternMatch.DeviceID = String.Format("USB\\VID_{0:X4}&PID_{1:X4}&MI_{2:X2}*",
                                                        Vid,
                                                        Pid,
                                                        MI);
            else
                patternMatch.DeviceID = String.Format("USB\\VID_{0:X4}&PID_{1:X4}*",
                                                        Vid,
                                                        Pid);

            LstK deviceList = new LstK(KLST_FLAG.NONE,
                                       ref patternMatch);
            KLST_DEVINFO_HANDLE deviceInfo;
            interfaceDescriptor = new USB_INTERFACE_DESCRIPTOR();
            pipeInfo = new WINUSB_PIPE_INFORMATION();
            usb = null;

            // Iterate the devices looking for a matching alt-interface and endpoint id.
            while (deviceList.MoveNext(out deviceInfo))
            {
                // libusbK class contructors can throw exceptions; For instance, if the device is
                // using the WinUsb driver and already in-use by another application.
                Console.WriteLine("Opening usb device..");
                usb = new UsbK(deviceInfo);

                Console.WriteLine("Finding interface and endpoint by PipeId..");
                success = FindPipeAndInterface(usb,
                                               out interfaceDescriptor,
                                               out pipeInfo);
                if (success) break;

                Console.WriteLine("PipeId {0:X2}h not found on this device.",
                                  PipeId);
                usb.Free();
                usb = null;
            }
            if (ReferenceEquals(usb,
                                null))
            {
                Console.WriteLine("Usb device not found: {0}",
                                  patternMatch.DeviceID);
                success = false;
                goto Done;
            }

            MI = interfaceDescriptor.bInterfaceNumber;
            AltInterfaceId = interfaceDescriptor.bAlternateSetting;
            PipeId = pipeInfo.PipeId;

            // Set interface alt setting.
            Console.WriteLine("Setting interface #{0} to bAlternateSetting #{1}..",
                              interfaceDescriptor.bInterfaceNumber,
                              interfaceDescriptor.bAlternateSetting);
            success = usb.SetAltInterface(interfaceDescriptor.bInterfaceNumber,
                                          false,
                                          interfaceDescriptor.bAlternateSetting);
            if (!success)
            {
                Console.WriteLine("SetAltInterface failed. ErrorCode={0:X8}h",
                                  Marshal.GetLastWin32Error());
                Console.WriteLine(interfaceDescriptor.ToString());
            }

            Done:
            deviceList.Free();

            return success;
        }
Пример #12
0
        public static void Main(string[] Args)
        {
            Initialize();
            var pat = new KLST_PATTERN_MATCH {
                DeviceID = @"USB\VID_057E&PID_3000"
            };
            var lst = new LstK(0, ref pat);

            try
            {
                lst.MoveNext(out var dinfo);
                USB = new UsbK(dinfo);
            }
            catch
            {
                // System.Diagnostics.Process.Start(System.Windows.Forms.Application.ExecutablePath);
                return;
            }
            while (USB.HandleNextCommand() == CommandHandleResult.Success)
            {
                ;
            }

            /*
             * usbnsp:
             * // Console.Clear();
             * Initialize();
             * try
             * {
             *  var pat = new KLST_PATTERN_MATCH { DeviceID = @"USB\VID_057E&PID_3000" };
             *  var lst = new LstK(0, ref pat);
             *  lst.MoveNext(out var dinfo);
             *  USB = new UsbK(dinfo);
             * }
             * catch
             * {
             *  Error.Log("No USB connection was found. Make sure you have Goldleaf open before running Goldtree.");
             * }
             * try
             * {
             *  Command c = new Command(CommandId.ConnectionRequest);
             *  USB.Write(c);
             *  Log.Log("Attempting to connect to Goldleaf via USB...");
             *  Command rc = USB.Read();
             *  if(rc.MagicOk())
             *  {
             *      if(rc.IsCommandId(CommandId.ConnectionResponse))
             *      {
             *          Log.Log("Connection was established with Goldleaf.");
             *          Log.Log("Select the NSP to send to Goldleaf on the dialog.");
             *          OpenFileDialog fd = new OpenFileDialog()
             *          {
             *              Title = "Select NSP to send to Goldleaf via USB",
             *              Filter = "NSP / Nintendo Submission Package (*.nsp)|*.nsp",
             *              Multiselect = false,
             *          };
             *          if(fd.ShowDialog() == DialogResult.OK)
             *          {
             *              string nsp = fd.FileName;
             *              string nspname = Path.GetFileName(nsp);
             *              c = new Command(CommandId.NSPName);
             *              USB.Write(c);
             *              USB.Write((uint)nspname.Length);
             *              USB.Write(nspname);
             *              Log.Log("Selected NSP's name was sent to Goldleaf. Waiting for install approval from Goldleaf...");
             *              Command rc2 = USB.Read();
             *              if(rc2.MagicOk())
             *              {
             *                  if(rc2.IsCommandId(CommandId.Start))
             *                  {
             *                      Log.Log("Goldleaf is ready for the installation. Preparing everything...");
             *                      try
             *                      {
             *                          FileStream fs = new FileStream(nsp, FileMode.Open);
             *                          StreamStorage ist = new StreamStorage(fs, true);
             *                          Pfs pnsp = new Pfs(ist);
             *                          ist.Dispose();
             *                          fs.Close();
             *                          fs = new FileStream(nsp, FileMode.Open);
             *                          uint filecount = (uint)pnsp.Files.Length;
             *                          c = new Command(CommandId.NSPData);
             *                          USB.Write(c);
             *                          USB.Write(filecount);
             *                          int tikidx = -1;
             *                          int certidx = -1;
             *                          int tmpidx = 0;
             *                          foreach(var file in pnsp.Files)
             *                          {
             *                              ulong offset = (ulong)pnsp.HeaderSize + (ulong)file.Offset;
             *                              ulong size = (ulong)file.Size;
             *                              uint len = (uint)file.Name.Length;
             *                              USB.Write(len);
             *                              USB.Write(file.Name);
             *                              USB.Write(offset);
             *                              USB.Write(size);
             *                              if(Path.GetExtension(file.Name).Replace(".", "").ToLower() == "tik") tikidx = tmpidx;
             *                              else if(Path.GetExtension(file.Name).Replace(".", "").ToLower() == "cert") certidx = tmpidx;
             *                              tmpidx++;
             *                          }
             *                          BinaryReader br = new BinaryReader(fs);
             *                          while(true)
             *                          {
             *                              Command ccmd = USB.Read();
             *                              if(ccmd.MagicOk())
             *                              {
             *                                  if(ccmd.IsCommandId(CommandId.NSPContent))
             *                                  {
             *                                      USB.Read(out uint idx);
             *                                      Log.Log("Sending content \'" + pnsp.Files[idx].Name + "\'... (" + (idx + 1) + " of " + pnsp.Files.Length + ")");
             *                                      PfsFileEntry ent = pnsp.Files[idx];
             *                                      long rsize = 0x100000;
             *                                      long coffset = pnsp.HeaderSize + ent.Offset;
             *                                      long toread = ent.Size;
             *                                      long tmpread = 1;
             *                                      byte[] bufb;
             *                                      while((tmpread > 0) && (toread > 0) && (coffset < (coffset + ent.Size)))
             *                                      {
             *                                          if(rsize >= ent.Size) rsize = ent.Size;
             *                                          int tor = (int)Math.Min(rsize, toread);
             *                                          br.BaseStream.Position = coffset;
             *                                          bufb = br.ReadBytes(tor);
             *                                          tmpread = bufb.Length;
             *                                          USB.Write(bufb);
             *                                          coffset += tmpread;
             *                                          toread -= tmpread;
             *                                      }
             *                                      Log.Log("Content was sent to Goldleaf.");
             *                                  }
             *                                  else if(ccmd.IsCommandId(CommandId.NSPTicket))
             *                                  {
             *                                      Log.Log("Sending ticket file...");
             *                                      PfsFileEntry tik = pnsp.Files[tikidx];
             *                                      br.BaseStream.Seek(pnsp.HeaderSize + tik.Offset, SeekOrigin.Begin);
             *                                      byte[] file = br.ReadBytes((int)tik.Size);
             *                                      USB.Write(file);
             *                                      Log.Log("Ticket was sent to Goldleaf.");
             *                                  }
             *                                  else if(ccmd.IsCommandId(CommandId.Finish)) break;
             *                                  else
             *                                  {
             *                                      USB = null;
             *                                      Error.Log("An invalid command was received. Are you sure Goldleaf is active?");
             *                                  }
             *                              }
             *                              else
             *                              {
             *                                  USB = null;
             *                                  Error.Log("An invalid command was received. Are you sure Goldleaf is active?");
             *                              }
             *                          }
             *                      }
             *                      catch
             *                      {
             *                          Error.Log("An error ocurred opening the selected NSP. Are you sure it's a valid NSP?");
             *                      }
             *                  }
             *                  else if(rc2.IsCommandId(CommandId.Finish))
             *                  {
             *                      USB = null;
             *                      Error.Log("Goldleaf has canceled the installation.");
             *                  }
             *                  else
             *                  {
             *                      USB = null;
             *                      Error.Log("An invalid command was received. Are you sure Goldleaf is active?");
             *                  }
             *              }
             *              else
             *              {
             *                  USB = null;
             *                  Error.Log("An invalid command was received. Are you sure Goldleaf is active?");
             *              }
             *          }
             *          else Error.Log("The dialog was closed without selecting a NSP, or another error ocurred. Reopen Goldleaf and Goldtree and try again.");
             *      }
             *      else if(rc.IsCommandId(CommandId.Finish))
             *      {
             *          USB = null;
             *          Error.Log("Goldleaf has canceled the installation.");
             *      }
             *      else
             *      {
             *          USB = null;
             *          Error.Log("An invalid command was received. Are you sure Goldleaf is active?");
             *      }
             *  }
             *  else
             *  {
             *      USB = null;
             *      Error.Log("An invalid command was received. Are you sure Goldleaf is active?");
             *  }
             * }
             * catch
             * {
             *  Error.Log("An error ocurred selecting the NSP to be sent.");
             * }
             * Log.Log("The installation has finished. Press ENTER to close Goldtree, or any other key to start another USB installation.", true);
             * ConsoleKeyInfo ki = Console.ReadKey();
             * if(ki.Key == ConsoleKey.Enter)
             * {
             *  if(USB != null)
             *  {
             *      Command cmd = new Command(CommandId.Finish);
             *      USB.Write(cmd);
             *  }
             *  Environment.Exit(0);
             * }
             * else goto usbnsp;
             */
        }