Exemplo n.º 1
0
        public int ScrapeBanner()
        {
            using (WebClient webclient = new WebClient())
            {
                if (!File.Exists(BannerPath))
                {
                    if (BannerURL != null)
                    {
                        Reporter.Report("Getting banner for LB release " + Title + "...");

                        if (webclient.DownloadFileFromDB(BannerURL, BannerPath))
                        {
                            Reporter.ReportInline("success!");
                            OnPropertyChanged("BannerPath");
                        }
                        else
                        {
                            Reporter.ReportInline("dammit!");
                            return(-1);
                        }
                    }

                    else
                    {
                        Reporter.Report("No banner URL exists for LB release " + Title);
                    }
                }

                else
                {
                    Reporter.Report("File already exists.");
                }
            }
            return(0);
        }
Exemplo n.º 2
0
        public int ScrapeScreen()
        {
            using (WebClient webclient = new WebClient())
            {
                if (!File.Exists(ScreenPath))
                {
                    if (ScreenURL != null)
                    {
                        Reporter.Report("Getting screen shot for LB Release " + Title + "...");

                        if (webclient.DownloadFileFromDB(ScreenURL, ScreenPath))
                        {
                            Reporter.ReportInline("success!");
                            OnPropertyChanged("ScreenPath");
                        }
                        else
                        {
                            Reporter.ReportInline("dammit!");
                            return(-1);
                        }
                    }

                    else
                    {
                        Reporter.Report("No screen shot URL exists for LB release" + Title);
                    }
                }

                else
                {
                    Reporter.Report("File already exists.");
                }
            }
            return(0);
        }
Exemplo n.º 3
0
        async void CacheReleases()
        {
            // Cache platforms to cache in case selection changes during operation
            List <IDBPlatform> IDBPlatforms = new List <IDBPlatform>();

            foreach (IDBPlatform idbPlatform in SelectedPlatforms)
            {
                IDBPlatforms.Add(idbPlatform);
            }

            Reporter.Report("Caching " + IDBPlatforms.Count + " " + SelectedIDB.Title + " platforms.");

            await Task.Run(() =>
            {
                foreach (IDBPlatform idbPlatform in IDBPlatforms)
                {
                    SelectedIDB.CachePlatformData(idbPlatform.RPlatform);
                    SelectedIDB.CachePlatformReleases(idbPlatform.RPlatform);
                    idbPlatform.CacheDate = DateTime.Now;
                    SelectedIDB.ReportUpdates(true);
                    R.Data.Save(true);
                }
            });

            //if (SelectedIDB != IDBs[0])
            //{
            //	IDBs[0].ReportUpdates(false);
            //}
        }
Exemplo n.º 4
0
        public void Save(bool detectChanges = false)
        {
            string backupFile;

            if (detectChanges)
            {
                ChangeTracker.DetectChanges();
            }

            if (ChangeTracker.Entries().Any())
            {
                backupFile = Backup();
            }

            try
            {
                int nChanges = SaveChanges();
                Reporter.Report($"{nChanges} Database changes saved successfully");
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Trace.TraceInformation("Property: {0} Error: {1}",
                                               validationError.PropertyName,
                                               validationError.ErrorMessage);

                        Reporter.Report($"Data validation error...\nProperty: {validationError.PropertyName} Error: {validationError.ErrorMessage}");
                    }
                }
            }
        }
