Exemplo n.º 1
0
        //public ElementSave ToElementSave(string projectroot, string extension)
        //{
        //    string fullName = projectroot + Subfolder + "/" + Name + "." + extension;

//    ElementSave elementSave = FileManager.XmlDeserialize<ElementSave>(fullName);

//    return elementSave;
//}


        public T ToElementSave <T>(string projectroot, string extension, GumLoadResult result, LinkLoadingPreference linkLoadingPreference = LinkLoadingPreference.PreferLinked) where T : ElementSave, new()
        {
            FilePath linkedName             = null;
            FilePath containedReferenceName = null;

            if (!string.IsNullOrWhiteSpace(this.Link))
            {
                linkedName = projectroot + this.Link;
            }
            containedReferenceName = projectroot + Subfolder + "/" + Name + "." + extension;

            if (linkedName != null && ToolsUtilities.FileManager.IsRelative(linkedName.Original))
            {
                linkedName = ToolsUtilities.FileManager.RelativeDirectory + linkedName.Original;
            }
            if (ToolsUtilities.FileManager.IsRelative(containedReferenceName.Original))
            {
                containedReferenceName = ToolsUtilities.FileManager.RelativeDirectory + containedReferenceName.Original;
            }

            if (linkedName?.Exists() == true)
            {
                T elementSave = FileManager.XmlDeserialize <T>(linkedName.FullPath);
                return(elementSave);
            }
            else if (containedReferenceName.Exists() && (linkedName == null || linkLoadingPreference == LinkLoadingPreference.PreferLinked))
            {
                T elementSave = FileManager.XmlDeserialize <T>(containedReferenceName.FullPath);

                if (Name != elementSave.Name)
                {
                    // The file name doesn't match the name of the element.  This can cause errors
                    // at runtime so let's tell the user:
                    result.ErrorMessage += "\nThe project references an element named " + Name + ", but the XML for this element has its name set to " + elementSave.Name + "\n";
                }

                return(elementSave);
            }
            else
            {
                // I don't think we want to consider this an error anymore
                // because Gum can handle it - it doesn't allow saving that
                // individual element and it shows a red ! next to the element.
                // We should just tolerate this and let the user deal with it.
                // If we do treat this as an error, then Gum goes into a state
                // where it can't save anything.
                //errors += "\nCould not find the file name " + fullName;
                // Update Feb 20, 2015
                // But we can record it:
                result.MissingFiles.Add(containedReferenceName.FullPath);


                T elementSave = new T();

                elementSave.Name = Name;
                elementSave.IsSourceFileMissing = true;

                return(elementSave);
            }
        }
Exemplo n.º 2
0
        static GumProjectSave LoadFromTitleStorage(string fileName, GumLoadResult result)
        {
            using (System.IO.Stream stream = Microsoft.Xna.Framework.TitleContainer.OpenStream(fileName))
            {
                GumProjectSave gps = FileManager.XmlDeserializeFromStream <GumProjectSave>(stream);

                string projectRootDirectory = FileManager.GetDirectory(fileName);

                gps.PopulateElementSavesFromReferences(projectRootDirectory, result);

                gps.FullFileName = fileName;

                return(gps);
            }
        }
Exemplo n.º 3
0
        public void ReloadElement(ElementSave element)
        {
            string projectRootDirectory = FileManager.GetDirectory(this.FullFileName);

            var gumLoadResult = new GumLoadResult();

            if (element is ScreenSave)
            {
                var matchingReference = ScreenReferences.FirstOrDefault(item => item.Name == element.Name);

                ScreenSave newScreen = matchingReference?.ToElementSave <ScreenSave>(
                    projectRootDirectory, GumProjectSave.ScreenExtension, gumLoadResult);

                if (newScreen != null)
                {
                    Screens.Remove(element as ScreenSave);
                    Screens.Add(newScreen);
                }
            }
            else if (element is ComponentSave)
            {
                var matchingReference = ComponentReferences.FirstOrDefault(item => item.Name == element.Name);

                ComponentSave newComonent = matchingReference?.ToElementSave <ComponentSave>(
                    projectRootDirectory, GumProjectSave.ComponentExtension, gumLoadResult);

                if (newComonent != null)
                {
                    Components.Remove(element as ComponentSave);
                    Components.Add(newComonent);
                }
            }
            else if (element is StandardElementSave)
            {
                var matchingReference = StandardElementReferences.FirstOrDefault(item => item.Name == element.Name);

                StandardElementSave newStandardElement = matchingReference?.ToElementSave <StandardElementSave>(
                    projectRootDirectory, GumProjectSave.ComponentExtension, gumLoadResult);

                if (newStandardElement != null)
                {
                    StandardElements.Remove(element as StandardElementSave);
                    StandardElements.Add(newStandardElement);
                }
            }
        }
