Exemplo 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);
            }
Exemplo n.º 2
0
        public HashSet <string> PreviewCloneDependencies(ModuleFile module, CloneObjectParameters cloneParameters)
        {
            HashSet <string> alreadyCloned = new HashSet <string>();

            module.Clone(cloneParameters, alreadyCloned, false);
            return(alreadyCloned);
        }
Exemplo n.º 3
0
        private void cloneDialogButton_Click(object sender, EventArgs e)
        {
            if (mCallback != null)
            {
                CloneObjectParameters parameters = new CloneObjectParameters();

                for (int row = 0; row < parametersTable.RowCount; row++)
                {
                    TextBox original    = parametersTable.GetControlFromPosition(0, row) as TextBox;
                    TextBox replacement = parametersTable.GetControlFromPosition(1, row) as TextBox;
                    if ((original != null) &&
                        (replacement != null) &&
                        (!string.IsNullOrWhiteSpace(original.Text)) &&
                        (!string.IsNullOrWhiteSpace(replacement.Text)))
                    {
                        parameters.AddStringReplacement(original.Text, replacement.Text);
                    }
                }

                bool isSuccess = mCallback.OnAccept(parameters);
                if (isSuccess)
                {
                    mCallback = null;
                    Close();
                }
            }
        }
Exemplo n.º 4
0
        public override bool Clone(string newPath, CloneObjectParameters parameters, HashSet <string> alreadyCloned, bool execute)
        {
            if (execute)
            {
                string newDirectory = System.IO.Path.GetDirectoryName(newPath);
                System.IO.Directory.CreateDirectory(newDirectory);
                if (!System.IO.File.Exists(newPath))
                {
                    System.IO.File.Copy(Path, newPath);
                }
            }

            string qmoPath = GetQmoPath();

            if (mIsQb && LinkedFileData.ContainsKey(qmoPath))
            {
                string newQmoPath = newPath.Replace(".qb", ".qmo");
                if (!alreadyCloned.Contains(newQmoPath))
                {
                    alreadyCloned.Add(newQmoPath);
                    LinkedFileData[qmoPath].Clone(newQmoPath, parameters, alreadyCloned, execute);
                }
            }

            return(true);
        }
Exemplo n.º 5
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);
        }
        /// <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);
        }
Exemplo n.º 7
0
        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 override bool Clone(string newPath, CloneObjectParameters parameters, HashSet<string> alreadyCloned, bool execute)
        {
            // Just pure file copy
            if (execute)
            {
                string newDirectory = System.IO.Path.GetDirectoryName(newPath);
                System.IO.Directory.CreateDirectory(newDirectory);
                if (!System.IO.File.Exists(newPath))
                {
                    System.IO.File.Copy(Path, newPath);
                }
            }

            return true;
        }
Exemplo n.º 9
0
        public override bool Clone(string newPath, CloneObjectParameters parameters, HashSet <string> alreadyCloned, bool execute)
        {
            // Just pure file copy
            if (execute)
            {
                string newDirectory = System.IO.Path.GetDirectoryName(newPath);
                System.IO.Directory.CreateDirectory(newDirectory);
                if (!System.IO.File.Exists(newPath))
                {
                    System.IO.File.Copy(Path, newPath);
                }
            }

            return(true);
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        private string ResolveLocalizedStrings(CloneObjectParameters parameters, string newFlatFile)
        {
            string pattern = @"(i18n\([\S]+\))";
            Regex  rgx     = new Regex(pattern, RegexOptions.IgnoreCase);

            MatchCollection matches = rgx.Matches(newFlatFile);

            if (matches.Count > 0)
            {
                foreach (Match match in matches)
                {
                    newFlatFile = newFlatFile.Replace(match.Value, ModuleDataManager.GetInstance().LocalizeString(match.Value));
                }
            }

            return(newFlatFile);
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
        public override bool ShouldCloneDependency(string dependencyName, CloneObjectParameters parameters)
        {
            if (JsonType == JSONTYPE.RECIPE)
            {
                JToken produces = mJson["produces"];
                if (produces != null)
                {
                    foreach (JToken child in produces.Children())
                    {
                        if (child["item"] != null && child["item"].ToString().Equals(dependencyName))
                        {
                            return(true);
                        }
                    }
                }
            }

            return(base.ShouldCloneDependency(dependencyName, parameters));
        }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
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));
        }
