Ejemplo n.º 1
0
        public static CssPatch Load(string fileName)
        {
            string[] lines = File.ReadAllLines(fileName);
            if (lines.Length < 3)
            {
                throw new InvalidDataException("Invalid file format.");
            }

            for (int n = 0; n < lines.Length; n++)
            {
                lines[n] = lines[n].Trim();
            }

            string description = lines[0];

            if (!description.StartsWith(PatchTitle))
            {
                throw new InvalidDataException("Invalid file format.");
            }

            description = description.Substring(PatchTitle.Length, description.Length - PatchTitle.Length - 2).Trim();
            CssPatch patch = new CssPatch(fileName, description);

            StringBuilder[] files = new StringBuilder[(int)CssPatchFile.Last];
            for (int n = 0; n < files.Length; n++)
            {
                files[n] = new StringBuilder();
            }
            StringBuilder currentFile = null;

            for (int n = 1; n < lines.Length; n++)
            {
                string line = lines[n];
                if (line.StartsWith(PatchFile))
                {
                    string file = line.Substring(PatchFile.Length, line.Length - PatchFile.Length - 2).Trim();
                    if (file == "Last")
                    {
                        throw new InvalidDataException("Invalid file format.");
                    }
                    currentFile = files[(int)Enum.Parse(typeof(CssPatchFile), file)];
                }
                else if (currentFile == null)
                {
                    throw new InvalidDataException("Invalid file format.");
                }
                else
                {
                    currentFile.Append(' ').Append(line);
                }
            }

            for (int n = 0; n < files.Length; n++)
            {
                patch.Files[n] = files[n].ToString();
            }
            return(patch);
        }
Ejemplo n.º 2
0
        public CssPatches()
        {
            Patches = new Dictionary <string, CssPatch>();

            string[] fileNames = Directory.GetFiles("sdpatch", "*.css");
            for (int n = 0; n < fileNames.Length; n++)
            {
                string fileName = fileNames[n];
                string name     = Path.GetFileNameWithoutExtension(fileName);
                try
                {
                    CssPatch patch = CssPatch.Load(fileName);
                    Patches.Add(name, patch);
                }
                catch (Exception)
                {
                    ColoredConsole.WriteLine("~y~KWarning:~k~Y patch file ~y~K{0}~k~Y is invalid.~N", name);
                }
            }
        }