diff --git a/ColtPlugin/COLTRemoteProject.cs b/ColtPlugin/COLTRemoteProject.cs index 2917f47..d199092 100644 --- a/ColtPlugin/COLTRemoteProject.cs +++ b/ColtPlugin/COLTRemoteProject.cs @@ -1,4 +1,5 @@ -namespace ColtPlugin +using System.Xml; +namespace ColtPlugin { public class COLTRemoteProject { @@ -23,5 +24,124 @@ public class COLTRemoteProject public string outputPath; public string targetPlayerVersion; public string compilerOptions; + + public void Save() + { + // + XmlDocument doc = new XmlDocument(); + XmlElement root = (XmlElement)doc.AppendChild(doc.CreateElement("", "xml", "")); + root.Attributes.Append(doc.CreateAttribute("projectType")).Value = "AS"; + root.Attributes.Append(doc.CreateAttribute("projectName")).Value = name; + + // src + XmlElement paths = (XmlElement)root.AppendChild(doc.CreateElement("", "paths", "")); + ((XmlElement)paths.AppendChild(doc.CreateElement("", "sources-set", ""))).InnerText = string.Join(", ", sources); + ((XmlElement)paths.AppendChild(doc.CreateElement("", "libraries-set", ""))).InnerText = string.Join(", ", libraries); + ((XmlElement)paths.AppendChild(doc.CreateElement("", "assets-set", ""))).InnerText = string.Join(", ", assets); + ((XmlElement)paths.AppendChild(doc.CreateElement("", "html-template", ""))).InnerText = htmlTemplateDir; + + // + // + // /Applications/COLT/COLT.app/flex_sdk + // true + // false + // + // + XmlElement build = (XmlElement)root.AppendChild(doc.CreateElement("", "build", "")); + XmlElement sdk = (XmlElement)build.AppendChild(doc.CreateElement("", "sdk", "")); + XmlElement sdkPath = (XmlElement)sdk.AppendChild(doc.CreateElement("", "sdk-path", "")); + if ((flexSDKPath != null) && (flexSDKPath.Length > 0)) + { + sdkPath.InnerText = flexSDKPath; + } + else + { + sdkPath.InnerText = "${colt_home}/flex_sdk"; + } + ((XmlElement)sdk.AppendChild(doc.CreateElement("", "use-flex", ""))).InnerText = "true"; + XmlElement useCustom = (XmlElement)sdk.AppendChild(doc.CreateElement("", "use-custom", "")); + XmlElement customConfig = (XmlElement)sdk.AppendChild(doc.CreateElement("", "custom-config", "")); + if ((customConfigPath != null) && (customConfigPath.Length > 0)) + { + useCustom.InnerText = "true"; + customConfig.InnerText = customConfigPath; + } + else + { + useCustom.InnerText = "false"; + } + + // + // /Users/eliseyev/IdeaProjects/untitled/src/com/codeorchestra/Tree.as + // untitled.swf + // /Users/eliseyev/IdeaProjects/untitled/output + // true + // 11.8 + // false + // + // false + // false + // 30 + // + // + XmlElement build2 = (XmlElement)build.AppendChild(doc.CreateElement("", "build", "")); + ((XmlElement)build2.AppendChild(doc.CreateElement("", "main-class", ""))).InnerText = mainClass; + ((XmlElement)build2.AppendChild(doc.CreateElement("", "output-name", ""))).InnerText = outputFileName; + ((XmlElement)build2.AppendChild(doc.CreateElement("", "output-path", ""))).InnerText = outputPath; // FIXME: same path in below - leave it blank here?? + ((XmlElement)build2.AppendChild(doc.CreateElement("", "use-max-version", ""))).InnerText = "true"; + ((XmlElement)build2.AppendChild(doc.CreateElement("", "player-version", ""))).InnerText = targetPlayerVersion; + ((XmlElement)build2.AppendChild(doc.CreateElement("", "is-rsl", ""))).InnerText = "false"; + build2.AppendChild(doc.CreateElement("", "locale", "")); + ((XmlElement)build2.AppendChild(doc.CreateElement("", "is-exclude", ""))).InnerText = "false"; + ((XmlElement)build2.AppendChild(doc.CreateElement("", "is-interrupt", ""))).InnerText = "true"; // "false"; + ((XmlElement)build2.AppendChild(doc.CreateElement("", "interrupt-value", ""))).InnerText = "30"; + ((XmlElement)build2.AppendChild(doc.CreateElement("", "compiler-options", ""))).InnerText = compilerOptions; + + // + // /Users/eliseyev/IdeaProjects/untitled/output + // false + // false + // + // + // SWF + // + XmlElement production = (XmlElement)build.AppendChild(doc.CreateElement("", "production", "")); + ((XmlElement)production.AppendChild(doc.CreateElement("", "output-path", ""))).InnerText = outputPath; + ((XmlElement)production.AppendChild(doc.CreateElement("", "compress", ""))).InnerText = "false"; + ((XmlElement)production.AppendChild(doc.CreateElement("", "optimize", ""))).InnerText = "false"; + XmlElement runTarget = (XmlElement)build.AppendChild(doc.CreateElement("", "run-target", "")); + ((XmlElement)runTarget.AppendChild(doc.CreateElement("", "run-target", ""))).InnerText = "SWF"; + + // + // + // false + // false + // + // + // DEFAULT + // + // + // + // annotated + // false + // false + // 10000 + // + // + XmlElement live = (XmlElement)root.AppendChild(doc.CreateElement("", "live", "")); + XmlElement settings = (XmlElement)live.AppendChild(doc.CreateElement("", "settings", "")); + ((XmlElement)settings.AppendChild(doc.CreateElement("", "clear-log", ""))).InnerText = "true"; // "false"; + ((XmlElement)settings.AppendChild(doc.CreateElement("", "disconnect", ""))).InnerText = "true"; // "false"; + XmlElement launch = (XmlElement)live.AppendChild(doc.CreateElement("", "launch", "")); + ((XmlElement)launch.AppendChild(doc.CreateElement("", "launcher", ""))).InnerText = "DEFAULT"; + launch.AppendChild(doc.CreateElement("", "player-path", "")); + XmlElement live2 = (XmlElement)live.AppendChild(doc.CreateElement("", "live", "")); + ((XmlElement)live2.AppendChild(doc.CreateElement("", "live-type", ""))).InnerText = "annotated"; + ((XmlElement)live2.AppendChild(doc.CreateElement("", "paused", ""))).InnerText = "false"; + ((XmlElement)live2.AppendChild(doc.CreateElement("", "make-gs-live", ""))).InnerText = "false"; + ((XmlElement)live2.AppendChild(doc.CreateElement("", "max-loop", ""))).InnerText = "10000"; + + doc.Save(path); + } } } diff --git a/ColtPlugin/PluginMain.cs b/ColtPlugin/PluginMain.cs index 741fcd1..ec991a1 100644 --- a/ColtPlugin/PluginMain.cs +++ b/ColtPlugin/PluginMain.cs @@ -20,6 +20,7 @@ using ASCompletion.Context; using System.Text.RegularExpressions; using ASCompletion.Model; +using System.Xml; namespace ColtPlugin { @@ -358,7 +359,8 @@ private ToolStripButton CreateToolbarButton(ToolStrip toolStrip, String image, S private void OnClick(Object sender, EventArgs e) { - if (settingObject.SecurityToken != null) + ExportAndOpen(settingObject.AutoRun);//FIXME +/* if (settingObject.SecurityToken != null) { new AppStarter(ExportAndOpen, settingObject.AutoRun); } @@ -366,12 +368,13 @@ private void OnClick(Object sender, EventArgs e) else { new AppStarter(GetSecurityToken, true); - } + }*/ } private void OnClick2(Object sender, EventArgs e) { - if (settingObject.SecurityToken != null) + FindAndOpen(settingObject.AutoRun);//FIXME +/* if (settingObject.SecurityToken != null) { new AppStarter(FindAndOpen, settingObject.AutoRun); } @@ -379,7 +382,7 @@ private void OnClick2(Object sender, EventArgs e) else { new AppStarter(GetSecurityToken, true); - } + }*/ } #endregion @@ -391,14 +394,27 @@ private void OnClick2(Object sender, EventArgs e) /// public void LoadSettings() { + string defaultExe = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + @"\COLT\colt.exe"; + settingObject = new Settings(); - if (!File.Exists(settingFilename)) SaveSettings(); + + if (!File.Exists(settingFilename)) + { + settingObject.Executable = defaultExe; + SaveSettings(); + } else { Object obj = ObjectSerializer.Deserialize(settingFilename, settingObject); settingObject = (Settings)obj; // debug //settingObject.SecurityToken = null; + string exe = settingObject.Executable; + if ((exe == null) || (exe.Length == 0)) + { + settingObject.Executable = defaultExe; + SaveSettings(); + } } } @@ -618,7 +634,7 @@ private string LineIndentPosition(ScintillaNet.ScintillaControl sci, int line) private void GetSecurityToken(Boolean param) { - JsonRpcClient client = new JsonRpcClient(); + JsonRpcClient client = new JsonRpcClient("FIXME"); try { @@ -657,7 +673,7 @@ private void ProductionBuild(Boolean run) try { - JsonRpcClient client = new JsonRpcClient(); + JsonRpcClient client = new JsonRpcClient("FIXME"); client.Invoke("runProductionCompilation", new Object[] { settingObject.SecurityToken, /*run*/false }); // leverage FD launch mechanism @@ -672,6 +688,22 @@ private void ProductionBuild(Boolean run) } } + private void OpenInCOLT(string pathToProject) + { + // put it on recent files list + string coltFolder = System.Environment.GetEnvironmentVariable("USERPROFILE") + @"\.colt\"; + + XmlDocument workingSet = new XmlDocument(); + workingSet.Load(coltFolder + "workingset.xml"); + XmlElement root = (XmlElement)workingSet.SelectSingleNode("/workingset"); + XmlElement project = (XmlElement)root.PrependChild(workingSet.CreateElement("", "project", "")); + project.Attributes.Append(workingSet.CreateAttribute("path")).Value = pathToProject; + workingSet.Save(coltFolder + "workingset.xml"); + + // open COLT exe + Process.Start(settingObject.Executable); + } + /// /// Opens the project in COLT and optionally runs live session @@ -685,14 +717,17 @@ private void FindAndOpen(Boolean run) // Find COLT project to open String coltFileName = GetCOLTFile(); - // Open it with default app (COLT) + // Open it if (coltFileName != null) { try { - JsonRpcClient client = new JsonRpcClient(); + OpenInCOLT(coltFileName); + + // TODO: if (run) client.Invoke... +/* JsonRpcClient client = new JsonRpcClient("FIXME"); client.Invoke("loadProject", new Object[] { settingObject.SecurityToken, coltFileName }); - if (run) client.Invoke("runBaseCompilation", new Object[] { settingObject.SecurityToken }); + if (run) client.Invoke("runBaseCompilation", new Object[] { settingObject.SecurityToken });*/ } catch (Exception details) { @@ -722,8 +757,15 @@ private void ExportAndOpen(Boolean run) { try { - JsonRpcClient client = new JsonRpcClient(); + // Export the project as xml file + project.Save(); + + // Open it + OpenInCOLT(project.path); + +/* JsonRpcClient client = new JsonRpcClient("FIXME"); client.Invoke("createProject", new Object[] { settingObject.SecurityToken, project }); + */ // Enable "open" button toolbarButton2.Enabled = true; @@ -737,7 +779,8 @@ private void ExportAndOpen(Boolean run) } } - if (run) client.Invoke("runBaseCompilation", new Object[] { settingObject.SecurityToken }); + //TODO this must return... +/* if (run) client.Invoke("runBaseCompilation", new Object[] { settingObject.SecurityToken });*/ } catch (Exception details) { @@ -843,7 +886,7 @@ private COLTRemoteProject ExportCOLTProject() { if (libraryPathsList[i].ToLower().EndsWith(".swc")) { - libraryPathsList[i] = project.GetAbsolutePath(libraryPathsList[i]); + libraryPathsList[i] = @"..\" + libraryPathsList[i]; } else @@ -875,14 +918,16 @@ private COLTRemoteProject ExportCOLTProject() else { + result.outputPath = project.GetAbsolutePath(""); result.outputFileName = outputPath; } String[] sourcePaths = project.SourcePaths.Clone() as String[]; - for (int i=0; i + // + XmlNodeList storageList = storageDescriptor.SelectNodes("/xml/storage[@path='" + projectPath + "']"); + if (storageList.Count == 1) + { + string storage = storageList[0].Attributes["subDir"].Value; + int port = int.Parse ( File.ReadAllText(coltFolder + @"storage\" + storage + @"\rpc.info").Split(':')[1] ); + + Url = "http://127.0.0.1:" + port + "/rpc/coltService"; return; + } + Url = "http://127.0.0.1:8092/rpc/coltService"; } diff --git a/ColtPlugin/Settings.cs b/ColtPlugin/Settings.cs index 9619a99..d83b9ad 100644 --- a/ColtPlugin/Settings.cs +++ b/ColtPlugin/Settings.cs @@ -11,10 +11,22 @@ public class Settings { public String SecurityToken; + private String coltExe = null; private String workingFolder = "colt"; private Boolean autorun = true; private Boolean fullConfig = false; private Boolean interceptBuilds = false; + + /// + /// Get and sets colt.exe path + /// + [DisplayName("Path to COLT")] + [Description("Path to COLT executable.")] + public String Executable + { + get { return this.coltExe; } + set { this.coltExe = value; } + } /// /// Get and sets colt folder