From e59e15ee78a1007361813ba686937c4f68b8de67 Mon Sep 17 00:00:00 2001 From: Grayfox Zou Date: Tue, 12 Dec 2023 00:19:12 +0800 Subject: [PATCH 1/2] Add Pause when running and separate the RunThreadLogic --- iOSFakeRun/MainWindow.xaml | 6 +- iOSFakeRun/MainWindow.xaml.cs | 259 +++++++++++++++++++++------------- 2 files changed, 166 insertions(+), 99 deletions(-) diff --git a/iOSFakeRun/MainWindow.xaml b/iOSFakeRun/MainWindow.xaml index 24e8038..68346b9 100644 --- a/iOSFakeRun/MainWindow.xaml +++ b/iOSFakeRun/MainWindow.xaml @@ -125,8 +125,10 @@ x:Name="DoubleUpDownSpeed" /> - - + + + + \ No newline at end of file diff --git a/iOSFakeRun/MainWindow.xaml.cs b/iOSFakeRun/MainWindow.xaml.cs index 443e575..07b0db1 100644 --- a/iOSFakeRun/MainWindow.xaml.cs +++ b/iOSFakeRun/MainWindow.xaml.cs @@ -18,9 +18,12 @@ public partial class MainWindow private readonly IiDeviceApi _ideviceInstance = LibiMobileDevice.Instance.iDevice; private readonly ILockdownApi _lockdownInstance = LibiMobileDevice.Instance.Lockdown; private iDeviceHandle? _idevice; - private bool _isRunning; + private bool _isRunning, _isPaused; private LockdownClientHandle? _lockdownClient; - + private int tmpPoint, tmpTime,totalRunTimes; + private double metersPerSecond, barPercentage; + private List pointFixedList, pointList; + public MainWindow() { InitializeComponent(); @@ -48,9 +51,11 @@ private void Link(object sender, RoutedEventArgs e) } _ideviceInstance.idevice_new(out _idevice, udids[0]).ThrowOnError(); - _lockdownInstance.lockdownd_client_new_with_handshake(_idevice, out _lockdownClient, "iOSFakeRun").ThrowOnError(); + _lockdownInstance.lockdownd_client_new_with_handshake(_idevice, out _lockdownClient, "iOSFakeRun") + .ThrowOnError(); - if (!DeviceUtils.GetName(_lockdownClient, out var deviceName) || !DeviceUtils.GetVersion(_lockdownClient, out var iosVersion)) + if (!DeviceUtils.GetName(_lockdownClient, out var deviceName) || + !DeviceUtils.GetVersion(_lockdownClient, out var iosVersion)) { _idevice?.Dispose(); _lockdownClient?.Dispose(); @@ -118,11 +123,129 @@ private void Quit(object sender, RoutedEventArgs e) Close(); } + public void RunThreadLogic(List inPointFixedList, List inPointList,double metersPerSecond, int totalRunTimes) + { + StatusBarTextBlock.Dispatcher.BeginInvoke((ThreadStart)delegate + { + ButtonRun.Visibility = Visibility.Hidden; + ButtonStop.Visibility = Visibility.Visible; + ButtonPause.Visibility = Visibility.Visible; + IntegerUpDownRunTimes.IsEnabled = false; + DoubleUpDownSpeed.IsEnabled = false; + StatusBarTextBlock.Text = "正在跑步中..."; + ProgressBarRun.Value = 0.0; + }); + + var pointFixedNumber = inPointFixedList.Count; + + var pointTrueList = new List { inPointFixedList[0] }; + + for (var i = 0; i < pointFixedNumber - 1;) + { + var distance = CoordinateUtils.CalcDistance(inPointFixedList[i], inPointFixedList.Last()); + + var j = i + 1; + for (; j < pointFixedNumber; j++) + { + distance = CoordinateUtils.CalcDistance(inPointFixedList[i], inPointFixedList[j]); + + if (!(distance > metersPerSecond)) + { + continue; + } + + break; + } + + inPointList = CoordinateUtils.CutLineToPoints(inPointFixedList[i], inPointFixedList[j], + (int)(distance / metersPerSecond)); + pointTrueList.AddRange(inPointList); + + i = j; + } + + var pointTrueNumber = pointTrueList.Count; + for (var time = tmpTime; time < totalRunTimes; time++) + { + for (var i = tmpPoint; i < pointTrueNumber; i++) + { + tmpPoint = i; + tmpTime = time; + if (!_isRunning || + !Location.SetLocation(_idevice, _lockdownClient, pointTrueList[i][0], pointTrueList[i][1])) + { + if (_isRunning) + { + _isRunning = false; + MessageBox.Show("修改定位失败\n请检查是否连接并尝试再次点击连接按钮"); + } + + if (_isPaused) + { + StatusBarTextBlock.Dispatcher.BeginInvoke((ThreadStart)delegate + { + StatusBarTextBlock.Text = "未在跑步状态"; + ButtonRun.Visibility = Visibility.Hidden; + ButtonPause.Visibility = Visibility.Hidden; + ButtonStop.Visibility = Visibility.Visible; + ButtonResume.Visibility = Visibility.Visible; + IntegerUpDownRunTimes.IsEnabled = true; + DoubleUpDownSpeed.IsEnabled = true; + ProgressBarRun.Value = barPercentage; + + }); + } + else + { + StatusBarTextBlock.Dispatcher.BeginInvoke((ThreadStart)delegate + { + StatusBarTextBlock.Text = "未在跑步状态"; + ButtonRun.Visibility = Visibility.Visible; + ButtonPause.Visibility = Visibility.Hidden; + ButtonStop.Visibility = Visibility.Hidden; + IntegerUpDownRunTimes.IsEnabled = true; + DoubleUpDownSpeed.IsEnabled = true; + ProgressBarRun.Value = barPercentage; + }); + } + + return; + } + + Thread.Sleep(1000); + i++; + var iOut = i; + var timeNow = time; + ProgressBarRun.Dispatcher.BeginInvoke((ThreadStart)delegate + { + ProgressBarRun.Value = + ((double)iOut / (pointTrueNumber * totalRunTimes) + (double)timeNow / totalRunTimes) * + ProgressBarRun.Maximum; + barPercentage =ProgressBarRun.Value; + }); + } + } + + _isRunning = false; + StatusBarTextBlock.Dispatcher.BeginInvoke((ThreadStart)delegate + { + StatusBarTextBlock.Text = "跑步完成"; + ButtonRun.Visibility = Visibility.Visible; + ButtonStop.Visibility = Visibility.Hidden; + ButtonPause.Visibility = Visibility.Hidden; + ButtonResume.Visibility = Visibility.Hidden; + IntegerUpDownRunTimes.IsEnabled = true; + DoubleUpDownSpeed.IsEnabled = true; + }); + } + private void StartRun(object sender, RoutedEventArgs e) { var pointText = TextBoxRoute.Text; - var pointList = new List(); - + pointList = new List(); + tmpTime = 0; + tmpPoint = 0; + barPercentage = 0.0; try { if (!pointText.Substring(0, 1).Equals("[")) @@ -155,7 +278,7 @@ private void StartRun(object sender, RoutedEventArgs e) var latitude = double.Parse(latitudeToken.ToString()); var longitude = double.Parse(longitudeToken.ToString()); - double[] route = {latitude, longitude}; + double[] route = { latitude, longitude }; pointList.Add(route); } } @@ -178,114 +301,56 @@ private void StartRun(object sender, RoutedEventArgs e) writer.WriteLine(pointText); writer.Close(); - var pointFixedList = pointList.Select(point => CoordinateUtils.Bd09ToWgs84(point[0], point[1])).ToList(); - - var metersPerSecond = DoubleUpDownSpeed.Value ?? 0.0; - var totalRunTimes = IntegerUpDownRunTimes.Value ?? 1; + pointFixedList = pointList.Select(point => CoordinateUtils.Bd09ToWgs84(point[0], point[1])).ToList(); + + metersPerSecond = DoubleUpDownSpeed.Value ?? 0.0; + totalRunTimes = IntegerUpDownRunTimes.Value ?? 1; if (totalRunTimes > 1) { pointFixedList.Add(pointFixedList[0]); } + + var runThread = new Thread(() => RunThreadLogic(pointFixedList, pointList, metersPerSecond, totalRunTimes)); - var runThread = new Thread(() => - { - StatusBarTextBlock.Dispatcher.BeginInvoke((ThreadStart) delegate - { - ButtonRun.Visibility = Visibility.Hidden; - ButtonStop.Visibility = Visibility.Visible; - IntegerUpDownRunTimes.IsEnabled = false; - DoubleUpDownSpeed.IsEnabled = false; - StatusBarTextBlock.Text = "正在跑步中..."; - ProgressBarRun.Value = 0.0; - }); - - var pointFixedNumber = pointFixedList.Count; - - var pointTrueList = new List {pointFixedList[0]}; - - for (var i = 0; i < pointFixedNumber - 1;) - { - var distance = CoordinateUtils.CalcDistance(pointFixedList[i], pointFixedList.Last()); - - var j = i + 1; - for (; j < pointFixedNumber; j++) - { - distance = CoordinateUtils.CalcDistance(pointFixedList[i], pointFixedList[j]); - - if (!(distance > metersPerSecond)) - { - continue; - } - - break; - } - - pointList = CoordinateUtils.CutLineToPoints(pointFixedList[i], pointFixedList[j], (int) (distance / metersPerSecond)); - pointTrueList.AddRange(pointList); - - i = j; - } - - var pointTrueNumber = pointTrueList.Count; - for (var time = 0; time < totalRunTimes; time++) - { - for (var i = 0; i < pointTrueNumber; i++) - { - if (!_isRunning || !Location.SetLocation(_idevice, _lockdownClient, pointTrueList[i][0], pointTrueList[i][1])) - { - if (_isRunning) - { - _isRunning = false; - MessageBox.Show("修改定位失败\n请检查是否连接并尝试再次点击连接按钮"); - } - - StatusBarTextBlock.Dispatcher.BeginInvoke((ThreadStart) delegate - { - StatusBarTextBlock.Text = "未在跑步状态"; - ButtonRun.Visibility = Visibility.Visible; - ButtonStop.Visibility = Visibility.Hidden; - IntegerUpDownRunTimes.IsEnabled = true; - DoubleUpDownSpeed.IsEnabled = true; - ProgressBarRun.Value = 0.0; - }); - - return; - } - - Thread.Sleep(1000); - i++; - var iOut = i; - var timeNow = time; - ProgressBarRun.Dispatcher.BeginInvoke((ThreadStart) delegate - { - ProgressBarRun.Value = ((double) iOut / (pointTrueNumber * totalRunTimes) + (double) timeNow / totalRunTimes) * ProgressBarRun.Maximum; - }); - } - } + _isRunning = true; + _isPaused = false; + runThread.Start(); + } - _isRunning = false; - StatusBarTextBlock.Dispatcher.BeginInvoke((ThreadStart) delegate - { - StatusBarTextBlock.Text = "跑步完成"; - ButtonRun.Visibility = Visibility.Visible; - ButtonStop.Visibility = Visibility.Hidden; - IntegerUpDownRunTimes.IsEnabled = true; - DoubleUpDownSpeed.IsEnabled = true; - }); - }); + private void PauseRun(object sender, RoutedEventArgs e) + { + _isRunning = false; + _isPaused = true; + ButtonResume.Visibility = Visibility.Visible; + ButtonPause.Visibility = Visibility.Hidden; + ButtonRun.Visibility = Visibility.Hidden; + } + private void ResumeRun(object sender, RoutedEventArgs e) + { _isRunning = true; + _isPaused = false; + ButtonPause.Visibility = Visibility.Visible; + ButtonResume.Visibility = Visibility.Hidden; + ButtonRun.Visibility = Visibility.Hidden; + + var runThread = new Thread(() => RunThreadLogic(pointFixedList, pointList, metersPerSecond, totalRunTimes)); runThread.Start(); } private void StopRun(object sender, RoutedEventArgs e) { _isRunning = false; + _isPaused = false; + ButtonRun.Visibility = Visibility.Visible; + ButtonStop.Visibility = Visibility.Hidden; + ButtonPause.Visibility = Visibility.Hidden; + ButtonResume.Visibility = Visibility.Hidden; } private void About(object sender, RoutedEventArgs e) { MessageBox.Show("iOS Fake Run\n版本: v0.9\n作者: Myth\n\n请勿将本工具用于任何非法用途"); } -} +} \ No newline at end of file From 715400694bfe918748ebca734ff3a2258f184ad1 Mon Sep 17 00:00:00 2001 From: Myth Date: Fri, 15 Dec 2023 01:14:00 +0800 Subject: [PATCH 2/2] fix: grid --- iOSFakeRun/MainWindow.xaml | 54 +++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/iOSFakeRun/MainWindow.xaml b/iOSFakeRun/MainWindow.xaml index 68346b9..ce929ce 100644 --- a/iOSFakeRun/MainWindow.xaml +++ b/iOSFakeRun/MainWindow.xaml @@ -71,7 +71,8 @@ - + @@ -84,10 +85,22 @@ - - - - + + + + @@ -100,9 +113,10 @@ + - +