예제 #1
0
        public static MyStorageBase LoadFromFile(string absoluteFilePath)
        {
            const string loadingMessage = "Loading voxel storage from file '{0}'";

            if (!MyFileSystem.FileExists(absoluteFilePath))
            {
                var oldPath = Path.ChangeExtension(absoluteFilePath, "vox");
                MySandboxGame.Log.WriteLine(string.Format(loadingMessage, oldPath));
                UpdateFileFormat(oldPath);
                Debug.Assert(MyFileSystem.FileExists(absoluteFilePath));
            }
            else
            {
                MySandboxGame.Log.WriteLine(string.Format(loadingMessage, absoluteFilePath));
            }
            Debug.Assert(absoluteFilePath.EndsWith(MyVoxelConstants.FILE_EXTENSION));

            byte[] compressedData = null;
            using (var file = MyFileSystem.OpenRead(absoluteFilePath))
            {
                compressedData = new byte[file.Length];
                file.Read(compressedData, 0, compressedData.Length);
            }
            return(Load(compressedData));
        }
예제 #2
0
        /// <summary>
        /// Absolute file path to the LOD model related to the parent assetFilePath.
        /// </summary>
        /// <param name="parentAssetFilePath">File path of parent asset.</param>
        /// <returns>Absolute file path.</returns>
        public string GetModelAbsoluteFilePath(string parentAssetFilePath)
        {
            if (Model == null)
            {
                return(null);
            }
            var filePathL     = parentAssetFilePath.ToLower();
            var modelFileName = Model;

            // Sometimes the models do not have the post fix
            if (!modelFileName.Contains(".mwm"))
            {
                modelFileName += ".mwm";
            }

            // Modded content has always absolute filepath of the asset
            if (Path.IsPathRooted(parentAssetFilePath) && filePathL.Contains("models"))
            {
                var contentPath      = parentAssetFilePath.Substring(0, filePathL.IndexOf("models"));
                var possibleFilePath = Path.Combine(contentPath, modelFileName);
                // Check the existence
                if (MyFileSystem.FileExists(possibleFilePath))
                {
                    return(possibleFilePath);
                }
                else
                {
                    possibleFilePath = Path.Combine(MyFileSystem.ContentPath, modelFileName);
                    return(MyFileSystem.FileExists(possibleFilePath) ? possibleFilePath : null);
                }
            }

            // Our vanilla content with relative file paths
            return(Path.Combine(MyFileSystem.ContentPath, modelFileName));
        }
예제 #3
0
        private static string GetCustomLoadingScreenImagePath(string relativePath)
        {
            if (string.IsNullOrEmpty(relativePath))
            {
                return(null);
            }

            var customLoadingScreenPath = Path.Combine(MyFileSystem.SavesPath, relativePath);

            if (!MyFileSystem.FileExists(customLoadingScreenPath))
            {
                customLoadingScreenPath = Path.Combine(MyFileSystem.ContentPath, relativePath);
            }

            if (!MyFileSystem.FileExists(customLoadingScreenPath))
            {
                customLoadingScreenPath = Path.Combine(MyFileSystem.ModsPath, relativePath);
            }

            if (!MyFileSystem.FileExists(customLoadingScreenPath))
            {
                customLoadingScreenPath = null;
            }

            return(customLoadingScreenPath);
        }
예제 #4
0
        bool TryGetAnimationDefinition(string animationSubtypeName, out MyAnimationDefinition animDefinition)
        {
            if (animationSubtypeName == null)
            {
                animDefinition = null;
                return(false);
            }

            animDefinition = MyDefinitionManager.Static.TryGetAnimationDefinition(animationSubtypeName);
            if (animDefinition == null)
            {
                //Try backward compatibility
                //Backward compatibility
                string oldPath = System.IO.Path.Combine(MyFileSystem.ContentPath, animationSubtypeName);
                if (MyFileSystem.FileExists(oldPath))
                {
                    animDefinition = new MyAnimationDefinition()
                    {
                        AnimationModel = oldPath,
                        ClipIndex      = 0,
                    };
                    return(true);
                }

                animDefinition = null;
                return(false);
            }

            return(true);
        }