Exemplo n.º 16
0
        private void makeFineVersionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode selectedNode     = treeView.SelectedNode;
            FileData selectedFileData = ModuleDataManager.GetInstance().GetSelectedFileData(treeView.SelectedNode);

            if (!CanAddFineVersion(selectedFileData))
            {
                return;
            }

            JsonFileData          jsonFileData = selectedFileData as JsonFileData;
            ModuleFile            moduleFile   = jsonFileData.GetModuleFile();
            CloneObjectParameters parameters   = new CloneObjectParameters();

            parameters.AddStringReplacement(moduleFile.ShortName, moduleFile.ShortName + "_fine");
            parameters.AddAliasReplacement(moduleFile.ShortName + "_fine", moduleFile.ShortName + ":fine");
            HashSet <string>          dependencies = ModuleDataManager.GetInstance().PreviewCloneDependencies(selectedFileData, parameters);
            PreviewCloneAliasCallback callback     = new PreviewCloneAliasCallback(this, selectedFileData, parameters);
            PreviewCloneDialog        dialog       = new PreviewCloneDialog("Creating " + moduleFile.ShortName + ":fine", dependencies, callback);

            dialog.ShowDialog();
        }
Exemplo n.º 17
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);
        }
Exemplo n.º 18
0
 public virtual bool ShouldCloneDependency(string dependencyName, CloneObjectParameters parameters)
 {
     return parameters.IsDependency(dependencyName);
 }
Exemplo n.º 19
0
 // 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 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;
            }
Exemplo n.º 21
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;
        }
Exemplo n.º 22
0
 public override bool Clone(string newPath, CloneObjectParameters parameters, HashSet <string> alreadyCloned, bool execute)
 {
     return(base.Clone(newPath, parameters, alreadyCloned, execute));
 }
 public PreviewCloneFileCallback(EffectsEditorView viewer, FileData fileData, CloneObjectParameters parameters)
 {
     mViewer = viewer;
     mFileData = fileData;
     mParameters = parameters;
 }
 // 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 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(ModuleFile module, CloneObjectParameters cloneParameters)
 {
     HashSet<string> alreadyCloned = new HashSet<string>();
     module.Clone(cloneParameters, alreadyCloned, false);
     return alreadyCloned;
 }
