public Clone ( string newPath, |
||
newPath | string | |
parameters | ||
alreadyCloned | HashSet |
|
execute | bool | whether to actual execute the clone. otherwise, this is just a preview |
return | bool |
/// <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); }
public bool ExecuteClone(FileData file, CloneObjectParameters parameters, HashSet <string> unwantedItems) { ModuleFile owningFile = (file as IModuleFileData).GetModuleFile(); if (owningFile != null) { return(ExecuteClone(owningFile, parameters, unwantedItems)); } string newPath = parameters.TransformParameter(file.Path); return(file.Clone(newPath, parameters, unwantedItems, true)); }
public HashSet <string> PreviewCloneDependencies(FileData file, CloneObjectParameters cloneParameters) { ModuleFile owningFile = (file as IModuleFileData).GetModuleFile(); if (owningFile != null) { return(PreviewCloneDependencies(owningFile, cloneParameters)); } HashSet <string> alreadyCloned = new HashSet <string>(); string newPath = cloneParameters.TransformParameter(file.Path); file.Clone(newPath, cloneParameters, alreadyCloned, false); return(alreadyCloned); }
public HashSet <string> PreviewCloneDependencies(FileData file, CloneObjectParameters cloneParameters) { ModuleFile owningFile = (file as IModuleFileData).GetModuleFile(); if (owningFile != null) { return(PreviewCloneDependencies(owningFile, cloneParameters)); } HashSet <string> alreadyCloned = new HashSet <string>(); string newPath = TransformPath(file.Path, cloneParameters); // Code will only get here if owningFile is null, so calling the below will cause a null ref exception when indexing the owningFile // .Replace(owningFile.Module.Name, cloneParameters.TargetModule); file.Clone(newPath, cloneParameters, alreadyCloned, false); return(alreadyCloned); }
public bool Clone(CloneObjectParameters parameters, HashSet <string> alreadyCloned, bool execute) { string newAlias = parameters.TransformAlias(mAlias); string sourceModName = Module.Name; string targetModName = parameters.TargetModule == null ? sourceModName : parameters.TargetModule; Module targetModule = ModuleDataManager.GetInstance().GetMod(targetModName); if (targetModule.GetAliasFile(newAlias) != null) { // MessageBox.Show("The alias " + newAlias + " already exists in manifest.json"); return(false); } string modPath = targetModule.ParentDirectory; string relativePath = ResolvedPath.Replace(mModule.Path + "/", ""); string newPath = parameters.TransformParameter(relativePath); string fullPath = modPath + "/" + targetModName + "/" + newPath; if (!FileData.Clone(fullPath, parameters, alreadyCloned, execute)) { return(false); } alreadyCloned.Add(targetModName + ':' + newAlias); if (execute) { string fileLocation = "file(" + newPath + ")"; ModuleFile file = new ModuleFile(targetModule, newAlias, fileLocation); file.TryLoad(); if (file.FileData != null) { targetModule.AddToManifest(newAlias, fileLocation, parameters.manifestEntryType); targetModule.WriteManifestToFile(); return(true); } } else { return(true); } return(false); }
public bool Clone(CloneObjectParameters parameters, HashSet <string> alreadyCloned, bool execute) { string newAlias = parameters.TransformAlias(mAlias); if (mModule.GetAliasFile(newAlias) != null) { // MessageBox.Show("The alias " + newAlias + " already exists in manifest.json"); return(false); } string newPath = parameters.TransformParameter(ResolvedPath); if (!FileData.Clone(newPath, parameters, alreadyCloned, execute)) { return(false); } alreadyCloned.Add(mModule.Name + ':' + newAlias); if (execute) { string fileLocation = "file(" + newPath.Replace(mModule.Path + "/", "") + ")"; ModuleFile file = new ModuleFile(Module, newAlias, fileLocation); file.TryLoad(); if (file.FileData != null) { mModule.AddToManifest(newAlias, fileLocation); mModule.WriteManifestToFile(); return(true); } } else { return(true); } return(false); }
public HashSet<string> PreviewCloneDependencies(FileData file, CloneObjectParameters cloneParameters) { ModuleFile owningFile = (file as IModuleFileData).GetModuleFile(); if (owningFile != null) { return PreviewCloneDependencies(owningFile, cloneParameters); } HashSet<string> alreadyCloned = new HashSet<string>(); string newPath = cloneParameters.TransformParameter(file.Path); // Code will only get here if owningFile is null, so calling the below will cause a null ref exception when indexing the owningFile // .Replace(owningFile.Module.Name, cloneParameters.TargetModule); file.Clone(newPath, cloneParameters, alreadyCloned, false); return alreadyCloned; }
public bool ExecuteClone(FileData file, CloneObjectParameters parameters, HashSet<string> unwantedItems) { ModuleFile owningFile = (file as IModuleFileData).GetModuleFile(); if (owningFile != null) { return ExecuteClone(owningFile, parameters, unwantedItems); } string newPath = parameters.TransformParameter(file.Path); return file.Clone(newPath, parameters, unwantedItems, true); }