예제 #5
0
파일: MyFont.cs 프로젝트: viktorius/Viktor
        /// <summary>
        /// Create a new font from the info in the specified font descriptor (XML) file
        /// </summary>
        public MyFont(string fontFilePath, int spacing = 1)
        {
            MyRenderProxy.Log.WriteLine("MyFont.Ctor - START");
            using (var indent = MyRenderProxy.Log.IndentUsing(LoggingOptions.MISC_RENDER_ASSETS))
            {
                Spacing = spacing;
                MyRenderProxy.Log.WriteLine("Font filename: " + fontFilePath);

                string path = fontFilePath;

                if (!Path.IsPathRooted(fontFilePath))
                {
                    path = Path.Combine(MyFileSystem.ContentPath, fontFilePath);
                }

                if (!MyFileSystem.FileExists(path))
                {
                    var message = string.Format("Unable to find font path '{0}'.", path);
                    Debug.Fail(message);
                    throw new Exception(message);
                }

                m_fontDirectory = Path.GetDirectoryName(path);

                LoadFontXML(path);

                MyRenderProxy.Log.WriteLine("FontFilePath: " + path);
                MyRenderProxy.Log.WriteLine("LineHeight: " + LineHeight);
                MyRenderProxy.Log.WriteLine("Baseline: " + Baseline);
                MyRenderProxy.Log.WriteLine("KernEnabled: " + KernEnabled);
            }
            MyRenderProxy.Log.WriteLine("MyFont.Ctor - END");
        }
예제 #6
0
        public MyHeightDetailTexture GetDetailMap(string path)
        {
            MyHeightDetailTexture texture;
            string str = Path.Combine(MyFileSystem.ContentPath, path);

            str = !MyFileSystem.FileExists(str + ".png") ? (str + ".dds") : (str + ".png");
            using (Image image = this.LoadTexture(str))
            {
                if (image != null)
                {
                    PixelBuffer buffer = image.GetPixelBuffer(0, 0, 0);
                    if (buffer.Format == Format.R8_UNorm)
                    {
                        texture = new MyHeightDetailTexture(buffer.GetPixels <byte>(0), (uint)buffer.Height);
                        image.Dispose();
                    }
                    else
                    {
                        string msg = $"Detail map '{str}' could not be loaded, expected format R8_UNorm, got {buffer.Format} instead.";
                        MyLog.Default.WriteLine(msg);
                        return(null);
                    }
                }
                else
                {
                    texture = new MyHeightDetailTexture(new byte[1], 1);
                }
            }
            return(texture);
        }
예제 #7
0
        public Stream Open(IncludeType type, string fileName, Stream parentStream)
        {
            string baseDir;

            if (type == IncludeType.Local)
            {
                baseDir = String.Concat(m_pathStacks.FindAll(item => item != "\\"));
            }
            else
            {
                baseDir = m_pathStacks.First();
            }

            string fullFileName = Path.Combine(baseDir, fileName);
            string localPath    = Path.GetDirectoryName(fullFileName.Substring(baseDir.Length));

            m_pathStacks.Add(localPath);

            if (MyFileSystem.FileExists(fullFileName))
            {
                return(new FileStream(fullFileName, FileMode.Open, FileAccess.Read));
            }
            else
            {
                return(Stream.Null);
            }
        }
예제 #8
0
        private string GetPath(string folder, string name, MyModContext context)
        {
            string str;

            if (!context.IsBaseGame)
            {
                str = Path.Combine(Path.Combine(context.ModPath, PlanetDataFilesPath), folder, name);
                if (!MyFileSystem.FileExists(str + ".png"))
                {
                    if (MyFileSystem.FileExists(str + ".dds"))
                    {
                        return(str + ".dds");
                    }
                }
                else
                {
                    return(str + ".png");
                }
            }
            str = Path.Combine(MyFileSystem.ContentPath, PlanetDataFilesPath, folder, name);
            if (MyFileSystem.FileExists(str + ".png"))
            {
                str = str + ".png";
            }
            else if (MyFileSystem.FileExists(str + ".dds"))
            {
                str = str + ".dds";
            }
            return(str);
        }
