/** * Saves the dictionary as an XML file to the local system (both formatted/easy to read and non-formatted) */ public void SubmitToFile() { if (TabManager == null) { BG = GameObject.Find("GaudyBG"); TabManager = BG.GetComponentInChildren <TabManager>(); ds = BG.GetComponentInChildren <DataScript>(); fileName = GlobalData.fileName; path = GlobalData.filePath; } if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } TabManager.sameTab = true; TabManager.AddToDictionary(); TabManager.GetSectionImages(); fileName = GlobalData.fileName; string tempFileName = fileName.Remove(fileName.Length - 3); string data = "<body>" + ds.GetData() + "</body>"; Debug.Log(data); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(data); string textDataExtension = "ced"; if (autosaving) { textDataExtension = "auto"; } //Outputting regular file StreamWriter sw = new StreamWriter(path + tempFileName + textDataExtension, false); //sw.WriteLine(data); sw.Close(); sw.Dispose(); File.WriteAllBytes(path + tempFileName + textDataExtension, EncryptStringToBytes_Aes(data)); if (!autosaving) //Don't want to save images when autosaving, just text for now. //Formatted, easy to read version { sw = new StreamWriter(path + tempFileName + "xml", false); xmlDoc.Save(sw); sw.Close(); sw.Dispose(); //Easy to read images (For testing) sw = new StreamWriter(path + "ImageTest" + tempFileName + "xml", false); xmlDoc.LoadXml(ds.GetImagesXML()); xmlDoc.Save(sw); sw.Close(); sw.Dispose(); File.Delete(path + tempFileName + "auto"); File.Delete(path + tempFileName + "iauto"); ds.RestartAutosave(); } //Images string imgDataExtension = "cei"; if (autosaving) { textDataExtension = "iauto"; // Autosaving should have the most recent save GlobalData.caseObj.dateModified = (long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; } sw = new StreamWriter(path + tempFileName + imgDataExtension, false); //sw.WriteLine (ds.GetImagesXML ()); sw.Close(); sw.Dispose(); File.WriteAllBytes(path + tempFileName + imgDataExtension, EncryptStringToBytes_Aes(ds.GetImagesXML())); //Update the caseObj to create the menu file Transform content = transform.Find("SaveCasePanel/Content"); GlobalData.caseObj.description = content.Find("Row3/TMPInputField/DescriptionValue").GetComponent <TMP_InputField>().text; GlobalData.caseObj.summary = content.Find("Row5/TMPInputField/SummaryValue").GetComponent <TMP_InputField>().text; GlobalData.caseObj.tags = GetComponent <AutofillTMP>().enteredTags.ToArray(); GlobalData.caseObj.audience = content.Find("Row7/TargetAudienceValue").GetComponent <TMP_Dropdown>().captionText.text; GlobalData.caseObj.difficulty = content.Find("Row7/DifficultyValue").GetComponent <TMP_Dropdown>().captionText.text; DateTime unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); DateTime localFileModified = File.GetLastWriteTime(GlobalData.filePath + GlobalData.fileName); //GlobalData.caseObj.dateModified = (long) DateTime.UtcNow.Subtract (unixEpoch).TotalSeconds;// Old method GlobalData.caseObj.dateModified = (long)localFileModified.ToUniversalTime().Subtract(unixEpoch).TotalSeconds; File.WriteAllText(GlobalData.filePath + GlobalData.fileName.Remove(GlobalData.fileName.Length - 4) + " menu.txt", ds.ServerUploader.GetMenuText()); //Old demo menu appending system /*if (GlobalData.demo) { * bool append = true; * * StreamReader reader = new StreamReader(Application.streamingAssetsPath + GlobalData.filePath + GlobalData.fileName); * string fileText = reader.ReadToEnd(); * string[] cases = fileText.Split(new string[] { "::" }, System.StringSplitOptions.RemoveEmptyEntries); * foreach (string s in cases) { * string[] caseSplit = s.Split(new string[] { "--" }, System.StringSplitOptions.None); * if (caseSplit[1].Equals(GlobalData.fileName)) { * caseSplit[3] = GlobalData.firstName + "_" + GlobalData.lastName; * fileText = fileText.Replace(s, string.Join("--", caseSplit)); * append = false; * break; * } * } * reader.Close(); * StreamWriter writer = new StreamWriter(Application.streamingAssetsPath + "/DemoCases/Cases/MenuCases/MenuCases.txt", append); * if (append) { * writer.Write("0--{0}--ECGC Guest--{1}--000000--Beginner--User Custom Case--This case was created by one of our guests!--N/A--0--ECGC Guests--1.0--N/A::", tempFileName + "ced", GlobalData.firstName + "_" + GlobalData.lastName); * } else { * writer.Write(fileText); //Write all of the cases including the edited one * } * writer.Close(); * }*/ Debug.Log("Saved: " + path + tempFileName); //b.interactable = false; if (autosaving) { autosaving = false; Debug.Log("Data Autosaved!"); ds.ShowMessage("Data Autosaved!", false); } else { Debug.Log("Data successfully submitted!"); ds.ShowMessage("Data saved successfully!", false); } }
/** * Called when removing a tab from the edit tab panel */ public void removeTab() { //Debug.Log (tObject.text); tm.AddToDictionary(); string tabData = ds.GetData(tm.getCurrentSection(), tabName.text); ds.RemoveTab(tabName.text); tm.DestroyCurrentTab(); tm.TabButtonContentPar.transform.Find(tabName.text + "TabButton"); if (!tabName.text.Contains("/")) { Destroy(tm.TabButtonContentPar.transform.Find(tabName.text + "TabButton").gameObject); } else { for (int i = 0; i < tm.TabButtonContentPar.transform.childCount; i++) { if (tm.TabButtonContentPar.transform.GetChild(i).name.Equals(tabName.text + "TabButton")) { Destroy(tm.TabButtonContentPar.transform.GetChild(i).gameObject); break; //break out of the loop } } } if (ds.GetData(tm.getCurrentSection()).GetTabList().Count != 0) { TabInfoScript newTabInfo = ds.GetData(tm.getCurrentSection()).GetTabInfo(ds.GetData(tm.getCurrentSection()).GetTabList() [0]); tm.setTabName(newTabInfo.customName); tm.SwitchTab(ds.GetData(tm.getCurrentSection()).GetTabList() [0]); } else { //BG.transform.Find ("TabSelectorBG").gameObject.SetActive (true); GameObject tabSelectorPrefab = Instantiate(Resources.Load("Writer/Prefabs/Panels/TabSelectorBG")) as GameObject; tabSelectorPrefab.transform.SetParent(BG.transform, false); if (tabSelectorPrefab.transform.Find("TabSelectorPanel/RowTitle/CancelButton")) { tabSelectorPrefab.transform.Find("TabSelectorPanel/RowTitle/CancelButton").gameObject.SetActive(false); } } //Debug.Log (ds.GetData (tm.getCurrentSection()).getTabList ()[0]); tabEditPrefab.transform.Find(TitleValuePath).GetComponent <TMP_InputField>().text = ""; //tabEditPrefab.gameObject.SetActive (false); if (tabName.text.StartsWith("Background_InfoTab")) { ds.transform.Find("TabSelectorBG/TabSelectorPanel/Content/ScrollView/Viewport/Content/BackgroundInfoTabPanel").gameObject.SetActive(true); } Destroy(tabEditPrefab); List <string> keyList = ds.GetImageKeys(); // ds.GetImages ().Keys.ToList(); foreach (string key in keyList) { if (tabData.Contains("<Image>" + key + "</Image>")) { Debug.Log("Removing Image: " + key); ds.RemoveImage(key); //ds.GetImages ().Remove (key); } } keyList = ds.GetDialogues().Keys.ToList(); foreach (string key in keyList) { if (key.StartsWith(tm.getCurrentSection() + "/" + tabName.text + "Tab")) { ds.GetDialogues().Remove(key); } } keyList = ds.GetQuizes().Keys.ToList(); foreach (string key in keyList) { if (key.StartsWith(tm.getCurrentSection() + "/" + tabName.text + "Tab")) { ds.GetQuizes().Remove(key); } } }