示例#1
0
        public bool RemoveFile(ProjectItem item)
        {
            bool result = IncludedFiles.Remove(item);

            SaveProject();
            return(result);
        }
示例#2
0
 public ProjectItem this[string key]
 {
     get
     {
         return(IncludedFiles.FirstOrDefault(x => x.RelativePath == key));
     }
 }
示例#3
0
        /// <summary>
        ///     Include or just save fileName into current KeyValues Class
        /// </summary>
        /// <returns>
        ///     true if the sucessfully include file (KeyValue is valid); otherwise, false.
        /// </returns>
        /// <param name="fileName">File to include on current KeyValues Class</param>
        /// <param name="loadToKeyValues">if true will load file and in current KeyValues Class; otherwise false.</param>
        /// <param name="addToList">
        ///     if true on save KeyValues to HDD will put a #include macro for the fileName on correct place;
        ///     otherwise false.
        /// </param>
        public bool AddIncludeFile(string fileName, bool loadToKeyValues, bool addToList)
        {
            if (addToList)
            {
                if (!ExistsInclude(fileName))
                {
                    IncludedFiles.Add(fileName);
                }
            }
            if (loadToKeyValues)
            {
                var incKv = new KeyValues("include");
                if (!incKv.LoadFromFile(fileName))
                {
                    return(false);
                }

                /*incKv.FirstParent = Parent == null ? this : Parent.FirstParent;
                 * incKv.Parent = this;
                 * incKv.DistanceFromTop = DistanceFromTop + 1;*/
                Update(incKv, true);
                KeyChilds.Add(incKv);
            }
            return(true);
        }
示例#4
0
        public void AddFile(string filepath)
        {
            var item = new ProjectItem();

            item.RealPath     = filepath;
            item.RelativePath = filepath.Replace(ProjDirectory, "");
            IncludedFiles.Add(item);
            SaveProject();
        }
示例#5
0
        public override void ReadProject(string filepath)
        {
            ProjFilepath = filepath;
            var proj = new XmlDocument();

            proj.Load(filepath);

            var node = proj.SelectSingleNode("//Project");

            this.ToolVer = node.Attributes["ToolVer"].Value;
            this.GameVer = node.Attributes["GameVer"].Value;

            if (node.Attributes["Platform"].Value == "WiiU")
            {
                this.Platform = ProjPlatform.WiiU;
            }
            else if (node.Attributes["Platform"].Value == "3DS")
            {
                this.Platform = ProjPlatform.ThreeDS;
            }

            var nodes = proj.SelectNodes("//Project/FileGroup");

            foreach (XmlNode n in nodes)
            {
                foreach (XmlNode child in n.ChildNodes)
                {
                    var item = new ProjectItem();
                    item.RelativePath = Runtime.CanonicalizePath(child.Attributes["Include"].Value);
                    item.RealPath     = Runtime.CanonicalizePath(Path.Combine(ProjDirectory, item.RelativePath));
                    if (child.HasChildNodes)
                    {
                        foreach (XmlNode child2 in child.ChildNodes)
                        {
                            if (child2.LocalName == "DependsUpon")
                            {
                                var path = Runtime.CanonicalizePath(Path.Combine(Path.GetDirectoryName(item.RelativePath), child2.InnerText));
                                item.Depends.Add(IncludedFiles.Find(x => x.RelativePath == path));
                            }
                        }
                    }
                    if (child.Name == "Folder")
                    {
                        IncludedFolders.Add(item);
                    }
                    else
                    {
                        IncludedFiles.Add(item);
                    }
                }
            }
            ProjFile = proj;
        }
示例#6
0
        public void RenameFile(string filepath, string oldname, string newname)
        {
            var entry = IncludedFiles.FirstOrDefault(x => x.RealPath == filepath || x.RelativePath == filepath);

            entry.RelativePath = entry.RelativePath.Replace(oldname, newname);
            entry.RealPath     = entry.RealPath.Replace(oldname, newname);
            if (entry.RealPath.EndsWith(".fitproj"))
            {
                File.Move(entry.RealPath, entry.RealPath.Remove(Runtime.CanonicalizePath(entry.RealPath).LastIndexOf(Path.DirectorySeparatorChar)) + newname + ".fitproj");
            }
            else
            {
                File.Move(filepath, entry.RealPath);
            }
            SaveProject();
        }
