Ejemplo n.º 1
0
        public string LoadUnzippedDeck(string originalZipPath, string unzippedDeckPath)
        {
            string deckTitle = string.Empty;

            try
            {
                if (string.IsNullOrEmpty(unzippedDeckPath))
                {
                    return(string.Empty);
                }

                using (Stream stream = File.OpenRead(Path.Combine(unzippedDeckPath, "deck.xml")))
                {
                    XmlSerializer SerializerObj = new XmlSerializer(typeof(CardDeck));
                    CardDeck      cDeck         = (CardDeck)SerializerObj.Deserialize(stream);

                    cDeck.ZipPath  = originalZipPath;
                    cDeck.RootPath = unzippedDeckPath;
                    if (cDeck != null)
                    {
                        CardDeck theDeck = Decks.Collection.FirstOrDefault(s => s.RootPath == unzippedDeckPath);

                        if (theDeck != null)
                        {
                            int index = Decks.Collection.IndexOf(theDeck);
                            Decks.Collection.Remove(theDeck);
                            Decks.Collection.Insert(index, cDeck);
                        }
                        else
                        {
                            Decks.Collection.Add(cDeck);
                        }
                    }

                    cDeck.Initialize();
                    foreach (CardPair cp in cDeck.Collection)
                    {
                        cp.ParentDeck = cDeck;
                        cp.Initialize();
                    }

                    deckTitle = cDeck.Title;
                }
            }
            catch (Exception e)
            {
                Utils.LogException(MethodBase.GetCurrentMethod(), e);
            }

            return(deckTitle);
        }
Ejemplo n.º 2
0
        public void LoadDeckFromZip(Stream zipStreamPackage)
        {
            try
            {
                StreamResourceInfo streamResourceInfo = new StreamResourceInfo(zipStreamPackage, @"application/zip");

                Uri uri;
                StreamResourceInfo xmlSri;
                XmlSerializer      SerializerObj;

                // get deck.xml
                uri    = new Uri("deck.xml", UriKind.Relative);
                xmlSri = Application.GetResourceStream(streamResourceInfo, uri);

                SerializerObj = new XmlSerializer(typeof(CardDeck));
                CardDeck cDeck = (CardDeck)SerializerObj.Deserialize(xmlSri.Stream);

                // get files list
                uri    = new Uri("files.xml", UriKind.Relative);
                xmlSri = Application.GetResourceStream(streamResourceInfo, uri);

                SerializerObj = new XmlSerializer(typeof(string[]));
                string[] fileNames = (string[])SerializerObj.Deserialize(xmlSri.Stream);

                _imagesDictionary.Clear();
                for (int i = 0; i < fileNames.Length; i += 2)
                {
                    string zippedFileName   = fileNames[i];
                    string originalFileName = fileNames[i + 1];

                    if (string.Compare(Path.GetExtension(zippedFileName), ".xml", StringComparison.InvariantCultureIgnoreCase) != 0)
                    {
                        try
                        {
                            uri    = new Uri(zippedFileName, UriKind.Relative);
                            xmlSri = Application.GetResourceStream(streamResourceInfo, uri);

                            Stream stream = xmlSri.Stream;

                            if (string.Compare(Path.GetExtension(zippedFileName), ".wmv", StringComparison.InvariantCultureIgnoreCase) != 0)
                            {
                                BitmapImage bi = new BitmapImage();
                                bi.SetSource(xmlSri.Stream);
                                _imagesDictionary[originalFileName] = bi;
                                stream.Close();
                            }
                            else
                            {
                                _videoDictionary[originalFileName] = stream;
                            }
                        }
                        catch (Exception e)
                        {
                            Utils.LogException(MethodBase.GetCurrentMethod(), e);
                        }
                    }
                }

                cDeck.RootPath = "";
                cDeck.DeckGUID = "";
                if (cDeck != null)
                {
                    Decks.SelectedDeck = cDeck;
                }

                cDeck.Initialize();
                foreach (CardPair cp in cDeck.Collection)
                {
                    cp.ParentDeck = cDeck;
                    cp.Initialize();
                }
            }
            catch (Exception e)
            {
                Utils.LogException(MethodBase.GetCurrentMethod(), e);
            }
        }