Exemplo n.º 4
0
        public T ToElementSave <T>(string projectroot, string extension, GumLoadResult result) where T : ElementSave, new()
        {
            string fullName = projectroot + Subfolder + "/" + Name + "." + extension;

            if (ToolsUtilities.FileManager.IsRelative(fullName))
            {
                fullName = ToolsUtilities.FileManager.RelativeDirectory + fullName;
            }
            fullName = ToolsUtilities.FileManager.Standardize(fullName);


            if (FileManager.FileExists(fullName))
            {
                T elementSave = FileManager.XmlDeserialize <T>(fullName);

                if (Name != elementSave.Name)
                {
                    // The file name doesn't match the name of the element.  This can cause errors
                    // at runtime so let's tell the user:
                    result.ErrorMessage += "\nThe project references an element named " + Name + ", but the XML for this element has its name set to " + elementSave.Name + "\n";
                }

                return(elementSave);
            }
            else
            {
                // I don't think we want to consider this an error anymore
                // because Gum can handle it - it doesn't allow saving that
                // individual element and it shows a red ! next to the element.
                // We should just tolerate this and let the user deal with it.
                // If we do treat this as an error, then Gum goes into a state
                // where it can't save anything.
                //errors += "\nCould not find the file name " + fullName;
                // Update Feb 20, 2015
                // But we can record it:
                result.MissingFiles.Add(fullName);


                T elementSave = new T();

                elementSave.Name = Name;
                elementSave.IsSourceFileMissing = true;

                return(elementSave);
            }
        }
Exemplo n.º 5
0
        public static GumProjectSave Load(string fileName, out GumLoadResult result)
        {
            result = new GumLoadResult();
            if (string.IsNullOrEmpty(fileName))
            {
                result.ErrorMessage = "Passed null file name, could not load GumProjectSave";
                return(null);
            }

            if (FileManager.IsRelative(fileName))
            {
                fileName = FileManager.MakeAbsolute(fileName);
            }

            GumProjectSave gps = null;

#if ANDROID || IOS || WINDOWS_8
            gps = LoadFromTitleStorage(fileName, result);
#else
            try
            {
                gps = FileManager.XmlDeserialize <GumProjectSave>(fileName);
            }
            catch (FileNotFoundException)
            {
                result.MissingFiles.Add(fileName);
                return(null);
            }
            catch (IOException ex)
            {
                result.ErrorMessage = ex.Message;
                return(null);
            }
#endif

            string projectRootDirectory = FileManager.GetDirectory(fileName);

            gps.PopulateElementSavesFromReferences(projectRootDirectory, result);
            gps.FullFileName = fileName.Replace('\\', '/');

            return(gps);
        }
Exemplo n.º 6
0
        static GumProjectSave LoadFromTitleStorage(string fileName, GumLoadResult result)
        {
            using (System.IO.Stream stream = Microsoft.Xna.Framework.TitleContainer.OpenStream(fileName))
            {
                GumProjectSave gps = FileManager.XmlDeserializeFromStream<GumProjectSave>(stream);

                string projectRootDirectory = FileManager.GetDirectory(fileName);

                gps.PopulateElementSavesFromReferences(projectRootDirectory, result);

                gps.FullFileName = fileName;

                return gps;
            }
        }
Exemplo n.º 7
0
        private void PopulateElementSavesFromReferences(string projectRootDirectory, GumLoadResult result)
        {
            string errors = "";

            Screens.Clear();
            Components.Clear();
            StandardElements.Clear();

            foreach (ElementReference reference in ScreenReferences)
            {
                ScreenSave toAdd = null;
                try
                {
                    toAdd = reference.ToElementSave<ScreenSave>(projectRootDirectory, ScreenExtension, result);
                }
                catch (Exception e)
                {
                    errors += "\nError loading " + reference.Name + ":\n" + e.Message;
                }
                if (toAdd != null)
                {
                    Screens.Add(toAdd);
                }
            }

            foreach (ElementReference reference in ComponentReferences)
            {
                ComponentSave toAdd = null;

                try
                {
                    toAdd = reference.ToElementSave<ComponentSave>(projectRootDirectory, ComponentExtension, result);
                }
                catch (Exception e)
                {
                    errors += "\nError loading " + reference.Name + ":\n" + e.Message;
                }
                if (toAdd != null)
                {
                    Components.Add(toAdd);
                }
            }

            foreach (ElementReference reference in StandardElementReferences)
            {
                StandardElementSave toAdd = null;
                try
                {
                    toAdd = reference.ToElementSave<StandardElementSave>(projectRootDirectory, StandardExtension, result);
                }
                catch (Exception e)
                {
                    errors += "\nError loading " + reference.Name + ":\n" + e.Message;
                }
                if (toAdd != null)
                {
                    StandardElements.Add(toAdd);
                }
            }

            result.ErrorMessage += errors;
        }
