public bool AutoSave(string data) { if (currentAutoSaves >= maximumAutoSaves) { fileHelper.DeleteFile(Folders.Saves, "Autosave_02" + saveExtension); fileHelper.RenameFile(Folders.Saves, "Autosave_01" + saveExtension, "Autosave_02" + saveExtension); return(fileHelper.SaveFile(Folders.Saves, "Autosave_01" + saveExtension, data)); } else { if (currentAutoSaves == 1) { fileHelper.RenameFile(Folders.Saves, "Autosave_01" + saveExtension, "Autosave_02" + saveExtension); } if (fileHelper.SaveFile(Folders.Saves, "Autosave_01" + saveExtension, data)) { currentAutoSaves++; return(true); } else { return(false); } } }
/// <summary> /// Save the specified file. /// </summary> /// <param name="file">The file name.</param> public void Save(string file) { string fileString = ""; List <string> noDup = new List <string>(); for (int i = 0; i < subSections.Count; i++) { if (!noDup.Contains(subSections[i])) { noDup.Add(subSections[i]); } } noDup.Sort(); List <string> keysC = keys.GetRange(0, keys.Count); List <string> valsC = vals.GetRange(0, keys.Count); List <string> comsC = comments.GetRange(0, keys.Count); List <string> subsC = subSections.GetRange(0, keys.Count); for (int i = 0; i < noDup.Count; i++) { int cur = 0; while (subsC.Contains(noDup[i])) { int pos = subsC.IndexOf(noDup[i]); if (cur == 0) { if (!noDup[i].Equals("")) { //wr.WriteLine("\n[" + noDup[i] + "]\n"); fileString += "\n[" + noDup[i] + "]\n"; } } if (!comsC[pos].Equals("")) { string p1 = keysC[pos] + "=" + valsC[pos]; int tabs = (commentMargin - p1.Length) / 4; //wr.WriteLine(p1 + new string('\t', tabs) + "; " + comsC[pos]); fileString += p1 + new string('\t', tabs) + "; " + comsC[pos] + "\n"; } else { //wr.WriteLine(keysC[pos] + "=" + valsC[pos]); fileString += keysC[pos] + "=" + valsC[pos] + "\n"; } subsC.RemoveAt(pos); keysC.RemoveAt(pos); comsC.RemoveAt(pos); valsC.RemoveAt(pos); cur++; } } IO.SaveFile(Folders.Configs, file + ".cfg", fileString); Debug.Log(file + ".ini Saved"); }
void SaveScreenshot(byte[] fileContents) { System.DateTime time = System.DateTime.Now; string fileTime = time.Hour.ToString() + "" + time.Minute.ToString() + "" + time.Second.ToString() + "" + time.Day.ToString() + "" + time.Month.ToString() + "" + time.Year.ToString(); IO.SaveFile(Folders.Screenshots, screenshotNamePrefix + fileTime + ".png", fileContents); }