protected override void DoBuild(string[] extraClasspaths, bool noTrace) { string tempFile = null; Environment.CurrentDirectory = project.Directory; try { string objDir = "obj"; if (!Directory.Exists(objDir)) { Directory.CreateDirectory(objDir); } tempFile = GetTempProjectFile(project); //create new config file double sdkVersion = ParseVersion(FDBuild.Program.BuildOptions.CompilerVersion ?? "4.0"); // create compiler configuration file string projectName = project.Name.Replace(" ", ""); string backupConfig = Path.Combine(objDir, projectName + "Config.old"); string configFileTmp = Path.Combine(objDir, projectName + "Config.tmp"); string configFile = Path.Combine(objDir, projectName + "Config.xml"); // backup the old Config.xml to Config.old so we can reference it if (File.Exists(configFile)) { File.Copy(configFile, backupConfig, true); } //write "new" config to tmp FlexConfigWriter config = new FlexConfigWriter(project.GetAbsolutePath(configFileTmp)); config.WriteConfig(project, sdkVersion, extraClasspaths, noTrace == false, asc2Mode); //compare tmp to current bool configChanged = !File.Exists(backupConfig) || !File.Exists(configFile) || !FileComparer.IsEqual(configFileTmp, configFile); //copy temp file to config if there is a change if (configChanged) { File.Copy(configFileTmp, configFile, true); } //remove temp File.Delete(configFileTmp); MxmlcArgumentBuilder mxmlc = new MxmlcArgumentBuilder(project, sdkVersion, asc2Mode); mxmlc.AddConfig(configFile); mxmlc.AddOptions(noTrace, fcsh != null); mxmlc.AddOutput(tempFile); string mxmlcArgs = mxmlc.ToString(); if (asc2Mode) { mxmlcArgs = AddBaseConfig(mxmlcArgs); Console.WriteLine("mxmlc-cli " + mxmlcArgs); } else { Console.WriteLine("mxmlc " + mxmlcArgs); } CompileWithMxmlc(project.Directory, mxmlcArgs, configChanged); // if we get here, the build was successful string output = project.FixDebugReleasePath(project.OutputPathAbsolute); string outputDir = Path.GetDirectoryName(output); if (!Directory.Exists(outputDir)) { Directory.CreateDirectory(outputDir); } File.Copy(tempFile, output, true); } finally { if (tempFile != null && File.Exists(tempFile)) { File.Delete(tempFile); } } }
private void PatchFbProject(AS3Project project) { if (project == null || !project.MovieOptions.Platform.StartsWithOrdinal("AIR")) { return; } // We do this because the batch files cannot automatically detect the path changes caused by debug/release differences bool trace = project.TraceEnabled; project.TraceEnabled = false; project.OutputPath = project.FixDebugReleasePath(project.OutputPath); project.TraceEnabled = trace; string path = Path.GetDirectoryName(project.ProjectPath); string descriptor = "src\\" + Path.GetFileNameWithoutExtension(project.OutputPath) + "-app.xml"; project.TestMovieBehavior = TestMovieBehavior.Custom; project.TestMovieCommand = "bat\\RunApp.bat"; // CrossOver template related mod if (PlatformHelper.isRunningOnWine()) { project.TestMovieCommand += " $(TargetBuild)"; } if (!File.Exists(Path.Combine(path, descriptor))) { // Either it's some library project (we'll deal with these later) // or it's placed in some folder different to the default one (same as above) return; } // We copy the needed project template files bool isFlex = project.CompileTargets.Count > 0 && Path.GetExtension(project.CompileTargets[0]).ToLower() == ".mxml"; string projectPath; var excludedFiles = new List <string>(); // This could be a setting, in any case, decided to do this in case someone added custom files to the project templates... if (project.MovieOptions.Platform == "AIR Mobile") { projectPath = isFlex ? project.MovieOptions.PlatformSupport.GetProjectTemplate("flex") : project.MovieOptions.PlatformSupport.GetProjectTemplate("as3"); excludedFiles.AddRange(new[] { "application.xml.template", "Project.as3proj", "Project.png", "Project.txt", "bin", "cert", "icons", "src" }); } else { // The files are the same for Flex 3 and 4, so no need to discern them projectPath = isFlex ? project.MovieOptions.PlatformSupport.GetProjectTemplate("flex4") : project.MovieOptions.PlatformSupport.GetProjectTemplate("as3"); excludedFiles.AddRange(new[] { "application.xml.template", "Project.as3proj", "Project.png", "Project.txt", "bin", "src" }); } if (projectPath == null || !Directory.Exists(projectPath = Path.Combine(PathHelper.ProjectsDir, projectPath))) { string info = TextHelper.GetString("Info.TemplateDirNotFound"); ErrorManager.ShowWarning(info, null); return; } var creator = new ProjectCreator(); creator.SetContext(Path.GetFileNameWithoutExtension(project.OutputPath), string.Empty); foreach (var file in Directory.GetFiles(projectPath, "*.*", SearchOption.AllDirectories)) { bool excluded = false; foreach (var excludedFile in excludedFiles) { if (file.StartsWithOrdinal(Path.Combine(projectPath, excludedFile))) { excluded = true; break; } } if (excluded) { continue; } var fileDirectory = Path.GetDirectoryName(file).Replace(projectPath, string.Empty); if (fileDirectory.StartsWith('\\')) { fileDirectory = fileDirectory.Substring(1); } var folder = Path.Combine(path, fileDirectory); if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } string newFile = Path.Combine(folder, Path.GetFileName(file)); if (Path.GetExtension(file).ToLower() == ".template") { creator.CopyFile(file, newFile); } else { File.Copy(file, newFile, true); } } // We configure the batch files var configurator = new AirConfigurator { ApplicationSetupBatch = Path.Combine(path, "bat\\SetupApp.bat") }; configurator.ApplicationSetupParams[AirConfigurator.DescriptorPath] = descriptor; configurator.ApplicationSetupParams[AirConfigurator.PackageDir] = Path.GetFileName(Path.GetDirectoryName(project.OutputPath)); configurator.SetUp(); // We change the descriptor file so it targets our output file. FB does this dynamically. descriptor = Path.Combine(path, descriptor); var fileInfo = FileHelper.GetEncodingFileInfo(descriptor); string contents = Regex.Replace(fileInfo.Contents, "<content>\\[This value will be overwritten by (Flex|Flash) Builder in the output app.xml]</content>", "<content>" + Path.GetFileName(project.OutputPath) + "</content>"); FileHelper.WriteFile(descriptor, contents, Encoding.GetEncoding(fileInfo.CodePage), fileInfo.ContainsBOM); }