예제 #9
0
        private void ScriptSelected(string scriptPath)
        {
            string programData   = null;
            string fileExtension = Path.GetExtension(scriptPath);

            if (fileExtension == MyGuiIngameScriptsPage.SCRIPT_EXTENSION && File.Exists(scriptPath))
            {
                programData = File.ReadAllText(scriptPath);
            }
            else if (fileExtension == MyGuiIngameScriptsPage.WORKSHOP_SCRIPT_EXTENSION)
            {
                foreach (var file in MyFileSystem.GetFiles(scriptPath, MyGuiIngameScriptsPage.SCRIPT_EXTENSION, VRage.FileSystem.MySearchOption.AllDirectories))
                {
                    if (MyFileSystem.FileExists(file))
                    {
                        using (var stream = MyFileSystem.OpenRead(file))
                        {
                            using (StreamReader reader = new StreamReader(stream))
                            {
                                programData = reader.ReadToEnd();
                            }
                        }
                    }
                }
            }
            if (programData != null)
            {
                SetDescription(Regex.Replace(programData, "\r\n", " \n"));
                m_lineCounter.Text = string.Format(MyTexts.GetString(MySpaceTexts.ProgrammableBlock_Editor_LineNo), m_editorWindow.GetCurrentCarriageLine(), m_editorWindow.GetTotalNumLines());
                EnableButtons();
            }
        }
예제 #10
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));
        }
        private Image TryGetPlanetTexture(string name, MyModContext context, string p, out string fullPath)
        {
            bool found = false;

            name    += p;
            fullPath = Path.Combine(context.ModPathData, "PlanetDataFiles", name) + ".png";

            // Check for modded textures
            if (!context.IsBaseGame)
            {
                if (!MyFileSystem.FileExists(fullPath))
                {
                    fullPath = Path.Combine(context.ModPathData, "PlanetDataFiles", name) + ".dds";
                    if (MyFileSystem.FileExists(fullPath))
                    {
                        found = true;
                    }
                }
                else
                {
                    found = true;
                }
            }

            // Check for default textures
            if (!found)
            {
                fullPath = Path.Combine(m_planetDataFolder, name) + ".png";

                if (!MyFileSystem.FileExists(fullPath))
                {
                    fullPath = Path.Combine(m_planetDataFolder, name) + ".dds";
                    if (!MyFileSystem.FileExists(fullPath))
                    {
                        return(null);
                    }
                }
            }

            if (fullPath.Contains(".sbm"))
            {
                string archivePath             = fullPath.Substring(0, fullPath.IndexOf(".sbm") + 4);
                string fileRelativeArchivePath = fullPath.Replace(archivePath + "\\", "");
                using (var sbm = VRage.Compression.MyZipArchive.OpenOnFile(archivePath))
                {
                    try
                    {
                        return(SharpDXImage.Load(sbm.GetFile(fileRelativeArchivePath).GetStream()));
                    }
                    catch (Exception ex)
                    {
                        MyDebug.FailRelease("Failed to load existing " + p + " file from .sbm archive. " + fullPath);
                        return(null);
                    }
                }
            }

            return(SharpDXImage.Load(fullPath));
        }
예제 #12
0
        /// <summary>
        /// c-tor - this constructor should be used just for max models - not voxels!
        /// </summary>
        public MyModel(string assetName, bool keepInMemory)
        {
            m_assetName  = assetName;
            m_loadedData = false;
            KeepInMemory = keepInMemory;

            var fsPath = Path.IsPathRooted(AssetName) ? AssetName : Path.Combine(MyFileSystem.ContentPath, AssetName);

            System.Diagnostics.Debug.Assert(MyFileSystem.FileExists(fsPath), "Model data for " + m_assetName + " does not exists!");
        }
