Esempio n. 1
0
        /// <summary>
        /// Exports the project to COLT and optionally runs live session
        /// </summary>
        private void ExportAndOpen(Boolean run)
        {
            // Create COLT subfolder if does not exist yet
            // While at that, start listening for colt/compile_errors.log changes
            WatchErrorsLog(true);

            // Create COLT project in it
            COLTRemoteProject project = ExportCOLTProject();

            if (project != null)
            {
                try
                {
                    // Export the project as xml file
                    project.Save();

                    // Optionally run base compilation
                    if (run)
                    {
                        JsonRpcClient client = new JsonRpcClient(project.path);
                        client.PingOrRunCOLT(settingObject.Executable);
                        client.InvokeAsync("runBaseCompilation", HandleAuthenticationExceptions, new Object[] { settingObject.SecurityToken });
                    }

                    // Enable "open" button
                    toolbarButton2.Enabled = true;

                    // Remove older *.colt files
                    foreach (String oldFile in Directory.GetFiles(Path.GetDirectoryName(project.path), "*.colt"))
                    {
                        if (!project.path.Contains(Path.GetFileName(oldFile)))
                        {
                            File.Delete(oldFile);
                        }
                    }
                }
                catch (Exception details)
                {
                    HandleAuthenticationExceptions(details);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Exports FD project setting to COLTRemoteProject instance.
        /// </summary>
        /// <returns></returns>
        private COLTRemoteProject ExportCOLTProject()
        {
            // our options: parse project.ProjectPath (xml file) or use api
            AS3Project project = (AS3Project)PluginBase.CurrentProject;

            String configCopy = "";

            if (settingObject.FullConfig)
            {
                // Construct flex config file name (see AS3ProjectBuilder, line 140)
                String projectName = project.Name.Replace(" ", "");
                String configFile  = Path.Combine("obj", projectName + "Config.xml");

                if (!File.Exists(project.GetAbsolutePath(configFile)))
                {
                    TraceManager.Add("Required file (" + projectName + "Config.xml) does not exist, project must be built first...", -1);

                    try
                    {
                        allowBuildInterception = false;
                        EventManager.DispatchEvent(this, new DataEvent(EventType.Command, "ProjectManager.BuildProject", null));
                    }

                    finally
                    {
                        allowBuildInterception = true;
                    }

                    return(null);
                }

                // Create config copy with <file-specs>...</file-specs> commented out
                configCopy = Path.Combine("obj", projectName + "ConfigCopy.xml");
                File.WriteAllText(project.GetAbsolutePath(configCopy),
                                  File.ReadAllText(project.GetAbsolutePath(configFile))
                                  .Replace("<file-specs", "<!-- file-specs")
                                  .Replace("/file-specs>", "/file-specs -->"));
            }


            // Export COLT project
            COLTRemoteProject result = new COLTRemoteProject();

            result.path = project.GetAbsolutePath(Path.Combine(settingObject.WorkingFolder, System.Guid.NewGuid() + ".colt"));

            result.name = project.Name;

            List <String> libraryPathsList = new List <String>(project.CompilerOptions.LibraryPaths);

            for (int i = 0; i < libraryPathsList.Count; i++)
            {
                if (libraryPathsList[i].ToLower().EndsWith(".swc"))
                {
                    libraryPathsList[i] = @"..\" + libraryPathsList[i];
                }

                else
                {
                    // workaround (FD saves empty paths for missing libs)
                    libraryPathsList.RemoveAt(i); i--;
                }
            }
            result.libraries = libraryPathsList.ToArray();

            result.targetPlayerVersion = project.MovieOptions.Version + ".0";

            result.mainClass = project.GetAbsolutePath(project.CompileTargets[0]);

            result.flexSDKPath = project.CurrentSDK;

            if (settingObject.FullConfig)
            {
                result.customConfigPath = project.GetAbsolutePath(configCopy);
            }

            String outputPath = project.OutputPath;
            int    lastSlash  = outputPath.LastIndexOf(@"\");

            if (lastSlash > -1)
            {
                result.outputPath     = project.GetAbsolutePath(outputPath.Substring(0, lastSlash));
                result.outputFileName = outputPath.Substring(lastSlash + 1);
            }

            else
            {
                result.outputPath     = project.GetAbsolutePath("");
                result.outputFileName = outputPath;
            }

            String[] sourcePaths = project.SourcePaths.Clone() as String[];
            for (int i = 0; i < sourcePaths.Length; i++)
            {
                sourcePaths[i] = @"..\" + sourcePaths[i];
            }
            result.sources = sourcePaths;

            result.assets = AssetFolders;
            for (int i = 0; i < result.assets.Length; i++)
            {
                result.assets[i] = @"..\" + project.GetRelativePath(result.assets[i]);
            }

            // size, frame rate and background color
            String[] coltAdditionalOptionsKeys =
            {
                "-default-size",
                "-default-frame-rate",
                "-default-background-color"
            };
            String[] coltAdditionalOptions =
            {
                coltAdditionalOptionsKeys[0] + " " + project.MovieOptions.Width + " " + project.MovieOptions.Height,
                coltAdditionalOptionsKeys[1] + " " + project.MovieOptions.Fps,
                coltAdditionalOptionsKeys[2] + " " + project.MovieOptions.BackgroundColorInt
            };

            String additionalOptions = "";

            foreach (String option in project.CompilerOptions.Additional)
            {
                for (int i = 0; i < coltAdditionalOptionsKeys.Length; i++)
                {
                    if (option.Contains(coltAdditionalOptionsKeys[i]))
                    {
                        coltAdditionalOptions[i] = "";
                    }
                }
                additionalOptions += option + " ";
            }

            foreach (String option in coltAdditionalOptions)
            {
                additionalOptions += option + " ";
            }


            // compiler constants
            // see AddCompilerConstants in FDBuild's Building.AS3.FlexConfigWriter
            Boolean debugMode = project.TraceEnabled;
            Boolean isMobile  = (project.MovieOptions.Platform == AS3MovieOptions.AIR_MOBILE_PLATFORM);
            Boolean isDesktop = (project.MovieOptions.Platform == AS3MovieOptions.AIR_PLATFORM);

            additionalOptions += "-define+=CONFIG::debug," + (debugMode ? "true" : "false") + " ";
            additionalOptions += "-define+=CONFIG::release," + (debugMode ? "false" : "true") + " ";
            additionalOptions += "-define+=CONFIG::timeStamp,\"'" + DateTime.Now.ToString("d") + "'\" ";
            additionalOptions += "-define+=CONFIG::air," + (isMobile || isDesktop ? "true" : "false") + " ";
            additionalOptions += "-define+=CONFIG::mobile," + (isMobile ? "true" : "false") + " ";
            additionalOptions += "-define+=CONFIG::desktop," + (isDesktop ? "true" : "false") + " ";

            if (project.CompilerOptions.CompilerConstants != null)
            {
                foreach (string define in project.CompilerOptions.CompilerConstants)
                {
                    if (define.IndexOf(',') >= 0)
                    {
                        additionalOptions += "-define+=" + define + " ";
                    }
                }
            }

            result.compilerOptions = additionalOptions.Trim() + (debugMode ? " -debug" : "");

            return(result);
        }