Example #1
0
 private void toolStripButton_delete_Click(object sender, EventArgs e)
 {
     if (detects == null)
     {
         return;
     }
     if (fileIndex >= 0 && fileIndex < detects.Length)
     {
         ManagedMessageBoxResult res = ManagedMessageBox.ShowQuestionMessage(
             Program.ResourceManager.GetString("Message_AreYouSuretoRemoveManual"),
             Program.ResourceManager.GetString("MessageCaption_RemoveManual"), true, false,
             Program.ResourceManager.GetString("MessageCheckBox_RemoveFileFromDiskToo"));
         if (res.ClickedButtonIndex == 0)// Yes !
         {
             if (res.Checked)
             {
                 try
                 {
                     File.Delete(detects[fileIndex].Path);
                 }
                 catch (Exception ex)
                 {
                     ManagedMessageBox.ShowErrorMessage(Program.ResourceManager.GetString("Text_UnableToRemoveFile") + ": " + detects[fileIndex].Path + "; ERROR: " + ex.Message);
                 }
             }
             // Remove from database.
             MyNesDB.DeleteDetect("MANUALS", currentID, detects[fileIndex].Path);
             RefreshForEntry(currentID);
         }
     }
 }
Example #2
0
 private void toolStripButton_deleteAll_Click(object sender, EventArgs e)
 {
     if (detects == null)
     {
         return;
     }
     if (fileIndex >= 0 && fileIndex < detects.Length)
     {
         ManagedMessageBoxResult res = ManagedMessageBox.ShowQuestionMessage(
             Program.ResourceManager.GetString("Message_AreYousureToRemoveAllManuals"),
             Program.ResourceManager.GetString("MessageCaption_RemoveManual"), true, false,
             Program.ResourceManager.GetString("MessageCheckBox_RemoveFileFromDiskToo"));
         if (res.ClickedButtonIndex == 0)// Yes !
         {
             if (res.Checked)
             {
                 foreach (MyNesDetectEntryInfo inf in detects)
                 {
                     try
                     {
                         File.Delete(inf.Path);
                     }
                     catch
                     {
                     }
                 }
             }
             // Remove from database.
             MyNesDB.DeleteDetects("MANUALS", currentID);
             RefreshForEntry(currentID);
         }
     }
 }
