Exemplo n.º 1
0
 private void ApplyVar(Mod mod)
 {
     this.LoadVar(mod);
     this.ReplaceVar(mod);
 }
Exemplo n.º 2
0
        public void ApplyCommands(Mod mod, XmlNode commandNode)
        {
            //XmlNode commandNode = mod.Xml.DocumentElement.SelectSingleNode ("command");
            //ReplaceVar (commandNode);
            int         index       = 0;
            XmlNodeList commandList = commandNode.ChildNodes;

            foreach (XmlNode command in commandList)
            {
                if (command.Name == "delete")
                {
                    string deleteDir = command.Attributes["target"].Value;
                    //deleteDir = filtPath(deleteDir, mod);
                    if (Directory.Exists(deleteDir))
                    {
                        DirectoryInfo dir = new DirectoryInfo(deleteDir);
                        dir.Delete(true);
                    }
                    else if (File.Exists(deleteDir))
                    {
                        FileInfo file = new FileInfo(deleteDir);
                        file.Delete();
                    }
                    else
                    {
                        throw new Exception("'" + deleteDir + "' not exits!");
                    }
                }
                if (command.Name == "copy")
                {
                    string from = command.Attributes ["from"].Value;
                    string to   = command.Attributes ["to"].Value;
                    //from = filtPath(from, mod);
                    //to = filtPath(to, mod);
                    Debug.Log("from: " + from);
                    Debug.Log("to: " + to);

                    if (Directory.Exists(from))
                    {
                        PShellUtil.CopyTo(new DirectoryInfo(from), new DirectoryInfo(to));
                    }
                    else if (File.Exists(from))
                    {
                        FileInfo fi = new FileInfo(from);
                        //FileInfo t = new FileInfo(to + "/" + fi.Name);
                        //t.Directory.Create();
                        fi.CopyTo(to, true);
                    }
                    else
                    {
                        throw new Exception("copy error: '" + from + "' not exsists!");
                    }

                    //--------------translate variables in these files--------------------
                    if (command.Attributes["translate-variables"] != null)
                    {
                        string        reg         = command.Attributes["translate-variables"].Value;
                        List <string> targetFiles = FindFile(to, reg);
                        TranslateVariables(mod, targetFiles);
                    }
                }
                if (command.Name == "copyInto")
                {
                    string from = command.Attributes ["from"].Value;
                    string into = command.Attributes ["into"].Value;
                    //from = filtPath(from, mod);
                    //into = filtPath(into, mod);
                    Debug.Log("from: " + from);
                    Debug.Log("into: " + into);

                    if (Directory.Exists(from))
                    {
                        PShellUtil.CopyInto(new DirectoryInfo(from), new DirectoryInfo(into));
                    }
                    else if (File.Exists(from))
                    {
                        FileInfo fi = new FileInfo(from);
                        FileInfo to = new FileInfo(into + "/" + fi.Name);
                        to.Directory.Create();
                        fi.CopyTo(to.FullName, true);
                    }
                    else
                    {
                        throw new Exception("copy error: '" + from + "' not exsists!");
                    }

                    //--------------translate variables in these files--------------------
                    if (command.Attributes["translate-variables"] != null)
                    {
                        FileInfo fi = new FileInfo(from);
                        FileInfo to = new FileInfo(into + "/" + fi.Name);

                        string        reg         = command.Attributes["translate-variables"].Value;
                        List <string> targetFiles = FindFile(to.FullName, reg);
                        TranslateVariables(mod, targetFiles);
                    }
                }

                if (command.Name == "add-lib-project")
                {
                    string modFilePath    = Path.Combine(this.rootPath, "project.properties");
                    string libProjectPath = command.Attributes["target"].Value;

                    FileInfo     file = new FileInfo(modFilePath);
                    StreamWriter sw   = file.AppendText();

                    List <string> lines = new List <string>();
                    index++;
                    lines.Add("android.library.reference." + index + "=./" + libProjectPath);

                    foreach (var line in lines)
                    {
                        sw.WriteLine(line);
                    }
                    sw.Close();
                }


                if (command.Name == "modify-code")
                {
                    string filePath = command.Attributes ["file"].Value;
                    //filePath = filtPath(filePath, mod);
                    if (!File.Exists(filePath))
                    {
                        throw new Exception("'" + filePath + "' not exits!");
                    }
                    string source = command.Attributes ["source"].Value;
                    string target = command.Attributes ["target"].Value;

                    XClass xc = new XClass(filePath);
                    xc.Replace(source, target);
                }
                if (command.Name == "rename")
                {
                    string from = command.Attributes ["from"].Value;
                    string to   = command.Attributes ["to"].Value;
                    //from = filtPath(from, mod);
                    //to = filtPath(to, mod);

                    if (Directory.Exists(from))
                    {
                        Directory.Move(from, to);
                    }
                    if (File.Exists(from))
                    {
                        File.Move(from, to);
                    }
                }
            }
        }