Ejemplo n.º 1
0
        public void create()
        {
            var text = new TextFile(FullName);

            text.Append("");
            text.Save();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Used by property Path
        /// </summary>
        /// <param name="rcFile">setup file as used in a source statement for the shell, i.e. "~/.zshrc </param>
        /// <param name="newPath">the directory path to add, i.e. ~/.mlw</param>
        /// <returns>true if Path was added or was there already</returns>
        public static string PATH(string newPath = null, string rcFile = "~/.zshrc")
        {
            var shrc = new TextFile(rcFile);

            if (!shrc.Exists())
            {
                return(null);
            }
            if (!string.IsNullOrEmpty(newPath))
            {
                int pathInserted = -1, exportExists = -1;
                for (int i = 0; i < shrc.Lines.Count; i++)
                {
                    if (shrc.Lines[i].StartsWith("path+="))                     // TODO bashrc syntax
                    {
                        if (shrc.Lines[i] != $"path+={newPath}")
                        {
                            shrc.Insert(i, $"path+={newPath}");
                            // TODO bashrc syntax
                            pathInserted = i++;
                        }
                    }
                    if (shrc.Lines[i].Contains("export PATH"))
                    {
                        exportExists = i;
                    }
                }
                if (pathInserted < 0)
                {
                    if (exportExists < 0)
                    {
                        shrc.Append($"path+={newPath}");
                        shrc.Append("export PATH");
                    }
                }
                else if (exportExists < pathInserted)
                {
                    shrc.Append("export PATH");
                }
                shrc.Save();
            }
            return(EnvironmentVariables["PATH"]);
        }
Ejemplo n.º 3
0
        public void ToJsonFile(string destFileName = null)
        {
            var fName = string.IsNullOrEmpty(destFileName) ? new RaiFile(FullName) : new RaiFile(destFileName);

            fName.Ext = "json";
            var jsonFile = new TextFile(fName.FullName);

            jsonFile.rm();
            var fieldNames = FieldNames();
            Dictionary <string, string> item = null;
            string line;
            string value;
            long   l;
            double d;

            jsonFile.Append("[");
            for (int i = 1; i < Lines.Count; i++)
            {
                line = "{";
                item = this[i];
                foreach (string name in fieldNames)
                {
                    value = item[name];
                    if (!(long.TryParse(value, out l) || double.TryParse(value, out d)))                     // problem? => will parse long until '.' and ignore rest
                    {
                        value = "\"" + value + "\"";
                    }
                    line += $"\"{name}\": {value},";
                }
                jsonFile.Append(line.Substring(0, line.Length - 1) + "},");
            }
            int llNr     = jsonFile.Lines.Count - 1;
            var lastLine = jsonFile.Lines[llNr];

            jsonFile.Delete(llNr);
            jsonFile.Append(lastLine.Substring(0, lastLine.Length - 1) + "]");
            jsonFile.Save();
        }