Esempio n. 1
0
        public List <string> GetMissingFiles()
        {
            List <string> texturesNotFound = new List <string>();

            // Get a list of all files that this .scnx references.  This won't return any duplicates
            List <string> allReferencedFiles = GetReferencedFiles(RelativeType.Relative);

            #region Set the FileManager.RelativeDirectory if necessary

            string oldRelativeDirectory = FileManager.RelativeDirectory;
            if (AssetsRelativeToSceneFile)
            {
                if (string.IsNullOrEmpty(ScenePath))
                {
                    throw new Exception("You must set ScenePath first before attempting to find missing files");
                }
                FileManager.RelativeDirectory = mSceneDirectory;
            }
            #endregion

            for (int i = 0; i < allReferencedFiles.Count; i++)
            {
                if (!FileManager.FileExists(allReferencedFiles[i]))
                {
                    texturesNotFound.Add(allReferencedFiles[i]);
                }
            }

            #region Set the FileManager.RelativeDirectory back to its old value

            FileManager.RelativeDirectory = oldRelativeDirectory;

            #endregion

            return(texturesNotFound);
        }
Esempio n. 2
0
        public T LoadFromProject <T>(string assetName)
        {
            string oldRelativePath = FileManager.RelativeDirectory;

            FlatRedBall.IO.FileManager.RelativeDirectory = FileManager.GetDirectory(assetName);



        #if DEBUG
            bool shouldCheckForXnb = true;

                #if ANDROID
            if (typeof(T) == typeof(Song))
            {
                shouldCheckForXnb = false;
            }
                #endif


            string fileToCheckFor = assetName + ".xnb";


            if (shouldCheckForXnb && !FileManager.FileExists(fileToCheckFor))
            {
                string errorString = "Could not find the file " + fileToCheckFor + "\n";

        #if !WINDOWS_8
                List <string> filesInDirectory = FileManager.GetAllFilesInDirectory(FileManager.GetDirectory(assetName), null, 0);

                errorString += "Found the following files:\n\n";

                foreach (string s in filesInDirectory)
                {
                    errorString += FileManager.RemovePath(s) + "\n";
                }
        #endif
                throw new FileNotFoundException(errorString);
            }
        #endif

        #if XNA4 && !MONOGAME
            if (!FileManager.IsRelative(assetName))
            {
                assetName = FileManager.MakeRelative(
                    assetName, System.Windows.Forms.Application.StartupPath + "/");
            }
        #endif

        #if USES_DOT_SLASH_ABOLUTE_FILES
            T asset;

            if (assetName.StartsWith(@".\") || assetName.StartsWith(@"./"))
            {
                asset = base.Load <T>(assetName.Substring(2));
            }
            else
            {
                asset = base.Load <T>(assetName);
            }
        #else
            T asset = base.Load <T>(assetName);
        #endif
            if (!mAssets.ContainsKey(assetName))
            {
                mAssets.Add(assetName, asset);
            }

            FileManager.RelativeDirectory = oldRelativePath;

            return(AdjustNewAsset(asset, assetName));
        }
Esempio n. 3
0
        public List <string> GetReferencedFiles(RelativeType relativeType)
        {
            List <string> referencedFiles = new List <string>();

            foreach (SpriteSave spriteSave in SpriteList)
            {
                spriteSave.GetReferencedFiles(referencedFiles);
            }

            foreach (SpriteGridSave spriteGridSave in SpriteGridList)
            {
                if (!string.IsNullOrEmpty(spriteGridSave.BaseTexture) && !referencedFiles.Contains(spriteGridSave.BaseTexture))
                {
                    referencedFiles.Add(spriteGridSave.BaseTexture);
                }

                foreach (string[] stringArray in spriteGridSave.GridTexturesArray)
                {
                    foreach (string texture in stringArray)
                    {
                        if (!string.IsNullOrEmpty(texture) && !referencedFiles.Contains(texture))
                        {
                            referencedFiles.Add(texture);
                        }
                    }
                }
            }

            foreach (SpriteFrameSave spriteFrameSave in SpriteFrameSaveList)
            {
                if (!string.IsNullOrEmpty(spriteFrameSave.ParentSprite.Texture) &&
                    !referencedFiles.Contains(spriteFrameSave.ParentSprite.Texture))
                {
                    referencedFiles.Add(spriteFrameSave.ParentSprite.Texture);
                }

                if (!string.IsNullOrEmpty(spriteFrameSave.ParentSprite.AnimationChainsFile) &&
                    !referencedFiles.Contains(spriteFrameSave.ParentSprite.AnimationChainsFile))
                {
                    referencedFiles.Add(spriteFrameSave.ParentSprite.AnimationChainsFile);
                }
            }

            foreach (TextSave textSave in TextSaveList)
            {
                string fontFile         = textSave.FontFile;
                bool   isThereAFontFile = !string.IsNullOrEmpty(fontFile);
                if (isThereAFontFile &&
                    !referencedFiles.Contains(fontFile))
                {
                    referencedFiles.Add(fontFile);
                }


                string textureFile = textSave.FontTexture;
                if (!string.IsNullOrEmpty(textureFile))
                {
                    if (!referencedFiles.Contains(textureFile))
                    {
                        referencedFiles.Add(textureFile);
                    }
                }
                else if (isThereAFontFile)
                {
                    // This may be a multi-texture font, so let's check for that
                    string absoluteFontDirectory = this.mSceneDirectory + fontFile;

                    if (FileManager.FileExists(absoluteFontDirectory))
                    {
                        string fontDirectory = FileManager.GetDirectory(fontFile, FlatRedBall.IO.RelativeType.Relative);

                        string contents = FileManager.FromFileText(absoluteFontDirectory);

                        string[] textures = BitmapFont.GetSourceTextures(contents);

                        for (int i = 0; i < textures.Length; i++)
                        {
                            string textureWithFontFileDirectory = textures[i];

                            //make the texture hae the font file's directory
                            textureWithFontFileDirectory = fontDirectory + textureWithFontFileDirectory;


                            if (!referencedFiles.Contains(textureWithFontFileDirectory))
                            {
                                referencedFiles.Add(textureWithFontFileDirectory);
                            }
                        }
                    }
                }
            }

            if (relativeType == RelativeType.Absolute)
            {
                string directory = this.ScenePath;

                for (int i = 0; i < referencedFiles.Count; i++)
                {
                    if (FileManager.IsRelative(referencedFiles[i]))
                    {
                        referencedFiles[i] = directory + referencedFiles[i];
                    }
                }
            }

            return(referencedFiles);
        }