Example #3
0
        private void toolStripButton_newFile_Click(object sender, EventArgs e)
        {
            if (currentID == "")
            {
                return;
            }
            SaveFileDialog sav = new SaveFileDialog();

            sav.Title  = Program.ResourceManager.GetString("Title_NewInfoFile");
            sav.Filter = Program.ResourceManager.GetString("Filter_InfoFile");
            // Determine file name
            MyNesDBEntryInfo entry = MyNesDB.GetEntry(currentID);

            sav.FileName = entry.Name + ".txt";
            if (sav.ShowDialog(this) == DialogResult.OK)
            {
                // Save the file !
                switch (Path.GetExtension(sav.FileName).ToLower())
                {
                case ".rtf":
                case ".doc": richTextBox1.SaveFile(sav.FileName); break;

                default: File.WriteAllLines(sav.FileName, richTextBox1.Lines, Encoding.UTF8); break;
                }
                // Make sure this file isn't exist for selected game
                bool found = false;
                if (detects != null)
                {
                    for (int i = 0; i < detects.Length; i++)
                    {
                        if (detects[i].Path == sav.FileName)
                        {
                            fileIndex = i;
                            ShowCurrentFile();
                            found = true;
                            return;
                        }
                    }
                }
                if (!found)
                {
                    // Add it !
                    MyNesDetectEntryInfo newDetect = new MyNesDetectEntryInfo();
                    newDetect.GameID   = currentID;
                    newDetect.Path     = sav.FileName;
                    newDetect.Name     = Path.GetFileNameWithoutExtension(sav.FileName);
                    newDetect.FileInfo = "";
                    MyNesDB.AddDetect("INFOS", newDetect);
                    // Refresh
                    RefreshForEntry(currentID);
                    fileIndex = detects.Length - 1;
                    ShowCurrentFile();
                }
            }
        }
        private void AddOverviewConentToGame(string tabName, string folder, string file_content, string gameID)
        {
            // Get the files
            string fileToAdd = tabName + "-" + gameID + ".txt";

            fileToAdd = Path.Combine(folder, fileToAdd);
            int i = 1;

            while (File.Exists(fileToAdd))
            {
                i++;
                fileToAdd = tabName + "-" + gameID + "_" + i + ".txt";
                fileToAdd = Path.Combine(folder, fileToAdd);
            }
            try
            {
                status_sub_sub = string.Format("[Saving file at {0} for {1}]", fileToAdd, tabName);
                File.WriteAllText(fileToAdd, file_content);
                Trace.WriteLine(string.Format("->File saved for '{0}' at '{1}'", tabName, fileToAdd), "Detect And Download From TheGamesDB.net");

                // Add it as detect
                // Make sure this file isn;t exist for selected game
                MyNesDetectEntryInfo[] detects = MyNesDB.GetDetects("INFOS", gameID);
                bool found = false;
                if (detects != null)
                {
                    foreach (MyNesDetectEntryInfo inf in detects)
                    {
                        if (inf.Path == fileToAdd)
                        {
                            found = true; break;
                        }
                    }
                }
                if (!found)
                {
                    // Add it !
                    MyNesDetectEntryInfo newDetect = new MyNesDetectEntryInfo();
                    newDetect.GameID   = gameID;
                    newDetect.Path     = fileToAdd;
                    newDetect.Name     = Path.GetFileNameWithoutExtension(fileToAdd);
                    newDetect.FileInfo = "";
                    MyNesDB.AddDetect("INFOS", newDetect);
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError(string.Format("XXX Unable to save file for '{0}' at '{1}'; " + ex.Message, tabName, fileToAdd));
            }
        }
 private void RefreshModeCombobox()
 {
     comboBox_searchBy.Items.Clear();
     // Add the columns here
     MyNesDBColumn[] columns = MyNesDB.GetColumns();
     foreach (MyNesDBColumn c in columns)
     {
         if (c.Visible)
         {
             comboBox_searchBy.Items.Add(c.Name);
         }
     }
     comboBox_searchBy.SelectedIndex = 0;
 }
Example #6
0
 private void rating1_RatingChanged(object sender, EventArgs e)
 {
     if (currentID == "")
     {
         rating1.rating = 0;
         return;
     }
     // Update entry
     if (MyNesDB.IsDatabaseLoaded)
     {
         MyNesDB.UpdateEntry(currentID, rating1.rating);
     }
     if (RatingChanged != null)
     {
         RatingChanged(rating1, new EventArgs());
     }
 }
Example #7
0
 private void ManualsViewer_DragDrop(object sender, DragEventArgs e)
 {
     if (detects == null)
     {
         return;
     }
     if (currentID == "")
     {
         return;
     }
     if (e.Data.GetDataPresent(DataFormats.FileDrop))
     {
         string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
         foreach (string file in files)
         {
             if (!extensions.Contains(Path.GetExtension(file).ToLower()))
             {
                 continue;
             }
             // Make sure this file isn't exist for selected game
             bool found = false;
             if (detects != null)
             {
                 foreach (MyNesDetectEntryInfo inf in detects)
                 {
                     if (inf.Path == file)
                     {
                         found = true; break;
                     }
                 }
             }
             if (!found)
             {
                 // Add it !
                 MyNesDetectEntryInfo newDetect = new MyNesDetectEntryInfo();
                 newDetect.GameID   = currentID;
                 newDetect.Path     = file;
                 newDetect.Name     = Path.GetFileNameWithoutExtension(file);
                 newDetect.FileInfo = "";
                 MyNesDB.AddDetect("MANUALS", newDetect);
             }
         }
         RefreshForEntry(currentID);
     }
 }
Example #8
0
 public void RefreshForEntry(string id)
 {
     currentID = id;
     Clear();
     if (id == "")
     {
         return;
     }
     // Get images for given game id
     detects = MyNesDB.GetDetects("MANUALS", id);
     toolStripButton_add.Enabled = true;
     if (detects == null)
     {
         return;
     }
     if (detects.Length > 0)
     {
         fileIndex = 0;
     }
     ShowCurrentFile();
 }
Example #9
0
 public void RefreshForEntry(string id)
 {
     currentID = id;
     Clear();
     if (id == "")
     {
         return;
     }
     // Get files for given game id
     detects = MyNesDB.GetDetects("INFOS", id);
     toolStripButton_addMoreFiles.Enabled = true;
     toolStripButton_get_tgdb.Enabled     = true;
     toolStripButton_newFile.Enabled      = true;
     if (detects == null)
     {
         return;
     }
     if (detects.Length > 0)
     {
         fileIndex = 0;
     }
     ShowCurrentFile();
 }
Example #10
0
        private void toolStripButton_add_Click(object sender, EventArgs e)
        {
            OpenFileDialog op = new OpenFileDialog();

            op.Title       = Program.ResourceManager.GetString("Title_AddMoreManuals");
            op.Filter      = Program.ResourceManager.GetString("Filter_PDF");
            op.Multiselect = true;
            if (op.ShowDialog(this) == DialogResult.OK)
            {
                foreach (string file in op.FileNames)
                {
                    // Make sure this file isn't exist for selected game
                    bool found = false;
                    if (detects != null)
                    {
                        foreach (MyNesDetectEntryInfo inf in detects)
                        {
                            if (inf.Path == file)
                            {
                                found = true; break;
                            }
                        }
                    }
                    if (!found)
                    {
                        // Add it !
                        MyNesDetectEntryInfo newDetect = new MyNesDetectEntryInfo();
                        newDetect.GameID   = currentID;
                        newDetect.Path     = file;
                        newDetect.Name     = Path.GetFileNameWithoutExtension(file);
                        newDetect.FileInfo = "";
                        MyNesDB.AddDetect("MANUALS", newDetect);
                    }
                }
                RefreshForEntry(currentID);
            }
        }
Example #11
0
        public void RefreshForEntry(string id)
        {
            currentID = id;
            Clear();
            if (id == "")
            {
                return;
            }
            // Get info for selected game
            MyNesDBEntryInfo inf = MyNesDB.GetEntry(id);

            label_name.Text = inf.Name;
            toolTip1.SetToolTip(label_name, inf.Name);
            label_size.Text = GetSize(inf.Size);
            toolTip1.SetToolTip(label_size, label_size.Text);
            label_path.Text = inf.Path;
            toolTip1.SetToolTip(label_path, inf.Path);
            rating1.rating  = inf.Rating;
            rating1.Enabled = true;
            // Add images
            List <MyNesDetectEntryInfo> detects = new List <MyNesDetectEntryInfo>();

            detects.AddRange(MyNesDB.GetDetects("SNAPS", id));
            detects.AddRange(MyNesDB.GetDetects("COVERS", id));
            images = detects.ToArray();
            if (images.Length > 0)
            {
                fileIndex = 0;
            }
            if (Program.Settings.LauncherAutoCycleImagesInGameTab)
            {
                timer1.Start();
            }
            ShowCurrentFile();
            // Load data infos
            DataSet ds = MyNesDB.GetEntryDataSet(currentID);

            for (int i = 0; i < ds.Tables[0].Columns.Count; i++)
            {
                if (ds.Tables[0].Columns[i].ToString() != "Id" && ds.Tables[0].Columns[i].ToString() != "IsDB")
                {
                    string colName = ds.Tables[0].Columns[i].ToString();
                    string subText = ds.Tables[0].Rows[0][ds.Tables[0].Columns[i].ToString()].ToString().Replace("&apos;", "'");
                    listView1.Items.Add(colName);
                    if (colName == "Played")
                    {
                        if (subText == "0")
                        {
                            subText = Program.ResourceManager.GetString("Text_NeverPlayed");
                        }
                        else if (subText == "1")
                        {
                            subText = Program.ResourceManager.GetString("Text_OneTime");
                        }
                        else
                        {
                            subText = subText + " " + Program.ResourceManager.GetString("Text_Times");
                        }
                    }
                    else if (colName == "Play Time")
                    {
                        if (subText == "0")
                        {
                            subText = Program.ResourceManager.GetString("Text_NeverPlayed");
                        }
                        else
                        {
                            int val = 0;
                            int.TryParse(subText, out val);
                            subText = TimeSpan.FromSeconds(val).ToString();
                        }
                    }
                    else if (colName == "Size")
                    {
                        int val = 0;
                        int.TryParse(subText, out val);
                        subText = GetSize(val);
                    }
                    else if (colName == "Last Played")
                    {
                        DateTime time = (DateTime)ds.Tables[0].Rows[0][colName];
                        if (time != DateTime.MinValue)
                        {
                            subText = time.ToLocalTime().ToString();
                        }
                        else
                        {
                            subText = Program.ResourceManager.GetString("Text_NeverPlayed");
                        }
                    }

                    listView1.Items[listView1.Items.Count - 1].SubItems.Add(subText);
                }
            }
        }
        private void SEARCH()
        {
            int           matchedRoms = 0;
            DataSet       set         = MyNesDB.GetDataSet("GAMES");
            List <string> files       = new List <string>();

            foreach (string folder in foldersToSearch)
            {
                files.AddRange(Directory.GetFiles(folder, "*",
                                                  includeSubFolders ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly));
            }
            // Clear detected files first ?
            if (clearOldRomDetectedFiles)
            {
                MyNesDB.DeleteDetects(mode.ToString());
            }
            // Start the operation, loop through roms
            for (int i = 0; i < set.Tables[0].Rows.Count; i++)
            {
                string id        = set.Tables[0].Rows[i]["Id"].ToString();
                string entryName = set.Tables[0].Rows[i]["Name"].ToString().Replace("&apos;", "'");
                string entryPath = set.Tables[0].Rows[i]["Path"].ToString().Replace("&apos;", "'");
                // Decode path
                if (entryPath.StartsWith("("))
                {
                    // Decode
                    string[] pathCodes = entryPath.Split(new char[] { '(', ')' });
                    entryPath = pathCodes[2];
                }
                // Loop through files, look for files for this rom
                for (int j = 0; j < files.Count; j++)
                {
                    if (!extensions.Contains(Path.GetExtension(files[j]).ToLower()))
                    {
                        Trace.WriteLine("File ignored (no match for extension): " + files[j], "Detect Files");
                        // Useless file ...
                        files.RemoveAt(j);
                        j--;
                        continue;
                    }
                    if (FilterSearch(entryName, entryPath, files[j]))
                    {
                        matchedRoms++;
                        // Add it !
                        // Make sure this file isn;t exist for selected game
                        MyNesDetectEntryInfo[] detects = MyNesDB.GetDetects(mode.ToString(), id);
                        bool found = false;
                        if (detects != null)
                        {
                            foreach (MyNesDetectEntryInfo inf in detects)
                            {
                                if (inf.Path == files[j])
                                {
                                    found = true; break;
                                }
                            }
                        }
                        if (!found)
                        {
                            // Add it !
                            MyNesDetectEntryInfo newDetect = new MyNesDetectEntryInfo();
                            newDetect.GameID   = id;
                            newDetect.Path     = files[j];
                            newDetect.Name     = Path.GetFileNameWithoutExtension(files[j]);
                            newDetect.FileInfo = "";
                            MyNesDB.AddDetect(mode.ToString(), newDetect);
                        }
                        // To reduce process, delete detected file
                        if (dontAllowSameFileDetectedByMoreThanOneRom)
                        {
                            files.RemoveAt(j);
                            j--;
                        }

                        if (oneFilePerRom)
                        {
                            break;
                        }
                    }
                }
                // Update progress
                process = (i * 100) / set.Tables[0].Rows.Count;
                status  = string.Format(Program.ResourceManager.GetString("Status_Detecting") +
                                        " {0} / {1} [{2} " + Program.ResourceManager.GetString("Status_Detected") + "][{3} %]", (i + 1),
                                        set.Tables[0].Rows.Count, matchedRoms, process);
            }
            // Done !
            Trace.WriteLine("Detect process finished at " + DateTime.Now.ToLocalTime().ToString(), "Detect Files");
            finished = true;
            Trace.WriteLine("----------------------------");
            CloseWin();
        }
Example #13
0
        private void toolStripButton_search_tgdb_Click(object sender, EventArgs e)
        {
            if (currentID == "")
            {
                return;
            }
            string entryName         = MyNesDB.GetEntry(currentID).Name;
            FormSearchTheGamesDB frm = new FormSearchTheGamesDB(entryName);

            if (frm.ShowDialog(this) == DialogResult.OK)
            {
                TheGamesDBAPI.Game      gm   = TheGamesDBAPI.GamesDB.GetGame(frm.SelectedResultID);
                FormTheGamesDBImageMode frm2 = new FormTheGamesDBImageMode(gm.Images);
                if (frm2.ShowDialog(this) == DialogResult.OK)
                {
                    // Browse for a folder
                    FolderBrowserDialog fol = new FolderBrowserDialog();

                    string selectedPath = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);

                    switch (MODE)
                    {
                    case DetectMode.COVERS:
                    {
                        if (Program.Settings.Database_FoldersCovers != null)
                        {
                            if (Program.Settings.Database_FoldersCovers.Count > 0)
                            {
                                selectedPath = Program.Settings.Database_FoldersCovers[0];
                            }
                        }
                        break;
                    }

                    case DetectMode.SNAPS:
                    {
                        if (Program.Settings.Database_FoldersSnapshots != null)
                        {
                            if (Program.Settings.Database_FoldersSnapshots.Count > 0)
                            {
                                selectedPath = Program.Settings.Database_FoldersSnapshots[0];
                            }
                        }
                        break;
                    }
                    }
                    fol.SelectedPath = selectedPath;
                    fol.Description  = Program.ResourceManager.GetString("Title_ChooseWhereToDownloadTheFiles");
                    if (fol.ShowDialog(this) == DialogResult.OK)
                    {
                        List <string> links = new List <string>();
                        if (frm2.SelectedBanners)
                        {
                            for (int i = 0; i < gm.Images.Banners.Count; i++)
                            {
                                links.Add(TheGamesDBAPI.GamesDB.BaseImgURL + gm.Images.Banners[i].Path);
                            }
                        }
                        else if (frm2.SelectedBoxArtBack)
                        {
                            links.Add(TheGamesDBAPI.GamesDB.BaseImgURL + gm.Images.BoxartBack.Path);
                        }
                        else if (frm2.SelectedBoxArtFront)
                        {
                            links.Add(TheGamesDBAPI.GamesDB.BaseImgURL + gm.Images.BoxartFront.Path);
                        }
                        else if (frm2.SelectedFanart)
                        {
                            for (int i = 0; i < gm.Images.Fanart.Count; i++)
                            {
                                links.Add(TheGamesDBAPI.GamesDB.BaseImgURL + gm.Images.Fanart[i].Path);
                            }
                        }
                        else if (frm2.SelectedScreenshots)
                        {
                            for (int i = 0; i < gm.Images.Screenshots.Count; i++)
                            {
                                links.Add(TheGamesDBAPI.GamesDB.BaseImgURL + gm.Images.Screenshots[i].Path);
                            }
                        }
                        FormDownloadFiles down = new FormDownloadFiles(fol.SelectedPath, links.ToArray(), entryName);
                        if (down.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                        {
                            if (down.DownloadedPaths.Count > 0)
                            {
                                foreach (string file in down.DownloadedPaths)
                                {
                                    // Make sure this file isn't exist for selected game
                                    bool found = false;
                                    if (detects != null)
                                    {
                                        foreach (MyNesDetectEntryInfo inf in detects)
                                        {
                                            if (inf.Path == file)
                                            {
                                                found = true; break;
                                            }
                                        }
                                    }
                                    if (!found)
                                    {
                                        // Add it !
                                        MyNesDetectEntryInfo newDetect = new MyNesDetectEntryInfo();
                                        newDetect.GameID   = currentID;
                                        newDetect.Path     = file;
                                        newDetect.Name     = Path.GetFileNameWithoutExtension(file);
                                        newDetect.FileInfo = "";
                                        MyNesDB.AddDetect(MODE.ToString(), newDetect);
                                    }
                                }
                                RefreshForEntry(currentID);
                            }
                            // Save folder
                            switch (MODE)
                            {
                            case DetectMode.COVERS:
                            {
                                if (Program.Settings.Database_FoldersCovers != null)
                                {
                                    if (!Program.Settings.Database_FoldersCovers.Contains(fol.SelectedPath))
                                    {
                                        Program.Settings.Database_FoldersCovers.Insert(0, fol.SelectedPath);
                                    }
                                }
                                break;
                            }

                            case DetectMode.SNAPS:
                            {
                                if (Program.Settings.Database_FoldersSnapshots != null)
                                {
                                    if (!Program.Settings.Database_FoldersSnapshots.Contains(fol.SelectedPath))
                                    {
                                        Program.Settings.Database_FoldersSnapshots.Insert(0, fol.SelectedPath);
                                    }
                                }
                                break;
                            }
                            }
                        }
                    }
                }
            }
        }
        private void ApplyRom(string gameName, string gameID, Game game)
        {
            if (_db_rename_rom_using_title)
            {
                MyNesDB.UpdateEntry(gameID, game.Title);
                Trace.WriteLine(string.Format("->Rom renamed from {0} to {1}", gameName, game.Title), "Detect And Download From TheGamesDB.net");
            }

            // Overview
            if (_db_add_overview_as_tab)
            {
                AddOverviewConentToGame("Overview", _db_overview_folder, game.Overview, gameID);
            }

            #region Banners
            if (_db_add_banners_as_tab)
            {
                if (game.Images.Banners != null)
                {
                    if (game.Images.Banners.Count > 0)
                    {
                        // Download the tabs for it !
                        List <string> links = new List <string>();
                        for (int i = 0; i < game.Images.Banners.Count; i++)
                        {
                            links.Add(GamesDB.BaseImgURL + game.Images.Banners[i].Path);
                            if (_db_banners_ic_limitdownload)
                            {
                                break;// one link added so far.
                            }
                        }
                        AddTabConentFilesToRom("Banners", _db_banners_folder, links, gameID, _db_banners_is_cover ? "COVERS" : "SNAPS");
                    }
                }
            }
            #endregion
            #region Screenshots
            if (_db_add_screenshots_as_tab)
            {
                if (game.Images.Screenshots != null)
                {
                    if (game.Images.Screenshots.Count > 0)
                    {
                        // Download the tabs for it !
                        List <string> links = new List <string>();
                        for (int i = 0; i < game.Images.Screenshots.Count; i++)
                        {
                            links.Add(GamesDB.BaseImgURL + game.Images.Screenshots[i].Path);
                            if (_db_screenshots_ic_limitdownload)
                            {
                                break;// one link added so far.
                            }
                        }
                        // Download for it !
                        AddTabConentFilesToRom("Screenshots", _db_screenshots_folder, links, gameID, _db_screenshots_is_cover ? "COVERS" : "SNAPS");
                    }
                }
            }
            #endregion
            #region Fanart
            if (_db_add_fanart_as_tab)
            {
                if (game.Images.Fanart != null)
                {
                    if (game.Images.Fanart.Count > 0)
                    {
                        // Download the tabs for it !
                        List <string> links = new List <string>();
                        for (int i = 0; i < game.Images.Fanart.Count; i++)
                        {
                            links.Add(GamesDB.BaseImgURL + game.Images.Fanart[i].Path);
                            if (_db_fanart_ic_limitdownload)
                            {
                                break;// one link added so far.
                            }
                        }
                        // Download the tabs for it !
                        AddTabConentFilesToRom("Fanart", _db_fanart_folder, links, gameID, _db_fanart_is_cover ? "COVERS" : "SNAPS");
                    }
                }
            }
            #endregion
            #region Boxart back
            if (_db_add_boxart_back_as_tab)
            {
                if (game.Images.BoxartBack != null)
                {
                    // Download the tabs for it !
                    List <string> links = new List <string>();
                    links.Add(GamesDB.BaseImgURL + game.Images.BoxartBack.Path);

                    // Download the tabs for it !
                    AddTabConentFilesToRom("Boxart Back", _db_boxart_back_folder, links, gameID, _db_boxart_back_is_cover ? "COVERS" : "SNAPS");
                }
            }
            #endregion
            #region Boxart Front
            if (_db_add_boxart_front_as_tab)
            {
                if (game.Images.BoxartFront != null)
                {
                    // Download the tabs for it !
                    List <string> links = new List <string>();
                    links.Add(GamesDB.BaseImgURL + game.Images.BoxartFront.Path);

                    // Download the tabs for it !
                    AddTabConentFilesToRom("Boxart Front", _db_boxart_front_folder, links, gameID, _db_boxart_front_is_cover ? "COVERS" : "SNAPS");
                }
            }
            #endregion
        }
        private void AddTabConentFilesToRom(string tabName, string downloads_folder, List <string> links, string gameID,
                                            string tableName)
        {
            // Download the files
            Trace.WriteLine(string.Format("Downloading files for '{0}'", tabName), "Detect And Download From TheGamesDB.net");
            string NameOfSavedFiles = tabName + "-" + gameID;

            int           c          = 1;
            List <string> filesToAdd = new List <string>();

            foreach (string link in links)
            {
                // Try downloading
                try
                {
                    Trace.WriteLine(string.Format("Downloading file from '{0}'", link), "Detect And Download From TheGamesDB.net");

                    Uri      uri     = new Uri(link);
                    string[] splited = link.Split(new char[] { '/' });
                    string   ext     = Path.GetExtension(splited[splited.Length - 1]);
                    int      j       = 0;
                    while (File.Exists(Path.GetFullPath(downloads_folder + "\\" + NameOfSavedFiles + "(" + (j + 1).ToString() + ")" + ext)))
                    {
                        j++;
                    }

                    client.DownloadFile(uri, Path.GetFullPath(downloads_folder + "\\" + NameOfSavedFiles + "(" + (j + 1).ToString() + ")" + ext));

                    filesToAdd.Add(downloads_folder + "\\" + NameOfSavedFiles + "(" + (j + 1).ToString() + ")" + ext);

                    status_sub_sub = string.Format("[Downloading file {0} of {1} from {2}]", c, links.Count, link);
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(string.Format("XXX Unable to download file from '{0}'; {1}", link, ex.Message), "Detect And Download From TheGamesDB.net");
                }
                c++;
            }
            // Add it !
            for (int j = 0; j < filesToAdd.Count; j++)
            {
                // Make sure this file isn;t exist for selected game
                MyNesDetectEntryInfo[] detects = MyNesDB.GetDetects(tableName, gameID);
                bool found = false;
                if (detects != null)
                {
                    foreach (MyNesDetectEntryInfo inf in detects)
                    {
                        if (inf.Path == filesToAdd[j])
                        {
                            found = true; break;
                        }
                    }
                }
                if (!found)
                {
                    // Add it !
                    MyNesDetectEntryInfo newDetect = new MyNesDetectEntryInfo();
                    newDetect.GameID   = gameID;
                    newDetect.Path     = filesToAdd[j];
                    newDetect.Name     = Path.GetFileNameWithoutExtension(filesToAdd[j]);
                    newDetect.FileInfo = "";
                    MyNesDB.AddDetect(tableName, newDetect);
                }
            }
        }
        private void PROCESS()
        {
            // Add listener
            string logFileName = string.Format("{0}-detect and download from the-game-db.txt",
                                               DateTime.Now.ToLocalTime().ToString());

            logFileName = logFileName.Replace(":", "");
            logFileName = logFileName.Replace("/", "-");
            Directory.CreateDirectory("Logs");
            logPath = Path.Combine("Logs", logFileName);
            listner = new TextWriterTraceListener(HelperTools.GetFullPath(logPath));
            Trace.Listeners.Add(listner);
            // Start
            Trace.WriteLine(string.Format("Detect and download from the-game-db.for started at {0}",
                                          DateTime.Now.ToLocalTime()), "Detect And Download From TheGamesDB.net");
            int step_index  = 0;
            int steps_count = 4;

            #region 1 Getting all platform entries from the internet
            Trace.WriteLine("Getting entries for selected platform ...", "Detect And Download From TheGamesDB.net");
            status_master   = "Getting entries for selected platform ...";
            progress_master = 100 / (steps_count - step_index);
            // Get database content
            Platform selectedPlatform = GamesDB.GetPlatform(_db_selected_platform_id);
            List <GameSearchResult> databaseEntries = new List <GameSearchResult>(GamesDB.GetPlatformGames(_db_selected_platform_id));
            Trace.WriteLine("Platform entries done, total of " + databaseEntries.Count + " entries found.", "Detect And Download From TheGamesDB.net");
            #endregion
            #region 2 Get the games
            step_index++;
            Trace.WriteLine("Collecting the roms ...", "Detect And Download From TheGamesDB.net");
            status_master   = "Collecting the roms ...";
            progress_master = 100 / (steps_count - step_index);
            DataSet set = MyNesDB.GetDataSet("GAMES");
            Trace.WriteLine("Roms collected, total of " + set.Tables[0].Rows.Count + " entries", "Detect And Download From TheGamesDB.net");

            // Clear detected files first ?
            if (_clear_info_table)
            {
                MyNesDB.DeleteDetects("INFOS");
            }
            if (_clear_snaps_table)
            {
                MyNesDB.DeleteDetects("SNAPS");
            }
            if (_clear_covers_table)
            {
                MyNesDB.DeleteDetects("COVERS");
            }

            #endregion
            #region 3 Compare and apply stuff
            step_index++;
            Trace.WriteLine("Comparing and applying naming", "Detect And Download From TheGamesDB.net");
            status_master   = "Comparing ...";
            progress_master = 100 / (steps_count - step_index);

            int           gameEntriesCount   = set.Tables[0].Rows.Count;
            int           matchedCount       = 0;
            List <string> matchedRomNames    = new List <string>();
            List <string> notMatchedRomNames = new List <string>();
            for (int game_index = 0; game_index < gameEntriesCount; game_index++)
            {
                string id        = set.Tables[0].Rows[game_index]["Id"].ToString();
                string entryName = set.Tables[0].Rows[game_index]["Name"].ToString().Replace("&apos;", "'");
                string entryPath = set.Tables[0].Rows[game_index]["Path"].ToString().Replace("&apos;", "'");

                status_sub_sub = "";

                // Loop through database entries looking for a match
                for (int entry_index = 0; entry_index < databaseEntries.Count; entry_index++)
                {
                    if (FilterSearch(entryName, entryPath, databaseEntries[entry_index].Title))
                    {
                        Trace.WriteLine("GAME MATCHED [" + id + "] (" + entryName + ")", "Detect And Download From TheGamesDB.net");
                        matchedRomNames.Add(entryName);

                        //  Apply
                        ApplyRom(entryName, id, GamesDB.GetGame(databaseEntries[entry_index].ID));
                        Trace.WriteLine("ROM DATA UPDATED.", "Detect And Download From TheGamesDB.net");

                        matchedCount++;

                        if (_turbo_speed)
                        {
                            databaseEntries.RemoveAt(entry_index);
                        }
                        break;
                    }
                }

                // Progress
                progress_sub = (game_index * 100) / gameEntriesCount;
                status_sub   = string.Format("{0} {1} / {2} ({3} MATCHED) ... {4} %",
                                             Program.ResourceManager.GetString("Status_ApplyingDatabase"), (game_index + 1).ToString(), gameEntriesCount,
                                             matchedCount.ToString(), progress_sub);
            }
            #endregion
            #region 4 Update log with matched and not found roms
            step_index++;
            Trace.WriteLine("Finishing", "Detect And Download From TheGamesDB.net");
            status_master   = "Finishing ...";
            progress_master = 100 / (steps_count - step_index);

            Trace.WriteLine("----------------------------");
            Trace.WriteLine("MATCHED ROMS ( total of " + matchedRomNames.Count + " rom(s) )");
            Trace.WriteLine("------------");
            for (int i = 0; i < matchedRomNames.Count; i++)
            {
                Trace.WriteLine((i + 1).ToString("D8") + "." + matchedRomNames[i]);
            }

            Trace.WriteLine("----------------------------");
            Trace.WriteLine("ROMS NOT FOUND ( total of " + notMatchedRomNames.Count + " rom(s) )");
            Trace.WriteLine("--------------");
            for (int i = 0; i < notMatchedRomNames.Count; i++)
            {
                Trace.WriteLine((i + 1).ToString("D8") + "." + notMatchedRomNames[i]);
            }

            Trace.WriteLine("----------------------------");

            Trace.WriteLine(string.Format("Detect And Download From TheGamesDB.net finished at {0}.", DateTime.Now.ToLocalTime()), "Detect And Download From TheGamesDB.net");
            listner.Flush();
            Trace.Listeners.Remove(listner);
            CloseAfterFinish();
            #endregion
        }