예제 #13
0
 private Image LoadTexture(string path)
 {
     if (!MyFileSystem.FileExists(path))
     {
         return(null);
     }
     using (Stream stream = MyFileSystem.OpenRead(path))
     {
         return((stream != null) ? Image.Load(stream) : null);
     }
 }
        private static Image LoadTexture(string path)
        {
            if (!MyFileSystem.FileExists(path))
            {
                return(null);
            }

            using (Stream textureStream = MyFileSystem.OpenRead(path))
            {
                return(textureStream != null?SharpDXImage.Load(textureStream) : null);
            }
        }
        public void Play(MyAnimationDefinition animationDefinition, bool firstPerson, MyFrameOption frameOption, float blendTime, float timeScale)
        {
            string model = firstPerson && !string.IsNullOrEmpty(animationDefinition.AnimationModelFPS) ? animationDefinition.AnimationModelFPS : animationDefinition.AnimationModel;

            System.Diagnostics.Debug.Assert(!string.IsNullOrEmpty(model));


            if (string.IsNullOrEmpty(animationDefinition.AnimationModel))
            {
                return;
            }


            if (animationDefinition.Status == MyAnimationDefinition.AnimationStatus.Unchecked)
            {
                var fsPath = System.IO.Path.IsPathRooted(model) ? model : System.IO.Path.Combine(MyFileSystem.ContentPath, model);
                if (!MyFileSystem.FileExists(fsPath))
                {
                    animationDefinition.Status = MyAnimationDefinition.AnimationStatus.Failed;
                    return;
                }
            }

            animationDefinition.Status = MyAnimationDefinition.AnimationStatus.OK;

            MyModel animation = VRage.Game.Models.MyModels.GetModelOnlyAnimationData(model);

            Debug.Assert(animation != null && animation.Animations != null && animation.Animations.Clips.Count > 0);
            if (animation != null && animation.Animations == null || animation.Animations.Clips.Count == 0)
            {
                return;
            }

            Debug.Assert(animationDefinition.ClipIndex < animation.Animations.Clips.Count);
            if (animation.Animations.Clips.Count <= animationDefinition.ClipIndex)
            {
                return;
            }

            if (ActualPlayer.IsInitialized)
            {
                BlendPlayer.Initialize(ActualPlayer);
            }

            // Create a clip player and assign it to this model
            ActualPlayer.Initialize(animation, m_name, animationDefinition.ClipIndex, m_skinnedEntity, 1, timeScale, frameOption, m_bones, m_boneLODs);
            ActualPlayer.AnimationMwmPathDebug = model;
            ActualPlayer.AnimationNameDebug    = animationDefinition.Id.SubtypeName;

            m_state            = AnimationBlendState.BlendIn;
            m_currentBlendTime = 0;
            m_totalBlendTime   = blendTime;
        }
예제 #16
0
        public static void Init()
        {
            if (!MyPerGameSettings.EnableTutorials)
            {
                return;
            }
            var path = Path.Combine(MyFileSystem.ContentPath, Path.Combine("Data", "Tutorials.sbx"));

            if (!MyFileSystem.FileExists(path))
            {
                Debug.Fail("Tutorials.sbx not found");
                return;
            }
            MyDataIntegrityChecker.HashInFile(path);
            MyObjectBuilder_TutorialsHelper objBuilder = null;

            if (!MyObjectBuilderSerializer.DeserializeXML(path, out objBuilder))
            {
                Debug.Fail("Tutorials deserialize fail");
            }

            if (objBuilder == null)
            {
                MyDefinitionErrors.Add(MyModContext.BaseGame, "Tutorials: Cannot load definition file, see log for details", TErrorSeverity.Error);
                return;
            }
            m_tutorialUnlockedBy = new Dictionary <string, List <string> >();

            if (objBuilder.Tutorials != null)
            {
                foreach (var tut in objBuilder.Tutorials)
                {
                    List <string> list;
                    if (!m_tutorialUnlockedBy.TryGetValue(tut.Name, out list))
                    {
                        list = new List <string>();
                        m_tutorialUnlockedBy.Add(tut.Name, list);
                    }

                    if (tut.UnlockedBy != null)
                    {
                        foreach (var other in tut.UnlockedBy)
                        {
                            list.Add(other);
                        }
                    }
                }
            }

            RefreshUnlocked();
        }
