private void StartMultiMacroInitAndPlaybackLoop(MacroRecording macro, double acceleration) { Logger.Info("Starting multi-macro playback loop"); foreach (MergedMacroConfiguration macroConfiguration in (Collection <MergedMacroConfiguration>)macro.MergedMacroConfigurations) { for (int index = 0; index < macroConfiguration.LoopCount; ++index) { foreach (string str in (Collection <string>)macroConfiguration.MacrosToRun) { string macroToRun = str; if (this.mWasMacroPlaybackStopped) { return; } MacroRecording macro1 = MacroGraph.Instance.Vertices.Cast <MacroRecording>().Where <MacroRecording>((Func <MacroRecording, bool>)(macro_ => string.Equals(macro_.Name, macroToRun, StringComparison.InvariantCultureIgnoreCase))).FirstOrDefault <MacroRecording>(); if (macro1 != null) { if (macro1.Childs.Count > 0) { this.StartMultiMacroInitAndPlaybackLoop(macro1, macroConfiguration.Acceleration * acceleration); } else { this.mMultiMacroEventHandle?.Reset(); InputMapper.Instance.RunMacroUnit(macroToRun, macroConfiguration.Acceleration * acceleration); this.mMultiMacroEventHandle?.WaitOne(); Logger.Info("inside StartMultiMacroInitAndPlaybackLoop: mMultiMacroEventHandle wait completed"); } } } Thread.Sleep(macroConfiguration.LoopInterval * 1000); } Thread.Sleep(macroConfiguration.DelayNextScript * 1000); } }
private void DeleteScriptImg_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e) { MacroRecording currentRecording = MacroGraph.Instance.Vertices.Cast <MacroRecording>().Where <MacroRecording>((Func <MacroRecording, bool>)(macro => string.Equals(macro.Name, this.mRecording.Name, StringComparison.InvariantCultureIgnoreCase))).FirstOrDefault <MacroRecording>(); if (currentRecording == null) { return; } if (currentRecording.Parents.Count > 0) { this.mDeleteScriptMessageWindow = new CustomMessageWindow(); this.mDeleteScriptMessageWindow.TitleTextBlock.Text = LocaleStrings.GetLocalizedString("STRING_DELETE_DEPENDENT_MACRO", ""); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(LocaleStrings.GetLocalizedString("STRING_MACRO_IN_USE_BY_OTHER_MACROS", "")); stringBuilder.Append(" "); stringBuilder.Append(string.Format((IFormatProvider)CultureInfo.InvariantCulture, LocaleStrings.GetLocalizedString("STRING_MACRO_LOSE_CONFIGURABILITY", ""), (object)this.mRecording.Name)); this.mDeleteScriptMessageWindow.BodyTextBlock.Text = stringBuilder.ToString(); this.mDeleteScriptMessageWindow.AddButton(ButtonColors.Red, LocaleStrings.GetLocalizedString("STRING_DELETE_ANYWAY", ""), (EventHandler)((o, evt) => { for (int i = currentRecording.Parents.Count - 1; i >= 0; i--) { MacroRecording macroRecording = MacroGraph.Instance.Vertices.Cast <MacroRecording>().Where <MacroRecording>((Func <MacroRecording, bool>)(macro => macro.Equals((object)currentRecording.Parents[i]))).FirstOrDefault <MacroRecording>(); this.mMacroRecorderWindow.FlattenRecording(currentRecording.Parents[i] as MacroRecording, false); CommonHandlers.SaveMacroJson(currentRecording.Parents[i] as MacroRecording, (currentRecording.Parents[i] as MacroRecording).Name + ".json"); foreach (SingleMacroControl child in this.mMacroRecorderWindow.mScriptsStackPanel.Children) { if (child.mRecording.Name.ToLower(CultureInfo.InvariantCulture).Trim() == macroRecording.Name.ToLower(CultureInfo.InvariantCulture).Trim()) { child.mScriptSettingsImg.ImageName = "macro_settings"; } } MacroGraph.Instance.DeLinkMacroChild((BiDirectionalVertex <MacroRecording>)(currentRecording.Parents[i] as MacroRecording)); } this.DeleteMacroScript(); CommonHandlers.RefreshAllMacroRecorderWindow(); }), (string)null, false, (object)null, true); this.mDeleteScriptMessageWindow.AddButton(ButtonColors.White, LocaleStrings.GetLocalizedString("STRING_DONT_DELETE", ""), (EventHandler)((o, evt) => {}), (string)null, false, (object)null, true); this.mDeleteScriptMessageWindow.CloseButtonHandle((EventHandler)((o, evt) => {}), (object)null); this.mDeleteScriptMessageWindow.Owner = (Window)this.ParentWindow; this.mDeleteScriptMessageWindow.ShowDialog(); } else if (!this.ParentWindow.EngineInstanceRegistry.ShowMacroDeletePopup) { this.DeleteMacroScript(); } else { this.mDeleteScriptMessageWindow = new CustomMessageWindow(); this.mDeleteScriptMessageWindow.TitleTextBlock.Text = LocaleStrings.GetLocalizedString("STRING_DELETE_MACRO", ""); this.mDeleteScriptMessageWindow.BodyTextBlock.Text = LocaleStrings.GetLocalizedString("STRING_DELETE_SCRIPT", ""); this.mDeleteScriptMessageWindow.CheckBox.Content = (object)LocaleStrings.GetLocalizedString("STRING_DOWNLOAD_GOOGLE_APP_POPUP_STRING_04", ""); this.mDeleteScriptMessageWindow.CheckBox.Visibility = Visibility.Visible; this.mDeleteScriptMessageWindow.CheckBox.IsChecked = new bool?(false); this.mDeleteScriptMessageWindow.AddButton(ButtonColors.Red, LocaleStrings.GetLocalizedString("STRING_DELETE", ""), new EventHandler(this.FlattenTargetMacrosAndDeleteSourceMacro), (string)null, false, (object)null, true); this.mDeleteScriptMessageWindow.AddButton(ButtonColors.White, LocaleStrings.GetLocalizedString("STRING_CANCEL", ""), (EventHandler)((o, evt) => this.ParentWindow.EngineInstanceRegistry.ShowMacroDeletePopup = !this.mDeleteScriptMessageWindow.CheckBox.IsChecked.Value), (string)null, false, (object)null, true); this.mDeleteScriptMessageWindow.CloseButtonHandle((EventHandler)((o, evt) => {}), (object)null); this.mDeleteScriptMessageWindow.Owner = (Window)this.ParentWindow; this.mDeleteScriptMessageWindow.ShowDialog(); } }
private void ScriptSettingsImg_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e) { this.mMacroRecorderWindow.mOverlayGrid.Visibility = Visibility.Visible; MacroRecording macroRecording = MacroGraph.Instance.Vertices.Cast <MacroRecording>().Where <MacroRecording>((Func <MacroRecording, bool>)(macro => macro.Equals(this.mRecording))).FirstOrDefault <MacroRecording>(); MacroRecording mRecording = this.mRecording; if ((mRecording != null ? (mRecording.RecordingType == RecordingTypes.MultiRecording ? 1 : 0) : 0) != 0) { ClientStats.SendMiscellaneousStatsAsync("MacroOperations", RegistryManager.Instance.UserGuid, RegistryManager.Instance.ClientVersion, "merge_macro_edit", (string)null, (string)null, (string)null, (string)null, (string)null, "Android"); if (this.mMacroRecorderWindow.mMergeMacroWindow == null) { MacroRecorderWindow macroRecorderWindow = this.mMacroRecorderWindow; MergeMacroWindow mergeMacroWindow = new MergeMacroWindow(this.mMacroRecorderWindow, this.ParentWindow); mergeMacroWindow.Owner = (Window)this.ParentWindow; macroRecorderWindow.mMergeMacroWindow = mergeMacroWindow; } this.mMacroRecorderWindow.mMergeMacroWindow.Init(macroRecording, this); this.mMacroRecorderWindow.mMergeMacroWindow.Show(); } else { ClientStats.SendMiscellaneousStatsAsync("MacroOperations", RegistryManager.Instance.UserGuid, RegistryManager.Instance.ClientVersion, "macro_window_settings", (string)null, this.mRecording.RecordingType.ToString(), (string)null, (string)null, (string)null, "Android"); if (this.mMacroSettingsWindow == null || this.mMacroSettingsWindow.IsClosed) { this.mMacroSettingsWindow = new MacroSettingsWindow(this.ParentWindow, macroRecording, this.mMacroRecorderWindow); } this.mMacroSettingsWindow.ShowDialog(); } }
private void UnifyButton_Click(object sender, RoutedEventArgs e1) { if (this.mOriginalMacroRecording == null) { this.mOriginalMacroRecording = new MacroRecording(); } this.mOriginalMacroRecording.CopyFrom(this.MergedMacroRecording); CustomMessageWindow customMessageWindow = new CustomMessageWindow(); customMessageWindow.TitleTextBlock.Text = string.Format((IFormatProvider)CultureInfo.InvariantCulture, LocaleStrings.GetLocalizedString("STRING_UNIFY_0", ""), (object)this.mOriginalMacroRecording.Name); BlueStacksUIBinding.Bind(customMessageWindow.BodyTextBlock, "STRING_UNIFIYING_LOSE_CONFIGURE", ""); bool closeWindow = false; customMessageWindow.AddButton(ButtonColors.Blue, string.Format((IFormatProvider)CultureInfo.InvariantCulture, LocaleStrings.GetLocalizedString("STRING_CONTINUE", ""), (object)"").Trim(), (EventHandler)((o, evt) => { ClientStats.SendMiscellaneousStatsAsync("MacroOperations", RegistryManager.Instance.UserGuid, RegistryManager.Instance.ClientVersion, "merge_unify", (string)null, (string)null, (string)null, (string)null, (string)null, "Android"); this.mMacroRecorderWindow.FlattenRecording(this.mOriginalMacroRecording, false); CommonHandlers.SaveMacroJson(this.mOriginalMacroRecording, this.mOriginalMacroRecording.Name + ".json"); CommonHandlers.RefreshAllMacroRecorderWindow(); closeWindow = true; }), (string)null, false, (object)null, true); customMessageWindow.AddButton(ButtonColors.White, "STRING_CANCEL", (EventHandler)((o, evt) => ClientStats.SendMiscellaneousStatsAsync("MacroOperations", RegistryManager.Instance.UserGuid, RegistryManager.Instance.ClientVersion, "merge_unify_cancel", (string)null, (string)null, (string)null, (string)null, (string)null, "Android")), (string)null, false, (object)null, true); customMessageWindow.CloseButtonHandle((EventHandler)((o, e2) => ClientStats.SendMiscellaneousStatsAsync("MacroOperations", RegistryManager.Instance.UserGuid, RegistryManager.Instance.ClientVersion, "merge_unify_cancel", (string)null, (string)null, (string)null, (string)null, (string)null, "Android")), (object)null); customMessageWindow.Owner = (Window)this; customMessageWindow.ShowDialog(); if (!closeWindow) { return; } this.CloseWindow(); }
internal void ShowMacroPlaybackOnTopBar(MacroRecording record) { if (this.ParentWindow.IsUIInPortraitMode) { this.mSettingsButton.Visibility = Visibility.Collapsed; } this.mMacroPlayControl.Init(this.ParentWindow, record); this.mMacroPlayGrid.Visibility = Visibility.Visible; }
private void MergeButton_Click(object sender, RoutedEventArgs e) { if (this.mOriginalMacroRecording == null) { this.mOriginalMacroRecording = new MacroRecording(); } this.mOriginalMacroRecording.CopyFrom(this.MergedMacroRecording); this.mMacroRecorderWindow.SaveMacroRecord(this.mOriginalMacroRecording); ClientStats.SendMiscellaneousStatsAsync("MacroOperations", RegistryManager.Instance.UserGuid, RegistryManager.Instance.ClientVersion, "merge_macro_success", (string)null, (string)null, (string)null, (string)null, (string)null, "Android"); this.CloseWindow(); }
internal void Init() { bool isSingleRecording = this.ParentWindow.MacroRecorderWindow.mRenamingMacrosList.Count == 1; try { this.mInited = false; this.mScriptsStackPanel.Children.Clear(); foreach (MacroRecording mRenamingMacros in this.ParentWindow.MacroRecorderWindow.mRenamingMacrosList) { string suggestedName1; ImportMacroScriptsControl stackPanelAndDict = this.AddRecordingToStackPanelAndDict(mRenamingMacros, isSingleRecording, out suggestedName1); if (mRenamingMacros.RecordingType == RecordingTypes.MultiRecording) { bool?multiMacroAsUnified = this.mOperationWindow.mImportMultiMacroAsUnified; if (0 == (multiMacroAsUnified.GetValueOrDefault() ? 1 : 0) & multiMacroAsUnified.HasValue) { stackPanelAndDict.mDependentScriptsMsg.Visibility = Visibility.Visible; stackPanelAndDict.mDependentScriptsPanel.Visibility = Visibility.Visible; stackPanelAndDict.mDependentScriptsPanel.Children.Clear(); foreach (string sourceRecording in mRenamingMacros.SourceRecordings) { MacroRecording macroRecording = JsonConvert.DeserializeObject <MacroRecording>(sourceRecording, Utils.GetSerializerSettings()); string dependentRecordingName = MacroRecorderWindow.GetDependentRecordingName(suggestedName1, macroRecording.Name); string suggestedName2 = !MacroGraph.Instance.Vertices.Cast <MacroRecording>().Select <MacroRecording, string>((Func <MacroRecording, string>)(macro => macro.Name)).Contains <string>(dependentRecordingName.ToLower(CultureInfo.InvariantCulture).Trim()) ? dependentRecordingName : CommonHandlers.GetMacroName(dependentRecordingName); CustomTextBox customTextBox = new CustomTextBox(); customTextBox.Height = 24.0; customTextBox.HorizontalAlignment = HorizontalAlignment.Left; customTextBox.Margin = new Thickness(0.0, 5.0, 0.0, 0.0); customTextBox.Text = this.ValidateSuggestedName(suggestedName2); customTextBox.Visibility = Visibility.Visible; customTextBox.IsEnabled = false; CustomTextBox index = customTextBox; stackPanelAndDict.mDependentScriptsPanel.Children.Add((UIElement)index); this.mDependentRecordingDict[index] = macroRecording; } } } } this.mNumberOfFilesSelectedForImport = 0; } catch (Exception ex) { Logger.Error("Error in import window init err: " + ex.ToString()); } this.mInited = true; if (isSingleRecording) { this.mSelectAllBtn.Visibility = Visibility.Hidden; } this.mSelectAllBtn.IsChecked = new bool?(true); this.SelectAllBtn_Click((object)null, (RoutedEventArgs)null); }
private void ParentWindow_MacroSettingChangedEvent(MacroRecording record) { try { this.mMainStackPanel.Children.Clear(); this.InitList(); } catch (Exception ex) { Logger.Error("Couldn't update name: {0}", (object)ex.Message); } }
private ImportMacroScriptsControl AddRecordingToStackPanelAndDict( MacroRecording record, bool isSingleRecording, out string suggestedName) { ImportMacroScriptsControl index = new ImportMacroScriptsControl(this, this.ParentWindow); index.Init(record.Name, isSingleRecording); suggestedName = !MacroGraph.Instance.Vertices.Cast <MacroRecording>().Select <MacroRecording, string>((Func <MacroRecording, string>)(macro => macro.Name.ToLower(CultureInfo.InvariantCulture))).Contains <string>(record.Name.ToLower(CultureInfo.InvariantCulture).Trim()) ? record.Name : CommonHandlers.GetMacroName(record.Name); index.mImportName.Text = this.ValidateSuggestedName(suggestedName); this.mScriptsStackPanel.Children.Add((UIElement)index); this.mBoxToRecordingDict[index] = record; return(index); }
internal void Init(MainWindow parentWindow, MacroRecording record) { this.ParentWindow = parentWindow; this.mOperationsRecord = record; this.mRunningScript.Text = this.mOperationsRecord.Name; this.mRunningIterations.Visibility = Visibility.Visible; this.mRunningScript.ToolTip = (object)string.Format((IFormatProvider)CultureInfo.InvariantCulture, "{0} {1}", (object)LocaleStrings.GetLocalizedString("STRING_PLAYING", ""), (object)this.mRunningScript.Text); if (this.mBlinkPlayingIconTimer != null) { return; } this.mBlinkPlayingIconTimer = new DispatcherTimer(new TimeSpan(0, 0, 0, 0, 500), DispatcherPriority.Render, new EventHandler(this.BlinkPlayingIcon_Tick), Dispatcher.CurrentDispatcher); this.mTimer = new DispatcherTimer(new TimeSpan(0, 0, 0, 0, 50), DispatcherPriority.Render, new EventHandler(this.T_Tick), Dispatcher.CurrentDispatcher); this.StartTimer(); }
private void GridElement_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { if (this.ParentWindow.mIsMacroRecorderActive) { return; } string macroFileName = (string)(sender as Grid).Tag; MacroRecording record = MacroGraph.Instance.Vertices.Cast <MacroRecording>().Where <MacroRecording>((Func <MacroRecording, bool>)(macro => string.Equals(macro.Name, macroFileName, StringComparison.InvariantCultureIgnoreCase))).FirstOrDefault <MacroRecording>(); if (record == null) { this.mMainStackPanel.Children.Remove((UIElement)(sender as Grid)); } else { try { if (!this.ParentWindow.mIsMacroPlaying) { this.ParentWindow.mCommonHandler.FullMacroScriptPlayHandler(record); ClientStats.SendMiscellaneousStatsAsync("MacroOperations", RegistryManager.Instance.UserGuid, RegistryManager.Instance.ClientVersion, "macro_play", "bookmark", record.RecordingType.ToString(), string.IsNullOrEmpty(record.MacroId) ? "local" : "community", (string)null, (string)null, "Android"); } else { CustomMessageWindow customMessageWindow = new CustomMessageWindow(); BlueStacksUIBinding.Bind(customMessageWindow.TitleTextBlock, "STRING_CANNOT_RUN_MACRO", ""); BlueStacksUIBinding.Bind(customMessageWindow.BodyTextBlock, "STRING_STOP_MACRO_SCRIPT", ""); customMessageWindow.AddButton(ButtonColors.Blue, "STRING_OK", (EventHandler)null, (string)null, false, (object)null, true); customMessageWindow.Owner = (Window)this.ParentWindow; customMessageWindow.ShowDialog(); } if (this.ParentWindow.mSidebar == null) { return; } this.ParentWindow.mSidebar.mMacroButtonPopup.IsOpen = false; this.ParentWindow.mSidebar.ToggleSidebarVisibilityInFullscreen(false); } catch (Exception ex) { int num = (int)MessageBox.Show(ex.ToString()); } } }
internal SingleMacroControl( MainWindow parentWindow, MacroRecording record, MacroRecorderWindow recorderWindow) { this.InitializeComponent(); this.mRecording = record; this.ParentWindow = parentWindow; this.mMacroRecorderWindow = recorderWindow; InputMethod.SetIsInputMethodEnabled((DependencyObject)this.mMacroShortcutTextBox, false); this.mTimestamp.Text = DateTime.ParseExact(this.mRecording.TimeCreated, "yyyyMMddTHHmmss", (IFormatProvider)CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal).ToString("yyyy.MM.dd HH.mm.ss", (IFormatProvider)CultureInfo.InvariantCulture); this.mScriptName.Text = this.mRecording.Name; this.mMacroShortcutTextBox.Text = IMAPKeys.GetStringForUI(this.mRecording.Shortcut); this.mScriptName.ToolTip = (object)this.mScriptName.Text; if (record.RecordingType == RecordingTypes.MultiRecording) { this.mScriptSettingsImg.Visibility = Visibility.Collapsed; this.mMergeScriptSettingsImg.Visibility = Visibility.Visible; } if (!string.IsNullOrEmpty(this.mRecording.Shortcut)) { this.mMacroShortcutTextBox.Tag = (object)IMAPKeys.GetStringForFile(IMAPKeys.mDictKeys.FirstOrDefault <KeyValuePair <Key, string> >((Func <KeyValuePair <Key, string>, bool>)(x => x.Value == this.mRecording.Shortcut)).Key); MainWindow.sMacroMapping[this.mMacroShortcutTextBox.Tag.ToString()] = this.mScriptName.Text; } else { this.mMacroShortcutTextBox.Tag = (object)""; } this.IsBookmarked = BlueStacksUIUtils.CheckIfMacroScriptBookmarked(this.mRecording.Name); if (record.PlayOnStart) { this.mAutorunImage.Visibility = Visibility.Visible; } if (this.ParentWindow.mIsMacroPlaying && string.Equals(this.mRecording.Name, this.ParentWindow.mMacroPlaying, StringComparison.InvariantCulture)) { this.ToggleScriptPlayPauseUi(true); } else { this.ToggleScriptPlayPauseUi(false); } }
private void DeleteMacroScript(MacroRecording mRecording) { string path = Path.Combine(RegistryStrings.MacroRecordingsFolderPath, mRecording.Name + ".json"); if (File.Exists(path)) { File.Delete(path); } if (mRecording.Shortcut != null && MainWindow.sMacroMapping.ContainsKey(mRecording.Shortcut)) { MainWindow.sMacroMapping.Remove(mRecording.Shortcut); } ImportMacroWindow.DeleteScriptNameFromBookmarkedScriptListIfPresent(mRecording.Name); MacroGraph.Instance.RemoveVertex((BiDirectionalVertex <MacroRecording>)MacroGraph.Instance.Vertices.Cast <MacroRecording>().Where <MacroRecording>((Func <MacroRecording, bool>)(macro => string.Equals(macro.Name, mRecording.Name, StringComparison.InvariantCultureIgnoreCase))).FirstOrDefault <MacroRecording>()); if (this.ParentWindow.mAutoRunMacro != null && this.ParentWindow.mAutoRunMacro.Name.ToLower(CultureInfo.InvariantCulture).Trim() == mRecording.Name.ToLower(CultureInfo.InvariantCulture).Trim()) { this.ParentWindow.mAutoRunMacro = (MacroRecording)null; } CommonHandlers.OnMacroDeleted(mRecording.Name); }
private static List <MacroEvents> GetRecordingEventsFromSourceRecording( MacroRecording srcRecording, double acceleration, long initialTime, ref long elapsedTime) { if (srcRecording == null) { throw new Exception("Source recording now found in multiMacro"); } List <MacroEvents> macroEventsList = new List <MacroEvents>(); foreach (MacroEvents macroEvents1 in srcRecording.Events) { MacroEvents macroEvents2 = macroEvents1; macroEvents2.Timestamp = (long)Math.Floor((double)macroEvents1.Timestamp / acceleration); macroEvents2.Timestamp += initialTime; elapsedTime = macroEvents2.Timestamp; } return(macroEventsList); }
private Grid CreateGrid(string fileName) { Grid grid = new Grid(); grid.MouseEnter += new MouseEventHandler(this.GridElement_MouseEnter); grid.MouseLeave += new MouseEventHandler(this.GridElement_MouseLeave); grid.MouseLeftButtonUp += new MouseButtonEventHandler(this.GridElement_MouseLeftButtonUp); grid.Background = (Brush)Brushes.Transparent; grid.Tag = (object)fileName; TextBlock textBlock1 = new TextBlock(); textBlock1.FontSize = 12.0; textBlock1.TextTrimming = TextTrimming.CharacterEllipsis; textBlock1.Margin = new Thickness(10.0, 5.0, 10.0, 5.0); TextBlock textBlock2 = textBlock1; BlueStacksUIBinding.BindColor((DependencyObject)textBlock2, TextBlock.ForegroundProperty, "GuidanceTextColorForeground"); string path = Path.Combine(RegistryStrings.MacroRecordingsFolderPath, fileName); if (File.Exists(path)) { try { MacroRecording macroRecording = JsonConvert.DeserializeObject <MacroRecording>(File.ReadAllText(path), Utils.GetSerializerSettings()); textBlock2.Text = macroRecording.Name; textBlock2.ToolTip = (object)macroRecording.Name; } catch { } } else { textBlock2.Text = fileName; textBlock2.ToolTip = (object)fileName; } grid.Children.Add((UIElement)textBlock2); return(grid); }
private void BgExport_DoWork(object sender, DoWorkEventArgs e) { List <object> objectList = e.Argument as List <object>; string path1 = objectList[0] as string; foreach (MacroRecording macroRecording1 in objectList[1] as List <MacroRecording> ) { string name = macroRecording1.Name; string str1 = Path.Combine(RegistryStrings.MacroRecordingsFolderPath, name.ToLower(CultureInfo.InvariantCulture).Trim()) + ".json"; string str2 = Path.Combine(path1, macroRecording1.Name.ToLower(CultureInfo.InvariantCulture).Trim()) + ".json"; if (macroRecording1.RecordingType == RecordingTypes.SingleRecording) { File.Copy(str1, str2, true); } else { try { Logger.Info("Saving multi-macro"); List <string> stringList = new List <string>(); foreach (MacroRecording allChild in MacroGraph.Instance.GetAllChilds((BiDirectionalVertex <MacroRecording>)macroRecording1)) { stringList.Add(File.ReadAllText(Path.Combine(RegistryStrings.MacroRecordingsFolderPath, allChild.Name.ToLower(CultureInfo.InvariantCulture).Trim() + ".json"))); } MacroRecording macroRecording2 = JsonConvert.DeserializeObject <MacroRecording>(File.ReadAllText(str1), Utils.GetSerializerSettings()); macroRecording2.SourceRecordings = stringList; JsonSerializerSettings serializerSettings = Utils.GetSerializerSettings(); serializerSettings.Formatting = Formatting.Indented; string contents = JsonConvert.SerializeObject((object)macroRecording2, serializerSettings); File.WriteAllText(str2, contents); } catch (Exception ex) { Logger.Error("Coulnd't take backup of script {0}, Ex: {1}", (object)name, (object)ex); } } } }
internal void InitMacroPlayback(string macroPath) { this.mWasMacroPlaybackStopped = false; MacroGraph.ReCreateMacroGraphInstance(); string macroName = Path.GetFileNameWithoutExtension(macroPath); this.MacroToPlay = MacroGraph.Instance.Vertices.Cast <MacroRecording>().Where <MacroRecording>((Func <MacroRecording, bool>)(macro_ => string.Equals(string.IsNullOrEmpty(macro_.FileName) ? macro_.Name : macro_.FileName, macroName, StringComparison.InvariantCultureIgnoreCase))).FirstOrDefault <MacroRecording>(); if (this.MacroToPlay.RecordingType == RecordingTypes.MultiRecording) { foreach (MacroRecording allLeaf in MacroGraph.Instance.GetAllLeaves(this.MacroToPlay)) { MacroRecording leafMacro = allLeaf; MacroRecording macroRecording = MacroGraph.Instance.Vertices.Cast <MacroRecording>().Where <MacroRecording>((Func <MacroRecording, bool>)(marco_ => marco_.Equals(leafMacro))).FirstOrDefault <MacroRecording>(); if (macroRecording.RecordingType == RecordingTypes.SingleRecording) { InputMapper.Instance.InitMacroPlayback(Path.Combine(RegistryStrings.MacroRecordingsFolderPath, (string.IsNullOrEmpty(macroRecording.FileName) ? macroRecording.Name.ToLower() : macroRecording.FileName) + ".json")); } } } else { InputMapper.Instance.InitMacroPlayback(macroPath); } }
internal void Init(MacroRecording mergedMacro = null, SingleMacroControl singleMacroControl = null) { try { this.mMacroNameStackPanel.Visibility = mergedMacro == null ? Visibility.Visible : Visibility.Collapsed; this.mOriginalMacroRecording = mergedMacro; int num = 0; foreach (MacroRecording macroRecording in MacroGraph.Instance.Vertices.Cast <MacroRecording>().OrderBy <MacroRecording, DateTime>((Func <MacroRecording, DateTime>)(o => DateTime.ParseExact(o.TimeCreated, "yyyyMMddTHHmmss", (IFormatProvider)CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal))).ToList <MacroRecording>()) { MacroRecording record = macroRecording; this.ParentWindow.mIsScriptsPresent = true; if (!record.Equals(mergedMacro) && (mergedMacro == null || !MacroGraph.Instance.DoesParentExist(MacroGraph.Instance.Vertices.Where <BiDirectionalVertex <MacroRecording> >((Func <BiDirectionalVertex <MacroRecording>, bool>)(macro => macro.Equals((object)mergedMacro))).FirstOrDefault <BiDirectionalVertex <MacroRecording> >(), MacroGraph.Instance.Vertices.Where <BiDirectionalVertex <MacroRecording> >((Func <BiDirectionalVertex <MacroRecording>, bool>)(macro => macro.Equals((object)record))).FirstOrDefault <BiDirectionalVertex <MacroRecording> >()))) { MacroToAdd macroToAdd = new MacroToAdd(this, record.Name); if (num % 2 == 0) { BlueStacksUIBinding.BindColor((DependencyObject)macroToAdd, Control.BackgroundProperty, "DarkBandingColor"); } else { BlueStacksUIBinding.BindColor((DependencyObject)macroToAdd, Control.BackgroundProperty, "LightBandingColor"); } this.mCurrentMacroScripts.Children.Add((UIElement)macroToAdd); ++num; } } if (singleMacroControl != null) { this.mSingleMacroControl = singleMacroControl; } if (mergedMacro == null) { string str = DateTime.Now.ToString("yyyyMMddTHHmmss", (IFormatProvider)CultureInfo.InvariantCulture); this.MergedMacroRecording = new MacroRecording() { Name = CommonHandlers.GetMacroName("Macro"), TimeCreated = str, MergedMacroConfigurations = new ObservableCollection <MergedMacroConfiguration>() }; this.mUnifyButton.Visibility = Visibility.Collapsed; BlueStacksUIBinding.Bind((Button)this.mMergeButton, "STRING_MERGE"); BlueStacksUIBinding.Bind(this.mMergeMacroWindowHeading, "STRING_MERGE_MACROS", ""); } else { this.MergedMacroRecording = mergedMacro.DeepCopy <MacroRecording>(); BlueStacksUIBinding.Bind((Button)this.mMergeButton, "STRING_UPDATE_SETTING"); BlueStacksUIBinding.Bind(this.mMergeMacroWindowHeading, "STRING_EDIT_MERGED_MACRO", ""); this.mUnifyButton.Visibility = Visibility.Visible; } this.MacroName.Text = this.MergedMacroRecording.Name; this.mMacroDragControl.Init(); this.MergedMacroRecording.MergedMacroConfigurations.CollectionChanged -= new NotifyCollectionChangedEventHandler(this.Items_CollectionChanged); this.MergedMacroRecording.MergedMacroConfigurations.CollectionChanged += new NotifyCollectionChangedEventHandler(this.Items_CollectionChanged); this.Items_CollectionChanged((object)null, (NotifyCollectionChangedEventArgs)null); this.DataModificationTracker.Lock((object)this.mOriginalMacroRecording, new List <string>() { "IsGroupButtonVisible", "IsUnGroupButtonVisible", "IsSettingsVisible", "IsFirstListBoxItem", "IsLastListBoxItem", "Parents", "Childs", "IsVisited" }, true); this.CheckIfCanSave(); } catch (Exception ex) { Logger.Error("Error in export window init err: " + ex.ToString()); } }
private void ImportBtn_Click(object sender, RoutedEventArgs e) { int num = 0; bool flag1 = false; bool flag2 = true; List <MacroRecording> newlyAddedMacro = new List <MacroRecording>(); foreach (ImportMacroScriptsControl child in this.mScriptsStackPanel.Children) { bool?isChecked = child.mContent.IsChecked; bool flag3 = true; if (isChecked.GetValueOrDefault() == flag3 & isChecked.HasValue) { if (child.mImportName.Text.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0) { string path = string.Format((IFormatProvider)CultureInfo.InvariantCulture, "{0} {1} {2}", (object)LocaleStrings.GetLocalizedString("STRING_MACRO_NAME_ERROR", ""), (object)Environment.NewLine, (object)"\\ / : * ? \" < > |"); BlueStacksUIBinding.Bind(child.mWarningMsg, path, ""); child.mImportName.InputTextValidity = TextValidityOptions.Error; if (child.mImportName.IsEnabled) { child.mWarningMsg.Visibility = Visibility.Visible; } flag2 = false; } else if (((IEnumerable <string>)Constants.ReservedFileNamesList).Contains <string>(child.mImportName.Text.Trim().ToLower(CultureInfo.InvariantCulture))) { BlueStacksUIBinding.Bind(child.mWarningMsg, "STRING_MACRO_FILE_NAME_ERROR", ""); child.mImportName.InputTextValidity = TextValidityOptions.Error; if (child.mImportName.IsEnabled) { child.mWarningMsg.Visibility = Visibility.Visible; } flag2 = false; } else if (!this.CheckIfEditedMacroNameIsAllowed(child.mImportName.Text, child) && child.IsScriptInRenameMode()) { if (!string.IsNullOrEmpty(child.mImportName.Text.Trim())) { BlueStacksUIBinding.Bind(child.mWarningMsg, LocaleStrings.GetLocalizedString("STRING_DUPLICATE_MACRO_NAME_WARNING", ""), ""); } child.mImportName.InputTextValidity = TextValidityOptions.Error; if (child.mImportName.IsEnabled) { child.mWarningMsg.Visibility = Visibility.Visible; } flag2 = false; } else if (child.mDependentScriptsPanel.Visibility == Visibility.Visible && child.mDependentScriptsPanel.Children.Count > 0) { string path = this.CheckIfDependentScriptsHaveInvalidName(child); if (path != "TEXT_VALID") { BlueStacksUIBinding.Bind(child.mWarningMsg, path, ""); child.mImportName.InputTextValidity = TextValidityOptions.Error; flag2 = false; } else { child.mImportName.InputTextValidity = TextValidityOptions.Success; child.mWarningMsg.Visibility = Visibility.Collapsed; } } else { child.mImportName.InputTextValidity = TextValidityOptions.Success; child.mWarningMsg.Visibility = Visibility.Collapsed; } flag1 = true; } ++num; } if (!flag1) { this.ParentWindow.mCommonHandler.AddToastPopup((Window)this, LocaleStrings.GetLocalizedString("STRING_NO_IMPORT_MACRO_SELECTED", ""), 4.0, true); } else { if (!flag2) { return; } if (!Directory.Exists(RegistryStrings.MacroRecordingsFolderPath)) { Directory.CreateDirectory(RegistryStrings.MacroRecordingsFolderPath); } foreach (ImportMacroScriptsControl child1 in this.mScriptsStackPanel.Children) { bool?isChecked = child1.mContent.IsChecked; if (isChecked.GetValueOrDefault()) { MacroRecording record = this.mBoxToRecordingDict[child1]; isChecked = child1.mReplaceExistingBtn.IsChecked; string str; if (isChecked.HasValue) { isChecked = child1.mReplaceExistingBtn.IsChecked; if (isChecked.Value) { str = child1.mContent.Content.ToString(); goto label_40; } } str = child1.mImportName.Text.Trim(); label_40: string newScript = str; MacroRecording existingMacro = MacroGraph.Instance.Vertices.Cast <MacroRecording>().Where <MacroRecording>((Func <MacroRecording, bool>)(m => string.Equals(m.Name, newScript, StringComparison.InvariantCultureIgnoreCase))).FirstOrDefault <MacroRecording>(); if (existingMacro != null) { if (existingMacro.Parents.Count > 0) { for (int index = existingMacro.Parents.Count - 1; index >= 0; index--) { MacroRecording macroRecording = MacroGraph.Instance.Vertices.Cast <MacroRecording>().Where <MacroRecording>((Func <MacroRecording, bool>)(macro => macro.Equals((object)existingMacro.Parents[index]))).FirstOrDefault <MacroRecording>(); this.mOperationWindow.FlattenRecording(existingMacro.Parents[index] as MacroRecording, false); CommonHandlers.SaveMacroJson(existingMacro.Parents[index] as MacroRecording, (existingMacro.Parents[index] as MacroRecording).Name + ".json"); foreach (SingleMacroControl child2 in this.mOperationWindow.mScriptsStackPanel.Children) { if (child2.mRecording.Name.ToLower(CultureInfo.InvariantCulture).Trim() == macroRecording.Name.ToLower(CultureInfo.InvariantCulture).Trim()) { child2.mScriptSettingsImg.ImageName = "macro_settings"; } } MacroGraph.Instance.DeLinkMacroChild((BiDirectionalVertex <MacroRecording>)(existingMacro.Parents[index] as MacroRecording)); } } this.DeleteMacroScript(existingMacro); } record.Name = newScript; if (record.RecordingType == RecordingTypes.MultiRecording) { this.mOperationWindow.ImportMultiMacro(record, this.mOperationWindow.mImportMultiMacroAsUnified.Value, newlyAddedMacro, this.GetDictionaryOfNewNamesForDependentRecordings(record.Name)); } else { CommonHandlers.SaveMacroJson(record, record.Name.ToLower(CultureInfo.InvariantCulture).Trim() + ".json"); MacroGraph.Instance.AddVertex((BiDirectionalVertex <MacroRecording>)record); newlyAddedMacro.Add(record); } } } foreach (MacroRecording macro in newlyAddedMacro) { MacroGraph.LinkMacroChilds(macro); } this.mOperationWindow.mNewlyAddedMacrosList.AddRange((IEnumerable <MacroRecording>)newlyAddedMacro); this.ParentWindow.MacroRecorderWindow.mRenamingMacrosList.Clear(); this.Close(); } }
private void SaveScriptSettings() { try { if (string.Equals(this.mRecording.Shortcut, this.mMacroShortcutTextBox.Tag.ToString(), StringComparison.InvariantCulture) && string.Equals(this.mRecording.Name.Trim(), this.mScriptName.Text.Trim(), StringComparison.InvariantCultureIgnoreCase)) { return; } JsonSerializerSettings serializerSettings = Utils.GetSerializerSettings(); serializerSettings.Formatting = Formatting.Indented; string str1 = Path.Combine(RegistryStrings.MacroRecordingsFolderPath, this.mRecording.Name + ".json"); if (this.mRecording.Shortcut != this.mMacroShortcutTextBox.Tag.ToString()) { if (!string.IsNullOrEmpty(this.mRecording.Shortcut) && MainWindow.sMacroMapping.ContainsKey(this.mRecording.Shortcut)) { MainWindow.sMacroMapping.Remove(this.mRecording.Shortcut); } if (this.mMacroShortcutTextBox.Tag != null && !string.IsNullOrEmpty(this.mMacroShortcutTextBox.Tag.ToString())) { MainWindow.sMacroMapping[this.mMacroShortcutTextBox.Tag.ToString()] = this.mScriptName.Text; } if (this.mRecording.Shortcut != null && this.mMacroShortcutTextBox.Tag != null && !string.Equals(this.mRecording.Shortcut, this.mMacroShortcutTextBox.Tag.ToString(), StringComparison.InvariantCulture)) { ClientStats.SendMiscellaneousStatsAsync("MacroOperations", RegistryManager.Instance.UserGuid, RegistryManager.Instance.ClientVersion, "macro_window_shortcutkey", (string)null, this.mRecording.RecordingType.ToString(), (string)null, (string)null, (string)null, "Android"); } if (this.mMacroShortcutTextBox.Tag != null) { this.mRecording.Shortcut = this.mMacroShortcutTextBox.Tag.ToString(); } if (this.mRecording.PlayOnStart) { this.ParentWindow.mAutoRunMacro = this.mRecording; } string contents = JsonConvert.SerializeObject((object)this.mRecording, serializerSettings); File.WriteAllText(str1, contents); } if (!string.Equals(this.mRecording.Name.Trim(), this.mScriptName.Text.Trim(), StringComparison.InvariantCultureIgnoreCase)) { string oldMacroName = this.mRecording.Name; MacroRecording macroRecording = MacroGraph.Instance.Vertices.Cast <MacroRecording>().Where <MacroRecording>((Func <MacroRecording, bool>)(macro => string.Equals(macro.Name, this.mRecording.Name, StringComparison.InvariantCultureIgnoreCase))).FirstOrDefault <MacroRecording>(); macroRecording.Name = this.mScriptName.Text.ToLower(CultureInfo.InvariantCulture).Trim(); this.mRecording.Name = this.mScriptName.Text.Trim(); if (this.mRecording.PlayOnStart) { this.ParentWindow.mAutoRunMacro = this.mRecording; } string contents = JsonConvert.SerializeObject((object)this.mRecording, serializerSettings); File.WriteAllText(str1, contents); string destFileName = Path.Combine(RegistryStrings.MacroRecordingsFolderPath, this.mScriptName.Text.Trim() + ".json"); File.Move(str1, destFileName); foreach (MacroRecording record in macroRecording.Parents.Cast <MacroRecording>()) { foreach (MergedMacroConfiguration macroConfiguration in (Collection <MergedMacroConfiguration>)record.MergedMacroConfigurations) { List <string> stringList = new List <string>(); foreach (string str2 in macroConfiguration.MacrosToRun.Select <string, string>((Func <string, string>)(macroToRun => !string.Equals(oldMacroName, macroToRun, StringComparison.CurrentCultureIgnoreCase) ? macroToRun : macroToRun.Replace(macroToRun, this.mRecording.Name)))) { stringList.Add(str2); } macroConfiguration.MacrosToRun.Clear(); foreach (string str2 in stringList) { macroConfiguration.MacrosToRun.Add(str2); } } CommonHandlers.SaveMacroJson(record, CommonHandlers.GetCompleteMacroRecordingPath(record.Name)); CommonHandlers.OnMacroSettingChanged(record); } if (this.IsBookmarked) { SingleMacroControl.DeleteScriptNameFromBookmarkedScriptListIfPresent(oldMacroName); this.AddScriptNameToBookmarkedScriptListIfNotPresent(this.mRecording.Name); } } CommonHandlers.OnMacroSettingChanged(this.mRecording); CommonHandlers.RefreshAllMacroRecorderWindow(); CommonHandlers.ReloadMacroShortcutsForAllInstances(); } catch (Exception ex) { Logger.Error("Error in saving macro settings: " + ex.ToString()); } }
private static IntPtr KeyboardHookCallback(int nCode, IntPtr wParam, IntPtr lParam) { try { if (GlobalKeyBoardMouseHooks.sIsEnableKeyboardHookLogging) { Logger.Info("Keyboard hook .." + nCode.ToString() + ".." + wParam.ToString() + ".." + lParam.ToString()); } MainWindow window = BlueStacksUIUtils.ActivatedWindow; if (nCode >= 0) { if (!(wParam == (IntPtr)256) && !(wParam == (IntPtr)260)) { if (!(wParam == (IntPtr)257)) { goto label_19; } } int virtualKey = Marshal.ReadInt32(lParam); Logger.Debug("Keyboard hook .." + virtualKey.ToString() + ".." + GlobalKeyBoardMouseHooks.sKey); if (!(wParam == (IntPtr)256)) { if (!(wParam == (IntPtr)260)) { goto label_19; } } if (!string.IsNullOrEmpty(GlobalKeyBoardMouseHooks.sKey) && (Keys)virtualKey == (Keys)Enum.Parse(typeof(Keys), GlobalKeyBoardMouseHooks.sKey, false) && (GlobalKeyBoardMouseHooks.sIsControlUsedInBossKey ? 1 : 0) == (Keyboard.IsKeyDown(Key.LeftCtrl) ? 1 : (Keyboard.IsKeyDown(Key.RightCtrl) ? 1 : 0)) && ((GlobalKeyBoardMouseHooks.sIsAltUsedInBossKey ? 1 : 0) == (Keyboard.IsKeyDown(Key.LeftAlt) ? 1 : (Keyboard.IsKeyDown(Key.RightAlt) ? 1 : 0)) && (GlobalKeyBoardMouseHooks.sIsShiftUsedInBossKey ? 1 : 0) == (Keyboard.IsKeyDown(Key.LeftShift) ? 1 : (Keyboard.IsKeyDown(Key.RightShift) ? 1 : 0)))) { ThreadPool.QueueUserWorkItem((WaitCallback)(obj => { if (BlueStacksUIUtils.DictWindows.Values.Count <= 0) { return; } MainWindow mainWindow = BlueStacksUIUtils.DictWindows.Values.ToList <MainWindow>()[0]; mainWindow.Dispatcher.Invoke((Delegate)(() => { try { if (mainWindow.OwnedWindows.OfType <OnBoardingPopupWindow>().Any <OnBoardingPopupWindow>() || mainWindow.OwnedWindows.OfType <GameOnboardingControl>().Any <GameOnboardingControl>()) { return; } GlobalKeyBoardMouseHooks.mIsHidden = !GlobalKeyBoardMouseHooks.mIsHidden; BlueStacksUIUtils.HideUnhideBlueStacks(GlobalKeyBoardMouseHooks.mIsHidden); } catch { } })); })); return((IntPtr)1); } if (window != null) { if (!Keyboard.IsKeyDown(Key.LeftCtrl)) { if (!Keyboard.IsKeyDown(Key.RightCtrl)) { goto label_19; } } if (!Keyboard.IsKeyDown(Key.LeftAlt)) { if (!Keyboard.IsKeyDown(Key.RightAlt)) { goto label_19; } } if (virtualKey >= 96 && virtualKey <= 105) { virtualKey -= 48; } string vkString = IMAPKeys.GetStringForFile(KeyInterop.KeyFromVirtualKey(virtualKey)); if (MainWindow.sMacroMapping.Keys.Contains <string>(vkString)) { ThreadPool.QueueUserWorkItem((WaitCallback)(obj => { try { window.Dispatcher.Invoke((Delegate)(() => { if (window.mSidebar.GetElementFromTag("sidebar_macro") != null && window.mSidebar.GetElementFromTag("sidebar_macro").Visibility == Visibility.Visible && window.mSidebar.GetElementFromTag("sidebar_macro").IsEnabled) { if (window.mIsMacroRecorderActive) { window.ShowToast(LocaleStrings.GetLocalizedString("STRING_STOP_RECORDING_FIRST", ""), "", "", false); } else if (window.mIsMacroPlaying) { CustomMessageWindow customMessageWindow = new CustomMessageWindow(); BlueStacksUIBinding.Bind(customMessageWindow.TitleTextBlock, "STRING_CANNOT_RUN_MACRO", ""); BlueStacksUIBinding.Bind(customMessageWindow.BodyTextBlock, "STRING_STOP_MACRO_SCRIPT", ""); customMessageWindow.AddButton(ButtonColors.Blue, "STRING_OK", (EventHandler)null, (string)null, false, (object)null, true); customMessageWindow.Owner = (Window)window; customMessageWindow.ShowDialog(); } else { try { string path = Path.Combine(RegistryStrings.MacroRecordingsFolderPath, MainWindow.sMacroMapping[vkString] + ".json"); if (!File.Exists(path)) { return; } MacroRecording record = JsonConvert.DeserializeObject <MacroRecording>(File.ReadAllText(path), Utils.GetSerializerSettings()); record.Name = MainWindow.sMacroMapping[vkString]; window.mCommonHandler.FullMacroScriptPlayHandler(record); ClientStats.SendMiscellaneousStatsAsync("MacroOperations", RegistryManager.Instance.UserGuid, RegistryManager.Instance.ClientVersion, "macro_play", "shortcut_keys", record.RecordingType.ToString(), string.IsNullOrEmpty(record.MacroId) ? "local" : "community", (string)null, (string)null, "Android"); } catch (Exception ex) { Logger.Error("Exception in macro play with shortcut: " + ex.ToString()); } } } else { Logger.Info("Macro not enabled for the current package: " + window.StaticComponents.mSelectedTabButton.PackageName); } })); } catch { } })); } } } } catch { } label_19: return(NativeMethods.CallNextHookEx(GlobalKeyBoardMouseHooks.mKeyboardHookID, nCode, wParam, lParam)); }
public void UpdateMacroRecordingObject(MacroRecording record) { this.mRecording = record; }