private void HandleDownloadFinished(CustomComponent cc, bool success) { cc.DownloadFinished -= cc_DownloadFinished; cc.DownloadProgressChanged -= cc_DownloadProgressChanged; var btn = installationButtons.Find(b => object.ReferenceEquals(b.Tag, cc)); btn.AllowClick = true; if (!success) { if (!downloadCancelled) { XNAMessageBox.Show(WindowManager, "Optional Component Download Failed", string.Format("Download of optional component {0} failed." + Environment.NewLine + "See client.log for details." + Environment.NewLine + Environment.NewLine + "If this problem continues, please contact your mod's authors for support.", cc.GUIName)); } btn.Text = "Install"; if (File.Exists(ProgramConstants.GamePath + cc.LocalPath)) { btn.Text = "Update"; } } else { XNAMessageBox.Show(WindowManager, "Download Completed", string.Format("Download of optional component {0} completed succesfully.", cc.GUIName)); btn.Text = "Uninstall"; } }
private void HandleDownloadFinished(CustomComponent cc, bool success) { cc.DownloadFinished -= cc_DownloadFinished; cc.DownloadProgressChanged -= cc_DownloadProgressChanged; var btn = installationButtons.Find(b => object.ReferenceEquals(b.Tag, cc)); btn.AllowClick = true; if (!success) { if (!downloadCancelled) { XNAMessageBox.Show(WindowManager, "可选组件下载失败", string.Format("组件 {0} 下载失败。" + Environment.NewLine + "打开 client.log 查看细节。" + Environment.NewLine + Environment.NewLine + "如果问题依旧存在,请联系mod作者寻求帮助。", cc.GUIName)); } btn.Text = "安装"; if (File.Exists(ProgramConstants.GamePath + cc.LocalPath)) { btn.Text = "更新"; } } else { XNAMessageBox.Show(WindowManager, "下载完成", string.Format("组件 {0} 下载完成。", cc.GUIName)); btn.Text = "卸载"; } }
static void Main(string[] args) { var fi = new FileInfo(@"TestDir\test.txt"); try { fi.Create(); } catch (Exception ex) { if (!Directory.Exists("TestDir")) { Directory.CreateDirectory("TestDir"); } fi.Create(); } var component = new CustomComponent(); var type = component.GetType(); var methodInfos = type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance) .Where(mi => mi.CustomAttributes.Any(ca => ca.AttributeType == typeof(CustomAttribute))); foreach (var methodInfo in methodInfos) { var attribute = methodInfo.CustomAttributes.FirstOrDefault(ca => ca.AttributeType == typeof(CustomAttribute)); Console.WriteLine($"Метод {methodInfo.Name} {attribute.ConstructorArguments.FirstOrDefault().Value} {attribute.NamedArguments.FirstOrDefault().TypedValue.Value}"); } }
private void HandleDownloadProgressChanged(CustomComponent cc, int percentage) { percentage = Math.Min(percentage, 100); var btn = installationButtons.Find(b => object.ReferenceEquals(b.Tag, cc)); btn.Text = "Downloading.. " + percentage + "%"; }
public override void OnInspectorGUI() { DrawDefaultInspector(); CustomComponent myScript = (CustomComponent)target; if (GUILayout.Button("Modify Value")) { myScript.ModifyValue(); } }
private void BtnSave_LeftClick(object sender, EventArgs e) { if (CustomComponent.IsDownloadInProgress()) { var msgBox = new XNAMessageBox(WindowManager, "正在下载", "可选组件正在下载。如果关闭设置窗口,下载将会取消。" + Environment.NewLine + Environment.NewLine + "确定要关闭?", XNAMessageBoxButtons.YesNo); msgBox.Show(); msgBox.YesClickedAction = SaveDownloadCancelConfirmation_YesClicked; return; } SaveSettings(); }
private void BtnSave_LeftClick(object sender, EventArgs e) { if (CustomComponent.IsDownloadInProgress()) { var msgBox = new XNAMessageBox(WindowManager, "Downloads in progress", "Optional component downloads are in progress. The downloads will be cancelled if you exit the Options menu." + Environment.NewLine + Environment.NewLine + "Are you sure you want to continue?", XNAMessageBoxButtons.YesNo); msgBox.Show(); msgBox.YesClickedAction = SaveDownloadCancelConfirmation_YesClicked; return; } SaveSettings(); }
private void BtnBack_LeftClick(object sender, EventArgs e) { if (CustomComponent.IsDownloadInProgress()) { var msgBox = new XNAMessageBox(WindowManager, "Downloads in progress", "Optional component downloads are in progress. The downloads will be cancelled if you exit the Options menu." + Environment.NewLine + Environment.NewLine + "Are you sure you want to continue?", XNAMessageBoxButtons.YesNo); msgBox.Show(); msgBox.YesClickedAction = ExitDownloadCancelConfirmation_YesClicked; return; } WindowManager.SoundPlayer.SetVolume(Convert.ToSingle(UserINISettings.Instance.ClientVolume)); Disable(); }
// This event handler updates the ListView control when the // PrimeNumberCalculator raises the CalculatePrimeCompleted // event. The ListView item is updated with the appropriate // outcome of the calculation: Canceled, Error, or result. private void primeNumberCalculator1_CalculatePrimeCompleted(object sender, CustomComponent.CalculatePrimeCompletedEventArgs e) { Guid taskId = (Guid)e.UserState; ListViewItem lvi = null; if (e.Cancelled) { string result = "Cancelled"; lvi = UpdateListViewItem(taskId, result); if (lvi != null) { lvi.BackColor = Color.Pink; lvi.Tag = null; } } else if (e.Error != null) { string result = "Error"; lvi = UpdateListViewItem(taskId, result); if (lvi != null) { lvi.BackColor = Color.Red; lvi.ForeColor = Color.White; lvi.Tag = null; } } else { bool result = e.IsPrime; lvi = UpdateListViewItem(taskId, result, e.FirstDivisor); if (lvi != null) { lvi.BackColor = Color.LightGray; lvi.Tag = null; } } }
/* * Given: * A Link instruction- a single instruction that has been parsed before, and a CustomComponent that has this link instruction * Output: * A Component that can be used to generate a project for this .dll * Note that we want to point to source files (.c, .h) instead of linking against things that are not in our current project. * */ public static Component resolveLinkInstruction(LinkInstruction linkInstr, CustomComponent rule, Makefile mkfile) { Component component = new Component(mkfile); string componentName = ""; componentName = rule.Name; component.setName(componentName); linkInstr.convertToLink(mkfile, component); //If the link instruction shares objs with the makefile's, then use its cflags. Otherwise, we assume that the link instruction has an accompanying compile instruction somewhere if (rule.contextSensitiveProps.Contains("OBJ_LIST_C_OBJS")) { component.CompilerFlags = new CompileFlags(mkfile); component.CompilerFlags.ParseString(mkfile.ResolveVariables(mkfile.CompilerFlagsStr, Makefile.VarType.RegularVariable | Makefile.VarType.PropSheetVariable, false)); } string extension = Path.GetExtension(rule.Output).Replace(".", ""); component.Type = extension; component.IsCustomLinkStep = true; return component; }
/* * Given: * A CustomComponent that creates a .dll. This CustomComponent should have a link instruction. * Output: * A Component that can be used to generate a project for this .dll * * */ public static Component generateComponentFromRule(CustomComponent rule, Makefile mkfile) { Component result = new Component(rule.Name); result.Owner = mkfile; List<CustomInstruction> preBuildInstrs = new List<CustomInstruction>(); List<CustomInstruction> postBuildInstrs = new List<CustomInstruction>(); bool afterLinkInstruction = false; foreach (string instr in rule.CustomInstructions) { CustomInstruction cinstr = new CustomInstruction(instr); if (cinstr.isNmake()) { LinkInstruction linkInstr = new LinkInstruction(cinstr); result = resolveLinkInstruction(linkInstr,rule,mkfile); afterLinkInstruction = true; } else if (cinstr.isCl()) { ClInstruction compileInstruction = new ClInstruction(cinstr); foreach (string sourceFile in compileInstruction.clFiles) result.SourceFileNames.Add(sourceFile); } else if (!afterLinkInstruction) { preBuildInstrs.Add(cinstr); } else { postBuildInstrs.Add(cinstr); } } result.PreBuildInstructions = preBuildInstrs; result.PostBuildInstructions = postBuildInstrs; return result; }
/* * Given: * A CustomComponent that has generic instructions with no associated target. * Output: * Create & execute a batch file with these instructions. * * */ public static void ExecAsBatchFile(CustomComponent rule) { try { using (FileStream fs = new FileStream("ExecInstr.bat", FileMode.Create)) { using (StreamWriter sw = new StreamWriter(fs)) { //Write instructions to file foreach (string instr in rule.CustomInstructions) { sw.WriteLine(instr); } } Process.Start("ExecInstr.bat"); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); } }
/* * Given: * A CustomComponent * Output: * Based on targets, * An appropriate action to take * * */ public static CustomAction determineAction(CustomComponent rule) { CustomAction ret = CustomAction.Unknown; string noExtension = ""; string extension = ""; foreach (string target in rule.CustomTargets) { extension = Path.GetExtension(target).Replace(".", ""); noExtension = Path.GetFileNameWithoutExtension(target); if (string.IsNullOrWhiteSpace(target)) continue; if (target.ToLower().Contains("clean")) return CustomAction.Ignore; if (target.Contains("stdafx")) return CustomAction.Ignore; if (extension.Equals("")) { //Phony target return CustomAction.AttachAsPostBuildEvent; } if (rule.CustomDependencies.Count > 0) { if (rule.CustomDependencies[0].Equals("stdafx.cpp") || rule.CustomDependencies[0].Equals("stdafx.h")) { return CustomAction.Ignore; } } if (extension.Equals("dll")) { ret = CustomAction.ConvertToProject; } else if (extension.Equals("exe")) { ret = CustomAction.ConvertToProject; } else if (extension.Equals("ocx")) { ret = CustomAction.ConvertToProject; } else if (extension.Equals("hlp")) { ret = CustomAction.Ignore; } else if (extension.Equals("cab")) { ret = CustomAction.Unknown; } else if (extension.Equals("obj")) { ret = CustomAction.ModifyComponent; } else if (extension.Equals("h")) { ret = CustomAction.AttachAsPreBuildEvent; } else if (extension.Equals("c")) { ret = CustomAction.AttachAsPreBuildEvent; } else if (extension.Equals("lib")) { ret = CustomAction.ConvertToProject; } else if (extension.Equals("dat")) { ret = CustomAction.Unknown; } else if (extension.Equals("idt")) { ret = CustomAction.Unknown; } else if (extension.Equals("res")) { ret = CustomAction.ModifyComponent; } else if (extension.Equals("tlb")) { //handled during makefile processing ret = CustomAction.Ignore; } else if (extension.Equals("def")) { ret = CustomAction.Unknown; } } return ret; }
/* * Given: * A Cl (command line compile) instruction with a /link flag- a single instruction that has been parsed before, and a CustomComponent that has this compile instruction * Output: * A Component that can generate a project. * Note that we want to point to source files (.c, .h) instead of linking against things that are not in our current project. * */ public static Component resolveClInstructionIntoComponent(ClInstruction clInstruction, CustomComponent rule, Makefile mkfile) { Component result = new Component(rule.Output); result.IsCustomLinkStep = true; string target = ""; //If the compile instruction has a /link flag, then it should ultimately become its own project. if (clInstruction.hasLinkFlags()) { foreach (string file in clInstruction.clFiles) { if (file.EndsWith(".c", StringComparison.CurrentCultureIgnoreCase) || file.EndsWith(".cpp", StringComparison.CurrentCultureIgnoreCase)) { result.SourceFiles.Add(Path.GetFileNameWithoutExtension(file)); } else if (file.Contains("lib")) { result.Link.Libs.Add(file); } else if (file.Contains("obj")) { result.Link.Objs.Add(file); target = file; } } CompileFlags flags = new CompileFlags(mkfile); flags.ParseString(clInstruction.clOptionsLiteral); result.CompilerFlags = flags; if (clInstruction.LinkOptionsLiteral_Words.Count > 0) { MakefileUtil.ParseLinkFlags(mkfile, clInstruction.LinkOptionsLiteral_Words, result); } } string extension = Path.GetExtension(rule.Output).Replace(".", ""); result.Type = extension; if (result.Name == "") result.setName(rule.Output); if (result.Link.Output == "") result.Link.Output = Path.GetFileName(rule.Output); return result; }
/// <summary> /// Called whenever a custom component download's progress is changed. /// </summary> /// <param name="c">The CustomComponent object.</param> /// <param name="percentage">The current download progress percentage.</param> private void cc_DownloadProgressChanged(CustomComponent c, int percentage) { WindowManager.AddCallback(new Action <CustomComponent, int>(HandleDownloadProgressChanged), c, percentage); }
public TriggerMessageHandler(CustomComponent customComponent) { this.customComponent = customComponent; }
public FollowupMessageHandler(CustomComponent customComponent) { this.customComponent = customComponent; }
public void AddRemoveToDictionary(CustomComponent component, bool add = true) { if (component.reactions.Length <= 0) { return; } for (int i = 0; i < component.reactions.Length; i++) { string key = component.reactions[i]; Debug.Log(key); //Is the reaction already present in the dictionary if (listeners.ContainsKey(key)) { List <CustomComponent> tempComponentArray = listeners[key]; //If yes, check if the component is registered for this reaction if (tempComponentArray.Count > 0) { //If he already is, do nothing if (tempComponentArray.Contains(component)) { if (add) { Debug.Log("component already registered for this reaction"); } else { tempComponentArray.Remove(component); if (tempComponentArray.Count <= 0) { listeners.Remove(key); } } } //Else add the component to the list else { if (add) { tempComponentArray.Add(component); } } } else { if (!add) { listeners.Remove(key); } } } //If not create the new pair key/value else { if (add) { listeners.Add(key, new List <CustomComponent>() { component }); } } } }
/// <summary> /// Called whenever a custom component download is finished. /// </summary> /// <param name="c">The CustomComponent object.</param> /// <param name="success">True if the download succeeded, otherwise false.</param> private void cc_DownloadFinished(CustomComponent c, bool success) { WindowManager.AddCallback(new Action <CustomComponent, bool>(HandleDownloadFinished), c, success); }