예제 #17
0
            public Stream Open(IncludeType type, string fileName, Stream parentStream)
            {
                string fullFileName = fileName;

                if (type == IncludeType.Local)
                {
                    string     baseDir    = null;
                    FileStream fileStream = parentStream as FileStream;
                    if (fileStream != null)
                    {
                        baseDir = Path.GetDirectoryName(fileStream.Name);
                    }
                    else if (m_basePath != null)
                    {
                        baseDir = m_basePath;
                    }

                    if (baseDir != null)
                    {
                        fullFileName = Path.Combine(baseDir, fileName);
                        if (MyFileSystem.FileExists(fullFileName))
                        {
                            return(new FileStream(fullFileName, FileMode.Open, FileAccess.Read));
                        }
                    }

                    // If base path is not defined, attempt resolving includes
                    if (m_basePath != null)
                    {
                        goto NotFound;
                    }
                }

                // Iterate defines in reverse order
                for (int it = MyShaders.Includes.Count - 1; it >= 0; it--)
                {
                    string define = MyShaders.Includes[it];
                    fullFileName = Path.Combine(define, fileName);
                    if (MyFileSystem.FileExists(fullFileName))
                    {
                        return(new FileStream(fullFileName, FileMode.Open, FileAccess.Read));
                    }
                }

NotFound:
                string message = "Include not found: " + fullFileName;

                MyRender11.Log.WriteLine(message);
                // NOTE: Throwing exception here will enable better error reporting in SharpDX
                throw new Exception(message);
            }
        public MyHeightDetailTexture GetDetailMap(string path)
        {
            if (m_first)
            {
                PreloadCrashingData();
                m_first = false;
            }

            MyHeightDetailTexture value;

            if (m_detailTextures.TryGetValue(path, out value))
            {
                return(value);
            }
            string fullPath = Path.Combine(MyFileSystem.ContentPath, path);

            if (MyFileSystem.FileExists(fullPath + ".png"))
            {
                fullPath += ".png";
            }
            else
            {
                fullPath += ".dds";
            }


            using (var image = LoadTexture(fullPath))
            {
                if (image == null)
                {
                    value = new MyHeightDetailTexture(new byte[1], 1);
                }
                else
                {
                    PixelBuffer buffer = image.GetPixelBuffer(0, 0, 0);

                    if (buffer.Format != Format.R8_UNorm)
                    {
                        string err = String.Format("Detail map '{0}' could not be loaded, expected format R8_UNorm, got {1} instead.", fullPath, buffer.Format);
                        Debug.Fail(err);
                        MyLog.Default.WriteLine(err);
                        return(null);
                    }

                    value = new MyHeightDetailTexture(buffer.GetPixels <byte>(), (uint)buffer.Height);
                }
            }
            m_detailTextures[path] = value;

            return(value);
        }
예제 #19
0
        public static MyObjectBuilder_Definitions LoadPrefab(string filePath)
        {
            MyObjectBuilder_Definitions loadedPrefab = null;

            if (MyFileSystem.FileExists(filePath))
            {
                var success = MyObjectBuilderSerializer.DeserializeXML(filePath, out loadedPrefab);
                if (!success)
                {
                    return(null);
                }
            }
            return(loadedPrefab);
        }
