Esempio n. 1
0
        public void BeginManualImport(int sysId)
        {
            // Start manual import process for a game based on sysId
            DiskGameFile gameFile = SelectGameFile(sysId);

            if (gameFile == null)
            {
                MessageBox.Show("No valid file was selected", "MedLaunch: Error");
                return;
            }
            else
            {
                // Add or update the returned GameFile to the database
                InsertOrUpdateDisk(gameFile, sysId);
                SaveToDatabase();
                MessageBox.Show("Game: " + gameFile.FileName + " has added to (or updated in) the library", "MedLaunch: Import or Update Completed");
                GameListBuilder.UpdateFlag();
            }
        }
Esempio n. 2
0
        public void InsertOrUpdateDisk(DiskGameFile f, int sysId)
        {
            // check whether game already exists (by gameName and systemId)
            Game chkGame = (from g in Games
                            where g.systemId == sysId && g.gameName == f.GameName
                            select g).SingleOrDefault();

            // create new Game object for import
            Game newGame = new Game();

            string hash = string.Empty;

            // calculate MD5 checksum hashes
            if (f.Extension.Contains("m3u"))
            {
                // this is an m3u playlist - inspect and get relevant cue files
                string[] lines = File.ReadAllLines(f.FullPath);

                if (lines.Length > 0)
                {
                    // get hash for first cue/toc/ccd
                    hash = Crypto.checkMD5(f.FolderPath + "\\" + lines[0]);
                }
            }
            else
            {
                hash = Crypto.checkMD5(f.FullPath);
            }



            // lookup md5 in master DAT
            List <DATMerge> lookup = (from i in DAT
                                      where i.SystemId == sysId && i.Roms.Any(l => l.MD5.ToUpper().Trim() == hash)
                                      select i).ToList();

            if (chkGame == null)
            {
                // does not already exist - create new game
                newGame.configId    = 1;
                newGame.gameName    = f.GameName;
                newGame.gamePath    = f.FullPath;
                newGame.hidden      = false;
                newGame.isDiskBased = true;
                newGame.isFavorite  = false;
                newGame.systemId    = sysId;

                if (lookup != null && lookup.Count > 0)
                {
                    newGame.gameNameFromDAT = lookup.First().GameName;
                    newGame.Publisher       = lookup.First().Publisher;
                    newGame.Year            = lookup.First().Year;

                    // get rom we are interested in
                    var rom = (from ro in lookup.First().Roms
                               where ro.MD5.ToUpper().Trim() == hash.ToUpper().Trim()
                               select ro).First();
                    newGame.romNameFromDAT    = rom.RomName;
                    newGame.Copyright         = rom.Copyright;
                    newGame.Country           = rom.Country;
                    newGame.DevelopmentStatus = rom.DevelopmentStatus;
                    newGame.Language          = rom.Language;
                    newGame.OtherFlags        = rom.OtherFlags;

                    if (rom.Year != null && rom.Year != "")
                    {
                        newGame.Year = rom.Year;
                    }
                    if (rom.Publisher != null && rom.Publisher != "")
                    {
                        newGame.Publisher = rom.Publisher;
                    }
                }

                // add to finaGames list
                DisksToAdd.Add(newGame);
                // increment the added counter
                AddedStats++;
                GameListBuilder.UpdateFlag();
            }
            else
            {
                // matching game found - update it
                if ((chkGame.gamePath == f.FullPath || chkGame.gamePath == f.FullPath) && chkGame.hidden == false)
                {
                    //nothing to update - Path is either identical either absoultely or relatively (against the systemPath set in the database)
                    UntouchedStats++;
                }
                else
                {
                    newGame = chkGame;
                    // update path in case it has changed location
                    newGame.gamePath = f.FullPath;
                    // mark as not hidden
                    newGame.hidden      = false;
                    newGame.isDiskBased = true;

                    if (lookup != null && lookup.Count > 0)
                    {
                        newGame.gameNameFromDAT = lookup.First().GameName;
                        newGame.Publisher       = lookup.First().Publisher;
                        newGame.Year            = lookup.First().Year;

                        // get rom we are interested in
                        var rom = (from ro in lookup.First().Roms
                                   where ro.MD5.ToUpper().Trim() == hash.ToUpper().Trim()
                                   select ro).First();
                        newGame.romNameFromDAT    = rom.RomName;
                        newGame.Copyright         = rom.Copyright;
                        newGame.Country           = rom.Country;
                        newGame.DevelopmentStatus = rom.DevelopmentStatus;
                        newGame.Language          = rom.Language;
                        newGame.OtherFlags        = rom.OtherFlags;

                        if (rom.Year != null && rom.Year != "")
                        {
                            newGame.Year = rom.Year;
                        }
                        if (rom.Publisher != null && rom.Publisher != "")
                        {
                            newGame.Publisher = rom.Publisher;
                        }
                    }

                    // add to finalGames list
                    DisksToUpdate.Add(newGame);
                    // increment updated counter
                    UpdatedStats++;
                    GameListBuilder.UpdateFlag();
                }
            }
        }
Esempio n. 3
0
        public DiskGameFile SelectGameFile(int sysId)
        {
            // get allowed file types for this system
            List <string> exts = (GetAllowedFileExtensions(sysId)).ToList();

            // convert allowed types to filter string
            string filter = "";
            string fStart = "Allowed Types (";
            string fEnd   = "";

            foreach (string i in exts)
            {
                if (i == "")
                {
                    continue;
                }

                fStart += "*" + i + ",";
                fEnd   += "*" + i + ";";
            }
            char comma = ',';
            char semi  = ';';

            filter = (fStart.TrimEnd(comma)) + ")|" + (fEnd.TrimEnd(semi));
            //MessageBox.Show(filter);

            // open the file dialog showing only allowed file types - multi-select enabled
            OpenFileDialog filePath = new OpenFileDialog();

            filePath.Multiselect = true;
            filePath.Filter      = filter;
            filePath.Title       = "Select a single (or multiple in the same directory) .cue or .ccd or .toc file(s)";
            filePath.ShowDialog();

            if (filePath.FileNames.Length > 0)
            {
                // file(s) have been selected
                List <string> files = filePath.FileNames.ToList();

                // single or multiple files?
                if (files.Count > 1)
                {
                    // Create a list of GameFile Objects to process
                    List <DiskGameFile> games = new List <DiskGameFile>();

                    // iterate through each game
                    foreach (string game in files)
                    {
                        // Create a new DiskGameFile instance with all path details
                        DiskGameFile g = new DiskGameFile(game, sysId);
                        // add to list
                        games.Add(g);
                    }

                    // process the list and create an m3u playlist file - all selected files have to be in the same directory
                    List <DiskGameFile> ordered = (from a in games
                                                   select a).OrderBy(a => a.FileName).ToList();

                    // check whether an m3u playlist file already exists
                    var firstEntry = (from a in ordered
                                      select a).First();

                    // create string for the new m3u path
                    string m3uPath = firstEntry.FolderPath + "\\" + firstEntry.GameName + ".m3u";
                    //MessageBox.Show(m3uPath);

                    // create GameFIle object for the m3u playlist
                    DiskGameFile mf = new DiskGameFile(m3uPath, sysId);

                    // Attempt M3U creation
                    bool create = CreateM3uPlaylist(ordered, m3uPath);

                    if (create == false)
                    {
                        // user cancelled import, return null
                        return(null);
                    }
                    else
                    {
                        // method returned true - begin to import m3u to games library
                        return(mf);
                    }
                }
                else
                {
                    // single file selected - create GameFile object and return it
                    DiskGameFile g = new DiskGameFile(files[0], sysId, true);
                    return(g);
                }
            }
            else
            {
                // no files selected - return empty string
                return(null);
            }
        }