Exemplo n.º 5
0
        public int ScrapeCart3D()
        {
            using (WebClient webclient = new WebClient())
            {
                if (!File.Exists(Cart3DPath))
                {
                    if (BoxFrontURL != null)
                    {
                        Reporter.Report("Getting 3D cartridge art for LB release " + Title + "...");

                        if (webclient.DownloadFileFromDB(Cart3DURL, Cart3DPath))
                        {
                            Reporter.ReportInline("success!");
                            OnPropertyChanged("Cart3DPath");
                        }
                        else
                        {
                            Reporter.ReportInline("dammit!");
                            return(-1);
                        }
                    }

                    else
                    {
                        Reporter.Report("No 3D cartridge art URL exists for LB release" + Title);
                    }
                }

                else
                {
                    Reporter.Report("File already exists.");
                }
            }
            return(0);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Implements IDB.ReportUpdates(). Report to the UI how many database entries and of what type have been updated or added since the last save changes for a local DB cache.
        /// </summary>
        /// <param name="detect">Whether to detect changes prior to reporting. Detecting changes takes about 4 seconds. This can be set to false if no changes have been made since the last detect changes. Detecting changes is only necessary for updates, it is not necessary to detect additions.</param>
        public void ReportUpdates(bool detect)
        {
#if DEBUG
            Stopwatch Watch = Stopwatch.StartNew();
#endif
            if (detect)
            {
                R.Data.ChangeTracker.DetectChanges();
#if DEBUG
                Debug.WriteLine("Detect changes: " + Watch.ElapsedMilliseconds);
                Watch.Restart();
#endif
            }
            var lbReleaseEntries = R.Data.ChangeTracker.Entries <LBRelease>();
            var lbImageEntries   = R.Data.ChangeTracker.Entries <LBImage>();
            var lbGameEntries    = R.Data.ChangeTracker.Entries <LBGame>();
#if DEBUG
            Debug.WriteLine("Get entries: " + Watch.ElapsedMilliseconds);
#endif
            int lbReleaseAddCount = lbReleaseEntries.Count(x => x.State == EntityState.Added);

            int lbImageAddCount = lbImageEntries.Count(x => x.State == EntityState.Added);
            int lbGameAddCount  = lbGameEntries.Count(x => x.State == EntityState.Added);

            int lbReleaseModCount = lbReleaseEntries.Count(x => x.State == EntityState.Modified);
            int lbImageModCount   = lbImageEntries.Count(x => x.State == EntityState.Modified);
            int lbGameModCount    = lbGameEntries.Count(x => x.State == EntityState.Modified);

            Reporter.Report("LBReleases added: " + lbReleaseAddCount + ", LBReleases updated: " + lbReleaseModCount);
            Reporter.Report("LBImages added: " + lbImageAddCount + ", LBImages updated: " + lbImageModCount);
            Reporter.Report("LBGames added: " + lbGameAddCount + ", LBgames updated: " + lbGameModCount);
        }
        public int ScrapeBoxBack()
        {
            using (WebClient webclient = new WebClient())
            {
                if (!File.Exists(BoxBackPath))
                {
                    if (BoxFrontURL != null)
                    {
                        Reporter.Report("Getting front box art for OVGRelease " + Title + "...");

                        if (webclient.DownloadFileFromDB(BoxBackURL, BoxBackPath))
                        {
                            Reporter.ReportInline("success!");
                            OnPropertyChanged("BoxBackPath");
                        }
                        else
                        {
                            Reporter.ReportInline("dammit!");
                            return(-1);
                        }
                    }

                    else
                    {
                        Reporter.Report("No back box art URL exists.");
                    }
                }

                else
                {
                    Reporter.Report("File already exists.");
                }
            }
            return(0);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Implements IDB.ReportUpdates(). Report to the UI how many database entries and of what type have been updated or added since the last save changes for a local DB cache.
        /// </summary>
        /// <param name="detect">Whether to detect changes prior to reporting. Detecting changes takes about 4 seconds. This can be set to false if no changes have been made since the last detect changes. Detecting changes is only necessary for updates, it is not necessary to detect additions.</param>
        public void ReportUpdates(bool detect)
        {
#if DEBUG
            Stopwatch Watch = Stopwatch.StartNew();
#endif
            if (detect)
            {
                R.Data.ChangeTracker.DetectChanges();
#if DEBUG
                Debug.WriteLine("Detect changes: " + Watch.ElapsedMilliseconds);
                Watch.Restart();
#endif
            }

            var releaseEntries = R.Data.ChangeTracker.Entries <Release>();
            var gameEntries    = R.Data.ChangeTracker.Entries <Game>();
            var romEntries     = R.Data.ChangeTracker.Entries <Rom>();
#if DEBUG
            Debug.WriteLine("Get entries: " + Watch.ElapsedMilliseconds);
#endif
            int gameAddCount = gameEntries.Count(x => x.State == EntityState.Added);
            int gameModCount = gameEntries.Count(x => x.State == EntityState.Modified);

            int releaseAddCount = releaseEntries.Count(x => x.State == EntityState.Added);
            int releaseModCount = releaseEntries.Count(x => x.State == EntityState.Modified);

            int romAddCount = romEntries.Count(x => x.State == EntityState.Added);
            int romModCount = romEntries.Count(x => x.State == EntityState.Modified);

            Reporter.Report("Releases added: " + releaseAddCount + ", Releases updated: " + releaseModCount);
            Reporter.Report("Games added: " + gameAddCount + ", Games updated: " + gameModCount);
            Reporter.Report("Roms added: " + romAddCount + ", Roms updated: " + romModCount);
        }
Exemplo n.º 9
0
        public void Add(string sourceFilePath)
        {
            if (Path.GetExtension(sourceFilePath) == ".exe")
            {
                try
                {
                    Reporter.Report("Adding " + Title);

                    string destinationDirectory = Path.GetDirectoryName(FilePath);
                    string sourceDirectory      = Path.GetDirectoryName(sourceFilePath);
                    string sourceFile           = Path.GetFileName(sourceFilePath);
                    string sourceFileAfterMove  = destinationDirectory + @"\" + sourceFile;

                    Directory.CreateDirectory(destinationDirectory);
                    Filex.CopyDirectory(sourceDirectory, destinationDirectory);
                    File.Move(sourceFileAfterMove, FilePath);
                    OnPropertyChanged("Included");
                }
                catch
                {
                    Reporter.Warn("Problem creating directory of moving file.");
                }
            }
            else
            {
                Reporter.Warn("The dropped file doesn't look like an executable.");
            }
        }
Exemplo n.º 10
0
        public static void Save(bool detectChanges = false)
        {
            if (detectChanges)
            {
                Data.ChangeTracker.DetectChanges();
            }

            if (Data.ChangeTracker.Entries().Any())
            {
                Backup();
            }

            try
            {
                int nChanges = Data.SaveChanges();
                Reporter.Report($"{nChanges} Database changes saved successfully");
            }

            catch (DbUpdateConcurrencyException ex)
            {
                HandleUpdateException(ex);
            }
            catch (DbUpdateException ex)
            {
                HandleUpdateException(ex);
            }
        }
Exemplo n.º 11
0
        public int ScrapeLogo()
        {
            using (WebClient webclient = new WebClient())
            {
                if (!File.Exists(LogoPath))
                {
                    if (BoxFrontURL != null)
                    {
                        Reporter.Report("Getting clear logo for LB Release " + Title + "...");

                        if (webclient.DownloadFileFromDB(LogoURL, LogoPath))
                        {
                            Reporter.ReportInline("success!");
                            OnPropertyChanged("LogoPath");
                        }
                        else
                        {
                            Reporter.ReportInline("dammit!");
                            return(-1);
                        }
                    }

                    else
                    {
                        Reporter.Report("No clear logo URL exists for LB release" + Title);
                    }
                }

                else
                {
                    Reporter.Report("File already exists.");
                }
            }
            return(0);
        }
Exemplo n.º 12
0
        /// <summary>
        /// SUb function to scrape art based on strings computed elsewhere.
        /// </summary>
        /// <param name="url">URL to scrape art from.</param>
        /// <param name="filePath">Path to download art to.</param>
        /// <param name="property">Property of this release to notify PropertyChanged if art is downloaded.</param>
        /// <param name="description">String describing the art to download.</param>
        /// <returns>Returns -1 if artwork to indicate the scrape attempt could be tried again, or 0 if the scrape attempt is successfull.</returns>
        int Scrape(string url, string filePath, string property, string description)
        {
            using (WebClient webclient = new WebClient())
            {
                if (!File.Exists(filePath))
                {
                    if (url != null)
                    {
                        Reporter.Report($"Getting {description} art for {Title}...");

                        if (webclient.DownloadFileFromDB(url, filePath))
                        {
                            Reporter.ReportInline("success!");
                            if (property == "BoxFrontPath")
                            {
                                CreateThumbnail();
                            }
                            OnPropertyChanged(property);
                            Game.OnPropertyChanged2(property);
                        }
                        else
                        {
                            Reporter.ReportInline("dammit!");
                            return(-1);
                        }
                    }
                }
            }

            return(0);
        }
Exemplo n.º 13
0
        public int ScrapeControlPanel()
        {
            using (WebClient webclient = new WebClient())
            {
                if (!File.Exists(ControlPanelPath))
                {
                    if (ControlPanelURL != null)
                    {
                        Reporter.Report("Getting control panel art for LB Release " + Title + "...");

                        if (webclient.DownloadFileFromDB(ControlPanelURL, ControlPanelPath))
                        {
                            Reporter.ReportInline("success!");
                            OnPropertyChanged("ControlPanelPath");
                        }
                        else
                        {
                            Reporter.ReportInline("dammit!");
                            return(-1);
                        }
                    }

                    else
                    {
                        Reporter.Report("No control panel art URL exists for LB release" + Title);
                    }
                }

                else
                {
                    Reporter.Report("File already exists.");
                }
            }
            return(0);
        }
Exemplo n.º 14
0
        public int ScrapeMarquee()
        {
            using (WebClient webclient = new WebClient())
            {
                if (!File.Exists(MarqueePath))
                {
                    if (MarqueeURL != null)
                    {
                        Reporter.Report("Getting marquee art for LB Release " + Title + "...");

                        if (webclient.DownloadFileFromDB(MarqueeURL, MarqueePath))
                        {
                            Reporter.ReportInline("success!");
                            OnPropertyChanged("MarqueePath");
                        }
                        else
                        {
                            Reporter.ReportInline("dammit!");
                            return(-1);
                        }
                    }

                    else
                    {
                        Reporter.Report("No marquee art URL exists for LB release" + Title);
                    }
                }

                else
                {
                    Reporter.Report("File already exists.");
                }
            }
            return(0);
        }
Exemplo n.º 15
0
        void Match()
        {
            LocalDB db = SelectedIDBRelease.LocalDB;

            switch (db)
            {
            case LocalDB.GamesDB:
                Release.ID_GDB = SelectedIDBRelease?.ID;
                break;

            case LocalDB.GiantBomb:
                Release.ID_GB = SelectedIDBRelease?.ID;
                break;

            case LocalDB.OpenVGDB:
                Release.ID_OVG = SelectedIDBRelease?.ID;
                break;

            case LocalDB.LaunchBox:
                Release.ID_LB = SelectedIDBRelease?.ID;
                break;

            default:
                break;
            }
            Reporter.Report(Release.Title + " matched to " + db.Description() + " release " + SelectedIDBRelease?.ID + ", " + SelectedIDBRelease?.Title + ".");
            OnPropertyChanged("IDBReleases");
            OnPropertyChanged("UnmatchedReleases");
        }
        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();
        }
Exemplo n.º 17
0
 public static bool DownloadFileFromDB(this WebClient webclient, string url, string fileName)
 {
     try
     {
         webclient.SetStandardHeaders();
         DBTimers.Wait(url);
         Debug.WriteLine($"Hit DB at: {url} {DateTime.Now}");
         webclient.DownloadFile(url, fileName);
         return(true);
     }
     catch (WebException ex)
     {
         if (ex.Response != null)
         {
             var response = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
             Debug.WriteLine(response);
             Debug.WriteLine(ex.Message);
             Debug.WriteLine(ex.Source);
             Debug.WriteLine(ex.TargetSite);
             Debug.WriteLine(ex.Status);
             Debug.WriteLine(ex.HResult);
             Reporter.Warn($"Failure getting {url}. The website responded:");
             Reporter.Report(response);
         }
         return(false);
     }
 }
 public void CopyData()
 {
     // TODO: Does this function even work? Is it even hooked-up to a button?
     Reporter.Report("Getting data...");
     foreach (Release release in R.Data.Releases)
     {
         release.CopyData();
     }
     Reporter.ReportInline("finished.");
 }
Exemplo n.º 19
0
        async void Audit()
        {
            Reporter.Report($"Auditing {SelectedPlatform.Title}");
            TitledCollection <Audit.Result> resultCollection = null;

            await Task.Run(() =>
            {
                resultCollection = Robin.Audit.AuditRoms(SelectedPlatform);
            });

            AuditResultsCollection.Add(resultCollection);
        }
Exemplo n.º 20
0
        public async void CreateThumbnail()
        {
            await Task.Run(() =>
            {
                if (File.Exists(BoxFrontPath))
                {
                    try
                    {
                        using (System.Drawing.Image image = System.Drawing.Image.FromFile(BoxFrontPath))
                        {
#if DEBUG
                            Stopwatch Watch = Stopwatch.StartNew();
#endif
                            File.Delete(BoxFrontThumbPath);
#if DEBUG
                            Debug.WriteLine("Delete" + Watch.ElapsedMilliseconds);
                            Watch.Restart();
#endif
                            if (image.Width > 255)
                            {
                                System.Drawing.Image thumb = Thumbs.ResizeImage(image, 255);
                                thumb.Save(BoxFrontThumbPath);
                            }

                            else
                            {
                                File.Copy(BoxFrontPath, BoxFrontThumbPath);
                            }
#if DEBUG
                            Debug.WriteLine("Create" + Watch.ElapsedMilliseconds);
                            Watch.Restart();
#endif
                        }
                    }
                    catch (OutOfMemoryException)
                    {
                        File.Delete(BoxFrontPath);
                        Reporter.Report("Bad image file: " + BoxFrontPath + " - " + Title + ", file deleted.");
                    }
                    OnPropertyChanged("BoxFrontThumbFile");
                    OnPropertyChanged("MainDisplay");
                    Game.OnPropertyChanged2("BoxFrontThumbFile");
                    Game.OnPropertyChanged2("MainDisplay");
                }
            });
        }
Exemplo n.º 21
0
        //public int ScrapeArt(LocalDB localDB)
        //{
        //	// TODO: Add other db options for art
        //	WebClient webclient = new WebClient();
        //	Stopwatch Watch = Stopwatch.StartNew();

        //	if (BoxFrontURL != null && !File.Exists(BoxFrontPath))
        //	{
        //		Reporter.Report("  Box front...");
        //		webclient.DownloadFileFromDB(BoxFrontURL, BoxFrontPath);
        //		OnPropertyChanged("BoxFrontPath");
        //		Reporter.ReportInline(Watch.Elapsed.ToString("ss"));
        //	}
        //	Watch.Restart();

        //	if (BoxBackURL != null && !File.Exists(BoxBackPath))
        //	{
        //		Reporter.Report("  Box back...");
        //		webclient.DownloadFileFromDB(BoxBackURL, BoxBackPath);
        //		OnPropertyChanged("BoxBackPath");
        //		Reporter.ReportInline(Watch.Elapsed.ToString("ss") + " s");
        //	}
        //	Watch.Restart();

        //	if (BannerURL != null && !File.Exists(BannerPath))
        //	{
        //		Reporter.Report("  Banner...");
        //		webclient.DownloadFileFromDB(BannerURL, BannerPath);
        //		OnPropertyChanged("BannerPath");
        //		Reporter.ReportInline(Watch.Elapsed.ToString("ss") + " s");
        //	}
        //	Watch.Restart();

        //	if (ConsoleURL != null && !File.Exists(ConsolePath))
        //	{
        //		Reporter.Report("  Console...");
        //		webclient.DownloadFileFromDB(ConsoleURL, ConsolePath);
        //		OnPropertyChanged("ConsolePath");
        //		OnPropertyChanged("MainDisplay");
        //		Reporter.ReportInline(Watch.Elapsed.ToString("ss") + " s");
        //	}
        //	Watch.Restart();

        //	if (ControllerURL != null && !File.Exists(ControllerPath))
        //	{
        //		Reporter.Report("  Controller...");
        //		webclient.DownloadFileFromDB(ControllerURL, ControllerPath);
        //		OnPropertyChanged("ControllerFile");
        //		Reporter.ReportInline(Watch.Elapsed.ToString("ss") + " s");
        //	}
        //	Watch.Restart();

        //	//TODO: Make the return integers make sense across all scrapeart functions
        //	return 0;
        //}

        public async void GetReleaseDirectoryAsync(string[] paths)
        {
            Reporter.Report("Getting " + Title + " files.");
            Directory.CreateDirectory(FileLocation.RomsBackup);

            await Task.Run(() =>
            {
                int[] totals = { 0, 0 };
                string[] deeperPaths;
                int k;

                Directory.CreateDirectory(RomDirectory);
                foreach (string path in paths)
                {
                    if (Directory.Exists(path))
                    {
                        deeperPaths = Directory.GetFiles(path, "*", searchOption: SearchOption.AllDirectories);
                        Reporter.Report("Found " + deeperPaths.Count() + " in " + path);
                    }
                    else
                    {
                        deeperPaths = paths;
                    }

                    foreach (string file in deeperPaths)
                    {
                        if (Path.GetExtension(file) == ".zip")
                        {
                            k = GetRomsFromZipFile(file);
                        }
                        else
                        {
                            k = GetRomFromFile(file);
                        }

                        totals[0] += k;
                        if (k > 0)
                        {
                            totals[1] += 1;
                        }
                    }
                }
                Reporter.Report("Added " + totals[1] + " ROMs to " + RomDirectory);
                Reporter.Report("Updated " + totals[0] + " releases.");
            });
        }
Exemplo n.º 22
0
        static R()
        {
            Stopwatch watch = Stopwatch.StartNew();

            Data = new RobinDataContext();

            Stopwatch watch2 = Stopwatch.StartNew();

            try
            {
                Data.ChangeTracker.LazyLoadingEnabled       = false;
                Data.ChangeTracker.AutoDetectChangesEnabled = false;

                watch2 = Stopwatch.StartNew();

                Data.Platforms.Include(x => x.Emulators).Include(y => y.Cores).Load();
                Reporter.Report($"Platforms loaded {watch2.Elapsed.TotalSeconds:F1} s."); watch2.Restart();
                Data.Roms.Load();
                Reporter.Report($"Roms loaded {watch2.Elapsed.TotalSeconds:F1} s."); watch2.Restart();
                Data.Games.Include(x => x.Releases).Load();
                Reporter.Report($"Games loaded {watch2.Elapsed.TotalSeconds:F1} s."); watch2.Restart();
                Data.Regions.Load();
                Reporter.Report($"Regions loaded {watch2.Elapsed.TotalSeconds:F1} s."); watch2.Restart();
                Data.Collections.Include(x => x.Games).Include(x => x.Releases).Load();
                Reporter.Report($"Collections loaded {watch2.Elapsed.TotalSeconds:F1} s."); watch2.Restart();
            }
            catch (InvalidOperationException ex)
            {
                MessageBox.Show(ex.Message, "Problem Creating RobinDataModel", MessageBoxButton.OK);
            }
            catch (Microsoft.Data.Sqlite.SqliteException ex)
            {
                MessageBox.Show(ex.Message, "Sqlite Exception loading Robin", MessageBoxButton.OK);
            }

            foreach (Game game in Data.Games)
            {
                game.Releases = game.Releases.OrderBy(x => x.Region.Priority).ThenByDescending(x => x.Version).ToList();
            }
            Reporter.Report($"Games ordered {watch2.Elapsed.Seconds} s."); watch2.Restart();

            Reporter.Report($"Database loaded {watch.Elapsed.TotalSeconds:F1} s.");
        }
Exemplo n.º 23
0
        /// <summary>
        /// Backup existing database.
        /// </summary>
        public static void Backup()
        {
            Directory.CreateDirectory(Robin.FileLocation.Backup);
            string Date = DateTime.Now.ToString("yyyy-MM-dd-HHmmss");

            string CurrentFile = FileLocation;

            string backupFile = $"{Robin.FileLocation.Backup}{Path.GetFileNameWithoutExtension(CurrentFile)}{Date}{Path.GetExtension(CurrentFile)}";

            try
            {
                File.Copy(CurrentFile, backupFile);
                Reporter.Report($"DB file backed up to {backupFile}");
            }
            catch (Exception ex)
            {
                Reporter.Report("Failed to backup file.");
                Reporter.Report(ex.Message);
            }
        }
Exemplo n.º 24
0
        /// <summary>
        /// Get the xml file containing hte entire Launchbox database. Use existing downloaded file if it was modified today. Load the xml file to memory as property launchboxFile.
        /// </summary>
        void GetLaunchBoxFile()
        {
            using (WebClient webclient = new WebClient())
            {
                if (File.Exists(LaunchBoxDataZipFile) && (File.GetLastWriteTime(LaunchBoxDataZipFile).Date == DateTime.Today))
                {
                    Reporter.Report("Found up to date LaunchBox zip file.");
                }
                else
                {
                    Reporter.Tic("Updating LaunchBox zip file...", out int tic1);

                    webclient.DownloadFileFromDB(@"http://gamesdb.launchbox-app.com/Metadata.zip", LaunchBoxDataZipFile);
                    Reporter.Toc(tic1);
                }
            }

            Reporter.Tic("Extracting info from zip file...", out int tic2);
            try
            {
                using (ZipArchive archive = ZipFile.Open(LaunchBoxDataZipFile, ZipArchiveMode.Read))
                    using (var dattext = archive.GetEntry("Metadata.xml").Open())
                    {
                        launchboxFile = XDocument.Load(dattext);
                    }
            }

            catch (InvalidDataException)
            {
                Reporter.Report("Error in LaunchBox Metadata file.");
                File.Delete(LaunchBoxDataZipFile);
                launchboxFile = null;
            }

            gameElementLookupByPlatform  = launchboxFile.Root.Elements("Game").ToLookup(x => x.Element("Platform").Value);
            releaseElementLookupByGameID = launchboxFile.Root.Elements("GameAlternateName").ToLookup(x => x.Element("DatabaseID").Value);
            imageElementLookupByGameID   = launchboxFile.Root.Elements("GameImage").ToLookup(x => x.Element("DatabaseID").Value);
            platformElements             = launchboxFile.Root.Elements("Platform").ToList();

            Reporter.Toc(tic2);
        }
        /// <summary>
        /// Sub function to download art based on options figured elsewhere
        /// </summary>
        /// <param name="db"></param>
        /// <param name="artType"></param>
        /// <returns></returns>
        int GetArtSub(List <IDBobject> list, ArtType artType, LocalDB localDB)
        {
            int misCount;
            int tryCount = 0;

            do
            {
                misCount = 0;
                foreach (IDBobject idbObject in list)
                {
                    if (tokenSource.Token.IsCancellationRequested)
                    {
                        Reporter.Report("Downloading art cancelled.");
                        tryCount = 6;
                        break;
                    }
                    misCount += idbObject.ScrapeArt(artType, localDB);
                }
            } while (misCount < 0 && ++tryCount < 5);
            return(misCount);
        }
Exemplo n.º 26
0
        async void CompareAsync()
        {
            if (SelectedPlatforms != null && SelectedPlatforms.Count > 0)
            {
                List <IDBPlatform> list = new List <IDBPlatform>();
                foreach (IDBPlatform platform in SelectedPlatforms)
                {
                    list.Add(platform);
                }

                if (SelectedIDB.DB == LocalDB.OpenVGDB)
                {
                    foreach (IDBPlatform platform in list)
                    {
                        Reporter.Report("Comparing " + platform.Releases.Count + " Robin " + platform.Title + " games to OVG.");

                        await Task.Run(() => { CompareToOVGDB(platform); });
                    }
                }

                else
                {
                    foreach (IDBPlatform idbPlatform in list)
                    {
                        Compares comparator = new Compares(SelectedIDB.DB, idbPlatform);
                        comparator.Title += "-" + ComparisonResults.Count;

                        Reporter.Report("Comparing " + idbPlatform.Releases.Count + " Robin " + idbPlatform.Title + " games to " + Enum.GetName(typeof(LocalDB), SelectedIDB.DB) + ".");

                        await Task.Run(() =>
                        {
                            comparator.CompareToDB(Threshold, (SelectedIDB.HasRegions));
                        });

                        ComparisonResults.Add(comparator);
                    }
                    Reporter.Report("Finished");
                }
            }
        }
Exemplo n.º 27
0
        void CompareToOVGDB(IDBPlatform idbPlatform)
        {
            // There are no results in OVGDB for arcade, so skip it
            if (idbPlatform.Title.Contains("Arcade"))
            {
                Reporter.Report("Skiping platform \"Arcade\"");
                return;
            }

            Platform RPlatform = R.Data.Platforms.FirstOrDefault(x => x.ID == idbPlatform.ID);

            OVGRelease ovgrelease;

            foreach (Release release in RPlatform.Releases)
            {
                ovgrelease = R.Data.OVGReleases.FirstOrDefault(x => x.SHA1 == release.Rom.SHA1 && x.Region_ID == release.Region_ID && (x.BoxFrontURL != null || x.BoxBackURL != null));
                if (ovgrelease != null)
                {
                    release.ID_OVG = ovgrelease.ID;
                }
            }
        }
Exemplo n.º 28
0
        /// <summary>
        /// Backup uexisting database.
        /// </summary>
        /// <returns></returns>
        public string Backup()
        {
            Directory.CreateDirectory(Robin.FileLocation.Backup);
            string Date = DateTime.Now.ToString("yyyy-MM-dd-HHmmss");

            string CurrentFile = FileLocation;

            string backupFile = Robin.FileLocation.Backup + Path.GetFileNameWithoutExtension(CurrentFile) + Date + Path.GetExtension(CurrentFile);

            try
            {
                File.Copy(CurrentFile, backupFile);
                Reporter.Report("DB file backed up to " + backupFile);
                return(backupFile);
            }
            catch (Exception ex)
            {
                Reporter.Report("Failed to backup file.");
                Reporter.Report(ex.Message);
                return(null);
            }
        }
Exemplo n.º 29
0
        private static void HandleUpdateException(DbUpdateException ex)
        {
            string entries = string.Empty;
            int    i       = 0;

            foreach (var entry in ex.Entries)
            {
                Type type  = entry.GetType();
                var  props = new List <PropertyInfo>(type.GetProperties());

                entries += $"Entry {i++}:\n";
                foreach (PropertyInfo prop in props)
                {
                    entries += $"{prop.Name}:\t{prop.GetValue(entry, null)}\n";
                }
                entries += "\n";
            }

            string message = $"ex.Message\n\nFailed Entries:\n{entries}";

            Reporter.Report(message);

            MessageBox.Show(message, "Database Update Error", MessageBoxButton.OK);
        }
        async void GetAllData()
        {
            // TODO: make this good for any idbobject and add get selected data command
            Stopwatch Watch  = Stopwatch.StartNew();
            Stopwatch Watch1 = Stopwatch.StartNew();

            int j = 0;

            await Task.Run(() =>
            {
                Reporter.Report("Opening local cache...");

                R.Data.GBReleases.Load();
                R.Data.GDBReleases.Load();
                R.Data.OVGReleases.Load();
                R.Data.LBReleases.Include(x => x.LBGame).Load();
                Reporter.ReportInline(Watch.Elapsed.ToString("ss") + " s");
                Watch.Restart();

                int count = R.Data.Releases.Count();
                foreach (Release release in R.Data.Releases)
                {
                    if (j++ % (count / 10) == 0)
                    {
                        Reporter.Report("Copying " + j + @" / " + count + " " + Watch.Elapsed.ToString(@"m\:ss") + " elapsed.");
                        Watch.Restart();
                    }
                    release.CopyData();
                }
            });

            Datomatic datomatic = new Datomatic();

            datomatic.ReportUpdates(true);
            R.Data.Save(false);
        }