コード例 #1
0
        private Image TryGetPlanetTexture(string name, MyModContext context, string p, out string fullPath)
        {
            bool   flag  = false;
            string text1 = name + p;

            name     = text1;
            fullPath = Path.Combine(context.ModPathData, "PlanetDataFiles", name) + ".png";
            if (!context.IsBaseGame)
            {
                if (MyFileSystem.FileExists(fullPath))
                {
                    flag = true;
                }
                else
                {
                    fullPath = Path.Combine(context.ModPathData, "PlanetDataFiles", name) + ".dds";
                    if (MyFileSystem.FileExists(fullPath))
                    {
                        flag = true;
                    }
                }
            }
            if (!flag)
            {
                string str = Path.Combine(MyFileSystem.ContentPath, PlanetDataFilesPath);
                fullPath = Path.Combine(str, name) + ".png";
                if (!MyFileSystem.FileExists(fullPath))
                {
                    fullPath = Path.Combine(str, name) + ".dds";
                    if (!MyFileSystem.FileExists(fullPath))
                    {
                        return(null);
                    }
                }
            }
            if (fullPath.Contains(MyWorkshop.WorkshopModSuffix))
            {
                string       path    = fullPath.Substring(0, fullPath.IndexOf(MyWorkshop.WorkshopModSuffix) + MyWorkshop.WorkshopModSuffix.Length);
                string       str3    = fullPath.Replace(path + @"\", "");
                MyZipArchive archive = MyZipArchive.OpenOnFile(path, FileMode.Open, FileAccess.Read, FileShare.Read, false);
                try
                {
                    return(Image.Load(archive.GetFile(str3).GetStream(FileMode.Open, FileAccess.Read)));
                }
                catch (Exception)
                {
                    MyLog.Default.Error("Failed to load existing " + p + " file mod archive. " + fullPath, Array.Empty <object>());
                    return(null);
                }
                finally
                {
                    if (archive != null)
                    {
                        archive.Dispose();
                    }
                }
            }
            return(Image.Load(fullPath));
        }
コード例 #2
0
ファイル: UnitTest1.cs プロジェクト: thedevouttrout/SEToolbox
        public void ExtractSandboxFromZip()
        {
            const string filename = @".\TestAssets\Sample World.sbw";

            MyObjectBuilder_Checkpoint checkpoint;

            using (MyZipArchive archive = MyZipArchive.OpenOnFile(filename))
            {
                MyZipFileInfo fileInfo = archive.GetFile(SpaceEngineersConsts.SandBoxCheckpointFilename);
                checkpoint = SpaceEngineersApi.ReadSpaceEngineersFile <MyObjectBuilder_Checkpoint>(fileInfo.GetStream());
            }

            Assert.AreEqual("Quad Scissor Doors", checkpoint.SessionName, "Checkpoint SessionName must match!");
        }