예제 #20
0
        bool Load(string contentDir, TextureQuality quality, bool canBeMissing)
        {
            string ext = Path.GetExtension(Name);

            if (String.IsNullOrEmpty(ext))
            {
                Debug.Fail("Texture without extension: " + Name);
                Name += ".dds";
                ext   = ".dds";
            }

            string path = Path.Combine(contentDir, Name);

            if (MyFileSystem.FileExists(path))
            {
                try
                {
                    if (ext.Equals(".dds", StringComparison.InvariantCultureIgnoreCase))
                    {
                        this.texture = LoadDDSTexture(path, quality);
                    }
                    else if (ext.Equals(".png", StringComparison.InvariantCultureIgnoreCase))
                    {
                        this.texture = LoadPNGTexture(path);
                    }
                    else
                    {
                        Debug.Fail("Unsupported texture format: " + path);
                        MyRender.Log.WriteLine(String.Format("Unsupported texture format: {0}", path));
                    }
                }
                catch (SharpDXException e)
                {
                    MyRender.Log.WriteLine(String.Format("Error decoding texture, file might be corrupt, quality {1}: {0}", path, quality));
                }
                catch (Exception e)
                {
                    MyRender.Log.WriteLine(String.Format("Error loading texture, quality {1}: {0}", path, quality));
                    throw new ApplicationException("Error loading texture: " + path, e);
                }
            }

            if (!canBeMissing && this.texture == null)
            {
                this.LoadState = LoadState.Error;
                return(false);
            }

            return(true);
        }
예제 #21
0
        private static MyObjectBuilder_Sector LoadSector(string path, bool allowXml, out ulong sizeInBytes, out bool needsXml)
        {
            MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Sector>();
            sizeInBytes = 0L;
            needsXml    = false;
            MyObjectBuilder_Sector objectBuilder = null;
            string str = path + MyObjectBuilderSerializer.ProtobufferExtension;

            if (!MyFileSystem.FileExists(str))
            {
                if (!allowXml)
                {
                    needsXml = true;
                }
                else
                {
                    MyObjectBuilderSerializer.DeserializeXML <MyObjectBuilder_Sector>(path, out objectBuilder, out sizeInBytes);
                    if (!MyFileSystem.FileExists(str))
                    {
                        MyObjectBuilderSerializer.SerializePB(path + MyObjectBuilderSerializer.ProtobufferExtension, false, objectBuilder);
                    }
                }
            }
            else
            {
                MyObjectBuilderSerializer.DeserializePB <MyObjectBuilder_Sector>(str, out objectBuilder, out sizeInBytes);
                if ((objectBuilder == null) || (objectBuilder.SectorObjects == null))
                {
                    if (!allowXml)
                    {
                        needsXml = true;
                    }
                    else
                    {
                        MyObjectBuilderSerializer.DeserializeXML <MyObjectBuilder_Sector>(path, out objectBuilder, out sizeInBytes);
                        if (objectBuilder != null)
                        {
                            MyObjectBuilderSerializer.SerializePB(str, false, objectBuilder);
                        }
                    }
                }
            }
            if (objectBuilder != null)
            {
                return(objectBuilder);
            }
            MySandboxGame.Log.WriteLine("Incorrect save data");
            return(null);
        }
