示例#1
0
        //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);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        //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);
        }