コード例 #1
0
ファイル: Package.cs プロジェクト: cg123/xenko
        public static List<string> FindCodeAssetsInProject(string projectFullPath, out string nameSpace)
        {
            var realFullPath = new UFile(projectFullPath);
            var project = VSProjectHelper.LoadProject(realFullPath);
            var dir = new UDirectory(realFullPath.GetFullDirectory());

            var nameSpaceProp = project.AllEvaluatedProperties.FirstOrDefault(x => x.Name == "RootNamespace");
            nameSpace = nameSpaceProp?.EvaluatedValue ?? string.Empty;

            var result = project.Items.Where(x => (x.ItemType == "Compile" || x.ItemType == "None") && string.IsNullOrEmpty(x.GetMetadataValue("AutoGen")))
                .Select(x => new UFile(x.EvaluatedInclude)).Where(x => AssetRegistry.IsProjectSourceCodeAssetFileExtension(x.GetFileExtension()))
                .Select(projectItem => UPath.Combine(dir, projectItem)).Select(csPath => (string)csPath).ToList();

            project.ProjectCollection.UnloadAllProjects();
            project.ProjectCollection.Dispose();

            return result;
        }
コード例 #2
0
ファイル: SettingsGroup.cs プロジェクト: robterrell/paradox
        /// <summary>
        /// Saves the given settings profile to a file at the given path.
        /// </summary>
        /// <param name="profile">The profile to save.</param>
        /// <param name="filePath">The path of the file.</param>
        /// <returns><c>true</c> if the file was correctly saved, <c>false</c> otherwise.</returns>
        public bool SaveSettingsProfile(SettingsProfile profile, UFile filePath)
        {
            if (profile == null) throw new ArgumentNullException("profile");
            try
            {
                profile.Saving = true;
                Directory.CreateDirectory(filePath.GetFullDirectory());

                var settingsFile = new SettingsFile();
                EncodeSettings(profile, settingsFile.Settings);

                using (var stream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Write))
                {
                    YamlSerializer.Serialize(stream, settingsFile);
                }
            }
            catch (Exception e)
            {
                Logger.Error("Error while saving settings file [{0}]: {1}", e, filePath, e.FormatForReport());
                return false;
            }
            finally
            {
                profile.Saving = false;
            }
            return true;
        }
コード例 #3
0
        public static bool SanityCheck(UFile file)
        {
            var xmlDoc = XDocument.Load(file);
            if (xmlDoc.Root == null) return false;

            var nameSpace = xmlDoc.Root.Name.Namespace;

            var cellMaps = xmlDoc.Descendants(nameSpace + "cellmapNames").Descendants(nameSpace + "value").ToList();
            return cellMaps.Select(cellMap => UPath.Combine(file.GetFullDirectory(), new UFile(cellMap.Value))).All(fileName => File.Exists(fileName.ToWindowsPath()));
        }
