public void sceneToJson(string sceneDir, Scene scene) { string json = JsonConvert.SerializeObject(scene, Formatting.Indented); Console.WriteLine(json); json = BluCodec.Encode(json); //Console.WriteLine(json); using (StreamWriter sw = new StreamWriter(File.Open(Path.Combine(App.SceneDir, sceneDir, AD_CONFIG_JSON), FileMode.Create))) { sw.WriteLine(json); } }
/// <summary> /// 文件夹名称就是场景名称, json 保存 video, subtitle, picture 位置等信息, /// 图片视频等资源拷贝进来即可 /// </summary> //private void doSaveScene(string sceneName) void doSaveScene(MarqueeProgress sender, DoWorkEventArgs e) { Toast("正在保存场景文件, 请稍候!", 3); string sceneName = (string)e.Argument; string dir = Path.Combine(App.SceneDir, sceneName); Scene scene = new Scene() { timing = AdScene.Timing_0000, name = sceneName, // + " (定时 " + SceneTiming.Replace(':', '.') + ")", }; for (int i = 0; i < CanvasMain.Kernel.getShapeList().Count; i++) { RectShape rect = CanvasMain.Kernel.getShapeList()[i] as RectShape; log.w("saveScene: " + rect.ItemType); scene.layers.Add(rect.ItemType); switch (rect.ItemType) { case AdItemType.Video: if (!App.VIDEO) { scene.video.Add(rect.Prop as Video); } else { Video video = rect.Prop as Video; if (video.filelist.Count == 0 && App.HDMI == false) { App.MsgBoxE("没有设置视频元素的视频源!"); Directory.Delete(dir, true); e.Result = false; return; } scene.video.Add(createVid(video, dir)); } break; case AdItemType.Picture: Picture picture = rect.Prop as Picture; if (picture.filelist.Count == 0) { App.MsgBoxE("没有设置图片元素的图片源!"); Directory.Delete(dir, true); e.Result = false; return; } scene.picture.Add(createPic(picture, dir)); break; case AdItemType.Subtitle: scene.subtitle.Add(rect.Prop as Subtitle); break; case AdItemType.Select: break; default: break; } } string json = JsonConvert.SerializeObject(scene, Formatting.Indented); log.t(json); json = BluCodec.Encode(json); //Console.WriteLine(json); using (StreamWriter sw = new StreamWriter(File.Open(Path.Combine(dir, AD_CONFIG_JSON), FileMode.Create))) { sw.WriteLine(json); } e.Result = true; //lbScene.Items.Add(scene.name); //endSceneEditing(); //App.MsgBox("保存成功!"); }