コード例 #1
0
        private static LibraryItem GetLibraryItem(string filePath)
        {
            string fileExtension = Path.GetExtension(filePath).ToUpper();
            //Get associated game console for file
            IEnumerable <GameConsole> fileTypeMatches = AllGameConsoles.Where(x => x.FileTypes.Contains(fileExtension.Replace(".", ""), StringComparer.OrdinalIgnoreCase));
            GameConsole matchedConsole;

            if (fileTypeMatches == null || fileTypeMatches.Count() <= 0)
            {
                //Unrecognised file type
                matchedConsole = null;
            }
            else if (fileTypeMatches.Count() == 1)
            {
                //Single file type match
                matchedConsole = fileTypeMatches.First();
            }
            else
            {
                //Multiple potential file type matches
                //TODO: Look at other files in this file's directory?
                matchedConsole = fileTypeMatches.First();
            }
            //Ignore unrecognised file type
            if (matchedConsole == null)
            {
                return(null);
            }
            //Create Library Item for file
            FileInfo    itemFile = new FileInfo(filePath);
            LibraryItem libItem  = new LibraryItem()
            {
                FilePath        = filePath,
                FileSize        = itemFile.Length,
                Title           = Path.GetFileNameWithoutExtension(filePath),
                FileExtension   = fileExtension,
                GameConsoleId   = matchedConsole?.Id,
                GameConsoleInfo = matchedConsole
            };

            return(libItem);
        }
コード例 #2
0
        private static List <LibraryItem> GetLibraryData()
        {
            //Check if Library Data file exists
            if (!File.Exists(LibraryDataFilePath))
            {
                return(null);
            }
            //Load and deserialise saved library data
            string             libraryDataString = File.ReadAllText(LibraryDataFilePath);
            List <LibraryItem> libraryData       = Tools.DeserialiseData <List <LibraryItem> >(libraryDataString);

            //TODO: If deserialisation fails (eg library data is corrupt), make a backup copy of the corrupted file and return null
            //Process the deserialised data
            foreach (LibraryItem item in libraryData)
            {
                item.FileExtension   = Path.GetExtension(item.FilePath).ToUpper();
                item.GameConsoleInfo = AllGameConsoles.Find(x => x.Id == item.GameConsoleId);
            }
            return(libraryData);
        }
コード例 #3
0
        public static GameConsole GetConsoleById(int gameConsoleId)
        {
            GameConsole foundConsole = AllGameConsoles.Find(x => x.Id == gameConsoleId);

            return(foundConsole);
        }