Exemplo n.º 27
0
        private void addIconicVersionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode selectedNode = treeView.SelectedNode;
            FileData selectedFileData = ModuleDataManager.GetInstance().GetSelectedFileData(treeView.SelectedNode);
            if (!CanAddEntityForm(selectedFileData, "iconic"))
            {
                return;
            }

            JsonFileData jsonFileData = selectedFileData as JsonFileData;
            string originalFileName = jsonFileData.FileName;
            string iconicFilePath = jsonFileData.Directory + "/" + originalFileName + "_iconic.json";

            try
            {
                string iconicJson = System.Text.Encoding.UTF8.GetString(StonehearthEditor.Properties.Resources.defaultIconic);
                if (iconicJson != null)
                {
                    // Get a linked qb file
                    string newQbFile = null;
                    JToken defaultModelVariant = jsonFileData.Json.SelectToken("components.model_variants.default");
                    string defaultModelVariantNames = defaultModelVariant != null ? defaultModelVariant.ToString() : "";
                    foreach (FileData data in jsonFileData.LinkedFileData.Values)
                    {
                        if (data is QubicleFileData)
                        {
                            string fileName = data.FileName + ".qb";
                            if (defaultModelVariantNames.Contains(fileName))
                            {
                                CloneObjectParameters parameters = new CloneObjectParameters();
                                parameters.AddStringReplacement(data.FileName, data.FileName + "_iconic");
                                newQbFile = data.Path.Replace(".qb", "_iconic.qb");
                                data.Clone(newQbFile, parameters, new HashSet<string>(), true);
                            }
                        }
                    }

                    if (newQbFile != null)
                    {
                        string relativePath = JsonHelper.MakeRelativePath(iconicFilePath, newQbFile);
                        iconicJson = iconicJson.Replace("default_iconic.qb", relativePath);
                    }

                    try
                    {
                        JObject parsedIconicJson = JObject.Parse(iconicJson);
                        iconicJson = JsonHelper.GetFormattedJsonString(parsedIconicJson); // put it in the parser and back again to make sure we get valid json.

                        using (StreamWriter wr = new StreamWriter(iconicFilePath, false, new UTF8Encoding(false)))
                        {
                            wr.Write(iconicJson);
                        }
                    }
                    catch (Exception e2)
                    {
                        MessageBox.Show("Unable to write new iconic file because " + e2.Message);
                        return;
                    }

                    JObject json = jsonFileData.Json;
                    JToken entityFormsComponent = json.SelectToken("components.stonehearth:entity_forms");
                    if (entityFormsComponent == null)
                    {
                        if (json["components"] == null)
                        {
                            json["components"] = new JObject();
                        }

                        JObject entityForms = new JObject();
                        json["components"]["stonehearth:entity_forms"] = entityForms;
                        entityFormsComponent = entityForms;
                    }

                   (entityFormsComponent as JObject).Add("iconic_form", "file(" + originalFileName + "_iconic.json" + ")");
                    jsonFileData.TrySetFlatFileData(jsonFileData.GetJsonFileString());
                    jsonFileData.TrySaveFile();
                    MessageBox.Show("Adding file " + iconicFilePath);
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show("Unable to add iconic file because " + ee.Message);
                return;
            }

            Reload();
        }
        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;
        }
Exemplo n.º 29
0
 public PreviewCloneAliasCallback(ManifestView viewer, FileData fileData, CloneObjectParameters parameters)
 {
     mViewer     = viewer;
     mFileData   = fileData;
     mParameters = parameters;
 }
Exemplo n.º 30
0
        private void makeFineVersionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode selectedNode = treeView.SelectedNode;
            FileData selectedFileData = ModuleDataManager.GetInstance().GetSelectedFileData(treeView.SelectedNode);
            if (!CanAddFineVersion(selectedFileData))
            {
                return;
            }

            JsonFileData jsonFileData = selectedFileData as JsonFileData;
            ModuleFile moduleFile = jsonFileData.GetModuleFile();
            CloneObjectParameters parameters = new CloneObjectParameters();
            parameters.AddStringReplacement(moduleFile.ShortName, moduleFile.ShortName + "_fine");
            parameters.AddAliasReplacement(moduleFile.ShortName + "_fine", moduleFile.ShortName + ":fine");
            HashSet<string> dependencies = ModuleDataManager.GetInstance().PreviewCloneDependencies(selectedFileData, parameters);
            PreviewCloneAliasCallback callback = new PreviewCloneAliasCallback(this, selectedFileData, parameters);
            PreviewCloneDialog dialog = new PreviewCloneDialog("Creating " + moduleFile.ShortName + ":fine", dependencies, callback);
            dialog.ShowDialog();
        }
Exemplo n.º 31
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;
        }
Exemplo n.º 32
0
 public PreviewCloneFileCallback(EffectsEditorView viewer, FileData fileData, CloneObjectParameters parameters)
 {
     mViewer     = viewer;
     mFileData   = fileData;
     mParameters = parameters;
 }
