Ejemplo n.º 1
0
        public static void Convert(IEnumerable <string> paths)
        {
            CfgFile file = new CfgFile();

            foreach (string path in paths)
            {
                //if path is directoy apply to all cfg files with in.
                if (Directory.Exists(path))
                {
                    Convert(Directory.GetFiles(path, "*.cfg", SearchOption.AllDirectories));
                }

                //if there is no file, skip
                else if (!File.Exists(path))
                {
                    continue;
                }

                string json_path = Path.ChangeExtension(path, "json");
                //skip if json already exits
                if (File.Exists(json_path))
                {
                    continue;
                }

                file.FromLines(File.ReadAllText(path));
                file.CollectionEntries.Add(new CollectionSprite()
                {
                    Name = FixName(Path.GetFileNameWithoutExtension(path))
                });

                File.WriteAllText(json_path, file.ToJson());
            }
        }
Ejemplo n.º 2
0
        public void SaveFile(string path)
        {
            //update binding in case the current control is a textbox,
            //because these only write once they lose foucus, which might not have happened yet.
            var bindings = this.ActiveControl?.DataBindings;

            if (bindings != null && bindings.Count != 0)
            {
                bindings[0].WriteValue();
            }

            if (!Data.DisplayEntries.IsDistinct(new DisplaySpriteUniqueComparer()))
            {
                throw new UserException("The combination of X, Y and ExtraBit settings must be unique for all entries in the Lunar Magic display sprites.");
            }

            Data.CustomMap16Data = map16Editor1.Map.GetNotEmptyData();

            string ext = Path.GetExtension(path);

            switch (ext.ToLower())
            {
            case ".cfg":
                File.WriteAllText(path, Data.ToLines());
                break;

            case ".json":
                File.WriteAllText(path, Data.ToJson());
                break;

            case ".smc":
            case ".sfc":
                Data.ToRomBytes(RomData, cmbType.SelectedIndex);
                File.WriteAllBytes(path, RomData);
                break;

            default:
                throw new FormatException($"Uknown file extension {ext}");
            }
        }