Exemplo n.º 1
0
        /// <summary>
        /// Run project (after build)
        /// </summary>
        /// <param name="command">Project's custom run command</param>
        /// <returns>Execution handled</returns>
        static internal bool Run(string command)
        {
            if (!string.IsNullOrEmpty(command)) // project has custom run command
            {
                return(false);
            }

            HaxeProject hxproj = PluginBase.CurrentProject as HaxeProject;

            if (!HandleProject(hxproj))
            {
                return(false);
            }

            var platform  = hxproj.MovieOptions.PlatformSupport;
            var toolchain = platform.ExternalToolchain;
            var exe       = GetExecutable(toolchain);

            if (exe == null)
            {
                return(false);
            }

            string args = GetCommand(hxproj, "run");

            if (args == null)
            {
                return(false);
            }

            string config = hxproj.TargetBuild;

            if (String.IsNullOrEmpty(config))
            {
                config = "flash";
            }
            else if (config.IndexOfOrdinal("android") >= 0)
            {
                CheckADB();
            }

            if (config.StartsWithOrdinal("html5") && ProjectManager.Actions.Webserver.Enabled && hxproj.RawHXML != null) // webserver
            {
                foreach (string line in hxproj.RawHXML)
                {
                    if (line.StartsWithOrdinal("-js "))
                    {
                        string path = line.Substring(4);
                        path = path.Substring(0, path.LastIndexOf('/'));
                        ProjectManager.Actions.Webserver.StartServer(hxproj.GetAbsolutePath(path));
                        return(true);
                    }
                }
            }

            TraceManager.Add(toolchain + " " + args);

            if (hxproj.TraceEnabled && hxproj.EnableInteractiveDebugger) // debugger
            {
                DataEvent de;
                if (config.StartsWithOrdinal("flash"))
                {
                    de = new DataEvent(EventType.Command, "AS3Context.StartProfiler", null);
                    EventManager.DispatchEvent(hxproj, de);
                }
                de = new DataEvent(EventType.Command, "AS3Context.StartDebugger", null);
                EventManager.DispatchEvent(hxproj, de);
            }

            exe = Environment.ExpandEnvironmentVariables(exe);
            if (ShouldCapture(platform.ExternalToolchainCapture, config))
            {
                string oldWD = PluginBase.MainForm.WorkingDirectory;
                PluginBase.MainForm.WorkingDirectory = hxproj.Directory;
                PluginBase.MainForm.CallCommand("RunProcessCaptured", exe + ";" + args);
                PluginBase.MainForm.WorkingDirectory = oldWD;
            }
            else
            {
                var infos = new ProcessStartInfo(exe, args);
                infos.WorkingDirectory = hxproj.Directory;
                infos.WindowStyle      = ProcessWindowStyle.Hidden;
                Process.Start(infos);
            }
            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Run NME project (after build)
        /// </summary>
        /// <param name="command">Project's custom run command</param>
        /// <returns>Execution handled</returns>
        static public bool Run(string command)
        {
            if (!string.IsNullOrEmpty(command)) // project has custom run command
            {
                return(false);
            }

            HaxeProject project = PluginBase.CurrentProject as HaxeProject;

            if (project == null || project.OutputType != OutputType.Application)
            {
                return(false);
            }

            string builder = HaxeProject.GetBuilder(project);

            if (builder == null)
            {
                return(true);
            }

            string config = project.TargetBuild;

            if (String.IsNullOrEmpty(config))
            {
                config = "flash";
            }
            else if (config.IndexOf("android") >= 0)
            {
                CheckADB();
            }

            if (project.TraceEnabled)
            {
                config += " -debug -Dfdb";
            }
            //if (config.StartsWith("flash") && config.IndexOf("-DSWF_PLAYER") < 0)
            //    config += GetSwfPlayer();

            string args    = "run " + builder + " run \"" + project.OutputPathAbsolute + "\" " + config;
            string haxelib = GetHaxelib(project);

            if (config.StartsWith("html5") && ProjectManager.Actions.Webserver.Enabled && project.RawHXML != null) // webserver
            {
                foreach (string line in project.RawHXML)
                {
                    if (line.StartsWith("-js "))
                    {
                        string path = line.Substring(4);
                        path = path.Substring(0, path.LastIndexOf("/"));
                        ProjectManager.Actions.Webserver.StartServer(project.GetAbsolutePath(path));
                        return(true);
                    }
                }
            }

            TraceManager.Add("haxelib " + args);

            if (config.StartsWith("flash") || config.StartsWith("html5")) // no capture
            {
                if (config.StartsWith("flash") && project.TraceEnabled)   // debugger
                {
                    DataEvent de = new DataEvent(EventType.Command, "AS3Context.StartProfiler", null);
                    EventManager.DispatchEvent(project, de);
                    de = new DataEvent(EventType.Command, "AS3Context.StartDebugger", null);
                    EventManager.DispatchEvent(project, de);
                }

                var infos = new ProcessStartInfo(haxelib, args);
                infos.WorkingDirectory = project.Directory;
                infos.WindowStyle      = ProcessWindowStyle.Hidden;
                Process.Start(infos);
            }
            else
            {
                string oldWD = PluginBase.MainForm.WorkingDirectory;
                PluginBase.MainForm.WorkingDirectory = project.Directory;
                PluginBase.MainForm.CallCommand("RunProcessCaptured", haxelib + ";" + args);
                PluginBase.MainForm.WorkingDirectory = oldWD;
            }
            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Classpathes & classes cache initialisation
        /// </summary>
        public override void BuildClassPath()
        {
            ReleaseClasspath();
            started = true;
            if (hxsettings == null)
            {
                throw new Exception("BuildClassPath() must be overridden");
            }

            // external version definition
            // expected from project manager: "9;path;path..."
            flashVersion = hxsettings.DefaultFlashVersion;
            string exPath = externalClassPath ?? "";

            if (exPath.Length > 0)
            {
                try
                {
                    int p = exPath.IndexOf(';');
                    flashVersion = Convert.ToInt16(exPath.Substring(0, p));
                    exPath       = exPath.Substring(p + 1).Trim();
                }
                catch { }
            }

            // NOTE: version > 10 for non-Flash platforms
            string lang = null;

            features.Directives = new List <string>();
            if (IsJavaScriptTarget)
            {
                lang = "js";
                features.Directives.Add(lang);
            }
            else if (IsNekoTarget)
            {
                lang = "neko";
                features.Directives.Add(lang);
            }
            else if (IsPhpTarget)
            {
                lang = "php";
                features.Directives.Add(lang);
            }
            else if (IsCppTarget)
            {
                lang = "cpp";
                features.Directives.Add(lang);
            }
            else
            {
                features.Directives.Add("flash");
                features.Directives.Add("flash" + flashVersion);
                lang = (flashVersion >= 9) ? "flash9" : "flash";
            }
            features.Directives.Add("true");

            //
            // Class pathes
            //
            classPath = new List <PathModel>();
            // haXe std
            if (hxsettings.HaXePath != null)
            {
                string haxeCP = Path.Combine(hxsettings.HaXePath, "std");
                if (Directory.Exists(haxeCP))
                {
                    PathModel std = PathModel.GetModel(haxeCP, this);
                    if (!std.WasExplored && !Settings.LazyClasspathExploration)
                    {
                        PathExplorer stdExplorer = new PathExplorer(this, std);
                        stdExplorer.HideDirectories(new string[] { "flash", "flash9", "js", "neko", "php", "cpp" });
                        stdExplorer.OnExplorationDone += new PathExplorer.ExplorationDoneHandler(RefreshContextCache);
                        stdExplorer.Run();
                    }
                    AddPath(std);

                    PathModel specific = PathModel.GetModel(Path.Combine(haxeCP, lang), this);
                    if (!specific.WasExplored && !Settings.LazyClasspathExploration)
                    {
                        PathExplorer speExplorer = new PathExplorer(this, specific);
                        speExplorer.OnExplorationDone += new PathExplorer.ExplorationDoneHandler(RefreshContextCache);
                        speExplorer.Run();
                    }
                    AddPath(specific);
                }
            }
            HaxeProject proj = PluginBase.CurrentProject as HaxeProject;

            // swf-libs
            if (IsFlashTarget && flashVersion >= 9 && proj != null)
            {
                foreach (LibraryAsset asset in proj.LibraryAssets)
                {
                    if (asset.IsSwf)
                    {
                        string path = proj.GetAbsolutePath(asset.Path);
                        if (File.Exists(path))
                        {
                            AddPath(path);
                        }
                    }
                }
                foreach (string p in proj.CompilerOptions.Additional)
                {
                    if (p.IndexOf("-swf-lib ") == 0)
                    {
                        string path = proj.GetAbsolutePath(p.Substring(9));
                        if (File.Exists(path))
                        {
                            AddPath(path);
                        }
                    }
                }
            }

            // add haxe libraries
            if (proj != null)
            {
                foreach (string param in proj.BuildHXML(new string[0], "", false))
                {
                    if (param.IndexOf("-lib ") == 0)
                    {
                        AddPath(LookupLibrary(param.Substring(5)));
                    }
                }
            }


            // add external pathes
            List <PathModel> initCP = classPath;

            classPath = new List <PathModel>();
            string[] cpathes;
            if (exPath.Length > 0)
            {
                cpathes = exPath.Split(';');
                foreach (string cpath in cpathes)
                {
                    AddPath(cpath.Trim());
                }
            }
            // add user pathes from settings
            if (settings.UserClasspath != null && settings.UserClasspath.Length > 0)
            {
                foreach (string cpath in settings.UserClasspath)
                {
                    AddPath(cpath.Trim());
                }
            }
            // add initial pathes
            foreach (PathModel mpath in initCP)
            {
                AddPath(mpath);
            }

            // parse top-level elements
            InitTopLevelElements();
            if (cFile != null)
            {
                UpdateTopLevelElements();
            }

            // add current temporaty path
            if (temporaryPath != null)
            {
                string tempPath = temporaryPath;
                temporaryPath = null;
                SetTemporaryPath(tempPath);
            }
            FinalizeClasspath();
        }