public RobinDataEntities(bool chooser)
        {
            string connectionString = $"metadata=res://*/{dbName}.csdl|res://*/{dbName}.ssdl|res://*/{dbName}.msl;provider=System.Data.SQLite.EF6;data source = {dataSource}";

            Database.Connection.ConnectionString = connectionString;

            Configuration.LazyLoadingEnabled       = false;
            Configuration.AutoDetectChangesEnabled = false;

            Stopwatch Watch = Stopwatch.StartNew();

            Platforms.Include(x => x.Emulators).Load();

            Reporter.Report("Platforms loaded " + Watch.Elapsed.TotalSeconds.ToString("F1") + " s."); Watch.Restart();
            Roms.Load();
            Reporter.Report("Roms loaded " + Watch.Elapsed.TotalSeconds.ToString("F1") + " s."); Watch.Restart();
            Games.Include(x => x.Releases).Load();
            Reporter.Report("Games loaded " + Watch.Elapsed.TotalSeconds.ToString("F1") + " s."); Watch.Restart();
            Regions.Load();
            Reporter.Report("Regions loaded " + Watch.Elapsed.TotalSeconds.ToString("F1") + " s."); Watch.Restart();
            Collections.Include(x => x.Games).Include(x => x.Releases).Load();
            Reporter.Report("Collections loaded " + Watch.Elapsed.TotalSeconds.ToString("F1") + " s."); Watch.Restart();

            foreach (Game game in Games)
            {
                game.Releases = game.Releases.OrderBy(x => x.Region.Priority).ThenByDescending(x => x.Version).ToList();
            }
            Reporter.Report("Games ordered " + Watch.Elapsed.Seconds + " s."); Watch.Restart();
        }
예제 #2
0
 public void AddRoms(List <string> files)
 {
     foreach (string file in files)
     {
         Roms.Add(new GameRom(file, new FileInfo(file).Name));
     }
 }
예제 #3
0
        public List <Rom> ListRoms()
        {
            if (!Roms.Any())
            {
                LoadRoms();
            }

            return(Roms);
        }
예제 #4
0
    public int GetRomFromFile(string foundFilePath)
    {
        int total = 0;

        var SHA1       = Audit.GetHash(foundFilePath, HashOption.SHA1, (int)HeaderLength);
        Rom matchedRom = Roms.FirstOrDefault(x => SHA1.Equals(x.SHA1, StringComparison.OrdinalIgnoreCase));

        if (matchedRom == null && HeaderLength > 0)
        {
            SHA1       = Audit.GetHash(foundFilePath, HashOption.SHA1, 0);
            matchedRom = Roms.FirstOrDefault(x => SHA1.Equals(x.SHA1, StringComparison.OrdinalIgnoreCase));
        }

        // Have found a match so do this stuff with it
        if (matchedRom != null)
        {
            // Check whether the release has a filename stored and that file exists
            if (string.IsNullOrEmpty(matchedRom.FileName) || !File.Exists(matchedRom.FilePath))
            {
                string extension = Path.GetExtension(foundFilePath);
                matchedRom.StoreFileName(extension);

                if (foundFilePath != matchedRom.FilePath)
                {
                    if (File.Exists(matchedRom.FilePath))
                    {
                        File.Move(matchedRom.FilePath, FileLocation.RomsBackup + matchedRom.FileName);
                    }

                    if (matchedRom.Platform_ID == CONSTANTS.Platform_ID.Lynx)
                    {
                        string tempFile  = "lnxtmp.lyx";
                        string tempFile2 = "lnxtmp.lnx";
                        string tempPath  = Path.GetDirectoryName(FileLocation.HandyConverter) + @"\" + tempFile;
                        string tempPath2 = Path.GetDirectoryName(FileLocation.HandyConverter) + @"\" + tempFile2;

                        File.Delete(tempPath);
                        Thread.Sleep(100);
                        File.Copy(foundFilePath, tempPath);
                        Thread.Sleep(100);
                        if (Handy.ConvertLynx(tempFile))
                        {
                            File.Move(tempPath2, matchedRom.FilePath);
                        }
                    }

                    else
                    {
                        File.Copy(foundFilePath, matchedRom.FilePath);
                    }
                }
                total = 1;
            }
        }
        return(total);
    }
예제 #5
0
        // TODO This should be removed from this class. Loading should happen through RomListViewModel.
        // There is, however, a usage of this when restoring a MenuLayout as well. Ideally, this would be
        // done by

        /// <summary>
        /// Initializes the contents of the singleton from a file.
        /// </summary>
        /// <param name="romListFile">The absolute path to the file to read from.</param>
        public static void InitializeFromFile(string romListFile)
        {
            if (File.Exists(romListFile))
            {
                try
                {
                    Roms.Initialize(romListFile);
                }
                catch (System.InvalidOperationException e)
                {
                    HandleLoadError(romListFile, e);
                }
                catch (System.Xml.XmlException e)
                {
                    HandleLoadError(romListFile, e);
                }
            }
        }
