Ejemplo n.º 1
0
        public static bool WaitForDevice(IWin32Window owner)
        {
            if (DeviceExists())
            {
                return(true);
            }
            var form = new WaitingShellForm();

            form.ShowDialog(owner);
            return(form.DialogResult == DialogResult.OK);
        }
Ejemplo n.º 2
0
 private void takeScreenshotToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         if (WaitingShellForm.WaitForDevice(this))
         {
             Program.FormContext.AddForm(new ScreenshotForm());
         }
     }
     catch (Exception ex)
     {
         Tasks.ErrorForm.Show(this, ex);
     }
 }
Ejemplo n.º 3
0
        private void loadFirmwares()
        {
            try
            {
                while (!IsHandleCreated)
                {
                    Thread.Sleep(100);
                }
                Invoke(new Action(delegate {
                    if (!WaitingShellForm.WaitForDevice(this))
                    {
                        Close();
                        return;
                    }
                }));

                var firmwareCurrent = hakchi.Shell.ExecuteSimple("hakchi currentFirmware", 1000, true);
                var firmwareList    = hakchi.Shell.ExecuteSimple("find \"/var/lib/hakchi/\" -iname \"*.hsqs\"", 10000, true);
                firmwarePaths = new List <string>();
                foreach (var firmware in firmwareList.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    firmwarePaths.Add(firmware);
                }

                Invoke(new Action(delegate
                {
                    listBoxFirmwares.Items.Clear();
                    listBoxFirmwares.Items.Add(Resources.FirmwareDefault + (firmwareCurrent == "_nand_" ? $" ({Resources.FirmwareCurrent})" : ""));
                    listBoxFirmwares.Items.AddRange(firmwarePaths.Select(
                                                        f => Path.GetFileNameWithoutExtension(f) + (f == firmwareCurrent ? $" ({Resources.FirmwareCurrent})" : "")).ToArray());
                    buttonOk.Enabled = true;
                }));
            }
            catch (ThreadAbortException) { }
            catch (ObjectDisposedException) { }
            catch (Exception ex)
            {
                try
                {
                    Tasks.ErrorForm.Show(this, ex);
                }
                catch { }
            }
        }
Ejemplo n.º 4
0
        private void buttonOk_Click(object sender, EventArgs e)
        {
            if (!WaitingShellForm.WaitForDevice(this))
            {
                Close();
                return;
            }

            var selected = listBoxFirmwares.SelectedIndex;

            if (selected == -1 || selected > firmwarePaths.Count)
            {
                Close();
                return;
            }

            try
            {
                var firmwareCurrent  = hakchi.Shell.ExecuteSimple("hakchi currentFirmware", 1000, true);
                var firmwareFullPath = selected == 0 ? "_nand_" : '"' + firmwarePaths[selected - 1] + '"';

                if (firmwareCurrent == firmwareFullPath)
                {
                    Close();
                    return;
                }

                try
                {
                    hakchi.Shell.ExecuteSimple("/bin/detached hsqs " + firmwareFullPath);
                }
                catch { }
                hakchi.Shell.Disconnect();

                Tasks.MessageForm.Show(this, Resources.Firmware, string.Format(Resources.FirmwareSwitched, (string)listBoxFirmwares.SelectedItem), Resources.sign_check, new Tasks.MessageForm.Button[] { Tasks.MessageForm.Button.OK });
            }
            catch (Exception ex)
            {
                Tasks.ErrorForm.Show(this, ex);
            }
            Close();
        }
