TransformParameter() public method

public TransformParameter ( string param ) : string
param string
return string
Esempio n. 1
0
            public bool OnAccept(CloneObjectParameters parameters)
            {
                // Do the cloning
                string originalName         = mFileData.GetNameForCloning();
                string potentialNewNodeName = parameters.TransformParameter(originalName);

                if (potentialNewNodeName.Length <= 1)
                {
                    MessageBox.Show("You must enter a name longer than 1 character for the clone!");
                    return(false);
                }

                if (potentialNewNodeName.Equals(originalName))
                {
                    MessageBox.Show("You must enter a new unique name for the clone!");
                    return(false);
                }

                HashSet <string> dependencies       = ModuleDataManager.GetInstance().PreviewCloneDependencies(mFileData, parameters);
                HashSet <string> savedUnwantedItems = mPreviewCallback != null?mPreviewCallback.GetSavedUnwantedItems() : null;

                mPreviewCallback = new PreviewCloneFileCallback(mViewer, mFileData, parameters);
                mPreviewCallback.SetUnwantedItems(savedUnwantedItems);
                PreviewCloneDialog dialog = new PreviewCloneDialog("Creating " + potentialNewNodeName, dependencies, mPreviewCallback);
                DialogResult       result = dialog.ShowDialog();

                if (result != DialogResult.OK)
                {
                    return(false);
                }

                return(true);
            }
Esempio n. 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);
        }
Esempio n. 3
0
            public bool OnAccept(HashSet <string> unwantedItems)
            {
                if (ModuleDataManager.GetInstance().ExecuteClone(mFileData, mParameters, unwantedItems))
                {
                    newFilePath = mParameters.TransformParameter(mFileData.Path);
                    mViewer.SetNewFilePath(newFilePath);
                    mViewer.Reload();
                }

                return(true);
            }
        /// <summary>
        /// Will do stringReplacements on the path, as well as adjust the path to the target module path
        /// </summary>
        /// <param name="path"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public string TransformPath(string path, CloneObjectParameters parameters)
        {
            string newPath       = string.Empty;
            string oldSourcePath = GetMod(parameters.SourceModule).ParentDirectory;
            string newTargetPath = GetMod(parameters.TargetModule).ParentDirectory;
            string cleanPath     = path.Replace(oldSourcePath, "");

            cleanPath = cleanPath.Replace(parameters.SourceModule, parameters.TargetModule);
            newPath   = newTargetPath + cleanPath;              // Do it this way to avoid weirdness while developing from stonehearth_data
            newPath   = parameters.TransformParameter(newPath); // and finally apply the string replacements
            return(newPath);
        }
        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);
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        public override bool Clone(string newPath, CloneObjectParameters parameters, HashSet <string> alreadyCloned, bool execute)
        {
            if (JsonType == JSONTYPE.RECIPE)
            {
                string newNameToUse = parameters.TransformParameter(GetNameForCloning()).Replace("_recipe", "");
                if (execute)
                {
                    JsonFileData recipesList = RelatedFiles[RelatedFiles.Count - 1] as JsonFileData;
                    // Only add the recipe to the recipe index if we're inside the same module
                    if (recipesList.Path.Contains(parameters.TargetModule))
                    {
                        JObject json        = recipesList.mJson;
                        JToken  foundParent = null;
                        foreach (JToken token in json["craftable_recipes"].Children())
                        {
                            if (foundParent != null)
                            {
                                break;
                            }

                            foreach (JToken recipe in token.First["recipes"].Children())
                            {
                                if (recipe.Last.ToString().Contains(FileName))
                                {
                                    foundParent = token.First["recipes"];
                                    break;
                                }
                            }
                        }

                        if (foundParent != null)
                        {
                            string recipeFileName = System.IO.Path.GetFileName(newPath);
                            (foundParent as JObject).Add(newNameToUse, JObject.Parse("{\"recipe\": \"file(" + recipeFileName + ")\"}"));
                            recipesList.TrySetFlatFileData(recipesList.GetJsonFileString());
                            recipesList.TrySaveFile();
                        }
                    }
                }
            }

            return(base.Clone(newPath, parameters, alreadyCloned, execute));
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        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;
        }
        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);
        }
            public bool OnAccept(CloneObjectParameters parameters)
            {
                // Do the cloning
                string originalName = mFileData.GetNameForCloning();
                string potentialNewNodeName = parameters.TransformParameter(originalName);
                if (potentialNewNodeName.Length <= 1)
                {
                    MessageBox.Show("You must enter a name longer than 1 character for the clone!");
                    return false;
                }

                if (potentialNewNodeName.Equals(originalName))
                {
                    MessageBox.Show("You must enter a new unique name for the clone!");
                    return false;
                }

                HashSet<string> dependencies = ModuleDataManager.GetInstance().PreviewCloneDependencies(mFileData, parameters);
                HashSet<string> savedUnwantedItems = mPreviewCallback != null ? mPreviewCallback.GetSavedUnwantedItems() : null;
                mPreviewCallback = new PreviewCloneFileCallback(mViewer, mFileData, parameters);
                mPreviewCallback.SetUnwantedItems(savedUnwantedItems);
                PreviewCloneDialog dialog = new PreviewCloneDialog("Creating " + potentialNewNodeName, dependencies, mPreviewCallback);
                DialogResult result = dialog.ShowDialog();
                if (result != DialogResult.OK)
                {
                    return false;
                }

                return true;
            }
Esempio n. 14
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 (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;
        }