private void btBrowseRomDir_Click(object sender, EventArgs e)
        {
            MulticoreCoreZipFile core = ((MulticoreCoreZipFile)btBrowseRomDir.Tag);
            FolderBrowserDialog  fbd  = new FolderBrowserDialog()
            {
                ShowNewFolderButton = true,
                Description         = "Selecione o diretorio com as ROMS de " + core.HardDir.ToString()
            };

            if (fbd.ShowDialog() == DialogResult.OK)
            {
                if (fbd.SelectedPath != core.RomsFolder)
                {
                    core.RomsFolder = fbd.SelectedPath;
                    txtRomsDir.Text = core.RomsFolder;
                    if (_romsPath.ContainsKey(core.Name))
                    {
                        _romsPath[core.Name] = core.RomsFolder;
                    }
                    else
                    {
                        _romsPath.Add(core.Name, core.RomsFolder);
                    }
                    this.saveConfig();
                }
            }
        }
        private void loadTreeView()
        {
            this._selectedCore = null;
            tvLocalPath.Nodes.Clear();
            TreeNode root = new TreeNode(_mc2repo.ToString());

            foreach (Multicore2TypeDirectory typeDir in _mc2repo.TypeDirs)
            {
                TreeNode typeNode = new TreeNode(typeDir.ToString());
                foreach (MulticoreDirectory mcDir in typeDir.Directories)
                {
                    foreach (MulticoreCoreZipFile core in mcDir.Cores)
                    {
                        TreeNode coreNode = new TreeNode(core.ToString().ToUpper().Replace(".ZIP", ""))
                        {
                            Tag = core
                        };
                        typeNode.Nodes.Add(coreNode);
                    }
                }
                root.Nodes.Add(typeNode);
            }
            tvLocalPath.Nodes.Add(root);
            tvLocalPath.Sort();
            tvLocalPath.Nodes[0].Expand();
        }
Beispiel #3
0
        private void tvLocalPath_DrawNode(object sender, DrawTreeNodeEventArgs e)
        {
            MulticoreCoreZipFile core = (MulticoreCoreZipFile)e.Node.Tag;

            e.DrawDefault = !core.WasUpdated;
            if (!e.DrawDefault)
            {
            }
        }
 private void updateCoresRomPaths()
 {
     foreach (KeyValuePair <string, string> kvp in _romsPath)
     {
         MulticoreCoreZipFile core = (from MulticoreCoreZipFile cz in _mc2repo.Cores where cz.Name.Equals(kvp.Key) select cz).FirstOrDefault();
         if (core != null)
         {
             core.RomsFolder = kvp.Value;
         }
     }
 }
        private void tvLocalPath_DrawNode(object sender, DrawTreeNodeEventArgs e)
        {
            bool hasUpdate = false;

            e.DrawDefault = false;
            if (e.Node.Tag != null)
            {
                MulticoreCoreZipFile core = (MulticoreCoreZipFile)e.Node.Tag;
                hasUpdate = core.WasUpdated;
            }
            Font font = new Font(tvLocalPath.Font, hasUpdate ? FontStyle.Bold : FontStyle.Regular);

            TextRenderer.DrawText(e.Graphics, e.Node.Text, font, new Point(e.Bounds.Left, e.Bounds.Top), tvLocalPath.ForeColor);
        }
