Example #1
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();
                }
            }
        }
Example #2
0
        public static MyNesDBEntryInfo GetEntry(string id)
        {
            if (myconnection == null)
            {
                throw new Exception("The SQLite connection is not running, can't make any requests.");
            }
            MyNesDBEntryInfo entry = new MyNesDBEntryInfo();

            using (SQLiteTransaction mytransaction = myconnection.BeginTransaction())
            {
                using (SQLiteCommand mycommand = new SQLiteCommand(myconnection))
                {
                    mycommand.CommandText = "SELECT [Name] FROM GAMES WHERE [Id]='" + id + "';";
                    entry.Name            = mycommand.ExecuteScalar().ToString().Replace("&apos;", "'");

                    mycommand.CommandText = "SELECT [Size] FROM GAMES WHERE [Id]='" + id + "';";
                    int val = 0;
                    int.TryParse(mycommand.ExecuteScalar().ToString(), out val);
                    entry.Size = val;

                    mycommand.CommandText = "SELECT [Path] FROM GAMES WHERE [Id]='" + id + "';";
                    entry.Path            = mycommand.ExecuteScalar().ToString().Replace("&apos;", "'");

                    mycommand.CommandText = "SELECT [Rating] FROM GAMES WHERE [Id]='" + id + "';";
                    val = 0;
                    int.TryParse(mycommand.ExecuteScalar().ToString(), out val);
                    entry.Rating = val;

                    mycommand.CommandText = "SELECT [IsDB] FROM GAMES WHERE [Id]='" + id + "';";
                    bool bval = false;
                    bool.TryParse(mycommand.ExecuteScalar().ToString(), out bval);
                    entry.IsDB = bval;

                    mycommand.CommandText = "SELECT [Played] FROM GAMES WHERE [Id]='" + id + "';";
                    val = 0;
                    int.TryParse(mycommand.ExecuteScalar().ToString(), out val);
                    entry.Played = val;

                    mycommand.CommandText = "SELECT [Play Time] FROM GAMES WHERE [Id]='" + id + "';";
                    val = 0;
                    int.TryParse(mycommand.ExecuteScalar().ToString(), out val);
                    entry.PlayTime = val;

                    mycommand.CommandText = "SELECT [Last Played] FROM GAMES WHERE [Id]='" + id + "';";
                    entry.LastPlayed      = mycommand.ExecuteScalar().ToString();
                }
                mytransaction.Commit();
            }
            return(entry);
        }
Example #3
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);
                }
            }
        }
Example #4
0
 public static void SetEntryToRow(MyNesDBEntryInfo entry, DataRow row)
 {
     // Fix
     if (entry.Name == null)
         entry.Name = "";
     if (entry.AlternativeName == null)
         entry.AlternativeName = "";
     if (entry.Path == null)
         entry.Path = "";
     if (entry.Class == null)
         entry.Class = "";
     if (entry.Publisher == null)
         entry.Publisher = "";
     if (entry.Developer == null)
         entry.Developer = "";
     if (entry.Region == null)
         entry.Region = "";
     if (entry.Players == null)
         entry.Players = "";
     if (entry.ReleaseDate == null)
         entry.ReleaseDate = "";
     if (entry.System == null)
         entry.System = "";
     if (entry.CRC == null)
         entry.CRC = "";
     if (entry.SHA1 == null)
         entry.SHA1 = "";
     if (entry.Dump == null)
         entry.Dump = "";
     if (entry.Dumper == null)
         entry.Dumper = "";
     if (entry.DateDumped == null)
         entry.DateDumped = "";
     if (entry.BoardType == null)
         entry.BoardType = "";
     if (entry.BoardPcb == null)
         entry.BoardPcb = "";
     row["IsDB"] = entry.IsDB;
     row["Name"] = entry.Name.Replace("'", "&apos;");
     row["Alternative Name"] = entry.AlternativeName.Replace("'", "&apos;");
     row["Size"] = entry.Size;
     row["Path"] = entry.Path.Replace("'", "&apos;");
     row["Rating"] = entry.Rating;
     row["Played"] = entry.Played;
     row["Play Time"] = entry.PlayTime;
     row["Last Played"] = entry.LastPlayed;
     row["Class"] = entry.Class.Replace("'", "&apos;");
     row["Catalog"] = entry.Catalog.Replace("'", "&apos;");
     row["Publisher"] = entry.Publisher.Replace("'", "&apos;");
     row["Developer"] = entry.Developer.Replace("'", "&apos;");
     row["Region"] = entry.Region.Replace("'", "&apos;");
     row["Players"] = entry.Players.Replace("'", "&apos;");
     row["Release Date"] = entry.ReleaseDate;
     row["System"] = entry.System.Replace("'", "&apos;");
     row["CRC"] = entry.CRC;
     row["SHA1"] = entry.SHA1;
     row["Dump"] = entry.Dump.Replace("'", "&apos;");
     row["Dumper"] = entry.Dumper.Replace("'", "&apos;");
     row["Date Dumped"] = entry.DateDumped.Replace("'", "&apos;");
     row["Board Type"] = entry.BoardType.Replace("'", "&apos;");
     row["Board Pcb"] = entry.BoardPcb.Replace("'", "&apos;");
     row["Board Mapper"] = entry.BoardMapper;
 }
