/// <summary> /// /// </summary> /// <param name="Msg"></param> private void SolicitRemoteActionRecieved(NetMessage_SolicitRemoteAction Msg) { bool Accepted = false; // Don't accept if we are running any other actions. if (!IsRunningRemoteActions()) { if (Msg.Type == RemoteActionType.Install) { Guid ManifestId = Guid.Parse(Msg.Settings["ManifestId"]); ManifestDownloadState State = DownloadManager.GetDownload(ManifestId); if (State != null && State.State == ManifestDownloadProgressState.Complete) { try { // TODO: We don't support json files here. Should we just remove them? Nobody uses them. string ConfigFilePath = Path.Combine(State.LocalFolder, "buildsync.cs"); BuildSettings Settings = new BuildSettings(); Settings.ScriptSource = File.ReadAllText(ConfigFilePath); List <BuildLaunchMode> Modes; Modes = Settings.Compile(); Accepted = (Modes.Count > 0); } catch (Exception Ex) { // We cannot compile or use this script :( } } } } if (Accepted) { NetMessage_SolicitAcceptRemoteAction Reply = new NetMessage_SolicitAcceptRemoteAction(); Reply.ActionId = Msg.ActionId; Client.Connection.Send(Reply); } }
/// <summary> /// /// </summary> public bool Init() { string ConfigFilePath = Path.Combine(Downloader.LocalFolder, "buildsync.json"); bool IsScript = false; if (!File.Exists(ConfigFilePath)) { ConfigFilePath = Path.Combine(Downloader.LocalFolder, "buildsync.cs"); IsScript = true; } if (!File.Exists(ConfigFilePath)) { MessageBox.Show("Build has no configured launch settings. Ensure a buildsync.json or buildsync.cs file is added to all builds.", "Not Configured", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (!IsScript) { if (!SettingsBase.Load(ConfigFilePath, out Settings)) { MessageBox.Show("The included buildsync.json file could not be loaded, it may be malformed. Check console output window for details.", "Malformed Config File", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } else { Settings = new BuildSettings(); try { Settings.ScriptSource = File.ReadAllText(ConfigFilePath); } catch (Exception Ex) { Logger.Log(LogLevel.Error, LogCategory.IO, "Failed to read file '{0}' due to exception: {1}", ConfigFilePath, Ex.Message); MessageBox.Show("The included buildsync.cs file could not be loaded, it may be malformed. Check console output window for details.", "Malformed Config File", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } List <BuildLaunchMode> Modes; try { Modes = Settings.Compile(); // Add various internal variables to pass in bits of info. foreach (BuildLaunchMode Mode in Modes) { Mode.AddStringVariable("INSTALL_LOCATION", DownloadState.InstallLocation); Mode.AddStringVariable("BUILD_DIR", Downloader.LocalFolder); // We show this internal var to the end user. BuildLaunchVariable DeviceVar = Mode.AddStringVariable("INSTALL_DEVICE_NAME", DownloadState.InstallDeviceName); DeviceVar.Internal = (DownloadState.InstallDeviceName.Length == 0); DeviceVar.FriendlyName = "Target Device"; DeviceVar.FriendlyDescription = "Device to install and launch on."; DeviceVar.FriendlyCategory = "Launch Device"; DeviceVar.Options = new List <string>(); DeviceVar.Value = ""; string[] Options = DownloadState.InstallDeviceName.Split(','); foreach (string Option in Options) { string Trimmed = Option.Trim(); if (Trimmed.Length > 0) { DeviceVar.Options.Add(Trimmed); if (DeviceVar.Value.Length == 0) { DeviceVar.Value = Trimmed; } } } } } catch (InvalidOperationException Ex) { MessageBox.Show("Error encountered while evaluating launch settings:\n\n" + Ex.Message, "Malformed Config File", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (Modes.Count == 0) { MessageBox.Show("None of the launch modes are usable.", "Not Configured", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } else if (Modes.Count == 1 && Modes[0].GetNonInternalVariableCount() == 0 && !DownloadState.InstallDeviceName.Contains(",")) { // Instant launch, nothing for us to select really. Launch(Modes[0]); return(false); } else { // Show options to launch. foreach (BuildLaunchMode Mode in Modes) { TreeNode Node = new TreeNode(); Node.Text = Mode.Name; Node.Tag = Mode; ModesTreeView.Nodes.Add(Node); } // Select first mode. ModesTreeView.SelectedNode = ModesTreeView.Nodes[0]; } return(true); }