Beispiel #6
0
        private void updateExistingCores()
        {
            this.UncheckAllNodes(tvLocalPath.Nodes);
            List <TreeNode> nodesCores  = new List <TreeNode>();
            bool            haveUpdates = false;

            foreach (TreeNode tnT in tvLocalPath.Nodes[0].Nodes)
            {
                foreach (TreeNode tnC in tnT.Nodes)
                {
                    nodesCores.Add(tnC);
                }
            }
            if (nodesCores.Count > 0)
            {
                foreach (TreeNode tnCore in nodesCores)
                {
                    MulticoreCoreZipFile mcZip = (MulticoreCoreZipFile)tnCore.Tag;
                    using (ZipFile zip = ZipFile.Read(mcZip.FileInfo.FullName))
                    {
                        foreach (ZipEntry e in zip)
                        {
                            FileInfo sdInfo = (from FileInfo fiSD in this._sdCardFiles where fiSD.Name == e.FileName select fiSD).FirstOrDefault();
                            tnCore.Checked = (sdInfo != null);

                            if (sdInfo == null)
                            {
                                continue;
                            }

                            #region check if was updated
                            mcZip.WasUpdated = (sdInfo.Length != mcZip.FileInfo.Length) || (sdInfo.LastWriteTime != mcZip.FileInfo.LastWriteTime);
                            if (mcZip.WasUpdated)
                            {
                                tnCore.Tag = mcZip;
                            }
                            haveUpdates |= mcZip.WasUpdated;
                            #endregion check if was updated
                            //zipContents += e.FileName + "\r\n";
                            //if (!haveAll) break;
                        }
                    }
                }
                if (haveUpdates)
                {
                    tvLocalPath.Refresh();
                }
            }
        }
 private void showCoreInfo(MulticoreCoreZipFile core)
 {
     this._selectedCore = core;
     this.clearInfo();
     gbReadme.Visible    = (!string.IsNullOrEmpty(core.HardDir.Readme));
     txtReadme.Text      = string.IsNullOrEmpty(core.HardDir.Readme) ? "" : core.HardDir.Readme;
     txtZipContents.Text = core.ZipContents;
     gbRomsDir.Visible   = core.HardDir.TypeDir.HaveRoms;
     txtRomsDir.Text     = core.RomsFolder;
     btBrowseRomDir.Tag  = core;
     if (core.HardDir.TypeDir.HaveRoms)
     {
         this.loadRomsTree(core);
     }
     else
     {
         tvRoms.Nodes.Clear();
     }
 }
        private void updateSDCores()
        {
            int ok = 0;

            lbProgressMsg.Text = ""; lbProgressMsg.Visible = true;
            btGitLab.Visible   = false; lbUpdateSD.Visible = false;
            try
            {
                for (int c = 0; c < this._updatedCores.Count; c++)
                {
                    MulticoreCoreZipFile zip = this._updatedCores[c];
                    lbProgressMsg.Text = $"Atualizando [{zip.Name}] - {c} de {this._updatedCores.Count}...";
                    using (ZipFile zipFile = ZipFile.Read(zip.FileInfo.FullName))
                    {
                        try
                        {
                            Cursor.Current = Cursors.WaitCursor;
                            try
                            {
                                zipFile.ExtractAll(_sdDrive.DriveInfo.RootDirectory.Name, ExtractExistingFileAction.OverwriteSilently);
                                ok++;
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                        finally
                        {
                            Cursor.Current = Cursors.Default;
                        }
                    } //using
                    Application.DoEvents(); //refresh progress
                }     //for
            }
            finally
            {
                lbProgressMsg.Text = ""; lbProgressMsg.Visible = false; btGitLab.Visible = true;
                MessageBox.Show($"{ok} de {this._updatedCores.Count} cores atualizados com sucesso");
            }
        }
Beispiel #9
0
 private void lvRoms_MouseUp(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         Point mousePos = lvRoms.PointToClient(Control.MousePosition);
         ListViewHitTestInfo hitTest = lvRoms.HitTest(mousePos);
         if (hitTest.Item != null)
         {
             int columnIndex = hitTest.Item.SubItems.IndexOf(hitTest.SubItem);
             if (columnIndex == 3) //directory navigator
             {
                 MulticoreCoreZipFile core = ((MulticoreCoreZipFile)hitTest.Item.Tag);
                 FolderBrowserDialog  fbd  = new FolderBrowserDialog()
                 {
                     ShowNewFolderButton = true,
                     Description         = "Selecione o diretorio com as ROMS de " + core.HardDir.DirInfo.Name,
                     SelectedPath        = core.RomsFolder
                 };
                 if (fbd.ShowDialog() == DialogResult.OK)
                 {
                     if (fbd.SelectedPath != core.RomsFolder)
                     {
                         //core.RomsFolder = fbd.SelectedPath;
                         if (_romPaths.ContainsKey(core.HardDir.DirInfo.Name.ToUpper()))
                         {
                             _romPaths[core.HardDir.DirInfo.Name.ToUpper()] = fbd.SelectedPath;
                         }
                         else
                         {
                             _romPaths.Add(core.HardDir.DirInfo.Name.ToUpper(), fbd.SelectedPath);
                         }
                         hitTest.Item.SubItems[2].Text = fbd.SelectedPath;
                         lvRoms.Refresh();
                     }
                 }
             }
         }
     }
 }
        private void loadRomsTree(MulticoreCoreZipFile core)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                _loading       = true;
                tvRoms.Nodes.Clear();
                gbRoms.Text = "Roms para core selecionado";

                if (string.IsNullOrEmpty(core.RomsFolder))
                {
                    tvRoms.CheckBoxes = false;
                    tvRoms.Nodes.Add(new TreeNode("Diretório de ROMs não informado"));
                }
                else
                {
                    gbRoms.Text      += " (" + _sdDrive.DriveInfo.RootDirectory + "ROMS" + Path.DirectorySeparatorChar + core.Name + ")";
                    tvRoms.CheckBoxes = true;
                    DirectoryInfo di = new DirectoryInfo(core.RomsFolder);
                    //foreach(DirectoryInfo dis in di.GetDirectories()) { }
                    foreach (FileInfo fi in di.GetFiles())
                    {
                        TreeNode tn = new TreeNode(fi.Name)
                        {
                            Tag = fi
                        };
                        tvRoms.Nodes.Add(tn);
                    }
                    this.updateExistingRoms();
                }
            }
            finally
            {
                _loading       = false;
                Cursor.Current = Cursors.Default;
            }
        }
        private void updateExistingCores()
        {
            bool loadingFlag = !_loading;

            if (loadingFlag)
            {
                _loading = true;
            }

            _updatedCores.Clear();

            this.UncheckAllNodes(tvLocalPath.Nodes);
            List <TreeNode> nodesCores  = new List <TreeNode>();
            bool            haveUpdates = false;

            foreach (TreeNode tnT in tvLocalPath.Nodes[0].Nodes)
            {
                foreach (TreeNode tnC in tnT.Nodes)
                {
                    nodesCores.Add(tnC);
                }
            }
            if (nodesCores.Count > 0)
            {
                foreach (TreeNode tnCore in nodesCores)
                {
                    MulticoreCoreZipFile mcZip = (MulticoreCoreZipFile)tnCore.Tag;
                    using (ZipFile zip = ZipFile.Read(mcZip.FileInfo.FullName))
                    {
                        foreach (ZipEntry e in zip)
                        {
                            FileInfo sdInfo = (from FileInfo fiSD in this._sdCardFiles where fiSD.Name == e.FileName select fiSD).FirstOrDefault();
                            tnCore.Checked = (sdInfo != null);

                            if (sdInfo == null)
                            {
                                continue;
                            }

                            #region check if was updated
                            mcZip.WasUpdated = (sdInfo.Length != e.UncompressedSize);// || (sdInfo.LastWriteTime != e.LastModified);
                            if (mcZip.WasUpdated)
                            {
                                tnCore.Tag = mcZip;
                                this._updatedCores.Add(mcZip);
                            }
                            haveUpdates |= mcZip.WasUpdated;
                            #endregion check if was updated
                            //zipContents += e.FileName + "\r\n";
                            //if (!haveAll) break;
                        }
                    }
                }
                if (haveUpdates)
                {
                    tvLocalPath.Refresh();
                    lbUpdateSD.Text    = $"{this._updatedCores.Count} cores atualizados. Clique AQUI para atualizar o SD";
                    lbUpdateSD.Visible = true;
                }
            }
            if (loadingFlag)
            {
                _loading = false;
            }
        }
        private void loadRepository(string path)
        {
            _mc2repo.TypeDirs.Clear(); _mc2repo.Model = _myModel;

            foreach (DirectoryInfo typeDir in new DirectoryInfo(path).GetDirectories())
            {
                Multicore2TypeDirectory mc2TDir = new Multicore2TypeDirectory()
                {
                    Name     = typeDir.Name,
                    HaveRoms = TYPES_WITH_ROMS.Contains(typeDir.Name)
                };

                foreach (DirectoryInfo hardDir in typeDir.GetDirectories())
                {
                    MulticoreDirectory MCDir = new MulticoreDirectory()
                    {
                        DirInfo = hardDir,
                        TypeDir = mc2TDir
                    };
                    foreach (FileInfo file in hardDir.GetFiles())
                    {
                        if ((file.Name.ToUpper().Equals("README.MD")) || (file.Name.ToUpper().Equals("README.TXT")))
                        {
                            MCDir.Readme = File.ReadAllText(file.FullName);
                        }
                        else
                        {
                            if (file.Extension.ToUpper().Equals(".ZIP"))
                            {
                                //bool haveAll = true;
                                string zipContents = "";
                                using (ZipFile zip = ZipFile.Read(file.FullName))
                                {
                                    foreach (ZipEntry e in zip)
                                    {
                                        //haveAll &= ((from FileInfo fi in this._sdCardFiles where fi.Name == e.FileName select fi.Name).FirstOrDefault() != null);
                                        zipContents += e.FileName + "\r\n";
                                        //if (!haveAll) break;
                                    }
                                }
                                MulticoreCoreZipFile core = new MulticoreCoreZipFile()
                                {
                                    FileInfo    = file,
                                    ZipContents = zipContents,//.Split(new char[] { '\r', '\n' }),
                                    HardDir     = MCDir
                                };
                                if (_romsPath.ContainsKey(file.Name))
                                {
                                    core.RomsFolder = _romsPath[file.Name];
                                }
                                MCDir.Cores.Add(core);
                            }
                        }
                    }
                    mc2TDir.Directories.Add(MCDir);
                } //hardwareDir
                _mc2repo.TypeDirs.Add(mc2TDir);
            }     // typeDir

            #region detect cores with repeating names
            //var dups = _mc2repo.Cores.GroupBy(n => n.FileInfo.Name).Where(c => c.Count() > 1).Select(x => x).ToList();
            List <string> dups = _mc2repo.Cores.GroupBy(n => n.FileInfo.Name).SelectMany(g => g.Skip(1)).Distinct().Select(s => s.FileInfo.Name).ToList();
            if (dups.Count > 0)
            {
                foreach (string corename in dups)
                {
                    foreach (MulticoreCoreZipFile core in _mc2repo.Cores.Where(c => c.FileInfo.Name.Equals(corename)).Select(s => s).ToList())
                    {
                        core.SameName = true;
                    }
                }
            }
            #endregion detect cores with repeating names

            this.updateCoresRomPaths();
        }