Esempio n. 1
0
        public void ExtractSandboxFromZip()
        {
            const string filename = @".\TestAssets\Sample World.sbw";

            MyObjectBuilder_Checkpoint checkpoint;

            using (var stream = ZipTools.ExtractZipFileToSteam(filename, null, SpaceEngineersConsts.SandBoxCheckpointFilename))
            {
                checkpoint = SpaceEngineersApi.ReadSpaceEngineersFile <MyObjectBuilder_Checkpoint>(stream);
            }

            Assert.AreEqual("Quad Scissor Doors", checkpoint.SessionName, "Checkpoint SessionName must match!");
        }
        private MyObjectBuilder_Definitions LoadAllDefinitionsZip(string stockContentPath, string zipModFile, ref Dictionary <string, ContentDataPath> contentData)
        {
            var zipFiles    = ZipTools.ExtractZipContentList(zipModFile, null);
            var definitions = new MyObjectBuilder_Definitions();

            if (!zipFiles.Any(f => Path.GetDirectoryName(f).Equals("Data", StringComparison.InvariantCultureIgnoreCase)))
            {
                return(definitions);
            }

            var files = zipFiles.Where(f => Path.GetDirectoryName(f).Equals("Data", StringComparison.InvariantCultureIgnoreCase) && Path.GetExtension(f).Equals(".sbc", StringComparison.InvariantCultureIgnoreCase)).ToArray();

            foreach (var filePath in files)
            {
                MyObjectBuilder_Definitions stockTemp = null;
                try
                {
                    using (var stream = ZipTools.ExtractZipFileToSteam(zipModFile, null, filePath))
                    {
                        stockTemp = SpaceEngineersApi.ReadSpaceEngineersFile <MyObjectBuilder_Definitions>(stream);
                    }
                }
                catch (Exception ex)
                {
                    // ignore errors, keep on trucking just like SE.
                    // write event log warning of any files not loaded.
                    DiagnosticsLogging.LogWarning(string.Format(Res.ExceptionState_CorruptContentFile, filePath), ex);
                }

                if (stockTemp != null)
                {
                    MergeDefinitions(ref definitions, stockTemp);
                }
            }

            LoadContent(stockContentPath, null, zipModFile, zipFiles, definitions, ref contentData);

            return(definitions);
        }