Example #5
0
        public static MyNesDBEntryInfo GetEntry(string id)
        {
            if (myconnection == null)
            {
                throw new Exception("The SQLite connection is not running, can't make any requests.");
            }
            MyNesDBEntryInfo entry = new MyNesDBEntryInfo();
            using (SQLiteTransaction mytransaction = myconnection.BeginTransaction())
            {
                using (SQLiteCommand mycommand = new SQLiteCommand(myconnection))
                {
                    mycommand.CommandText = "SELECT [Name] FROM GAMES WHERE [Id]='" + id + "';";
                    entry.Name = mycommand.ExecuteScalar().ToString().Replace("&apos;", "'");

                    mycommand.CommandText = "SELECT [Size] FROM GAMES WHERE [Id]='" + id + "';";
                    int val = 0;
                    int.TryParse(mycommand.ExecuteScalar().ToString(), out val);
                    entry.Size = val;

                    mycommand.CommandText = "SELECT [Path] FROM GAMES WHERE [Id]='" + id + "';";
                    entry.Path = mycommand.ExecuteScalar().ToString().Replace("&apos;", "'");

                    mycommand.CommandText = "SELECT [Rating] FROM GAMES WHERE [Id]='" + id + "';";
                    val = 0;
                    int.TryParse(mycommand.ExecuteScalar().ToString(), out val);
                    entry.Rating = val;

                    mycommand.CommandText = "SELECT [IsDB] FROM GAMES WHERE [Id]='" + id + "';";
                    bool bval = false;
                    bool.TryParse(mycommand.ExecuteScalar().ToString(), out bval);
                    entry.IsDB = bval;

                    mycommand.CommandText = "SELECT [Played] FROM GAMES WHERE [Id]='" + id + "';";
                    val = 0;
                    int.TryParse(mycommand.ExecuteScalar().ToString(), out val);
                    entry.Played = val;

                    mycommand.CommandText = "SELECT [Play Time] FROM GAMES WHERE [Id]='" + id + "';";
                    val = 0;
                    int.TryParse(mycommand.ExecuteScalar().ToString(), out val);
                    entry.PlayTime = val;

                    mycommand.CommandText = "SELECT [Last Played] FROM GAMES WHERE [Id]='" + id + "';";
                    entry.LastPlayed = mycommand.ExecuteScalar().ToString();
                }
                mytransaction.Commit();
            }
            return entry;
        }
Example #6
0
        /// <summary>
        /// Add new entry to the database.
        /// </summary>
        /// <param name="entry">The entry info</param>
        /// <returns>True if the entry added successfully otherwise false.</returns>
        public static bool AddEntry(MyNesDBEntryInfo entry)
        {
            // Fix
            if (entry.Name == null)
                entry.Name = "";
            if (entry.AlternativeName == null)
                entry.AlternativeName = "";
            if (entry.Path == null)
                entry.Path = "";
            if (entry.Class == null)
                entry.Class = "";
            if (entry.Publisher == null)
                entry.Publisher = "";
            if (entry.Developer == null)
                entry.Developer = "";
            if (entry.Region == null)
                entry.Region = "";
            if (entry.Players == null)
                entry.Players = "";
            if (entry.ReleaseDate == null)
                entry.ReleaseDate = "";
            if (entry.System == null)
                entry.System = "";
            if (entry.CRC == null)
                entry.CRC = "";
            if (entry.SHA1 == null)
                entry.SHA1 = "";
            if (entry.Dump == null)
                entry.Dump = "";
            if (entry.Dumper == null)
                entry.Dumper = "";
            if (entry.DateDumped == null)
                entry.DateDumped = "";
            if (entry.BoardType == null)
                entry.BoardType = "";
            if (entry.BoardPcb == null)
                entry.BoardPcb = "";
            // try
            {
                using (SQLiteTransaction mytransaction = myconnection.BeginTransaction())
                {
                    using (SQLiteCommand mycommand = new SQLiteCommand(myconnection))
                    {
                        // Main info
                        string command = string.Format(
                            "INSERT INTO GAMES([IsDB], [Name], [Alternative Name], [Size], [Path], [Rating], [Played], [Play Time]," +
                            " [Last Played], [Class], [Catalog], [Publisher], [Developer], [Region], [Players], [Release Date]," +
                            " [System], [CRC], [SHA1], [Dump], [Dumper], [Date Dumped], [Board Type], [Board Pcb], [Board Mapper])" +
                            " VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}'," +
                            " '{10}', '{11}', '{12}', '{13}', '{14}', '{15}', '{16}', '{17}', '{18}', '{19}'," +
                            " '{20}', '{21}', '{22}', '{23}', '{24}');",
                            entry.IsDB,
                            entry.Name.Replace("'", "&apos;"),
                            entry.AlternativeName.Replace("'", "&apos;"),
                            entry.Size,
                            entry.Path.Replace("'", "&apos;"),
                            entry.Rating,
                            entry.Played,
                            entry.PlayTime,
                            entry.LastPlayed,
                            entry.Class.Replace("'", "&apos;"),
                            entry.Catalog.Replace("'", "&apos;"),
                            entry.Publisher.Replace("'", "&apos;"),
                            entry.Developer.Replace("'", "&apos;"),
                            entry.Region.Replace("'", "&apos;"),
                            entry.Players.Replace("'", "&apos;"),
                            entry.ReleaseDate,
                            entry.System.Replace("'", "&apos;"),
                            entry.CRC,
                            entry.SHA1,
                            entry.Dump.Replace("'", "&apos;"),
                            entry.Dumper.Replace("'", "&apos;"),
                            entry.DateDumped.Replace("'", "&apos;"),
                            entry.BoardType.Replace("'", "&apos;"),
                            entry.BoardPcb.Replace("'", "&apos;"),
                            entry.BoardMapper);

                        //"INSERT INTO GAMES([Name], [Alternative Name], [Size], [Path], [Rating], [Class], [Publisher], [Developer], [Region], [Players], [Release Date], [System], [CRC], [SHA1], [Dump], [Date Dumped], [Board Type], [Board Pcb], [Board Mapper]) VALUES ('Muppet Adventure: Chaos at the Carnival', '', 'N/A', 'N/A', '0', 'Licensed', 'Hi Tech Expressions', 'Mind's Eye', 'USA', '1', '1990-11', 'NES-NTSC', '7156CB4D', '03A111AC0FA78E566814D6F9296454BFC34E7B3C', 'ok', '2006-03-18', 'NES-SGROM', 'NES-SGROM-04', '1');
                        mycommand.CommandText = command;
                        mycommand.ExecuteNonQuery();
                    }
                    mytransaction.Commit();
                }
            }
            // catch (Exception ex)
            // {
            //     Trace.TraceError(ex.Message);
            //     return false;
            //}
            return true;
        }