示例#7
0
 /// <summary>
 ///     Check if a filename is already in the list
 /// </summary>
 /// <returns>
 ///     true if exists; otherwise, false.
 /// </returns>
 /// <param name="fileName">fileName to check.</param>
 public bool ExistsInclude(string fileName)
 {
     return(IncludedFiles.Any(t => t == fileName));
 }
示例#8
0
        public static async Task <StringBuilder> ParseAsync(string data, StateManager stateManager, IncludedFiles includedFiles, bool isInclude = false)
        {
            if (stateManager.NeedBase)
            {
                stateManager.NeedBase = false;
                // TODO - make this as base...
                await stateManager.Push("void Echo(string input) { builder.Append(input); } void Echo(byte[] buffer) { builder.Length = 0; Context.Response.OutputStream.Write(buffer, 0, buffer.Length); } ");
            }

            var builder = stateManager.Builder;

            var codeBuilder = new StringBuilder();
            int length      = data.Length;

            int startLength       = ScriptStart.Length;
            int endLength         = ScriptEnd.Length;
            int includeLength     = ScriptInclude.Length;
            int includeOnceLength = ScriptIncludeOnce.Length;

            bool inServerCode = false;

            string content;

            for (int i = 0; i < length; i++)
            {
                if (inServerCode)
                {
                    if (i + endLength <= length)
                    {
                        if (data[i] == '?' && data[i + 1] == '>')
                        {
                            i += 1;
                            if (codeBuilder.Length > 0)
                            {
                                content = codeBuilder.ToString();
                                if (!string.IsNullOrWhiteSpace(content))
                                {
                                    if (!isInclude)
                                    {
                                        await stateManager.Push(codeBuilder.ToString());
                                    }
                                }
                                if (!isInclude)
                                {
                                    codeBuilder.Length = 0;
                                }
                            }

                            inServerCode = false;
                            continue;
                        }
                    }

                    if (i + includeLength <= length &&
                        data[i] == 'i' && data[i + 1] == 'n' && data[i + 2] == 'c' && data[i + 3] == 'l' && data[i + 4] == 'u' && data[i + 5] == 'd' & data[i + 6] == 'e')
                    {
                        bool includeOnce = false;
                        if (i + includeOnceLength <= length)
                        {
                            if (data[i + 7] == '_' && data[i + 8] == 'o' && data[i + 9] == 'n' && data[i + 10] == 'c' && data[i + 11] == 'e')
                            {
                                includeOnce = true;
                            }
                        }

                        int x;
                        for (x = i; x < length && data[x] != '"'; x++)
                        {
                        }

                        if (x < length && data[x] == '"')
                        {
                            var path = new StringBuilder();
                            for (x = x + 1; x < length && data[x] != '"'; x++)
                            {
                                path.Append(data[x]);
                            }
                            if (x < length && data[x] == '"')
                            {
                                int increment = 2;
                                if (x + 1 < length && data[x + 1] == ';' || (x + 2 < length && data[x + 2] == ';' && (increment = 3) == 3))
                                {
                                    i = x + increment;                    // just incase they have ) at the end for php support.

                                    var file = path.ToString().ToLower(); // RIP LINUX
                                    if (!includedFiles.Files.Contains(file))
                                    {
                                        includedFiles.Files.Add(file);
                                    }
                                    else
                                    {
                                        if (includeOnce)
                                        {
                                            continue;
                                        }
                                    }

                                    codeBuilder.Append(await ParseAsync(System.IO.File.ReadAllText(Directory.GetCurrentDirectory() + "/wwwroot/" + file), stateManager, includedFiles, true));


                                    continue;
                                }
                            }
                        }
                    }

                    codeBuilder.Append(data[i]);
                }
                else
                {
                    if (i + startLength <= length)
                    {
                        if (data[i] == '<' && data[i + 1] == '?' && data[i + 2] == 'c' && data[i + 3] == 's')
                        {
                            i           += 3;
                            inServerCode = true;
                            continue;
                        }
                    }
                    stateManager.StateCache.Append(data[i]);
                    builder.Append(data[i]);
                }
            }

            return(isInclude ? codeBuilder : builder);
        }