private void saveAllButton_Click(object sender, RoutedEventArgs e) { SaveFileDialog saveFileDlg = new SaveFileDialog(); saveFileDlg.Filter = "*.xml|*.xml"; if (saveFileDlg.ShowDialog().Value) { try { string path = System.IO.Path.GetDirectoryName(saveFileDlg.FileName); string backgroundPath = System.IO.Path.Combine(path, "Background"); string goodsPath = System.IO.Path.Combine(path, "Goods"); string backgroundMusic = System.IO.Path.Combine(path, "Music"); this.CreateDirectory(backgroundPath); this.CreateDirectory(goodsPath); this.CreateDirectory(backgroundMusic); this.SaveMusics(backgroundMusic); foreach (ReadCountStage stage in this.stageCollection) { this.SaveImages(backgroundPath, goodsPath, stage); } if (System.IO.File.Exists(saveFileDlg.FileName)) { System.IO.File.Delete(saveFileDlg.FileName); } ReadCountStageCollection readCountStageCollection = new ReadCountStageCollection(); foreach (ImageItem musicItem in this.musicCollection) { readCountStageCollection.BackgroundMusicList.Add(System.IO.Path.GetFileName(musicItem.File)); } foreach (ReadCountStage stage in Enumerable.ToArray <ReadCountStage>(this.stageCollection)) { readCountStageCollection.StageCollection.Add(stage); } SerializerHelper <ReadCountStageCollection> .XmlSerialize(saveFileDlg.FileName, readCountStageCollection); foreach (ReadCountStage stage in this.stageCollection) { stage.BackgroundImage = System.IO.Path.Combine(backgroundPath, stage.BackgroundImage); foreach (ReadCountItem item in stage.Items) { item.GoodsImage = System.IO.Path.Combine(goodsPath, item.GoodsImage); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void PrepareStages() { this.Dispatcher.Invoke(new ThreadStart(() => { this.backgroundImagePath = System.IO.Path.Combine(ReadCountStartupPage.Instance.DataBasePath, @"Background"); this.goodsImagePath = System.IO.Path.Combine(ReadCountStartupPage.Instance.DataBasePath, @"Goods"); this.backgroundMusicPath = System.IO.Path.Combine(ReadCountStartupPage.Instance.DataBasePath, @"Music"); string configFile = System.IO.Path.Combine(ReadCountStartupPage.Instance.DataBasePath, @"Setting.xml"); ReadCountStageCollection stages = SerializerHelper <ReadCountStageCollection> .XmlDeserialize(configFile); ReadCountDataMgr.Instance.StageCollection = stages; this.Next(); }), null); }
private void loadButton_Click(object sender, RoutedEventArgs e) { OpenFileDialog openFileDlg = new OpenFileDialog(); openFileDlg.Filter = "*.xml|*.xml"; if (openFileDlg.ShowDialog().Value) { try { string path = System.IO.Path.GetDirectoryName(openFileDlg.FileName); string backgroundPath = System.IO.Path.Combine(path, "Background"); string goodsPath = System.IO.Path.Combine(path, "Goods"); string musicPath = System.IO.Path.Combine(path, "Music"); ReadCountStageCollection stages = SerializerHelper <ReadCountStageCollection> .XmlDeserialize(openFileDlg.FileName); foreach (ReadCountStage stage in stages.StageCollection) { this.stageCollection.Add(stage); bool found = false; stage.BackgroundImage = System.IO.Path.Combine(backgroundPath, stage.BackgroundImage); foreach (ImageItem bk in this.backgroundImageCollection) { if (bk.File == stage.BackgroundImage) { found = true; break; } } if (!found) { ImageItem bkItem = new ImageItem(); bkItem.File = stage.BackgroundImage; bkItem.Title = System.IO.Path.GetFileNameWithoutExtension(bkItem.File); this.backgroundImageCollection.Add(bkItem); } foreach (ReadCountItem item in stage.Items) { item.GoodsImage = System.IO.Path.Combine(goodsPath, item.GoodsImage); found = false; foreach (ImageItem temp in this.goodsImageCollection) { if (temp.File == item.GoodsImage) { found = true; break; } } if (found) { continue; } ImageItem imageItem = new ImageItem(); imageItem.File = item.GoodsImage; imageItem.Title = System.IO.Path.GetFileNameWithoutExtension(imageItem.File); this.goodsImageCollection.Add(imageItem); } } for (int i = 0; i < stages.BackgroundMusicList.Count; i++) { stages.BackgroundMusicList[i] = System.IO.Path.Combine(musicPath, stages.BackgroundMusicList[i]); ImageItem musicItem = new ImageItem(); musicItem.File = stages.BackgroundMusicList[i]; musicItem.Title = System.IO.Path.GetFileName(stages.BackgroundMusicList[i]); this.musicCollection.Add(musicItem); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }