/** * 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); } }
/** * Saves the dictionary as an XML file (both formatted/easy to read and non-formatted) */ private IEnumerator SubmitToFile() { //Toggle overwriteToggle = transform.Find("SaveCaseBG/SaveCasePanel/Content/Row1/OverwriteTemplateToggle").GetComponent<Toggle>(); print(GlobalData.caseObj.IsTemplate()); //Is template //print(!overwriteToggle.isOn); //Overwrite template? if (GlobalData.createCopy || GlobalData.fileName.StartsWith("[CHECKFORDUPLICATE]")) { //if ((GlobalData.caseObj.caseType.GetHashCode() & GlobalData.caseObj.templateCompare) == GlobalData.caseObj.templateCompare && //!overwriteToggle.isOn) { yield return(StartCoroutine(ds.ServerUploader.AvoidServerDuplicates())); GlobalData.createCopy = false; } //We set the case type to the new case type after we have handled any case relying on previous case type GlobalData.caseObj.caseType = newCaseType; fileName = GlobalData.fileName; string tempFileName = fileName.Remove(fileName.Length - 3); string data = "<body>" + ds.GetData() + "</body>"; Debug.Log(data); //Outputting regular file StreamWriter sw = new StreamWriter(path + tempFileName + "ced", false); //sw.WriteLine(data); sw.Close(); sw.Dispose(); File.WriteAllBytes(path + tempFileName + "ced", EncryptStringToBytes_Aes(data)); //Formatted, easy to read version sw = new StreamWriter(path + tempFileName + "xml", false); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(data); xmlDoc.Save(sw); sw.Close(); sw.Dispose(); //Images sw = new StreamWriter(path + tempFileName + "cei", false); //sw.WriteLine (ds.GetImagesXML ()); sw.Close(); sw.Dispose(); File.WriteAllBytes(path + tempFileName + "cei", EncryptStringToBytes_Aes(ds.GetImagesXML())); /* Non-encrypted local saving * //Outputting regular file * StreamWriter sw = new StreamWriter(path + tempFileName + "ced", false); * sw.WriteLine(data); * sw.Close(); * sw.Dispose (); * * //Formatted, easy to read version * data = replaceValues(data); * XmlDocument xmlDoc = new XmlDocument(); * //data = WWW.UnEscapeURL (data); * xmlDoc.LoadXml(data); * * //XmlWriter xw = XmlWriter.Create(path + tempFileName + "xml"); * sw = new StreamWriter(path + tempFileName + "xml", false); * xmlDoc.Save(sw); * sw.Close(); * sw.Dispose (); * * //Images * sw = new StreamWriter(path + tempFileName + "cei", false); * sw.WriteLine (ds.GetImagesXML()); * sw.Close (); * sw.Dispose (); */ //Delete the menu text file since we will have the information up on the server File.Delete(GlobalData.filePath + fileName.Remove(fileName.Length - 4) + " menu.txt"); //Delete the autosave as well File.Delete(path + tempFileName + "auto"); File.Delete(path + tempFileName + "iauto"); ds.RestartAutosave(); 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; Debug.Log("Saved: " + path + tempFileName); //ShowConfirmation("Case saved locally! Uploading to server..."); ds.ShowMessage("Saved locally! Uploading to server..."); yield return(StartCoroutine(Upload())); //b.interactable = false; //Debug.Log("Data successfully submitted!"); }