예제 #22
0
        private string GetImagePath(MyObjectBuilder_Campaign campaign)
        {
            string imagePath = campaign.ImagePath;

            if (!campaign.IsVanilla)
            {
                imagePath = Path.Combine(campaign.ModFolderPath, campaign.ImagePath);
                if (!MyFileSystem.FileExists(imagePath))
                {
                    imagePath = Path.Combine(MyFileSystem.ContentPath, campaign.ImagePath);
                }
            }

            return(imagePath);
        }
        // Loads campaign bundle with provided files
        // This is and should be used only
        public void LoadCampaignLocalization(IEnumerable <string> paths, string campaignModFolderPath = null)
        {
            // Remove the first part of the full path
            m_campaignModFolderName = Path.GetFileName(campaignModFolderPath);
            m_campaignBundle.FilePaths.Clear();
            // Add campaign mod folder
            if (campaignModFolderPath != null)
            {
                m_campaignBundle.FilePaths.Add(campaignModFolderPath);
            }

            // Add custom content folders
            foreach (var path in paths)
            {
                try
                {
                    var contentPath = Path.Combine(MyFileSystem.ContentPath, path);
                    var modPath     = campaignModFolderPath != null?Path.Combine(campaignModFolderPath, path) : string.Empty;

                    if (MyFileSystem.FileExists(contentPath))
                    {
                        m_campaignBundle.FilePaths.Add(contentPath);
                    }
                    else if (!string.IsNullOrEmpty(campaignModFolderPath) && MyFileSystem.FileExists(modPath))
                    {
                        m_campaignBundle.FilePaths.Add(modPath);
                    }
                    else
                    {
                        var files = MyFileSystem.GetFiles(Path.Combine(MyFileSystem.ContentPath, path), "*.sbl", MySearchOption.AllDirectories);
                        foreach (var filePath in files)
                        {
                            m_campaignBundle.FilePaths.Add(filePath);
                        }
                    }
                }
                catch
                { }
            }


            // For nonempty bundles, clear contexts
            if (m_campaignBundle.FilePaths.Count > 0)
            {
                MyLocalization.Static.LoadBundle(m_campaignBundle, m_influencedContexts);
            }
        }
예제 #24
0
        public static MyStorageBase LoadFromFile(MyVoxelMap voxelMap, string absoluteFilePath)
        {
            if (!MyFileSystem.FileExists(absoluteFilePath))
            {
                var oldPath = Path.ChangeExtension(absoluteFilePath, "vox");
                UpdateFileFormat(oldPath);
                Debug.Assert(MyFileSystem.FileExists(absoluteFilePath));
            }
            Debug.Assert(absoluteFilePath.EndsWith(MyVoxelConstants.FILE_EXTENSION));

            byte[] compressedData = null;
            using (var file = MyFileSystem.OpenRead(absoluteFilePath))
            {
                compressedData = new byte[file.Length];
                file.Read(compressedData, 0, compressedData.Length);
            }
            return(Load(voxelMap, compressedData, Path.GetFileNameWithoutExtension(absoluteFilePath)));
        }
예제 #25
0
        private void ResolveMwmPaths(MyModContext modContext, MyObjectBuilder_AnimationTreeNode objBuilderNode)
        {
            // ------- tree node track -------
            var objBuilderNodeTrack = objBuilderNode as VRage.Game.ObjectBuilders.MyObjectBuilder_AnimationTreeNodeTrack;

            if (objBuilderNodeTrack != null && objBuilderNodeTrack.PathToModel != null)
            {
                string testMwmPath = Path.Combine(modContext.ModPath, objBuilderNodeTrack.PathToModel);
                if (MyFileSystem.FileExists(testMwmPath))
                {
                    objBuilderNodeTrack.PathToModel = testMwmPath;
                }
            }
            // ------ tree node mix -----------------------
            var objBuilderNodeMix1D = objBuilderNode as MyObjectBuilder_AnimationTreeNodeMix1D;

            if (objBuilderNodeMix1D != null)
            {
                if (objBuilderNodeMix1D.Children != null)
                {
                    foreach (var mappingObjBuilder in objBuilderNodeMix1D.Children)
                    {
                        if (mappingObjBuilder.Node != null)
                        {
                            ResolveMwmPaths(modContext, mappingObjBuilder.Node);
                        }
                    }
                }
            }
            // ------ tree node add -----------------------
            var objBuilderNodeAdd = objBuilderNode as MyObjectBuilder_AnimationTreeNodeAdd;

            if (objBuilderNodeAdd != null)
            {
                if (objBuilderNodeAdd.BaseNode.Node != null)
                {
                    ResolveMwmPaths(modContext, objBuilderNodeAdd.BaseNode.Node);
                }
                if (objBuilderNodeAdd.AddNode.Node != null)
                {
                    ResolveMwmPaths(modContext, objBuilderNodeAdd.AddNode.Node);
                }
            }
        }
