public void SaveProject() { Action <MessageResult> onComplete = (MessageResult result) => { if (result == MessageResult.Yes) { string mapJson = JsonUtility.ToJson(interactiveMap, false); File.WriteAllText(settings.StaticDataPath, mapJson); SimpleZipper zipper = new SimpleZipper(); string targetPath = settings.IsNewProject ? Path.ChangeExtension( Path.Combine( settings.StoragePath, settings.Name), "irm") : settings.MapFilePath; zipper.Zip(settings.StaticPath, targetPath); if (endingSession) { ClearAppData(); } Editor.SessionEnded(); } else { endingSession = false; } }; MessageBox.ShowMessage(MessageType.YesNoCancel, onComplete, OnSaveProjectMessage, OnSaveProjectCaption); }
private void LoadProjectFromPath() { try { SimpleZipper zipper = new SimpleZipper(); byte[] data = File.ReadAllBytes(settings.MapFilePath); zipper.Unzip(data, settings.StaticPath); string dataJson = File.ReadAllText(settings.StaticDataPath); interactiveMap = JsonUtility.FromJson <InteractiveMap>(dataJson); } catch (Exception ex) { Debug.LogError(ex.Message); Action <MessageResult> onComplete = (MessageResult result) => { Editor.GoToMainMenu(); }; MessageBox.ShowMessage(MessageType.OK, onComplete, OnLoadErrorMessage, OnLoadErrorCaption); } }
/// <summary> /// Loads a complete project. /// </summary> public void HardLoad(ref Timeline timeline, string path) { Debug.LogFormat("Attempting to load file from: ({0}) to ({1})", path, SoftSavePath); if (!Directory.Exists(SoftSavePath)) { Directory.CreateDirectory(SoftSavePath); } else { SaveLoad.CleanPath(SoftSavePath); } SimpleZipper zipper = new SimpleZipper(); zipper.Unzip(path, SoftSavePath); SoftLoad(ref timeline, Path.GetFileNameWithoutExtension(path)); timeline.ForEach((TimelineChapter tlc) => { if (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsEditor) { tlc.VideoName = Path.Combine(SoftSavePath, Path.GetFileName(tlc.VideoName)); } else if (Application.platform == RuntimePlatform.Android) { // HACK: for some reason 'Path.GetFileName("")' does not work on Android. string[] splittedPath = tlc.VideoName.Split('/', '\\'); tlc.VideoName = Path.Combine(SoftSavePath, splittedPath[splittedPath.Length - 1]); } else { throw new System.Exception("Unpacking at unsupported platform"); } }); }
/// <summary> /// Saves a compiled project to the provided path. /// Should only be used in the editor. /// </summary> public void HardSave(Timeline timeline, string path) { Debug.LogFormat("Attempting to load save file to ({0})", path); // TODO: Make this aSync HardSavePath = path; SoftSave(timeline); List <string> filePaths = new List <string>(); string timelinePath = Path.Combine(SoftSavePath, Path.ChangeExtension(timeline.Name, TIMELINEEXTENTION)); filePaths.Add(timelinePath); // Copies all videos to buildpath. timeline.ForEach((TimelineChapter chapter) => { string videoName = chapter.VideoName; if (!filePaths.Contains(videoName)) { filePaths.Add(videoName); } }); // Creates filepath. string target = Path.ChangeExtension((Path.Combine(HardSavePath, timeline.Name)), PROJECTEXTENTION); if (File.Exists(target)) { File.Delete(target); } // Zips the file. SimpleZipper zipper = new SimpleZipper(); zipper.Zip(filePaths, target); }