Example #7
0
        private void AddFiles(string[] files)
        {
            // Create temp folder
            string tempFolder = Path.GetTempPath() + "\\MYNES\\";
            string tempFile = tempFolder + "fileTemp";
            Directory.CreateDirectory(tempFolder);
            Trace.WriteLine(Program.ResourceManager.GetString("Status_SearchingFiles"));
            DataSet ds = MyNesDB.GetDataSet("GAMES");
            foreach (string file in files)
            {
                if (frmG.CancelRequest)
                {
                    break;
                }
                switch (Path.GetExtension(file).ToLower())
                {
                    #region INES
                    case ".nes":
                        {
                            // Read header !
                            INes header = new INes();
                            header.Load(file, false);
                            // Search for the match, only NesCartDB get searched.
                            bool found = false;
                            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                            {
                                if (ds.Tables[0].Rows[i]["SHA1"].ToString().ToLower() == header.SHA1.ToLower()
                                    && (bool)ds.Tables[0].Rows[i]["IsDB"])
                                {
                                    // This is it !!
                                    // MyNesDB.UpdateEntry(ds.Tables[0].Rows[i]["Id"].ToString(), file, GetFileSize(file));
                                    string path = ds.Tables[0].Rows[i]["Path"].ToString().Replace("&apos;", "'");
                                    if (File.Exists(path) && path != "")
                                    {
                                        if (_assign_update_entries_already_assigned)
                                        {
                                            ds.Tables[0].Rows[i]["Path"] = file.Replace("'", "&apos;");
                                            ds.Tables[0].Rows[i]["Size"] = GetFileSize(file);
                                            Trace.WriteLine(Program.ResourceManager.GetString("Status_EntryUPDATED") +
                                                ": [" + ds.Tables[0].Rows[i]["Name"].ToString() + "]");
                                        }
                                        else
                                        {
                                            Trace.WriteLine(Program.ResourceManager.GetString("Status_EntrySkipped") +
                                               ": [" + ds.Tables[0].Rows[i]["Name"].ToString() + "]");
                                        }
                                    }
                                    else// Force assign; no file assigned or file not exist
                                    {
                                        ds.Tables[0].Rows[i]["Path"] = file;
                                        ds.Tables[0].Rows[i]["Size"] = GetFileSize(file);
                                        Trace.WriteLine(Program.ResourceManager.GetString("Status_EntryUPDATED") +
                                            ": [" + ds.Tables[0].Rows[i]["Name"].ToString() + "]");
                                    }
                                    found = true;
                                    break;
                                }
                            }
                            if (!found && _assign_addFilesNotFound)
                            {
                                // File not found in the database, add brand new entry
                                found = false;
                                // Check if path already exist ...
                                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                                {
                                    if (ds.Tables[0].Rows[i]["Path"].ToString().Replace("&apos;", "'") == file)
                                    {
                                        found = true;
                                        // File is exist here since 'file' value is real
                                        if (_assign_update_entries_already_assigned)
                                        {
                                            ds.Tables[0].Rows[i]["Path"] = file.Replace("'", "&apos;");
                                            ds.Tables[0].Rows[i]["Size"] = GetFileSize(file);
                                            Trace.WriteLine(Program.ResourceManager.GetString("Status_EntryUPDATED") +
                                                ": [" + ds.Tables[0].Rows[i]["Name"].ToString() + "]");
                                        }
                                        else
                                        {
                                            Trace.WriteLine(Program.ResourceManager.GetString("Status_EntrySkipped") +
                                               ": [" + ds.Tables[0].Rows[i]["Name"].ToString() + "]");
                                        }

                                        break;
                                    }
                                }
                                if (!found)
                                {
                                    DataRow row = ds.Tables[0].NewRow();
                                    MyNesDBEntryInfo infEntry = new MyNesDBEntryInfo();
                                    infEntry.IsDB = false;
                                    infEntry.AlternativeName = "";
                                    infEntry.BoardMapper = header.IsValid ? header.MapperNumber : 0;
                                    infEntry.BoardPcb = "";
                                    infEntry.BoardType = "";
                                    infEntry.Catalog = "";
                                    infEntry.Class = "";
                                    infEntry.Developer = "";
                                    infEntry.Name = Path.GetFileNameWithoutExtension(file);
                                    infEntry.Players = "";
                                    infEntry.Publisher = "";
                                    infEntry.Region = "";
                                    infEntry.ReleaseDate = "";
                                    infEntry.CRC = CalculateCRC(file, 16);
                                    infEntry.DateDumped = "";
                                    infEntry.Dump = "";
                                    infEntry.Dumper = "";
                                    infEntry.System = "";
                                    infEntry.SHA1 = header.SHA1.ToUpper();
                                    // These info should be set when user detect files.
                                    infEntry.Path = file;
                                    infEntry.Rating = 0;
                                    infEntry.Size = GetFileSize(file);
                                    infEntry.LastPlayed = DateTimeFormater.ToFull(DateTime.MinValue);
                                    infEntry.Played = 0;
                                    infEntry.PlayTime = 0;

                                    MyNesDB.SetEntryToRow(infEntry, row);
                                    ds.Tables[0].Rows.Add(row);
                                    Trace.WriteLine(Program.ResourceManager.GetString("Status_EntryADDED") +
                                        ":[" + infEntry.Name + "]");
                                }
                            }
                            break;
                        }
                    #endregion
                    #region Archive file
                    case ".7z":
                    case ".zip":
                    case ".rar":
                    case ".gzip":
                    case ".tar":
                    case ".bzip2":
                    case ".xz":
                        {
                            try
                            {
                                // Open the archive
                                SevenZipExtractor extractor = new SevenZipExtractor(file);
                                // Extract the archive first !!
                                Directory.CreateDirectory(Path.GetTempPath() + "\\MyNes\\");
                                // Make sure the temp folder is clear
                                string[] arFiles = Directory.GetFiles(Path.GetTempPath() + "\\MyNes\\");
                                foreach (string a in arFiles)
                                    File.Delete(a);
                                extractor.ExtractArchive(Path.GetTempPath() + "\\MyNes\\");
                                arFiles = Directory.GetFiles(Path.GetTempPath() + "\\MyNes\\");
                                foreach (ArchiveFileInfo f in extractor.ArchiveFileData)
                                {
                                    if (Path.GetExtension(f.FileName).ToLower() == ".nes")
                                    {
                                        string entryPath = "(" + f.Index + ")" + file;
                                        // Read header !
                                        INes header = new INes();
                                        header.Load(Path.GetTempPath() + "\\MyNes\\" + f.FileName, false);
                                        // Search for the match
                                        bool found = false;
                                        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                                        {
                                            if (ds.Tables[0].Rows[i]["SHA1"].ToString().ToLower() == header.SHA1.ToLower()
                                                 && (bool)ds.Tables[0].Rows[i]["IsDB"])
                                            {
                                                string path = GetFilePathFromArchivePath(ds.Tables[0].Rows[i]["Path"].ToString().Replace("&apos;", "'"));
                                                if (File.Exists(path) && path != "")
                                                {
                                                    // This is it !!
                                                    if (_assign_update_entries_already_assigned)
                                                    {
                                                        // The file path code is (index within archive)archivePath
                                                        ds.Tables[0].Rows[i]["Path"] = entryPath;
                                                        ds.Tables[0].Rows[i]["Size"] = GetFileSize(tempFile);
                                                        Trace.WriteLine(Program.ResourceManager.GetString("Status_EntryUPDATED") +
                                                            ": [" + ds.Tables[0].Rows[i]["Name"].ToString() + "]");
                                                    }
                                                    else
                                                    {
                                                        Trace.WriteLine(Program.ResourceManager.GetString("Status_EntrySkipped") +
                                                           ": [" + ds.Tables[0].Rows[i]["Name"].ToString() + "]");
                                                    }
                                                }
                                                else
                                                {
                                                    // Force assign since the file is not valid
                                                    ds.Tables[0].Rows[i]["Path"] = entryPath;
                                                    ds.Tables[0].Rows[i]["Size"] = GetFileSize(tempFile);
                                                    Trace.WriteLine(Program.ResourceManager.GetString("Status_EntryUPDATED") +
                                                        ": [" + ds.Tables[0].Rows[i]["Name"].ToString() + "]");
                                                }
                                                found = true;
                                                break;
                                            }
                                        }
                                        if (!found && _assign_addFilesNotFound)
                                        {
                                            found = false;
                                            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                                            {
                                                if (ds.Tables[0].Rows[i]["Path"].ToString().Replace("&apos;", "'") == entryPath)
                                                {
                                                    found = true;
                                                    // This is it !!
                                                    if (_assign_update_entries_already_assigned)
                                                    {
                                                        ds.Tables[0].Rows[i]["Path"] = entryPath;
                                                        ds.Tables[0].Rows[i]["Size"] = GetFileSize(tempFile);
                                                        Trace.WriteLine(Program.ResourceManager.GetString("Status_EntryUPDATED") +
                                                            ": [" + ds.Tables[0].Rows[i]["Name"].ToString() + "]");
                                                    }
                                                    else
                                                    {
                                                        Trace.WriteLine(Program.ResourceManager.GetString("Status_EntrySkipped") +
                                                           ": [" + ds.Tables[0].Rows[i]["Name"].ToString() + "]");
                                                    }
                                                    break;
                                                }
                                            }
                                            if (!found)
                                            {
                                                DataRow row = ds.Tables[0].NewRow();
                                                MyNesDBEntryInfo infEntry = new MyNesDBEntryInfo();
                                                infEntry.IsDB = false;
                                                infEntry.AlternativeName = "";
                                                infEntry.BoardMapper = header.IsValid ? header.MapperNumber : 0;
                                                infEntry.BoardPcb = "";
                                                infEntry.BoardType = "";
                                                infEntry.Catalog = "";
                                                infEntry.Class = "";
                                                infEntry.Developer = "";
                                                infEntry.Name = Path.GetFileNameWithoutExtension(f.FileName);
                                                infEntry.Players = "";
                                                infEntry.Publisher = "";
                                                infEntry.Region = "";
                                                infEntry.ReleaseDate = "";
                                                infEntry.CRC = CalculateCRC(tempFile, 16);
                                                infEntry.DateDumped = "";
                                                infEntry.Dump = "";
                                                infEntry.Dumper = "";
                                                infEntry.System = "";
                                                infEntry.SHA1 = header.SHA1.ToUpper();
                                                // These info should be set when user detect files.
                                                infEntry.Path = entryPath;
                                                infEntry.Rating = 0;
                                                infEntry.Size = GetFileSize(tempFile);
                                                infEntry.LastPlayed = DateTimeFormater.ToFull(DateTime.MinValue);
                                                infEntry.Played = 0;
                                                infEntry.PlayTime = 0;

                                                MyNesDB.SetEntryToRow(infEntry, row);
                                                ds.Tables[0].Rows.Add(row);
                                                Trace.WriteLine(Program.ResourceManager.GetString("Status_EntryADDED") +
                                                    ":[" + infEntry.Name + "]");
                                            }
                                        }
                                    }
                                }
                                // Clear the temp folder (to make sure)
                                foreach (string a in arFiles)
                                    File.Delete(a);
                                /*foreach (ArchiveFileInfo f in extractor.ArchiveFileData)
                                {
                                    if (Path.GetExtension(f.FileName).ToLower() == ".nes")
                                    {
                                        string entryPath = "(" + f.Index + ")" + file;
                                        // Extract it !
                                        Stream aStream = new FileStream(tempFile, FileMode.Create, FileAccess.Write);
                                        extractor.ExtractFile(f.Index, aStream);
                                        aStream.Close();
                                        // Read header !
                                        INes header = new INes();
                                        header.Load(tempFile, false);
                                        // Search for the match
                                        bool found = false;
                                        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                                        {
                                            if (ds.Tables[0].Rows[i]["SHA1"].ToString().ToLower() == header.SHA1.ToLower()
                                                 && (bool)ds.Tables[0].Rows[i]["IsDB"])
                                            {
                                                string path = GetFilePathFromArchivePath(ds.Tables[0].Rows[i]["Path"].ToString().Replace("&apos;", "'"));
                                                if (File.Exists(path) && path != "")
                                                {
                                                    // This is it !!
                                                    if (_assign_update_entries_already_assigned)
                                                    {
                                                        // The file path code is (index within archive)archivePath
                                                        ds.Tables[0].Rows[i]["Path"] = entryPath;
                                                        ds.Tables[0].Rows[i]["Size"] = GetFileSize(tempFile);
                                                        Trace.WriteLine(Program.ResourceManager.GetString("Status_EntryUPDATED") +
                                                            ": [" + ds.Tables[0].Rows[i]["Name"].ToString() + "]");
                                                    }
                                                    else
                                                    {
                                                        Trace.WriteLine(Program.ResourceManager.GetString("Status_EntrySkipped") +
                                                           ": [" + ds.Tables[0].Rows[i]["Name"].ToString() + "]");
                                                    }
                                                }
                                                else
                                                {
                                                    // Force assign since the file is not valid
                                                    ds.Tables[0].Rows[i]["Path"] = entryPath;
                                                    ds.Tables[0].Rows[i]["Size"] = GetFileSize(tempFile);
                                                    Trace.WriteLine(Program.ResourceManager.GetString("Status_EntryUPDATED") +
                                                        ": [" + ds.Tables[0].Rows[i]["Name"].ToString() + "]");
                                                }
                                                found = true;
                                                break;
                                            }
                                        }
                                        if (!found && _assign_addFilesNotFound)
                                        {
                                            found = false;
                                            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                                            {
                                                if (ds.Tables[0].Rows[i]["Path"].ToString().Replace("&apos;", "'") == entryPath)
                                                {
                                                    found = true;
                                                    // This is it !!
                                                    if (_assign_update_entries_already_assigned)
                                                    {
                                                        ds.Tables[0].Rows[i]["Path"] = entryPath;
                                                        ds.Tables[0].Rows[i]["Size"] = GetFileSize(tempFile);
                                                        Trace.WriteLine(Program.ResourceManager.GetString("Status_EntryUPDATED") +
                                                            ": [" + ds.Tables[0].Rows[i]["Name"].ToString() + "]");
                                                    }
                                                    else
                                                    {
                                                        Trace.WriteLine(Program.ResourceManager.GetString("Status_EntrySkipped") +
                                                           ": [" + ds.Tables[0].Rows[i]["Name"].ToString() + "]");
                                                    }
                                                    break;
                                                }
                                            }
                                            if (!found)
                                            {
                                                DataRow row = ds.Tables[0].NewRow();
                                                MyNesDBEntryInfo infEntry = new MyNesDBEntryInfo();
                                                infEntry.IsDB = false;
                                                infEntry.AlternativeName = "";
                                                infEntry.BoardMapper = header.IsValid ? header.MapperNumber : 0;
                                                infEntry.BoardPcb = "";
                                                infEntry.BoardType = "";
                                                infEntry.Catalog = "";
                                                infEntry.Class = "";
                                                infEntry.Developer = "";
                                                infEntry.Name = Path.GetFileNameWithoutExtension(f.FileName);
                                                infEntry.Players = "";
                                                infEntry.Publisher = "";
                                                infEntry.Region = "";
                                                infEntry.ReleaseDate = "";
                                                infEntry.CRC = CalculateCRC(tempFile, 16);
                                                infEntry.DateDumped = "";
                                                infEntry.Dump = "";
                                                infEntry.Dumper = "";
                                                infEntry.System = "";
                                                infEntry.SHA1 = header.SHA1.ToUpper();
                                                // These info should be set when user detect files.
                                                infEntry.Path = entryPath;
                                                infEntry.Rating = 0;
                                                infEntry.Size = GetFileSize(tempFile);
                                                infEntry.LastPlayed = DateTimeFormater.ToFull(DateTime.MinValue);
                                                infEntry.Played = 0;
                                                infEntry.PlayTime = 0;

                                                MyNesDB.SetEntryToRow(infEntry, row);
                                                ds.Tables[0].Rows.Add(row);
                                                Trace.WriteLine(Program.ResourceManager.GetString("Status_EntryADDED") +
                                                    ":[" + infEntry.Name + "]");
                                            }
                                        }
                                    }
                                }*/
                            }
                            catch
                            {
                                Trace.WriteLine("File [" + file + "] is archive but can't be opened.");
                            }
                            break;
                        }
                    #endregion
                }
            }
            Trace.WriteLine(".... " + Program.ResourceManager.GetString("Status_UpdatingDatabase") + " ....");
            MyNesDB.UpdateTableFromDataSet("GAMES", ds);
        }