예제 #26
0
        static string GetFilepath(string contentPath, string filepath)
        {
            if (string.IsNullOrEmpty(filepath))
            {
                return(null);
            }

            if (!string.IsNullOrEmpty(contentPath))
            {
                // Mod models may still refer to vanilla texture
                string path = Path.Combine(contentPath, filepath);
                if (MyFileSystem.FileExists(path))
                {
                    return(path);
                }
            }

            return(Path.Combine(MyFileSystem.ContentPath, filepath));
        }
        private void SavePrefab(MyGuiControlButton obj)
        {
            string name     = MyUtils.StripInvalidChars(MyClipboardComponent.Static.Clipboard.CopiedGridsName);
            string filePath = Path.Combine(MyFileSystem.UserDataPath, "Export", name + ".sbc");
            int    index    = 1;

            try
            {
                while (MyFileSystem.FileExists(filePath))
                {
                    filePath = Path.Combine(MyFileSystem.UserDataPath, "Export", name + "_" + index + ".sbc");
                    index++;
                }
                MyClipboardComponent.Static.Clipboard.SaveClipboardAsPrefab(name, filePath);
            }
            catch (Exception e)
            {
                MySandboxGame.Log.WriteLine(String.Format("Failed to write prefab at file {0}, message: {1}, stack:{2}", filePath, e.Message, e.StackTrace));
            }
        }
        private string GetImagePath(MyObjectBuilder_Campaign campaign)
        {
            string imagePath = campaign.ImagePath;

            if (string.IsNullOrEmpty(campaign.ImagePath))
            {
                return(string.Empty);
            }

            if (!campaign.IsVanilla)
            {
                imagePath = campaign.ModFolderPath != null?Path.Combine(campaign.ModFolderPath, campaign.ImagePath) : string.Empty;

                if (!MyFileSystem.FileExists(imagePath))
                {
                    imagePath = Path.Combine(MyFileSystem.ContentPath, campaign.ImagePath);
                }
            }

            return(imagePath);
        }
예제 #29
0
        private void CheckBuildProgressModels()
        {
            if (BuildProgressModels == null)
            {
                return;
            }

            foreach (var model in BuildProgressModels)
            {
                Debug.Assert(model != null, string.Format("Build progress model is null"));
                if (model == null)
                {
                    continue;
                }

                var path   = model.File;
                var fsPath = Path.IsPathRooted(path) ? path : Path.Combine(MyFileSystem.ContentPath, path);
                Debug.Assert(MyFileSystem.FileExists(fsPath) || MyFileSystem.FileExists(fsPath + ".mwm"),
                             string.Format("Build progress model does not exists: '{0}'", path));
            }
        }
예제 #30
0
        public static bool LoadFromFile(string filepath, out MyFileTextureParams outParams)
        {
            outParams = new MyFileTextureParams();
            if (string.IsNullOrEmpty(filepath))
            {
                return(false);
            }

            filepath = MyResourceUtils.GetTextureFullPath(filepath);
            if (m_dictCached.TryGetValue(filepath, out outParams))
            {
                return(true);
            }
            if (!MyFileSystem.FileExists(filepath))
            {
                MyRender11.Log.WriteLine("Missing texture: " + filepath);
                return(false);
            }

            try
            {
                using (var s = MyFileSystem.OpenRead(filepath))
                {
                    Image image = Image.Load(s);
                    outParams.Resolution.X = image.Description.Width;
                    outParams.Resolution.Y = image.Description.Height;
                    outParams.Format       = image.Description.Format;
                    outParams.Mipmaps      = image.Description.MipLevels;
                    outParams.ArraySize    = image.Description.ArraySize;
                }

                m_dictCached.Add(filepath, outParams);
                return(true);
            }
            catch (Exception)
            {
                MyRenderProxy.Assert(false, "The file in textures exists, but cannot be loaded. Please, investigate!");
                return(false);
            }
        }