Ejemplo n.º 1
0
        private static void AddFilesFromDirectory(AsmProject project, DirectoryInfo directory)
        {
            foreach (var file in directory.GetFiles())
            {
                var newFile = new AsmProjectFile {
                    Project = project, Mode = CompileMode.Ignore, File = file
                };

                if (newFile.Type == FileType.Image)
                {
                    newFile.Mode = CompileMode.ContentPipeline;
                }
                if (newFile.Type == FileType.Source)
                {
                    newFile.Mode = CompileMode.IncludeInAssembly;
                }

                project.Files.Add(newFile);
            }
            foreach (var subDirectory in directory.GetDirectories())
            {
                if (subDirectory.Name[0] == '.')
                {
                    continue;
                }
                AddFilesFromDirectory(project, subDirectory);
            }
        }
Ejemplo n.º 2
0
        public static AsmProject DeserializeBwmFile(FileInfo file)
        {
            var header = new ProjectFileHeader();

            var xmlDocument = new XmlDocument();

            xmlDocument.Load(file.FullName);
            string xmlString = xmlDocument.OuterXml;

            using (var read = new StringReader(xmlString))
            {
                var serializer = new XmlSerializer(typeof(ProjectFileHeader));
                using (var reader = new XmlTextReader(read))
                {
                    if (serializer.CanDeserialize(reader))
                    {
                        header = (ProjectFileHeader)serializer.Deserialize(reader);
                    }
                    else
                    {
                        serializer = new XmlSerializer(typeof(LegacyProjectFileHeaderV1));
                        var legacyHeader = (LegacyProjectFileHeaderV1)serializer.Deserialize(reader);
                        legacyHeader.FixCompatibility();
                        header = legacyHeader;
                    }
                }
            }

            var project = new AsmProject {
                Directory = file.Directory, ProjectFile = file
            };

            header.GetProjectModel(project);
            return(project);
        }
Ejemplo n.º 3
0
        public static AsmProject ImportFromDirectory(DirectoryInfo parentDirectory)
        {
            var project = new AsmProject {
                Directory = parentDirectory
            };

            AddFilesFromDirectory(project, parentDirectory);

            return(project);
        }
Ejemplo n.º 4
0
 public static string GetRelativePath(AsmProject project, string filePath)
 {
     if (filePath == null)
     {
         return(null);
     }
     if (filePath == project.Directory.FullName)
     {
         return("");
     }
     return(Uri.UnescapeDataString(new Uri(project.Directory.FullName + @"\")
                                   .MakeRelativeUri(new Uri(filePath)).ToString()));
 }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        // 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;
        }
Ejemplo n.º 7
0
        // EXPORT
        public static ProjectFileHeader GetFileHeader(AsmProject project)
        {
            var header         = new ProjectFileHeader();
            var fileReferences = new Dictionary <AsmProjectFile, int>();

            header.Type             = project.Type;
            header.Name             = project.Name;
            header.ExtraDirectories = project.Directories.Select(d => project.GetRelativePath(d.FullName)).ToArray();

            var filesHeaders = new List <ProjectFileFileHeader>();

            for (var i = 0; i < project.Files.Count; i++)
            {
                var file = project.Files[i];

                var fileHeader = new ProjectFileFileHeader();
                fileHeader.RelativePath = project.GetRelativePath(file.File.FullName);
                fileHeader.Id           = i;
                fileHeader.Mode         = file.Mode;
                if (file.Pipeline != null)
                {
                    var pipelineHeader = new PipelineHeader();
                    if (file.Pipeline is ChrPipeline)
                    {
                        pipelineHeader.Type = "chr";
                    }
                    file.Pipeline.GetSettings(pipelineHeader.Settings);
                    pipelineHeader.LastProcessed = file.Pipeline.LastProcessed;
                    pipelineHeader.Output        = file.Pipeline.OutputFiles.Select(project.GetRelativePath).ToArray();

                    fileHeader.Pipeline = pipelineHeader;
                }

                fileReferences.Add(file, i);
                filesHeaders.Add(fileHeader);
            }

            header.Files = filesHeaders.ToArray();
            var configurations = new List <BuildConfigurationHeader>();

            foreach (var c in project.BuildConfigurations)
            {
                var buildConfigurationHeader = new BuildConfigurationHeader
                {
                    Data = new[]
                    {
                        c.ChrBuildPath, c.PrgBuildPath, c.BuildPath, c.ChrFile,
                        c.DebugFile, c.Filename, c.LinkerConfigFile, c.MapFile, c.PrgFile,
                        c.Name, string.Join(",", c.Symbols), c.CalculateChecksum ? "1" : "0"
                    },
                    ChrBankFileIds = c.ChrBanks.Select(b =>
                                                       b.Sources.Select(f => fileReferences[f]).ToArray()).ToArray()
                };
                if (buildConfigurationHeader.ChrBankFileIds.Length == 0)
                {
                    buildConfigurationHeader.ChrBankFileIds = null;
                }
                configurations.Add(buildConfigurationHeader);
            }
            header.BuildConfigurations = configurations.ToArray();

            return(header);
        }