Clone() public method

public Clone ( CloneObjectParameters parameters, HashSet alreadyCloned, bool execute ) : bool
parameters CloneObjectParameters
alreadyCloned HashSet
execute bool
return bool
        public HashSet <string> PreviewCloneDependencies(ModuleFile module, CloneObjectParameters cloneParameters)
        {
            HashSet <string> alreadyCloned = new HashSet <string>();

            module.Clone(cloneParameters, alreadyCloned, false);
            return(alreadyCloned);
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="newPath"></param>
        /// <param name="oldName"></param>
        /// <param name="newFileName"></param>
        /// <param name="alreadyCloned"></param>
        /// <param name="execute">whether to actual execute the clone. otherwise, this is just a preview</param>
        /// <returns></returns>
        public virtual bool Clone(string newPath, CloneObjectParameters parameters, HashSet <string> alreadyCloned, bool execute)
        {
            // Ensure directory exists
            string directory = System.IO.Path.GetDirectoryName(newPath);

            alreadyCloned.Add(newPath);
            if (execute)
            {
                System.IO.Directory.CreateDirectory(directory);
            }

            // Figure out what dependency files need to exist
            foreach (KeyValuePair <string, FileData> dependencyKV in GetDependencies())
            {
                string   dependencyName = dependencyKV.Key;
                FileData dependencyFile = dependencyKV.Value;
                if (dependencyFile != null && ShouldCloneDependency(dependencyName, parameters))
                {
                    // We want to clone this dependency
                    IModuleFileData modFileData = dependencyFile as IModuleFileData;
                    if (modFileData != null && modFileData.GetModuleFile() != null)
                    {
                        // This dependency is an alias. Clone the alias.
                        ModuleFile linkedAlias  = modFileData.GetModuleFile();
                        string     aliasNewName = parameters.TransformAlias(dependencyName);
                        if (!alreadyCloned.Contains(aliasNewName))
                        {
                            alreadyCloned.Add(aliasNewName);
                            linkedAlias.Clone(parameters, alreadyCloned, execute);
                        }
                    }
                    else
                    {
                        // This dependency is just a FileData, clone the fileData.
                        string transformedDependencyName = parameters.TransformModPath(dependencyName);
                        string newDependencyPath         = ModuleDataManager.GetInstance().GetMod(parameters.TargetModule).ParentDirectory + parameters.TransformParameter(transformedDependencyName);
                        if (!alreadyCloned.Contains(newDependencyPath))
                        {
                            alreadyCloned.Add(newDependencyPath);
                            dependencyFile.Clone(newDependencyPath, parameters, alreadyCloned, execute);
                        }
                    }
                }
            }

            if (execute)
            {
                string flatFileData = ResolveLocalizedStrings(parameters, FlatFileData);
                string newFlatFile  = parameters.TransformParameter(flatFileData);

                using (StreamWriter wr = new StreamWriter(newPath, false, new UTF8Encoding(false)))
                {
                    wr.Write(newFlatFile);
                }
            }

            return(true);
        }
 // Call to clone an alias. top level. nested clone calls should call the module directly.
 public bool ExecuteClone(ModuleFile module, CloneObjectParameters parameters, HashSet <string> unwantedItems)
 {
     return(module.Clone(parameters, unwantedItems, true));
 }
 public HashSet<string> PreviewCloneDependencies(ModuleFile module, CloneObjectParameters cloneParameters)
 {
     HashSet<string> alreadyCloned = new HashSet<string>();
     module.Clone(cloneParameters, alreadyCloned, false);
     return alreadyCloned;
 }
 // Call to clone an alias. top level. nested clone calls should call the module directly.
 public bool ExecuteClone(ModuleFile module, CloneObjectParameters parameters, HashSet<string> unwantedItems)
 {
     return module.Clone(parameters, unwantedItems, true);
 }