private void OpenProject_Button_Click(object sender, RoutedEventArgs e) { OpenFileDialog fileDialog = new OpenFileDialog(); fileDialog.InitialDirectory = Environment.CurrentDirectory; fileDialog.Title = "Select project path"; fileDialog.CheckFileExists = true; fileDialog.CheckPathExists = true; fileDialog.Multiselect = false; fileDialog.DefaultExt = "wbp"; fileDialog.Filter = "Workbench projects (*.wbp)|*.wbp"; var result = fileDialog.ShowDialog(); if (result == DialogResult.OK) { if (!UserData.Instance.PreviousProjects.Contains(fileDialog.FileName)) { UserData.Instance.PreviousProjects.Add(fileDialog.FileName); UserData.SaveUserData(); } Wbp proj = new Wbp(fileDialog.FileName); ProjectData.Instance = proj.getProjectData(); ProjectData.Instance.WBP_Path = fileDialog.FileName; ProjectData.Instance.LastOpened = DateTime.Now; proj.setProjectData(ProjectData.Instance); //update projData to have latest info (like date and path) JetEditor jetEditor = new JetEditor(fileDialog.FileName); MainWindow.Instance.Close(); } }
public static ProjectData LoadProject(string WBP_Path) { Wbp wbp = new Wbp(WBP_Path); return(wbp.getProjectData()); /* * foreach (var item in wbp.Archive.Entries) * { * if (!item.FileName.Contains("project data.json")) * continue; * * string json = wbp.ReadFileInZip(item.FileName); * if (json == "null" || !Guard.IsJsonValid(json)) * { * Log.Output("ProjectData has invalid json, generating a new one."); * return Instance = new ProjectData(); * } * * return Instance = JsonConvert.DeserializeObject<ProjectData>(json); * } * * return new ProjectData(); */ }
public JetEditor(string projectPath) : this() { Wbp project = new Wbp(projectPath); GameInfo gameInfo = GameInfo.GetGame(ProjectData.Instance.TargetGame); string jetPath = gameInfo.GameDir; var game = ProjectData.Instance.TargetGame; if (game == GameType.BMC || game == GameType.BTD5 || game == GameType.BTDB) { jetPath += "\\Assets\\" + gameInfo.JetName; } else if (game == GameType.BTD6) { if (File.Exists(jetPath + "\\" + gameInfo.JetName)) { jetPath += "\\" + gameInfo.JetName; } } if (!File.Exists(jetPath)) { Log.Output("This Jetfile doesn't exist! : " + jetPath); throw new Exception("Jetfile: \"" + jetPath + "\" doesnt exist so the window cannot open"); } jet = new Zip(jetPath); if (!String.IsNullOrEmpty(ProjectData.Instance.JetPassword)) { jet.Password = ProjectData.Instance.JetPassword; } Show(); }
public static void SaveProject(ProjectData project, string WBP_Path) { /*Zip wbp = new Zip(WBP_Path); * if (project.WBP_Path == null) * project.WBP_Path = WBP_Path; * * if (!wbp.Archive.EntryFileNames.Contains("project data.json")) * { * MessageBox.Show(project.WBP_Path); * string output = JsonConvert.SerializeObject(Instance, Formatting.Indented); * StreamWriter serialize = new StreamWriter(Environment.CurrentDirectory + "\\project data.json", false); * serialize.Write(output); * serialize.Close(); * * wbp.Archive.AddEntry("project data.json", output); * MessageBox.Show(output); * }*/ Wbp wbp = new Wbp(WBP_Path); wbp.setProjectData(project); }