public TransformAlias ( string alias ) : string | ||
alias | string | |
return | string |
/// <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 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 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 newPath = parameters.TransformParameter(ResolvedPath.Replace(sourceModName, targetModName)); if (!FileData.Clone(newPath, parameters, alreadyCloned, execute)) { return false; } alreadyCloned.Add(targetModName + ':' + newAlias); if (execute) { string fileLocation = "file(" + newPath.Replace(mModule.Path.Replace(sourceModName, targetModName) + "/", "") + ")"; ModuleFile file = new ModuleFile(targetModule, newAlias, fileLocation); file.TryLoad(); if (file.FileData != null) { targetModule.AddToManifest(newAlias, fileLocation); targetModule.WriteManifestToFile(); return true; } } else { return true; } return false; }
/// <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 (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 linkedPath = ModuleDataManager.GetInstance().ModsDirectoryPath + transformedDependencyName; string newDependencyPath = ModuleDataManager.GetInstance().ModsDirectoryPath + parameters.TransformParameter(transformedDependencyName); if (!alreadyCloned.Contains(newDependencyPath)) { alreadyCloned.Add(newDependencyPath); dependencyFile.Clone(newDependencyPath, parameters, alreadyCloned, execute); } } } } if (execute) { string newFlatFile = parameters.TransformParameter(FlatFileData); using (StreamWriter wr = new StreamWriter(newPath, false, new UTF8Encoding(false))) { wr.Write(newFlatFile); } } return true; }