Exemplo n.º 8
0
        public static GumProjectSave Load(string fileName, out GumLoadResult result)
        {
            result = new GumLoadResult();
            if (string.IsNullOrEmpty(fileName))
            {
                result.ErrorMessage = "Passed null file name, could not load GumProjectSave";
                return null;
            }

            GumProjectSave gps = null;

            #if ANDROID || IOS || WINDOWS_8
            gps = LoadFromTitleStorage(fileName, result);
            #else
            try
            {
                gps = FileManager.XmlDeserialize<GumProjectSave>(fileName);
            }
            catch (FileNotFoundException)
            {
                result.ErrorMessage = "The Gum project file does not exist";
                return null;
            }
            catch (IOException ex)
            {
                result.ErrorMessage = ex.Message;
                return null;
            }
            #endif

            string projectRootDirectory = FileManager.GetDirectory(fileName);

            gps.PopulateElementSavesFromReferences(projectRootDirectory, result);
            gps.FullFileName = fileName;

            return gps;
        }
Exemplo n.º 9
0
        private void PopulateElementSavesFromReferences(string projectRootDirectory, GumLoadResult result)
        {
            string errors = "";

            Screens.Clear();
            Components.Clear();
            StandardElements.Clear();
            Behaviors.Clear();

            foreach (ElementReference reference in ScreenReferences)
            {
                ScreenSave toAdd = null;
                try
                {
                    toAdd = reference.ToElementSave <ScreenSave>(projectRootDirectory, ScreenExtension, result);
                }
                catch (Exception e)
                {
                    errors += "\nError loading " + reference.Name + ":\n" + e.Message;
                }
                if (toAdd != null)
                {
                    Screens.Add(toAdd);
                }
            }

            foreach (ElementReference reference in ComponentReferences)
            {
                ComponentSave toAdd = null;

                try
                {
                    toAdd = reference.ToElementSave <ComponentSave>(projectRootDirectory, ComponentExtension, result);
                }
                catch (Exception e)
                {
                    errors += "\nError loading " + reference.Name + ":\n" + e.Message;
                }
                if (toAdd != null)
                {
                    Components.Add(toAdd);
                }
            }

            foreach (ElementReference reference in StandardElementReferences)
            {
                StandardElementSave toAdd = null;
                try
                {
                    toAdd = reference.ToElementSave <StandardElementSave>(projectRootDirectory, StandardExtension, result);
                }
                catch (Exception e)
                {
                    errors += "\nError loading " + reference.Name + ":\n" + e.Message;
                }
                if (toAdd != null)
                {
                    StandardElements.Add(toAdd);
                }
            }

            foreach (var reference in BehaviorReferences)
            {
                BehaviorSave toAdd = null;

                try
                {
                    toAdd = reference.ToBehaviorSave(projectRootDirectory);
                }
                catch (Exception e)
                {
                    errors += "\nError loading " + reference.Name + ":\n" + e.Message;
                }
                if (toAdd != null)
                {
                    Behaviors.Add(toAdd);
                }
            }

            result.ErrorMessage += errors;
        }
Exemplo n.º 10
0
 public static GumProjectSave Load(string fileName, out GumLoadResult result)
 {
     return(Load(fileName, LinkLoadingPreference.PreferLinked, out result));
 }
Exemplo n.º 11
0
        static GumProjectSave LoadFromTitleStorage(string fileName, LinkLoadingPreference linkLoadingPreference, GumLoadResult result)
        {
            using (System.IO.Stream stream = Microsoft.Xna.Framework.TitleContainer.OpenStream(fileName))
            {
                GumProjectSave gps = FileManager.XmlDeserializeFromStream <GumProjectSave>(stream);

                gps.FullFileName = fileName;

                return(gps);
            }
        }