public Project NewProject() { NewProjectDialog dialog = new NewProjectDialog(); if (dialog.ShowDialog(owner) == DialogResult.OK) { try { FlashDevelopActions.CheckAuthorName(); ProjectCreator creator = new ProjectCreator(); return creator.CreateProject(dialog.TemplateDirectory, dialog.ProjectLocation, dialog.ProjectName, dialog.PackageName); } catch (Exception exception) { string msg = TextHelper.GetString("Info.CouldNotCreateProject"); ErrorManager.ShowInfo(msg + " " + exception.Message); } } return null; }
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); }