Exemplo n.º 1
0
        private void LoadAllAvailableDecks()
        {
            DirectoryInfo info = new DirectoryInfo(DeckFileHelper.ZippedDecksPath);

            // if the decks directory is not created then create it.
            if (!info.Exists)
            {
                info.Create();
            }

            string searchPattern = string.Format("*{0}", ZippedDeckExtension);

            FileInfo[] decks = info.GetFiles(searchPattern, SearchOption.TopDirectoryOnly);

            foreach (FileInfo deck in decks)
            {
                try
                {
                    string outputPath = DeckPackagingHelper.ExtractFromZip(deck.FullName);
                    if (!string.IsNullOrEmpty(outputPath))
                    {
                        LoadUnzippedDeck(deck.FullName, outputPath);
                    }
                }
                catch (Exception e)
                {
                    Utils.LogException(MethodBase.GetCurrentMethod(), e);
                }
            }

            CurrentView = this.Decks;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Saving to Disk , this fucntion needs to be Async and have a Status Datatrigger for View animation.
        /// </summary>
        private void SaveTheDeck()
        {
            IsBusy = true;

            try
            {
                GenerateRootPath();

                CreatedTime = DateTime.Now;
                CreatedBy   = Environment.UserName;

                List <CardPair> _pairs = Collection.ToList();

                foreach (CardPair pair in _pairs)
                {
                    if (pair.IsDeleted)
                    {
                        Collection.Remove(pair);
                        continue;
                    }
                }

                foreach (CardPair pair in Collection)
                {
                    CopyResources(pair.Card1);
                    CopyResources(pair.Card2);
                }

                string path = RootPath + "\\deck.xml";


                File.Delete(path);

                FileStream fs = File.Create(path);

                XmlSerializer SerializerObj = new XmlSerializer(typeof(CardDeck));
                SerializerObj.Serialize(fs, this);

                fs.Close();

                if (!MainViewModel.Instance.Decks.Collection.Contains(this))
                {
                    MainViewModel.Instance.Decks.Collection.Add(this);
                }

                Taskbar.AddEntryToJumpList(ZipPath, Title);

                DeckPackagingHelper.PackageDeck(RootPath, Title);
            }
            catch (Exception e)
            {
                Utils.LogException(MethodBase.GetCurrentMethod(), e);

                //There are some problem Saving the Deck..
                IsBusy = false;
            }

            IsBusy  = false;
            IsDirty = false;

            Count = _cardPairs.Count;
        }