예제 #6
0
        // Currently we will require at least one rom.  If multiple they MUST be all the same media type in the same format
        // Given a good enough use case we could in theory expand those requirements, but for now we need a sanity check
        private void RomSanityCheck()
        {
            if (Roms.Count == 0)
            {
                throw new NotSupportedException("Currently, a Rom is required to run this core.");
            }

            var formats = Roms.Select(rom => C64FormatFinder.GetFormat(rom));

            HashSet <C64Format> uniqueFormats = new HashSet <C64Format>();

            foreach (var format in formats)
            {
                uniqueFormats.Add(format);
            }

            if (uniqueFormats.Count > 1)
            {
                throw new NotSupportedException("Currently Roms must all be of the same type.");
            }
        }
예제 #7
0
        protected virtual void LoadRoms()
        {
            try
            {
                var files = System.IO.Directory.GetFiles(RomsPath);

                string lastImageFile = string.Empty;

                foreach (var file in files)
                {
                    if (IsImagePath(file))
                    {
                        lastImageFile = file;
                        Rom rImageAux = new Rom(file);
                        var rom       = Roms.FirstOrDefault(x => x.GetRomName().Equals(rImageAux.GetRomName()));
                        if (rom != null)
                        {
                            rom.SetImagePath(file);
                        }
                    }
                    else
                    {
                        Rom r = new Rom(file);
                        if (lastImageFile.Contains(r.GetRomName()))
                        {
                            r.SetImagePath(lastImageFile);
                        }

                        Roms.Add(r);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"{nameof(LoadRoms)}: {ex.Message}");
            }
        }
예제 #8
0
 public void SetRoms(List <string> files)
 {
     Roms.Clear();
     AddRoms(files);
 }
예제 #9
0
    public int GetRomsFromZipFile(string filename)
    {
        int    total = 0;
        string SHA1;
        Rom    matchedRom;

        try
        {
            using ZipArchive archive = ZipFile.Open(filename, ZipArchiveMode.Read);
            foreach (ZipArchiveEntry entry in archive.Entries)
            {
                using Stream stream             = entry.Open();
                using MemoryStream memoryStream = new();
                int count;
                do
                {
                    byte[] buffer = new byte[1024];
                    count = stream.Read(buffer, 0, 1024);
                    memoryStream.Write(buffer, 0, count);
                } while (stream.CanRead && count > 0);

                // TODO Some roms in DB have no SHA1 this is a substantial bug

                SHA1       = Audit.GetHash(memoryStream, HashOption.SHA1, (int)HeaderLength);
                matchedRom = Roms.FirstOrDefault(x => SHA1.Equals(x.SHA1, StringComparison.OrdinalIgnoreCase));

                if (matchedRom == null && HeaderLength > 0)
                {
                    SHA1 = Audit.GetHash(memoryStream, HashOption.SHA1, 0);

                    matchedRom = Roms.FirstOrDefault(x => SHA1.Equals(x.SHA1, StringComparison.OrdinalIgnoreCase));
                }

                // Have found a match so do this stuff with it
                if (matchedRom != null)
                {
                    // Check that the release has no filename, or the file doesn't yet exist
                    if (string.IsNullOrEmpty(matchedRom.FileName) || !File.Exists(matchedRom.FilePath))
                    {
                        string extension = Path.GetExtension(entry.Name);
                        matchedRom.StoreFileName(extension);

                        if (File.Exists(matchedRom.FilePath))
                        {
                            File.Move(matchedRom.FilePath, FileLocation.RomsBackup + matchedRom.FileName);
                        }

                        if (matchedRom.Platform_ID == CONSTANTS.Platform_ID.Lynx)
                        {
                            //TODO: This looks pretty shady
                            string tempFile  = "lnxtmp.lyx";
                            string tempFile2 = "lnxtmp.lnx";
                            string tempPath  = Path.GetDirectoryName(FileLocation.HandyConverter) + @"\" + tempFile;
                            string tempPath2 = Path.GetDirectoryName(FileLocation.HandyConverter) + @"\" + tempFile2;
                            File.Delete(tempPath);
                            File.Delete(tempPath2);

                            entry.ExtractToFile(tempPath);
                            Handy.ConvertLynx(tempFile);
                            File.Move(tempPath, matchedRom.FilePath);
                        }
                        else
                        {
                            entry.ExtractToFile(matchedRom.FilePath);
                        }
                        total += 1;
                    }
                }
            }
        }

        catch (Exception)
        {
        }

        return(total);
    }