private static bool FixLink(ProjectItem item, ProjectBase project) { bool didFix = false; string oldLink = item.GetLink(); string newLink = project.ProcessLink(oldLink); if (oldLink != newLink) { item.SetLink(newLink); didFix = true; } return didFix; }
private static bool AddAudioBuildItemToProject(ProjectBase project, ProjectItem buildItem) { bool wasAnythingChanged = false; // This item needs an associated entry in the project // The item will be relative to the main project as opposed // to the content project, inside the CopiedXnbs directory: string copiedXnb = ProjectManager.ProjectBase.Directory + "CopiedXnbs\\content\\" + buildItem.UnevaluatedInclude; var link = buildItem.GetLink(); if(!string.IsNullOrEmpty( link )) { copiedXnb = ProjectManager.ProjectBase.Directory + "CopiedXnbs\\content\\" + link; } copiedXnb = FileManager.RemoveDotDotSlash(copiedXnb); string extension = FileManager.GetExtension(buildItem.UnevaluatedInclude); bool isIos = project is IosMonogameProject; bool isAndroid = project is AndroidProject; string whatToAddToProject = null; // bool copyOriginalFile = (isIos || isAndroid) && FileManager.GetExtension(buildItem.UnevaluatedInclude) != "wav"; if (copyOriginalFile) { // Jan 1, 2014 // Not sure why // we were making // this file absolute // using the synced project's // directory. The file will be // shared by synced and original // projects so the file needs to be // made absolute according to that project. //whatToAddToProject = project.MakeAbsolute("content/" + buildItem.Include); whatToAddToProject = ProjectManager.MakeAbsolute("content/" + buildItem.UnevaluatedInclude, true); } else { whatToAddToProject = copiedXnb; } // Both sound and music files have XNBs associated with them so let's add that: whatToAddToProject = FileManager.RemoveExtension(whatToAddToProject) + ".xnb"; copiedXnb = FileManager.RemoveExtension(copiedXnb) + ".xnb"; var item = project.GetItem(whatToAddToProject, true); if (item == null) { item = project.AddContentBuildItem(whatToAddToProject, SyncedProjectRelativeType.Linked, false); string linkToSet = null; if (!string.IsNullOrEmpty(buildItem.GetLink())) { linkToSet = "Content\\" + FileManager.RemoveExtension(buildItem.GetLink()) + ".xnb"; } else { linkToSet = "Content\\" + FileManager.RemoveExtension(buildItem.UnevaluatedInclude) + ".xnb"; } if(project is AndroidProject) { linkToSet = "Assets\\" + linkToSet; } item.SetMetadataValue("Link", linkToSet); PluginManager.ReceiveOutput("Added " + buildItem.EvaluatedInclude + " through the file " + whatToAddToProject); wasAnythingChanged = true; } wasAnythingChanged |= FixLink(item, project); if (isIos && extension == "mp3") { if (FileManager.FileExists(copiedXnb)) { ReplaceWmaReferenceToMp3ReferenceInXnb(copiedXnb, whatToAddToProject); } } // I think we want to tell the user that the XNB is missing so they know to build the PC project if(!FileManager.FileExists(copiedXnb)) { PluginManager.ReceiveError("XNB file is missing - try rebuilding PC project: " + copiedXnb); } // Music files also have a wma file: if ((extension == "mp3" || extension == "wma") && // iOS doesn't ignore MP3, so it's already there. !isIos) { if (isIos) { whatToAddToProject = "Content\\" + buildItem.UnevaluatedInclude; } else { whatToAddToProject = FileManager.RemoveExtension(whatToAddToProject) + ".wma"; } var item2 = project.GetItem(whatToAddToProject, true); if (item2 == null) { item2 = project.AddContentBuildItem(whatToAddToProject, SyncedProjectRelativeType.Linked, false); item2.SetMetadataValue("Link", "Content\\" + FileManager.RemoveExtension(buildItem.UnevaluatedInclude) + "." + FileManager.GetExtension(whatToAddToProject)); PluginManager.ReceiveOutput("Added " + buildItem.EvaluatedInclude + " through the file " + whatToAddToProject); wasAnythingChanged = true; } wasAnythingChanged |= FixLink(item2, project); } return wasAnythingChanged; }