コード例 #4
0
        public static bool ParseCellMaps(UFile file, List<UFile> textures, List<SpriteStudioCell> cells)
        {
            var xmlDoc = XDocument.Load(file);
            if (xmlDoc.Root == null) return false;

            var nameSpace = xmlDoc.Root.Name.Namespace;

            var cellMaps = xmlDoc.Descendants(nameSpace + "cellmapNames").Descendants(nameSpace + "value");

            foreach (var cellMap in cellMaps)
            {
                var mapFile = UPath.Combine(file.GetFullDirectory(), new UFile(cellMap.Value));
                var cellDoc = XDocument.Load(mapFile);
                if (cellDoc.Root == null) return false;

                var cnameSpace = cellDoc.Root.Name.Namespace;

                var cellNodes = cellDoc.Descendants(nameSpace + "cell");
                foreach (var cellNode in cellNodes)
                {
                    var cell = new SpriteStudioCell
                    {
                        Name = cellNode.Descendants(cnameSpace + "name").First().Value,
                        TextureIndex = textures.Count
                    };

                    var posData = cellNode.Descendants(nameSpace + "pos").First().Value;
                    var posValues = Regex.Split(posData, "\\s+");
                    var sizeData = cellNode.Descendants(nameSpace + "size").First().Value;
                    var sizeValues = Regex.Split(sizeData, "\\s+");
                    cell.Rectangle = new RectangleF(
                        float.Parse(posValues[0], CultureInfo.InvariantCulture),
                        float.Parse(posValues[1], CultureInfo.InvariantCulture),
                        float.Parse(sizeValues[0], CultureInfo.InvariantCulture),
                        float.Parse(sizeValues[1], CultureInfo.InvariantCulture));

                    var pivotData = cellNode.Descendants(nameSpace + "pivot").First().Value;
                    var pivotValues = Regex.Split(pivotData, "\\s+");
                    cell.Pivot = new Vector2((float.Parse(pivotValues[0], CultureInfo.InvariantCulture) + 0.5f) * cell.Rectangle.Width, (-float.Parse(pivotValues[1], CultureInfo.InvariantCulture) + 0.5f) * cell.Rectangle.Height);

                    cells.Add(cell);
                }

                var textPath = cellDoc.Descendants(nameSpace + "imagePath").First().Value;

                textures.Add(UPath.Combine(file.GetFullDirectory(), new UFile(textPath)));
            }

            return true;
        }
コード例 #5
0
        /// <summary>
        /// Saves the given settings profile to a file at the given path.
        /// </summary>
        /// <param name="profile">The profile to save.</param>
        /// <param name="filePath">The path of the file.</param>
        /// <returns><c>true</c> if the file was correctly saved, <c>false</c> otherwise.</returns>
        public bool SaveSettingsProfile(SettingsProfile profile, UFile filePath)
        {
            if (profile == null) throw new ArgumentNullException(nameof(profile));
            try
            {
                profile.Saving = true;
                Directory.CreateDirectory(filePath.GetFullDirectory());

                var settingsFile = new SettingsFile(profile);
                using (var stream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Write))
                {
                    SettingsYamlSerializer.Default.Serialize(stream, settingsFile);
                }

                if (filePath != profile.FilePath)
                {
                    if (File.Exists(profile.FilePath))
                    {
                        File.Delete(profile.FilePath);
                    }

                    profile.FilePath = filePath;
                }               
            }
            catch (Exception e)
            {
                Logger.Error("Error while saving settings file [{0}]: {1}", e, filePath, e.FormatFull());
                return false;
            }
            finally
            {
                profile.Saving = false;
            }
            return true;
        }
コード例 #6
0
ファイル: SettingsGroup.cs プロジェクト: ItayGal2/paradox
        /// <summary>
        /// Saves the given settings profile to a file at the given path.
        /// </summary>
        /// <param name="profile">The profile to save.</param>
        /// <param name="filePath">The path of the file.</param>
        /// <returns><c>true</c> if the file was correctly saved, <c>false</c> otherwise.</returns>
        public bool SaveSettingsProfile(SettingsProfile profile, UFile filePath)
        {
            if (profile == null) throw new ArgumentNullException("profile");
            try
            {
                profile.Saving = true;
                Directory.CreateDirectory(filePath.GetFullDirectory());

                var settingsFile = new SettingsFile();
                foreach (var entry in profile.Settings.Values)
                {
                    try
                    {
                        // Find key
                        SettingsKey key;
                        settingsKeys.TryGetValue(entry.Name, out key);
                        settingsFile.Settings.Add(entry.Name, entry.GetSerializableValue(key));
                    }
                    catch (Exception)
                    {
                    }
                }

                using (var stream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Write))
                {
                    YamlSerializer.Serialize(stream, settingsFile);
                }
            }
            catch (Exception e)
            {
                Logger.Error("Error while saving settings file [{0}]: {1}", e, filePath, e.FormatForReport());
                return false;
            }
            finally
            {
                profile.Saving = false;
            }
            return true;
        }