public static void MakeSceneRelativeAndSave(Scene scene, string fileName, string contentManager, List<string> filesToMakeDotDotRelative, ReplaceTextureDelegate replaceTextureDelegate, SaveSceneDelegate saveDelegate) { if(replaceTextureDelegate == null) { replaceTextureDelegate = DefaultReplaceTexture; } mTexturesNotRelative.Clear(); mAnimationChainListsNotRelative.Clear(); mFntFilesNotRelative.Clear(); mModelsNotRelative.Clear(); mExtraFilesToCopy.Clear(); mSaveDelegate = saveDelegate; mLastFileName = fileName; mContentManager = contentManager; string pathOfFile = FileManager.GetDirectory(fileName); #region Find any not-relative Sprites foreach (Sprite s in scene.Sprites) { if (s.Texture == null) continue; string textureFileName = s.Texture.SourceFile(); if (!FileManager.IsRelativeTo(textureFileName, pathOfFile) && !mTexturesNotRelative.Contains(s.Texture)) { mTexturesNotRelative.Add(s.Texture); } if (s.AnimationChains != null && string.IsNullOrEmpty(s.AnimationChains.Name) == false && !FileManager.IsRelativeTo(s.AnimationChains.Name, pathOfFile) && !mAnimationChainListsNotRelative.Contains(s.AnimationChains)) { mAnimationChainListsNotRelative.Add(s.AnimationChains); } } #endregion #region Find any not-relative SpriteGrids foreach (SpriteGrid sg in scene.SpriteGrids) { List<Texture2D> usedTextures = sg.GetUsedTextures(); foreach (Texture2D texture in usedTextures) { if (!FileManager.IsRelativeTo(texture.SourceFile(), pathOfFile) && !mTexturesNotRelative.Contains(texture)) { mTexturesNotRelative.Add(texture); } } } #endregion #region Find any not-relative SpriteFrames foreach (SpriteFrame sf in scene.SpriteFrames) { if (!FileManager.IsRelativeTo(sf.Texture.SourceFile(), pathOfFile) && !mTexturesNotRelative.Contains(sf.Texture)) { mTexturesNotRelative.Add(sf.Texture); } } #endregion #region Find any not-relative Fonts (Text objects) foreach (Text t in scene.Texts) { BitmapFont bitmapFont = t.Font; if (bitmapFont == TextManager.DefaultFont) continue; foreach (Texture2D texture in bitmapFont.Textures) { if (!FileManager.IsRelativeTo(texture.SourceFile(), pathOfFile) && !mTexturesNotRelative.Contains(texture)) { mTexturesNotRelative.Add(texture); } } if (!FileManager.IsRelativeTo(bitmapFont.FontFile, pathOfFile) && !mFntFilesNotRelative.Contains(bitmapFont.FontFile)) { mFntFilesNotRelative.Add(bitmapFont.FontFile); } } #endregion #region Find any non-relative PositionedModels foreach (PositionedModel positionedModel in scene.PositionedModels) { if (!FileManager.IsRelativeTo(positionedModel.ModelFileName, pathOfFile) && !mModelsNotRelative.Contains(positionedModel.ModelFileName)) { mModelsNotRelative.Add(positionedModel.ModelFileName); } #if !FRB_MDX // Extra files which won't be re-referenced foreach (SourceReferencingFile extraFile in positionedModel.ExtraFiles) { if (!FileManager.IsRelativeTo(extraFile.DestinationFile, pathOfFile) && !mExtraFilesToCopy.Contains(extraFile.DestinationFile)) { mExtraFilesToCopy.Add(extraFile.DestinationFile); } } #endif } #endregion #region Loop through all AnimationChains and add any missing files foreach (AnimationChainList acl in mAnimationChainListsNotRelative) { foreach (AnimationChain chain in acl) { foreach (AnimationFrame frame in chain) { Texture2D texture = frame.Texture; if (!FileManager.IsRelativeTo(texture.SourceFile(), pathOfFile) && !mTexturesNotRelative.Contains(texture)) { mTexturesNotRelative.Add(texture); } } } } #endregion mLastFileName = fileName; mContentManager = contentManager; mSaveDelegate = saveDelegate; #region If there are files which are not relative, show the multi button message box SceneSaving = scene; mReplaceTextureDelegate = replaceTextureDelegate; string message = "The file\n\n" + fileName + "\n\nreferences the following which are not relative:"; CopyTexturesMultiButtonMessageBox mbmb = new CopyTexturesMultiButtonMessageBox(); mbmb.Text = message; mbmb.SaveClick += CopyAssetsToFileFolder; //mbmb.AddButton("Make all references relative using \"..\\\"", MakeSceneRelativeWithDotDots); //mbmb.AddButton("Copy textures to relative and reference copies.", new GuiMessage(CopyAssetsToFileFolder)); foreach (Texture2D texture in mTexturesNotRelative) { mbmb.AddItem(texture.SourceFile()); } foreach (AnimationChainList animationChainList in mAnimationChainListsNotRelative) { mbmb.AddItem(animationChainList.Name); } foreach (string s in mFntFilesNotRelative) { mbmb.AddItem(s); } foreach (string s in mModelsNotRelative) { mbmb.AddItem(s); } foreach (string s in mExtraFilesToCopy) { mbmb.AddItem(s); } //mbmb.FilesToMakeDotDotRelative = filesToMakeDotDotRelative; if (filesToMakeDotDotRelative.Count != mbmb.ItemsCount) { mbmb.FilesMarkedDotDotRelative = filesToMakeDotDotRelative; GuiManager.AddDominantWindow(mbmb); } else { saveDelegate(fileName, true); } #endregion }
public static void MakeSceneRelativeAndSave(Scene scene, string fileName, string contentManager, List <string> filesToMakeDotDotRelative, ReplaceTextureDelegate replaceTextureDelegate, SaveSceneDelegate saveDelegate) { if (replaceTextureDelegate == null) { replaceTextureDelegate = DefaultReplaceTexture; } mTexturesNotRelative.Clear(); mAnimationChainListsNotRelative.Clear(); mFntFilesNotRelative.Clear(); mModelsNotRelative.Clear(); mExtraFilesToCopy.Clear(); mSaveDelegate = saveDelegate; mLastFileName = fileName; mContentManager = contentManager; string pathOfFile = FileManager.GetDirectory(fileName); #region Find any not-relative Sprites foreach (Sprite s in scene.Sprites) { if (s.Texture == null) { continue; } string textureFileName = s.Texture.SourceFile(); if (!FileManager.IsRelativeTo(textureFileName, pathOfFile) && !mTexturesNotRelative.Contains(s.Texture)) { mTexturesNotRelative.Add(s.Texture); } if (s.AnimationChains != null && string.IsNullOrEmpty(s.AnimationChains.Name) == false && !FileManager.IsRelativeTo(s.AnimationChains.Name, pathOfFile) && !mAnimationChainListsNotRelative.Contains(s.AnimationChains)) { mAnimationChainListsNotRelative.Add(s.AnimationChains); } } #endregion #region Find any not-relative SpriteGrids foreach (SpriteGrid sg in scene.SpriteGrids) { List <Texture2D> usedTextures = sg.GetUsedTextures(); foreach (Texture2D texture in usedTextures) { if (!FileManager.IsRelativeTo(texture.SourceFile(), pathOfFile) && !mTexturesNotRelative.Contains(texture)) { mTexturesNotRelative.Add(texture); } } } #endregion #region Find any not-relative SpriteFrames foreach (SpriteFrame sf in scene.SpriteFrames) { if (!FileManager.IsRelativeTo(sf.Texture.SourceFile(), pathOfFile) && !mTexturesNotRelative.Contains(sf.Texture)) { mTexturesNotRelative.Add(sf.Texture); } } #endregion #region Find any not-relative Fonts (Text objects) foreach (Text t in scene.Texts) { BitmapFont bitmapFont = t.Font; if (bitmapFont == TextManager.DefaultFont) { continue; } foreach (Texture2D texture in bitmapFont.Textures) { if (!FileManager.IsRelativeTo(texture.SourceFile(), pathOfFile) && !mTexturesNotRelative.Contains(texture)) { mTexturesNotRelative.Add(texture); } } if (!FileManager.IsRelativeTo(bitmapFont.FontFile, pathOfFile) && !mFntFilesNotRelative.Contains(bitmapFont.FontFile)) { mFntFilesNotRelative.Add(bitmapFont.FontFile); } } #endregion #region Find any non-relative PositionedModels foreach (PositionedModel positionedModel in scene.PositionedModels) { if (!FileManager.IsRelativeTo(positionedModel.ModelFileName, pathOfFile) && !mModelsNotRelative.Contains(positionedModel.ModelFileName)) { mModelsNotRelative.Add(positionedModel.ModelFileName); } #if !FRB_MDX // Extra files which won't be re-referenced foreach (SourceReferencingFile extraFile in positionedModel.ExtraFiles) { if (!FileManager.IsRelativeTo(extraFile.DestinationFile, pathOfFile) && !mExtraFilesToCopy.Contains(extraFile.DestinationFile)) { mExtraFilesToCopy.Add(extraFile.DestinationFile); } } #endif } #endregion #region Loop through all AnimationChains and add any missing files foreach (AnimationChainList acl in mAnimationChainListsNotRelative) { foreach (AnimationChain chain in acl) { foreach (AnimationFrame frame in chain) { Texture2D texture = frame.Texture; if (!FileManager.IsRelativeTo(texture.SourceFile(), pathOfFile) && !mTexturesNotRelative.Contains(texture)) { mTexturesNotRelative.Add(texture); } } } } #endregion mLastFileName = fileName; mContentManager = contentManager; mSaveDelegate = saveDelegate; #region If there are files which are not relative, show the multi button message box SceneSaving = scene; mReplaceTextureDelegate = replaceTextureDelegate; string message = "The file\n\n" + fileName + "\n\nreferences the following which are not relative:"; CopyTexturesMultiButtonMessageBox mbmb = new CopyTexturesMultiButtonMessageBox(); mbmb.Text = message; mbmb.SaveClick += CopyAssetsToFileFolder; //mbmb.AddButton("Make all references relative using \"..\\\"", MakeSceneRelativeWithDotDots); //mbmb.AddButton("Copy textures to relative and reference copies.", new GuiMessage(CopyAssetsToFileFolder)); foreach (Texture2D texture in mTexturesNotRelative) { mbmb.AddItem(texture.SourceFile()); } foreach (AnimationChainList animationChainList in mAnimationChainListsNotRelative) { mbmb.AddItem(animationChainList.Name); } foreach (string s in mFntFilesNotRelative) { mbmb.AddItem(s); } foreach (string s in mModelsNotRelative) { mbmb.AddItem(s); } foreach (string s in mExtraFilesToCopy) { mbmb.AddItem(s); } //mbmb.FilesToMakeDotDotRelative = filesToMakeDotDotRelative; if (filesToMakeDotDotRelative.Count != mbmb.ItemsCount) { mbmb.FilesMarkedDotDotRelative = filesToMakeDotDotRelative; GuiManager.AddDominantWindow(mbmb); } else { saveDelegate(fileName, true); } #endregion }