This repository was archived by the owner on Mar 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
305 lines (265 loc) · 10.3 KB
/
MainWindow.xaml.cs
File metadata and controls
305 lines (265 loc) · 10.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
//.____ __ _____ .__ .__ ____
//| | __ __ ____ | | __ ___.__. / \ |__| ____ |__| ____ / ___\
//| | | | \ _/ ___\ | |/ / < | | / \ / \ | | / \ | | / \ / /_/ >
//| |___ | | / \ \___ | < \___ | / Y \ | | | | \ | | | | \ \___ /
//|_______ \ |____/ \___ > |__|_ \ / ____| \____|__ / |__| |___| / |__| |___| / /_____/
// |
// Copyright 2021 by YK303
// |
// Licensed under the Apache License , Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// |
// http://www.apache.org/licenses/
// |
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using DiscordRPC;
using DiscordRPC.Logging;
using LuckyMining.Models;
using LuckyMining.Saving;
using LuckyMining.Views;
using System;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace LuckyMining
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public static Users user;
public static MainWindow mainwindow;
public static DiscordRpcClient client;
private static int idleTime = 0;
public MainWindow()
{
this.InitializeComponent();
startStatusBarTimer();
Discord();
//views pages
mainwindow = this;
grid.Children.Clear();
grid.Children.Add(new MinerLauncher());
foreach (UIElement uie in grid.Children)
{
uie.Visibility = Visibility.Hidden;
}
grid.Children[0].Visibility = Visibility.Visible;
}
private void startStatusBarTimer()
{
try
{
System.Timers.Timer statusTime = new System.Timers.Timer();
statusTime.Interval = 1000;
statusTime.Elapsed += new System.Timers.ElapsedEventHandler(data);
statusTime.Enabled = true;
}
catch
{
}
}
private void ListViewMenu_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//on listviewmenu selected item change page
if (grid == null)
return;
foreach (UIElement uie in grid.Children)
{
uie.Visibility = Visibility.Hidden;
}
grid.Children[0].Visibility = Visibility.Visible;
}
//exit app
private void Button_Click_2(object sender, RoutedEventArgs e)
{
//on button click exit Application
if (Process.GetProcesses().Count(p => p.ProcessName == "lolMiner") >= 1)
{
foreach (Process process in Process.GetProcessesByName("lolMiner"))
{
process.Kill();
}
}
client.Dispose();
System.Windows.Application.Current.Shutdown();
}
//minimize app
private void Button_Click_3(object sender, RoutedEventArgs e)
{
//Minimize window
this.WindowState = WindowState.Minimized;
}
//move system window
private void Window_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
{
//Move window on leftbutton mouse clicked
if (e.LeftButton == MouseButtonState.Pressed)
{
this.DragMove();
}
}
//double click maximize
private long doublePressInterval_ms = 300; private DateTime lastPressTime = DateTime.Now;
private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
DateTime pressTime = DateTime.Now;
if ((pressTime - lastPressTime).TotalMilliseconds <= doublePressInterval_ms)
{
//clicked twice
if (this.WindowState == WindowState.Maximized)
this.WindowState = WindowState.Normal;
else
this.WindowState = WindowState.Maximized;
}
lastPressTime = pressTime;
}
//maximize window button
private void Button_Click_4(object sender, RoutedEventArgs e)
{
//var btn = (Button)sender;
if (this.WindowState == WindowState.Normal)
{
this.WindowState = WindowState.Maximized;
}
else
{
this.WindowState = WindowState.Normal;
}
}
//Called when your application first starts.
private void Discord()
{
user = SaveManager.ReadFromXmlFile<Users>("data", "account");
Uri uri = new Uri($"https://cdn.discordapp.com/avatars/{user.id}/{user.avatar}.png", UriKind.Absolute);
ImageSource imgSource = new BitmapImage(uri);
//Create a Discord client
client = new DiscordRpcClient("//Your Client id");
//Set the logger
client.Logger = new ConsoleLogger() { Level = LogLevel.Warning };
//Subscribe to events
client.OnReady += (sender, e) =>
{
Debug.WriteLine("Received Ready from user {0}", e.User.Username);
};
client.OnPresenceUpdate += (sender, e) =>
{
Debug.WriteLine("Received Update! {0}", e.Presence);
};
//Connect to the RPC
client.Initialize();
}
[DllImport("user32.dll")]
private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
private static int GetLastInputTime()
{
LASTINPUTINFO lastInputInfo = new LASTINPUTINFO();
lastInputInfo.cbSize = Marshal.SizeOf(lastInputInfo);
lastInputInfo.dwTime = 0;
int envTicks = Environment.TickCount;
if (GetLastInputInfo(ref lastInputInfo))
{
int lastInputTick = (int)lastInputInfo.dwTime;
idleTime = envTicks - lastInputTick;
}
return (idleTime > 0) ? (idleTime / 1000) : idleTime;
}
[StructLayout(LayoutKind.Sequential)]
private struct LASTINPUTINFO
{
public static readonly int SizeOf = Marshal.SizeOf(typeof(LASTINPUTINFO));
[MarshalAs(UnmanagedType.U4)]
public int cbSize;
[MarshalAs(UnmanagedType.U4)]
public UInt32 dwTime;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
var url = "https://github.com/YoussofKhawaja/LuckyMining";
Process newProcess = Process.Start(new ProcessStartInfo(url) { UseShellExecute = true });
}
private void data(object sender, ElapsedEventArgs e)
{
this.Dispatcher.Invoke(() =>
{
GetLastInputTime();
if (Process.GetProcesses().Count(p => p.ProcessName == "lolMiner") == 0 && idleTime / 1000 > 60)
{
//Invoke all the events, such as OnPresenceUpdate
MainWindow.client.Invoke();
MainWindow.client.SetPresence(new RichPresence()
{
Details = "In MinerLauncher",
State = "Idle Not Mining",
Assets = new Assets()
{
LargeImageKey = "lm",
LargeImageText = "LuckyMining",
SmallImageKey = "moon",
SmallImageText = "Idle"
}
});
}
else if (Process.GetProcesses().Count(p => p.ProcessName == "lolMiner") == 1 && idleTime / 1000 > 60)
{
//Invoke all the events, such as OnPresenceUpdate
MainWindow.client.Invoke();
MainWindow.client.SetPresence(new RichPresence()
{
Details = "In MinerLauncher",
State = "Idle Mining Ethereum",
Assets = new Assets()
{
LargeImageKey = "mining",
LargeImageText = "LuckyMining",
SmallImageKey = "moon",
SmallImageText = "Idle"
}
});
}
else if (Process.GetProcesses().Count(p => p.ProcessName == "lolMiner") == 0)
{
//Invoke all the events, such as OnPresenceUpdate
MainWindow.client.Invoke();
MainWindow.client.SetPresence(new RichPresence()
{
Details = "In MinerLauncher",
State = "Not Mining",
Assets = new Assets()
{
LargeImageKey = "lm",
LargeImageText = "LuckyMining"
}
});
}
else if (Process.GetProcesses().Count(p => p.ProcessName == "lolMiner") == 1)
{
//Invoke all the events, such as OnPresenceUpdate
MainWindow.client.Invoke();
MainWindow.client.SetPresence(new RichPresence()
{
Details = "In MinerLauncher",
State = "Mining Ethereum",
Assets = new Assets()
{
LargeImageKey = "mining",
LargeImageText = "LuckyMining"
}
});
}
});
}
}
}