Exemple #1
0
        public static AsmProject ImportFromFile(FileInfo file)
        {
            var project = new AsmProject {
                Directory = file.Directory
            };
            var doc = new XmlDocument();

            doc.Load(file.FullName);
            var projectNode = doc.SelectSingleNode("nesicideproject");
            var properties  = projectNode.SelectSingleNode("properties");

            project.Name = projectNode.Attributes["title"].Value;
            var buildConfiguration = new NesCartridge
            {
                Name         = "NES",
                Filename     = "obj/" + properties.Attributes["cartridgeoutputname"].Value,
                PrgFile      = properties.Attributes["linkeroutputname"].Value,
                ChrFile      = properties.Attributes["chrromoutputname"].Value,
                PrgBuildPath = "obj/nes",
                DebugFile    = "obj/" + properties.Attributes["debuginfoname"].Value,
                ChrBuildPath = "obj/nes",
                BuildPath    = "obj/nes",
                MapFile      = "obj/map.txt"
            };

            if (buildConfiguration.Filename.EndsWith(".sfc"))
            {
                project.Type            = ProjectType.Snes;
                buildConfiguration.Name = "SNES";
            }
            project.BuildConfigurations.Add(buildConfiguration);
            var fileReferences = new Dictionary <string, AsmProjectFile>();

            foreach (XmlNode sourceNode in projectNode.SelectNodes("project/sources/source"))
            {
                var newFile = new AsmProjectFile {
                    Project = project, Mode = CompileMode.Ignore
                };
                newFile.File = new FileInfo(project.Directory.FullName + @"\" + sourceNode.Attributes["path"].Value);
                if (newFile.File.Extension.ToLower() == ".s")
                {
                    newFile.Mode = CompileMode.IncludeInAssembly;
                }
                project.Files.Add(newFile);

                fileReferences.Add(sourceNode.Attributes["uuid"].Value, newFile);
            }
            foreach (XmlNode sourceNode in projectNode.SelectNodes("project/binaryfiles/binaryfile"))
            {
                var relativeFilePath = sourceNode.Attributes["path"].Value;
                var newFile          = new AsmProjectFile {
                    Project = project, Mode = CompileMode.Ignore
                };
                newFile.File = new FileInfo(project.Directory.FullName + @"\" + relativeFilePath);
                if (newFile.Type == FileType.Image)
                {
                    newFile.Mode = CompileMode.ContentPipeline;
                    var baseFile = newFile.File.DirectoryName + @"\" + Path.GetFileNameWithoutExtension(newFile.File.Name);
                    newFile.Pipeline = new ChrPipeline(newFile, baseFile + ".chr", baseFile + ".pal");
                    //var directory = Path.GetDirectoryName(relativeFilePath);
                    //if (!string.IsNullOrWhiteSpace(directory)) directory += @"\";
                    //newFile.Pipeline = new ChrPipeline(newFile, directory + Path.GetFileNameWithoutExtension(relativeFilePath) + ".chr");
                }
                project.Files.Add(newFile);

                fileReferences.Add(sourceNode.Attributes["uuid"].Value, newFile);
            }
            foreach (XmlNode sourceNode in projectNode.SelectNodes("project/sounds/musics/music"))
            {
                var newFile = new AsmProjectFile {
                    Project = project, Mode = CompileMode.ContentPipeline
                };
                newFile.File = new FileInfo(project.Directory.FullName + @"\" + sourceNode.Attributes["name"].Value);
                project.Files.Add(newFile);

                fileReferences.Add(sourceNode.Attributes["uuid"].Value, newFile);
            }
            var linkerConfig = new AsmProjectFile {
                Project = project, Mode = CompileMode.LinkerConfig
            };

            linkerConfig.File = new FileInfo(project.Directory.FullName + @"\" + properties.Attributes["linkerconfigfile"].Value);
            project.Files.Add(linkerConfig);

            foreach (XmlNode bankNode in projectNode.SelectNodes("project/graphicsbanks/graphicsbank"))
            {
                var bank = new ChrBank();

                foreach (XmlNode dataNode in bankNode.SelectNodes("graphicitem"))
                {
                    bank.Sources.Add(fileReferences[dataNode.Attributes["uuid"].Value]);
                }

                buildConfiguration.ChrBanks.Add(bank);
            }

            return(project);
        }
        // IMPORT
        public void GetProjectModel(AsmProject project)
        {
            var errors         = new List <string>();
            var fileReferences = new Dictionary <int, AsmProjectFile>();

            project.Type = Type;
            project.Name = Name;
            if (ExtraDirectories != null)
            {
                project.Directories = ExtraDirectories
                                      .Select(d => new DirectoryInfo(Path.Combine(project.Directory.FullName, d)))
                                      .Where(d => d.Exists).ToList();
            }
            foreach (var fileHeader in Files)
            {
                var fileInfo = new FileInfo(Path.Combine(project.Directory.FullName, fileHeader.RelativePath));
                var file     = new AsmProjectFile {
                    Project = project
                };

                file.File = fileInfo;
                if (!fileInfo.Exists)
                {
                    file.Missing = true;
                }

                file.Mode = fileHeader.Mode;

                if (fileHeader.Pipeline != null)
                {
                    switch (fileHeader.Pipeline.Type)
                    {
                    case "chr":
                        // TODO: Deserialization method on the pipeline itself
                        var chrOutput     = Path.Combine(project.Directory.FullName, fileHeader.Pipeline.Output[0]);
                        var paletteOutput = fileHeader.Pipeline.Output.Length < 2 || fileHeader.Pipeline.Output[1] == null ? null : Path.Combine(project.Directory.FullName, fileHeader.Pipeline.Output[1]);

                        var pipeline = new ChrPipeline(file, chrOutput, paletteOutput, fileHeader.Pipeline.LastProcessed);
                        pipeline.SetSettings(fileHeader.Pipeline.Settings);
                        file.Pipeline = pipeline;
                        break;
                    }
                }

                fileReferences.Add(fileHeader.Id, file);
                project.Files.Add(file);
            }

            var buildConfigurations = new List <BuildConfigurationHeader>();

            if (Cartridge != null)
            {
                buildConfigurations.Add(Cartridge);
            }
            if (BuildConfigurations != null)
            {
                buildConfigurations.AddRange(BuildConfigurations);
            }

            foreach (var configurationHeader in buildConfigurations)
            {
                var cData         = configurationHeader.Data;
                var configuration = new NesCartridge
                {
                    ChrBuildPath      = cData[0],
                    PrgBuildPath      = cData[1],
                    BuildPath         = cData[2],
                    ChrFile           = cData[3],
                    DebugFile         = cData[4],
                    Filename          = cData[5],
                    LinkerConfigFile  = cData[6],
                    MapFile           = cData[7],
                    PrgFile           = cData[8],
                    Name              = cData.Length > 9 ? cData[9] : null,
                    Symbols           = cData.Length > 10 ? cData[10].Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList() : new List <string>(),
                    CalculateChecksum = cData.Length > 11 ? cData[11] != "0" : true,
                };
                if (configurationHeader.ChrBankFileIds != null)
                {
                    foreach (var bank in configurationHeader.ChrBankFileIds)
                    {
                        var chrBank = new ChrBank();
                        foreach (var fileId in bank)
                        {
                            chrBank.Sources.Add(fileReferences[fileId]);
                        }
                        configuration.ChrBanks.Add(chrBank);
                    }
                }
                project.BuildConfigurations.Add(configuration);
            }

            if (errors.Any())
            {
                throw new Exception(string.Join(Environment.NewLine, errors));
            }
            project.Pristine = true;
        }