예제 #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());
            }
        }
예제 #2
0
        public void LoadFile(string path)
        {
            if (!File.Exists(path))
            {
                throw new FileNotFoundException($"\"{path}\" not found.");
            }
            string ext = Path.GetExtension(path);

            switch (ext.ToLower())
            {
            case ".cfg":
                Data.FromLines(File.ReadAllText(path));
                FileType = FileType.CfgFile;
                break;

            case ".json":
                Data.FromJson(File.ReadAllText(path));
                FileType = FileType.CfgFile;
                break;

            case ".smc":
            case ".sfc":
                FileType = FileType.RomFile;
                break;

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

            if (FileType == FileType.CfgFile)
            {
                cmbType.DataSource = types_list;

                if (Data.Type == (int)CFG_SpriteType.GeneratorShooter)
                {
                    cmbType.SelectedIndex = 2;
                }
                else
                {
                    cmbType.SelectedIndex = Data.Type;
                }
            }
            else if (FileType == FileType.RomFile)
            {
                RomData            = File.ReadAllBytes(path);
                cmbType.DataSource = sprites_list;
            }

            control_enablers.ForEach(c => c.Evaluate());

            if (Data.DisplayEntries.Count == 0)
            {
                Data.DisplayEntries.Add(Map16.DisplaySprite.Default);
            }
            if (Data.CollectionEntries.Count == 0)
            {
                Data.CollectionEntries.Add(new CollectionSprite()
                {
                    Name = Converter.FixName(System.IO.Path.GetFileNameWithoutExtension(path))
                });
            }

            Unsaved  = false;
            Filename = path;
            map16Editor1.Map.ChangeData(Data.CustomMap16Data, 0x300);

            if (Data.CustomMap16Data.Length <= 0x800)
            {
                byte[] clear_data = new byte[0x800 - Data.CustomMap16Data.Length];
                map16Editor1.Map.ChangeData(clear_data, 0x300 + (Data.CustomMap16Data.Length / 8));
            }
        }