//saving/loading ---------------------------------------------------- public bool SaveAs(string filePath, System.IO.MemoryStream previewImage = null) { var newElement = new XElement(SubmarineElement.Name, SubmarineElement.Attributes().Where(a => !string.Equals(a.Name.LocalName, "previewimage", StringComparison.InvariantCultureIgnoreCase) && !string.Equals(a.Name.LocalName, "name", StringComparison.InvariantCultureIgnoreCase)), SubmarineElement.Elements()); if (Type == SubmarineType.OutpostModule) { OutpostModuleInfo.Save(newElement); OutpostModuleInfo = new OutpostModuleInfo(this, newElement); } XDocument doc = new XDocument(newElement); doc.Root.Add(new XAttribute("name", Name)); if (previewImage != null) { doc.Root.Add(new XAttribute("previewimage", Convert.ToBase64String(previewImage.ToArray()))); } try { SaveUtil.CompressStringToFile(filePath, doc.ToString()); Md5Hash.RemoveFromCache(filePath); } catch (Exception e) { DebugConsole.ThrowError("Saving submarine \"" + filePath + "\" failed!", e); return(false); } return(true); }
public bool SaveAs(string filePath, MemoryStream previewImage = null) { name = Path.GetFileNameWithoutExtension(filePath); XDocument doc = new XDocument(new XElement("Submarine")); SaveToXElement(doc.Root); hash = new Md5Hash(doc); doc.Root.Add(new XAttribute("md5hash", hash.Hash)); if (previewImage != null) { doc.Root.Add(new XAttribute("previewimage", Convert.ToBase64String(previewImage.ToArray()))); } try { SaveUtil.CompressStringToFile(filePath, doc.ToString()); } catch (Exception e) { DebugConsole.ThrowError("Saving submarine \"" + filePath + "\" failed!", e); return(false); } return(true); }
public bool SaveAs(string filePath) { name = System.IO.Path.GetFileNameWithoutExtension(filePath); XDocument doc = new XDocument(new XElement("Submarine")); SaveToXElement(doc.Root); hash = new Md5Hash(doc); doc.Root.Add(new XAttribute("md5hash", hash.Hash)); try { SaveUtil.CompressStringToFile(filePath, doc.ToString()); } catch (Exception e) { DebugConsole.ThrowError("Saving submarine \"" + filePath + "\" failed!", e); return(false); } return(true); }
//saving/loading ---------------------------------------------------- public bool SaveAs(string filePath, MemoryStream previewImage = null) { var newElement = new XElement(SubmarineElement.Name, SubmarineElement.Attributes().Where(a => !string.Equals(a.Name.LocalName, "previewimage", StringComparison.InvariantCultureIgnoreCase)), SubmarineElement.Elements()); XDocument doc = new XDocument(newElement); if (previewImage != null) { doc.Root.Add(new XAttribute("previewimage", Convert.ToBase64String(previewImage.ToArray()))); } try { SaveUtil.CompressStringToFile(filePath, doc.ToString()); } catch (Exception e) { DebugConsole.ThrowError("Saving submarine \"" + filePath + "\" failed!", e); return(false); } return(true); }