Ejemplo n.º 1
0
 public void installSet(Windows.ChangeSetsProgressDialog wnd, int max, Octgn.Data.Game game)
 {
     wnd.UpdateProgress(0, max, "Retrieving xml...", false);
     XmlSetParser xmls = xml_set;
     wnd.UpdateProgress(1, max, "Parsing retrieved xml...", false);
     xmls.check();
     bool is_spoiler_installed = true;
     Data.Set set = null;
     string path = Path.Combine(Prefs.DataDirectory, "Games", game.Id.ToString(), "Sets");
     string downloadto = Path.Combine(path) + xmls.name() + ".o8s";
     var cli = new WebClient();
     wnd.UpdateProgress(2, max, "Downloading new definition...", false);
     cli.Credentials = new System.Net.NetworkCredential(xmls.user(), xmls.password());
     cli.DownloadFile(xmls.link(), downloadto);
     wnd.UpdateProgress(3, max, "Checking for existence of old definition...", false);
     try
     {
         set = game.Sets.First<Data.Set>(_set => _set.Id.ToString() == xmls.uuid());
     }
     catch
     {
         is_spoiler_installed = false;
     }
     if (is_spoiler_installed)
     {
         wnd.UpdateProgress(4, max, "Removing old definition...", false);
         game.DeleteSet(set);
     }
     wnd.UpdateProgress(5, max, "Installing new definition...", false);
     game.InstallSet(downloadto);
     wnd.UpdateProgress(6, max, "Set installed correctly", false);
 }
Ejemplo n.º 2
0
        private void DeleteGame(Octgn.Data.Game game)
        {
            String opath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Octgn");
            String masterDbPath = Path.Combine(opath, "master.vdb3"); ;
            using(var dda = VistaDBEngine.Connections.OpenDDA())
            using(var masterDb = dda.OpenDatabase(masterDbPath, VistaDBDatabaseOpenMode.NonexclusiveReadWrite, null))
            using(var gamesTable = masterDb.OpenTable("Game", false, false))
            {
                masterDb.BeginTransaction();
                try
                {
                    if(gamesTable.Find("id:'" + game.Id.ToString() + "'", "GamePK", false, false))
                    {
                        gamesTable.Unlock(gamesTable.CurrentRow.RowId);
                        gamesTable.Delete();

                        foreach(Set s in game.Sets)
                        {
                            game.DeleteSet(s);
                        }
                    }
                }
                catch(VistaDBException e)
                {
                    String s = e.StackTrace;
                    MessageBox.Show(s);
                    masterDb.RollbackTransaction();
                }
            }
        }