private void convert() { if (platformBox.Text.Length > 0 && profileBox.Text.Length > 0 && fileNames != null && fileNames.Length > 0) { statusLabel.Text = ""; bool shouldLog = logBox.Checked; bool buildStatus = false; XNBBuilder packager = new XNBBuilder(platformBox.Text, profileBox.Text, compressBox.Checked); packager.BuildAudioAsSongs = audioBox.Checked; packager.PackageContent(fileNames, outputDirectory, shouldLog, Path.GetDirectoryName(fileNames[0]), out buildStatus); //buildStatus will be true for a successful build, or else false for one that has failed. if (!buildStatus) { //If the build failed, we'll display that fact here. If they logged the conversion, they'll also see a note //to check the log, which is located in the same directory as the .exe and .dll are. statusLabel.Text = "Build Failed" + ((shouldLog)?("\r\n See Log"):("")); } else { //The build completed successfully, and we can end our conversion. statusLabel.Text = "Build Completed"; } try { //During the build, a file called "ContentPipeline.xml" is created and is what is used by the Content Pipeline to //determine what files are to be built. If we leave it alone, on the next build, all the previous build's files //are erased, for some internal reason. File.Delete("ContentPipeline.xml"); } catch { /* We don't care if the file doesn't exist (although it would be odd) */ } fileNames = null; displayFileNames = null; sourceFileTextBox.Text = ""; } else if (sourceFileTextBox.Text.Length == 0) { statusLabel.Text = "No Source Files\r\n Selected"; } }
static void Main(string[] args) { if (args.Length != 2) { return; } XNBBuilder xnbBuilder = new XNBBuilder("Windows", "Reach", false); bool buildStatus = false; string[] fileNames = new string[] { args[0] }; xnbBuilder.PackageContent(fileNames, args[1], false, Path.GetDirectoryName(fileNames[0]), out buildStatus); try { File.Delete("ContentPipeline.xml"); } catch { } }
private void DoXNBCompile(string fullpath, bool doFBXCheck, bool doIgnoreCheck = true) { FileInfo file = new FileInfo(fullpath); if (!file.Exists || !IsAcceptableFile(file) || (IsInIgnoredFolder(file) && doIgnoreCheck)) { return; } string outputFolder = file.DirectoryName; if (doFBXCheck && file.Extension.ToLowerInvariant() != ".fbx") { //Do the FBX texture workaround. //See if there is an FBX in this folder. string[] fbxFiles = Directory.GetFiles(outputFolder, "*.fbx"); if (fbxFiles.Length > 0) { //Yes. There is one or more FBXs in this folder. //Just recompile all the FBXs. TODO: figure out how to recompile only the affected FBX, and not all of them. for (int i = 0; i < fbxFiles.Length; i++) { DoXNBCompile(fbxFiles[i], false); } return; } } //Found a file. Process it. List <string> errorArray = new List <string>(); List <string> outputFiles = new List <string>(); bool buildStatus = false; try { XNBBuilder packager = new XNBBuilder("Windows", "HiDef", false); //packager.BuildAudioAsSongs = audioBox.Checked; packager.PackageContent(new string[] { fullpath }, outputFolder, false, outputFolder, out errorArray, out outputFiles, out buildStatus); } catch (Exception err) { AddLogInvoke(err.Message); buildStatus = false; } if (!buildStatus) { //Fail. listBox1.BackColor = Color.Pink; AddLogInvoke("Failed to export: {0}", file.Name); if (errorArray.Count > 0) { for (int i = 0; i < errorArray.Count; i++) { AddLogInvoke(errorArray[i]); } } AddLogInvoke("************* E R R O R *************"); //Flash the taskbar icon. MethodInvoker mi = delegate() { FlashWindow(this.Handle, false); }; this.Invoke(mi); } else { //Success. listBox1.BackColor = Color.GreenYellow; for (int i = 0; i < outputFiles.Count; i++) { string filename = Path.GetFileName(outputFiles[i]); AddLogInvoke(filename); } AddLogInvoke("- Export done -"); } //Clean up try { //Do some cleanup. string[] xmlFiles = Directory.GetFiles(Environment.CurrentDirectory, "*.xml"); for (int i = 0; i < xmlFiles.Length; i++) { if (File.Exists(xmlFiles[i])) { File.Delete(xmlFiles[i]); } } } catch { } AddLogInvoke(string.Empty); }