Example #8
0
        private void GenerateEntriesFromNesCart()
        {
            // Adding entries from the NesCart database.
            Trace.WriteLine(Program.ResourceManager.GetString("Status_GeneratingDefaultEntriesFromNesCartDB"));
            int x = 0;
            if (NesCartDatabase.DatabaseRoms != null)
            {
                // Get the dataset
                DataSet ds = MyNesDB.GetDataSet("GAMES");
                for (int i = 0; i < NesCartDatabase.DatabaseRoms.Count; i++)
                {
                    if (frmG.CancelRequest)
                    {
                        break;
                    }
                    MyNesDBEntryInfo infEntry = new MyNesDBEntryInfo();
                    infEntry.IsDB = true;
                    infEntry.AlternativeName = NesCartDatabase.DatabaseRoms[i].Game_AltName;
                    if (NesCartDatabase.DatabaseRoms[i].Cartridges != null)
                    {
                        infEntry.BoardMapper = Convert.ToInt32(NesCartDatabase.DatabaseRoms[i].Cartridges[0].Board_Mapper);
                        foreach (NesCartDatabaseCartridgeInfo crt in NesCartDatabase.DatabaseRoms[i].Cartridges)
                        {
                            if (infEntry.BoardPcb != null)
                            {
                                if (!infEntry.BoardPcb.Contains(crt.Board_Pcb))
                                    infEntry.BoardPcb += crt.Board_Pcb + ", ";
                            }
                            else
                                infEntry.BoardPcb = crt.Board_Pcb + ", ";
                            if (infEntry.BoardType != null)
                            {
                                if (!infEntry.BoardType.Contains(crt.Board_Type))
                                    infEntry.BoardType += crt.Board_Type + ", ";
                            }
                            else
                                infEntry.BoardType = crt.Board_Type + ", ";
                        }
                    }

                    infEntry.Catalog = NesCartDatabase.DatabaseRoms[i].Game_Catalog;
                    infEntry.Class = NesCartDatabase.DatabaseRoms[i].Game_Class;
                    infEntry.Developer = NesCartDatabase.DatabaseRoms[i].Game_Developer;
                    infEntry.Name = NesCartDatabase.DatabaseRoms[i].Game_Name;
                    infEntry.Players = NesCartDatabase.DatabaseRoms[i].Game_Players;
                    infEntry.Publisher = NesCartDatabase.DatabaseRoms[i].Game_Publisher;
                    infEntry.Region = NesCartDatabase.DatabaseRoms[i].Game_Region;
                    infEntry.ReleaseDate = NesCartDatabase.DatabaseRoms[i].Game_ReleaseDate;
                    for (int j = 0; j < NesCartDatabase.DatabaseRoms[i].Cartridges.Count; j++)
                    {
                        infEntry.CRC = NesCartDatabase.DatabaseRoms[i].Cartridges[j].CRC;
                        infEntry.DateDumped = NesCartDatabase.DatabaseRoms[i].Cartridges[j].DateDumped;
                        infEntry.Dump = NesCartDatabase.DatabaseRoms[i].Cartridges[j].Dump;
                        infEntry.Dumper = NesCartDatabase.DatabaseRoms[i].Cartridges[j].Dumper;
                        infEntry.System = NesCartDatabase.DatabaseRoms[i].Cartridges[j].System;
                        infEntry.SHA1 = NesCartDatabase.DatabaseRoms[i].Cartridges[j].SHA1;
                        // These info should be set when user detect files.
                        infEntry.Path = "N/A";
                        infEntry.Rating = 0;
                        infEntry.Size = 0;
                        infEntry.Played = 0;
                        infEntry.PlayTime = 0;
                        infEntry.LastPlayed = DateTimeFormater.ToFull(DateTime.MinValue);

                        //MyNesDB.AddEntry(infEntry);
                        DataRow row = ds.Tables[0].NewRow();
                        MyNesDB.SetEntryToRow(infEntry, row);
                        ds.Tables[0].Rows.Add(row);
                    }
                    x = (i * 100) / NesCartDatabase.DatabaseRoms.Count;
                    frmG.WriteStatus(Program.ResourceManager.GetString("Status_AddingEntries") + " ... (" + x + "%)", Color.Black);
                }
                Trace.WriteLine("..... " + Program.ResourceManager.GetString("Status_UpdatingDatabase") + " .....");
                MyNesDB.UpdateTableFromDataSet("GAMES", ds);
                Trace.WriteLine(Program.ResourceManager.GetString("Status_DefaultEntriesFromNesCartDBGeneratedSuccessfully"));
            }
        }
