예제 #1
0
        public static bool WaitForDevice(IWin32Window owner)
        {
            if (DeviceExists())
            {
                return(true);
            }
            var form = new WaitingClovershellForm();

            form.ShowDialog(owner);
            return(form.DialogResult == DialogResult.OK);
        }
예제 #2
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 (!WaitingClovershellForm.WaitForDevice(this))
                        {
                            return;
                        }
                        var clovershell = MainForm.Clovershell;
                        using (var save = new MemoryStream())
                        {
                            clovershell.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)
            {
                Debug.WriteLine(ex.Message + ex.StackTrace);
                try
                {
                    Invoke(new Action(delegate
                    {
                        MessageBox.Show(this, ex.Message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }));
                }
                catch { }
            }
        }
예제 #3
0
        public static bool WaitForDevice(IWin32Window owner, bool justWaiting = false)
        {
            if (DeviceExists())
            {
                return(true);
            }
            var form = new WaitingClovershellForm();

            if (justWaiting)
            {
                form.label1.Text = "1. " + Resources.MakeSureYourMiniIsConnected;
                form.label2.Text = "2. " + Resources.JustWaitForYourMini;
                //form.label3.Enabled = false;
                //form.buttonDriver.Enabled = false;
            }
            form.ShowDialog(owner);
            return(form.DialogResult == DialogResult.OK);
        }
예제 #4
0
        DialogResult WaitForClovershellFromThread()
        {
            if (InvokeRequired)
            {
                return((DialogResult)Invoke(new Func <DialogResult>(WaitForClovershellFromThread)));
            }
            SetStatus(Resources.WaitingForDevice);
            TaskbarProgress.SetState(this, TaskbarProgress.TaskbarStates.Paused);
            var result = WaitingClovershellForm.WaitForDevice(this);

            TaskbarProgress.SetState(this, TaskbarProgress.TaskbarStates.Normal);
            if (result)
            {
                return(DialogResult.OK);
            }
            else
            {
                return(DialogResult.Abort);
            }
        }
예제 #5
0
 void importSaves(object o)
 {
     try
     {
         var files = (string[])o;
         if (!(bool)Invoke(new Func <bool>(delegate
         {
             if (!WaitingClovershellForm.WaitForDevice(this))
             {
                 return(false);
             }
             return(true);
         })))
         {
             return;
         }
         foreach (var file in files)
         {
             var clovershell = MainForm.Clovershell;
             using (var f = new FileStream(file, FileMode.Open))
             {
                 clovershell.Execute("cd /var/lib/clover/profiles/0 && tar -xvz", f, null, null, 10000, true);
             }
         }
     }
     catch (ThreadAbortException) { }
     catch (ObjectDisposedException) { }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.Message + ex.StackTrace);
         try
         {
             Invoke(new Action(delegate
             {
                 MessageBox.Show(this, ex.Message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
             }));
         }
         catch { }
     }
     LoadSaveStatesList();
 }
예제 #6
0
 void deleteRowsThread(object o)
 {
     try
     {
         var savesToDelete = (IEnumerable <ListViewItem>)o;
         if (!(bool)Invoke(new Func <bool>(delegate
         {
             if (!WaitingClovershellForm.WaitForDevice(this))
             {
                 return(false);
             }
             return(true);
         })))
         {
             return;
         }
         foreach (ListViewItem game in savesToDelete)
         {
             var clovershell = MainForm.Clovershell;
             clovershell.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)
     {
         Debug.WriteLine(ex.Message + ex.StackTrace);
         try
         {
             Invoke(new Action(delegate
             {
                 MessageBox.Show(this, ex.Message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
             }));
         }
         catch { }
     }
 }
예제 #7
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 (!WaitingClovershellForm.WaitForDevice(this))
                    {
                        return(false);
                    }
                    return(true);
                })))
                {
                    Close();
                    return;
                }

                var clovershell = MainForm.Clovershell;
                WorkerForm.ShowSplashScreen();
                var listSavesScript =
                    "#!/bin/sh\n" +
                    "savespath=/var/lib/clover/profiles/0\n" +
                    "find $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 /var/lib -type f -name \"$code.desktop\" -exec cat {} + | sed -n 's/Name=\\(.*\\)/\\1/p')\n" +
                    "    [ -z \"$name\" ] && name=UNKNOWN\n" +
                    "    echo $code $size $flags $name\n" +
                    "    unset flags\n" +
                    "    unset name\n" +
                    "  else\n" +
                    "    rm -rf $savespath/$code\n" +
                    "  fi\n" +
                    "done";
                var listSavesScriptStream = new MemoryStream(Encoding.UTF8.GetBytes(listSavesScript));
                listSavesScriptStream.Seek(0, SeekOrigin.Begin);
                var output = new MemoryStream();
                clovershell.Execute("sh", listSavesScriptStream, output, null, 10000, 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)
            {
                Debug.WriteLine(ex.Message + ex.StackTrace);
                try
                {
                    Invoke(new Action(delegate
                    {
                        MessageBox.Show(this, ex.Message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Close();
                    }));
                }
                catch { }
            }
        }