Exemplo n.º 1
0
        public void SaveToFile(string filePath, CardSetFile cardSetFile)
        {
            File.Delete(filePath);
            string json = JsonConvert.SerializeObject(cardSetFile, Formatting.Indented, new CardJsonConverter(typeof(Card)));

            using (var archive = ZipFile.Open(filePath, ZipArchiveMode.Create))
            {
                var configEntry = archive.CreateEntry("config.json");
                using (var writer = new StreamWriter(configEntry.Open()))
                {
                    writer.WriteLine(json);
                }

                foreach (var card in cardSetFile.Cards)
                {
                    if (card.ImagePath != null && card.ImagePath != string.Empty)
                    {
                        archive.CreateEntryFromFile(card.ImagePath, Path.GetFileName(card.ImagePath));
                    }
                    if (card.AudioPath != null && card.AudioPath != string.Empty)
                    {
                        archive.CreateEntryFromFile(card.AudioPath, Path.GetFileName(card.AudioPath));
                    }
                }
            }
        }
Exemplo n.º 2
0
        private bool SaveCardSet(string fileName)
        {
            try
            {
                var cardSetFile   = new CardSetFile(cardBoard.Columns, cardBoard.Rows, WithoutSpace, _cards, Description, DirectSet);
                var cardSetLoader = new CardSetLoader();
                cardSetLoader.SaveToFile(fileName, cardSetFile);

                MessageBox.Show(this, "Набор успешно сохранен!", "Успешно", MessageBoxButton.OK, MessageBoxImage.Information);

                CurrentFileName = fileName;

                IsEdited = false;

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, string.Format("При сохранении набора произошла ошибка! Подробнее: {0}", ex.Message), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            return(false);
        }
Exemplo n.º 3
0
        public void SaveToFile(string filePath, CardSetFile cardSetFile)
        {
            File.Delete(filePath);

            using (var archive = ZipFile.Open(filePath, ZipArchiveMode.Create))
            {
                List <string> paths = new List <string>();
                foreach (var card in cardSetFile.Cards)
                {
                    string fix  = card.ImagePath;
                    string name = Path.GetFileName(fix);
                    while (paths.Contains(name))
                    {
                        name = "_" + name;
                    }
                    paths.Add(name);
                    card.ImagePath = name;
                    if (card.ImagePath != null && card.ImagePath != string.Empty)
                    {
                        archive.CreateEntryFromFile(fix, name);
                    }
                    if (card.AudioPath != null && card.AudioPath != string.Empty)
                    {
                        archive.CreateEntryFromFile(card.AudioPath, Path.GetFileName(card.AudioPath));
                    }
                }

                string json = JsonConvert.SerializeObject(cardSetFile, Formatting.Indented, new CardJsonConverter(typeof(Card)));

                var configEntry = archive.CreateEntry("config.json");
                using (var writer = new StreamWriter(configEntry.Open()))
                {
                    writer.WriteLine(json);
                }
            }
        }