Example #9
0
 public static void SetEntryToRow(MyNesDBEntryInfo entry, DataRow row)
 {
     // Fix
     if (entry.Name == null)
     {
         entry.Name = "";
     }
     if (entry.AlternativeName == null)
     {
         entry.AlternativeName = "";
     }
     if (entry.Path == null)
     {
         entry.Path = "";
     }
     if (entry.Class == null)
     {
         entry.Class = "";
     }
     if (entry.Publisher == null)
     {
         entry.Publisher = "";
     }
     if (entry.Developer == null)
     {
         entry.Developer = "";
     }
     if (entry.Region == null)
     {
         entry.Region = "";
     }
     if (entry.Players == null)
     {
         entry.Players = "";
     }
     if (entry.ReleaseDate == null)
     {
         entry.ReleaseDate = "";
     }
     if (entry.System == null)
     {
         entry.System = "";
     }
     if (entry.CRC == null)
     {
         entry.CRC = "";
     }
     if (entry.SHA1 == null)
     {
         entry.SHA1 = "";
     }
     if (entry.Dump == null)
     {
         entry.Dump = "";
     }
     if (entry.Dumper == null)
     {
         entry.Dumper = "";
     }
     if (entry.DateDumped == null)
     {
         entry.DateDumped = "";
     }
     if (entry.BoardType == null)
     {
         entry.BoardType = "";
     }
     if (entry.BoardPcb == null)
     {
         entry.BoardPcb = "";
     }
     row["IsDB"]             = entry.IsDB;
     row["Name"]             = entry.Name.Replace("'", "&apos;");
     row["Alternative Name"] = entry.AlternativeName.Replace("'", "&apos;");
     row["Size"]             = entry.Size;
     row["Path"]             = entry.Path.Replace("'", "&apos;");
     row["Rating"]           = entry.Rating;
     row["Played"]           = entry.Played;
     row["Play Time"]        = entry.PlayTime;
     row["Last Played"]      = entry.LastPlayed;
     row["Class"]            = entry.Class.Replace("'", "&apos;");
     row["Catalog"]          = entry.Catalog.Replace("'", "&apos;");
     row["Publisher"]        = entry.Publisher.Replace("'", "&apos;");
     row["Developer"]        = entry.Developer.Replace("'", "&apos;");
     row["Region"]           = entry.Region.Replace("'", "&apos;");
     row["Players"]          = entry.Players.Replace("'", "&apos;");
     row["Release Date"]     = entry.ReleaseDate;
     row["System"]           = entry.System.Replace("'", "&apos;");
     row["CRC"]          = entry.CRC;
     row["SHA1"]         = entry.SHA1;
     row["Dump"]         = entry.Dump.Replace("'", "&apos;");
     row["Dumper"]       = entry.Dumper.Replace("'", "&apos;");
     row["Date Dumped"]  = entry.DateDumped.Replace("'", "&apos;");
     row["Board Type"]   = entry.BoardType.Replace("'", "&apos;");
     row["Board Pcb"]    = entry.BoardPcb.Replace("'", "&apos;");
     row["Board Mapper"] = entry.BoardMapper;
 }