Exemplo n.º 33
0
        private void addIconicVersionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode selectedNode     = treeView.SelectedNode;
            FileData selectedFileData = ModuleDataManager.GetInstance().GetSelectedFileData(treeView.SelectedNode);

            if (!CanAddEntityForm(selectedFileData, "iconic"))
            {
                return;
            }

            JsonFileData jsonFileData     = selectedFileData as JsonFileData;
            string       originalFileName = jsonFileData.FileName;
            string       iconicFilePath   = jsonFileData.Directory + "/" + originalFileName + "_iconic.json";

            try
            {
                string iconicJson = System.Text.Encoding.UTF8.GetString(StonehearthEditor.Properties.Resources.defaultIconic);
                if (iconicJson != null)
                {
                    // Get a linked qb file
                    string newQbFile                = null;
                    JToken defaultModelVariant      = jsonFileData.Json.SelectToken("components.model_variants.default");
                    string defaultModelVariantNames = defaultModelVariant != null?defaultModelVariant.ToString() : "";

                    foreach (FileData data in jsonFileData.LinkedFileData.Values)
                    {
                        if (data is QubicleFileData)
                        {
                            string fileName = data.FileName + ".qb";
                            if (defaultModelVariantNames.Contains(fileName))
                            {
                                CloneObjectParameters parameters = new CloneObjectParameters();
                                parameters.AddStringReplacement(data.FileName, data.FileName + "_iconic");
                                newQbFile = data.Path.Replace(".qb", "_iconic.qb");
                                data.Clone(newQbFile, parameters, new HashSet <string>(), true);
                            }
                        }
                    }

                    if (newQbFile != null)
                    {
                        string relativePath = JsonHelper.MakeRelativePath(iconicFilePath, newQbFile);
                        iconicJson = iconicJson.Replace("default_iconic.qb", relativePath);
                    }

                    try
                    {
                        JObject parsedIconicJson = JObject.Parse(iconicJson);
                        iconicJson = JsonHelper.GetFormattedJsonString(parsedIconicJson); // put it in the parser and back again to make sure we get valid json.

                        using (StreamWriter wr = new StreamWriter(iconicFilePath, false, new UTF8Encoding(false)))
                        {
                            wr.Write(iconicJson);
                        }
                    }
                    catch (Exception e2)
                    {
                        MessageBox.Show("Unable to write new iconic file because " + e2.Message);
                        return;
                    }

                    JObject json = jsonFileData.Json;
                    JToken  entityFormsComponent = json.SelectToken("components.stonehearth:entity_forms");
                    if (entityFormsComponent == null)
                    {
                        if (json["components"] == null)
                        {
                            json["components"] = new JObject();
                        }

                        JObject entityForms = new JObject();
                        json["components"]["stonehearth:entity_forms"] = entityForms;
                        entityFormsComponent = entityForms;
                    }

                    (entityFormsComponent as JObject).Add("iconic_form", "file(" + originalFileName + "_iconic.json" + ")");
                    jsonFileData.TrySetFlatFileData(jsonFileData.GetJsonFileString());
                    jsonFileData.TrySaveFile();
                    MessageBox.Show("Adding file " + iconicFilePath);
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show("Unable to add iconic file because " + ee.Message);
                return;
            }

            Reload();
        }
Exemplo n.º 34
0
 public virtual bool ShouldCloneDependency(string dependencyName, CloneObjectParameters parameters)
 {
     return(parameters.IsDependency(dependencyName));
 }
Exemplo n.º 35
0
 public override bool Clone(string newPath, CloneObjectParameters parameters, HashSet<string> alreadyCloned, bool execute)
 {
     return base.Clone(newPath, parameters, alreadyCloned, execute);
 }
Exemplo n.º 36
0
 public PreviewCloneAliasCallback(ManifestView viewer, FileData fileData, CloneObjectParameters parameters)
 {
     mViewer = viewer;
     mFileData = fileData;
     mParameters = parameters;
 }