Пример #1
0
        public CustomizationManager(CustomizationInitializationParameters initParams)
        {
            var writeableCdfPath = CryPak.AdjustFileName(initParams.CharacterDefinitionLocation, PathResolutionRules.RealPath | PathResolutionRules.ForWriting);

            var baseCdfPath = Path.Combine(CryPak.GameFolder, initParams.BaseCharacterDefinition);

            BaseDefinition = XDocument.Load(baseCdfPath);

            if (File.Exists(writeableCdfPath))
            {
                CharacterDefinition = XDocument.Load(writeableCdfPath);
            }
            else
            {
                var directory = new DirectoryInfo(Path.GetDirectoryName(writeableCdfPath));
                while (!directory.Exists)
                {
                    Directory.CreateDirectory(directory.FullName);

                    directory = Directory.GetParent(directory.FullName);
                }

                File.Copy(baseCdfPath, writeableCdfPath);

                CharacterDefinition = XDocument.Load(writeableCdfPath);
            }

            InitParameters = initParams;

            Initialize();
        }
Пример #2
0
 public void Save()
 {
     CharacterDefinition.Save(CryPak.AdjustFileName(InitParameters.CharacterDefinitionLocation, PathResolutionRules.RealPath | PathResolutionRules.ForWriting));
 }
Пример #3
0
        public void Save()
        {
            var basePath = Path.Combine(CryPak.GameFolder, BaseFilePath);

            if (!File.Exists(basePath + ".mtl"))
            {
                throw new CustomizationConfigurationException(string.Format("Could not save modified material, base {0} did not exist.", basePath));
            }

            var materialDocument = XDocument.Load(basePath + ".mtl");

            var materialElement = materialDocument.Element("Material");

            // Store boolean to determine whether we need to save to an alternate location.
            bool modifiedMaterial = false;

            if (Submaterials.Length == 0)
            {
                modifiedMaterial = UpdateMaterialElement(materialElement, this);
            }
            else
            {
                var subMaterialsElement = materialElement.Element("SubMaterials");

                var subMaterialElements = subMaterialsElement.Elements("Material");

                for (var i = 0; i < Submaterials.Length; i++)
                {
                    var subMaterial = Submaterials.ElementAt(i);

                    var modifiedSubMaterial = UpdateMaterialElement(subMaterialElements.FirstOrDefault(x =>
                    {
                        var nameAttribute = x.Attribute("Name");

                        if (nameAttribute != null)
                        {
                            return(nameAttribute.Value == subMaterial.BaseFilePath);
                        }

                        return(false);
                    }), subMaterial);

                    if (modifiedSubMaterial)
                    {
                        modifiedMaterial = modifiedSubMaterial;
                    }
                }
            }

            if (modifiedMaterial)
            {
                if (string.IsNullOrEmpty(FilePath))
                {
                    var chars       = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
                    var stringChars = new char[16];

                    for (int i = 0; i < stringChars.Length; i++)
                    {
                        stringChars[i] = chars[CustomizationManager.Selector.Next(chars.Length)];
                    }

                    var fileName = new string(stringChars);

                    FilePath = Path.Combine(Attachment.Slot.Manager.InitParameters.TempDirectory, "Materials", Attachment.Slot.Name, Attachment.Name ?? "unknown", fileName);
                }

                var fullFilePath = CryPak.AdjustFileName(FilePath, PathResolutionRules.RealPath | PathResolutionRules.ForWriting) + ".mtl";

                if (!File.Exists(fullFilePath))
                {
                    var directory = new DirectoryInfo(Path.GetDirectoryName(fullFilePath));
                    while (!directory.Exists)
                    {
                        Directory.CreateDirectory(directory.FullName);

                        directory = Directory.GetParent(directory.FullName);
                    }

                    var file = File.Create(fullFilePath);
                    file.Close();
                }

                materialDocument.Save(fullFilePath);
            }
            else
            {
                FilePath = BaseFilePath;
            }
        }