Example #10
0
        /// <summary>
        /// Add new entry to the database.
        /// </summary>
        /// <param name="entry">The entry info</param>
        /// <returns>True if the entry added successfully otherwise false.</returns>
        public static bool AddEntry(MyNesDBEntryInfo entry)
        {
            // Fix
            if (entry.Name == null)
            {
                entry.Name = "";
            }
            if (entry.AlternativeName == null)
            {
                entry.AlternativeName = "";
            }
            if (entry.Path == null)
            {
                entry.Path = "";
            }
            if (entry.Class == null)
            {
                entry.Class = "";
            }
            if (entry.Publisher == null)
            {
                entry.Publisher = "";
            }
            if (entry.Developer == null)
            {
                entry.Developer = "";
            }
            if (entry.Region == null)
            {
                entry.Region = "";
            }
            if (entry.Players == null)
            {
                entry.Players = "";
            }
            if (entry.ReleaseDate == null)
            {
                entry.ReleaseDate = "";
            }
            if (entry.System == null)
            {
                entry.System = "";
            }
            if (entry.CRC == null)
            {
                entry.CRC = "";
            }
            if (entry.SHA1 == null)
            {
                entry.SHA1 = "";
            }
            if (entry.Dump == null)
            {
                entry.Dump = "";
            }
            if (entry.Dumper == null)
            {
                entry.Dumper = "";
            }
            if (entry.DateDumped == null)
            {
                entry.DateDumped = "";
            }
            if (entry.BoardType == null)
            {
                entry.BoardType = "";
            }
            if (entry.BoardPcb == null)
            {
                entry.BoardPcb = "";
            }
            // try
            {
                using (SQLiteTransaction mytransaction = myconnection.BeginTransaction())
                {
                    using (SQLiteCommand mycommand = new SQLiteCommand(myconnection))
                    {
                        // Main info
                        string command = string.Format(
                            "INSERT INTO GAMES([IsDB], [Name], [Alternative Name], [Size], [Path], [Rating], [Played], [Play Time]," +
                            " [Last Played], [Class], [Catalog], [Publisher], [Developer], [Region], [Players], [Release Date]," +
                            " [System], [CRC], [SHA1], [Dump], [Dumper], [Date Dumped], [Board Type], [Board Pcb], [Board Mapper])" +
                            " VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}'," +
                            " '{10}', '{11}', '{12}', '{13}', '{14}', '{15}', '{16}', '{17}', '{18}', '{19}'," +
                            " '{20}', '{21}', '{22}', '{23}', '{24}');",
                            entry.IsDB,
                            entry.Name.Replace("'", "&apos;"),
                            entry.AlternativeName.Replace("'", "&apos;"),
                            entry.Size,
                            entry.Path.Replace("'", "&apos;"),
                            entry.Rating,
                            entry.Played,
                            entry.PlayTime,
                            entry.LastPlayed,
                            entry.Class.Replace("'", "&apos;"),
                            entry.Catalog.Replace("'", "&apos;"),
                            entry.Publisher.Replace("'", "&apos;"),
                            entry.Developer.Replace("'", "&apos;"),
                            entry.Region.Replace("'", "&apos;"),
                            entry.Players.Replace("'", "&apos;"),
                            entry.ReleaseDate,
                            entry.System.Replace("'", "&apos;"),
                            entry.CRC,
                            entry.SHA1,
                            entry.Dump.Replace("'", "&apos;"),
                            entry.Dumper.Replace("'", "&apos;"),
                            entry.DateDumped.Replace("'", "&apos;"),
                            entry.BoardType.Replace("'", "&apos;"),
                            entry.BoardPcb.Replace("'", "&apos;"),
                            entry.BoardMapper);

                        //"INSERT INTO GAMES([Name], [Alternative Name], [Size], [Path], [Rating], [Class], [Publisher], [Developer], [Region], [Players], [Release Date], [System], [CRC], [SHA1], [Dump], [Date Dumped], [Board Type], [Board Pcb], [Board Mapper]) VALUES ('Muppet Adventure: Chaos at the Carnival', '', 'N/A', 'N/A', '0', 'Licensed', 'Hi Tech Expressions', 'Mind's Eye', 'USA', '1', '1990-11', 'NES-NTSC', '7156CB4D', '03A111AC0FA78E566814D6F9296454BFC34E7B3C', 'ok', '2006-03-18', 'NES-SGROM', 'NES-SGROM-04', '1');
                        mycommand.CommandText = command;
                        mycommand.ExecuteNonQuery();
                    }
                    mytransaction.Commit();
                }
            }
            // catch (Exception ex)
            // {
            //     Trace.TraceError(ex.Message);
            //     return false;
            //}
            return(true);
        }