Ejemplo n.º 5
0
        private void buttonExport_Click(object sender, EventArgs e)
        {
            try
            {
                string invalidChars       = new string(Path.GetInvalidFileNameChars());
                Regex  removeInvalidChars = new Regex($"[{Regex.Escape(invalidChars)}]", RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.CultureInvariant);

                foreach (ListViewItem game in listViewSaves.SelectedItems)
                {
                    saveFileDialog.FileName = removeInvalidChars.Replace(game.SubItems["colName"].Text, "") + ".clvs";
                    var name = game.SubItems["colName"].Text != null ? game.SubItems["colName"].Text : "save";
                    saveFileDialog.Title = name;
                    if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        if (!WaitingShellForm.WaitForDevice(this))
                        {
                            return;
                        }
                        using (var save = new MemoryStream())
                        {
                            hakchi.Shell.Execute("cd /var/lib/clover/profiles/0 && tar -cz " + game.SubItems["colCode"].Text, null, save, null, 10000, true);
                            var buffer = save.ToArray();
                            File.WriteAllBytes(saveFileDialog.FileName, buffer);
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                try
                {
                    Tasks.ErrorForm.Show(this, ex);
                }
                catch { }
            }
        }
Ejemplo n.º 6
0
 void deleteRowsThread(object o)
 {
     try
     {
         var savesToDelete = (IEnumerable <ListViewItem>)o;
         if (!(bool)Invoke(new Func <bool>(delegate
         {
             if (!WaitingShellForm.WaitForDevice(this))
             {
                 return(false);
             }
             return(true);
         })))
         {
             return;
         }
         foreach (ListViewItem game in savesToDelete)
         {
             hakchi.Shell.ExecuteSimple("rm -rf /var/lib/clover/profiles/0/" + game.SubItems["colCode"].Text, 3000, true);
             Invoke(new Action(delegate
             {
                 listViewSaves.Items.Remove(game);
             }));
         }
     }
     catch (ThreadAbortException) { }
     catch (ObjectDisposedException) { }
     catch (Exception ex)
     {
         Trace.WriteLine(ex.Message + ex.StackTrace);
         try
         {
             Tasks.ErrorForm.Show(this, ex);
         }
         catch { }
     }
 }
Ejemplo n.º 7
0
 void importSaves(object o)
 {
     try
     {
         var files = (string[])o;
         if (!(bool)Invoke(new Func <bool>(delegate
         {
             if (!WaitingShellForm.WaitForDevice(this))
             {
                 return(false);
             }
             return(true);
         })))
         {
             return;
         }
         foreach (var file in files)
         {
             using (var f = new FileStream(file, FileMode.Open, FileAccess.Read))
             {
                 hakchi.Shell.Execute("cd /var/lib/clover/profiles/0 && tar -xvz", f, null, null, 10000, true);
             }
         }
     }
     catch (ThreadAbortException) { }
     catch (ObjectDisposedException) { }
     catch (Exception ex)
     {
         try
         {
             Tasks.ErrorForm.Show(this, ex);
         }
         catch { }
     }
     LoadSaveStatesList();
 }
Ejemplo n.º 8
0
        void LoadSaveStatesList()
        {
            try
            {
                while (!this.IsHandleCreated)
                {
                    Thread.Sleep(100);
                }
                if (!(bool)Invoke(new Func <bool>(delegate
                {
                    listViewSaves.Visible = false;
                    exportToolStripMenuItem.Enabled = importToolStripMenuItem.Enabled =
                        buttonExport.Enabled = buttonImport.Enabled = false;
                    if (!WaitingShellForm.WaitForDevice(this))
                    {
                        return(false);
                    }
                    return(true);
                })))
                {
                    Close();
                    return;
                }

                hakchi.ShowSplashScreen();
                var listSavesScript =
                    "#!/bin/sh\n" +
                    "savespath=/var/saves\n" +
                    "gamestorage=$(hakchi findGameSyncStorage)\n" +
                    "find -L $savespath -mindepth 1 -maxdepth 1 -type d -name \"CLV-*\" | sed 's#.*/##' | while read code ; do\n" +
                    "  flags=F\n" +
                    "  [ -f $savespath/$code/save.sram ] && flags=${flags}-S\n" +
                    "  [ -f $savespath/$code/cartridge.sram ] && [ $(wc -c <$savespath/$code/cartridge.sram) -gt 20 ] && flags=${flags}-S\n" +
                    "  [ -f $savespath/$code/1.state ] && flags=${flags}-1\n" +
                    "  [ -d $savespath/$code/suspendpoint1  ] && flags=${flags}-1\n" +
                    "  [ -f $savespath/$code/2.state ] && flags=${flags}-2\n" +
                    "  [ -d $savespath/$code/suspendpoint2 ] && flags=${flags}-2\n" +
                    "  [ -f $savespath/$code/3.state ] && flags=${flags}-3\n" +
                    "  [ -d $savespath/$code/suspendpoint3 ] && flags=${flags}-3\n" +
                    "  [ -f $savespath/$code/4.state ] && flags=${flags}-4\n" +
                    "  [ -d $savespath/$code/suspendpoint4 ] && flags=${flags}-4\n" +
                    "  if [ \"$flags\" != \"F\" ]; then\n" +
                    "    size=$(du -d 0 $savespath/$code | awk '{ print $1 }')\n" +
                    "    name=$(find -L \"$gamestorage\" -type f -name \"$code.desktop\" -exec cat {} + | sed -n 's/Name=\\(.*\\)/\\1/p' | head -n 1)\n" +
                    "    [ -z \"$name\" ] && name=UNKNOWN\n" +
                    "    echo $code $size $flags $name\n" +
                    "    unset flags\n" +
                    "    unset name\n" +
                    "  fi\n" +
                    "done";
                var listSavesScriptStream = new MemoryStream(Encoding.UTF8.GetBytes(listSavesScript));
                listSavesScriptStream.Seek(0, SeekOrigin.Begin);
                var output = new MemoryStream();
                hakchi.Shell.Execute("sh", listSavesScriptStream, output, null, 0, true);
                var lines = Encoding.UTF8.GetString(output.ToArray()).Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
                Invoke(new Action(delegate
                {
                    listViewSaves.Items.Clear();
                    foreach (var line in lines)
                    {
                        var l     = line;
                        var code  = l.Substring(0, l.IndexOf(' '));
                        l         = l.Substring(l.IndexOf(' ') + 1);
                        var size  = l.Substring(0, l.IndexOf(' ')) + "KB";
                        l         = l.Substring(l.IndexOf(' ') + 1);
                        var flags = l.Substring(0, l.IndexOf(' ')).Replace("F-", "").Replace("-", " ").Trim();
                        l         = l.Substring(l.IndexOf(' ') + 1);
                        var name  = l;
                        if (name == "UNKNOWN")
                        {
                            if (gameNames.ContainsKey(code))
                            {
                                name = gameNames[code];
                            }
                            else
                            {
                                name = Resources.UnknownGame;
                            }
                        }
                        listViewSaves.Items.Add(new ListViewItem(new ListViewItem.ListViewSubItem[] {
                            new  ListViewItem.ListViewSubItem()
                            {
                                Name = "colName", Text = name
                            },
                            new  ListViewItem.ListViewSubItem()
                            {
                                Name = "colCode", Text = code
                            },
                            new  ListViewItem.ListViewSubItem()
                            {
                                Name = "colSize", Text = size
                            },
                            new  ListViewItem.ListViewSubItem()
                            {
                                Name = "colFlags", Text = flags
                            }
                        }, 0));
                        listViewSaves.ListViewItemSorter = new SavesSorter(0, false);
                        listViewSaves.Sort();
                    }
                    listViewSaves.Visible           = true;
                    importToolStripMenuItem.Enabled = true;
                    buttonImport.Enabled            = true;
                }));
            }
            catch (ThreadAbortException) { }
            catch (ObjectDisposedException) { }
            catch (Exception ex)
            {
                try
                {
                    Tasks.ErrorForm.Show(this, ex);
                }
                catch { }
            }
        }