-
Notifications
You must be signed in to change notification settings - Fork 96
/
Helper.cs
131 lines (112 loc) · 4 KB
/
Helper.cs
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
using System;
using System.Collections.Generic;
using System.Threading;
using System.Windows.Controls;
namespace FastbootEnhance
{
class Helper
{
public class TaskbarItemHelper
{
public static void start()
{
MainWindow.THIS.taskbariteminfo.ProgressValue = 0;
MainWindow.THIS.taskbariteminfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.Normal;
}
public static void stop()
{
MainWindow.THIS.taskbariteminfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.None;
}
public static void update(int percent)
{
MainWindow.THIS.taskbariteminfo.ProgressValue = percent / 100.0;
}
}
public static void offloadAndRun(Action bigtask, Action callbackOnUIThread)
{
new Thread(new ThreadStart(delegate
{
bigtask();
MainWindow.THIS.Dispatcher.Invoke(callbackOnUIThread);
})).Start();
}
public class ListHelper<T>
{
public delegate bool Filter(T t);
ListView listView;
List<T> items;
Filter filter;
public ListHelper(ListView listView, Filter filter)
{
this.listView = listView;
items = new List<T>();
this.filter = filter;
}
public void clear()
{
listView.SelectedItems.Clear();
listView.Items.Clear();
items = new List<T>();
}
public void addItem(T item)
{
items.Add(item);
}
public void render()
{
listView.Items.Clear();
foreach (T t in items)
{
listView.Items.Add(t);
}
}
public void doFilter()
{
listView.Items.Clear();
foreach (T t in items)
{
if (filter(t))
listView.Items.Add(t);
}
}
}
public delegate void PathSelectCallback(string path);
public static void fileSelect(PathSelectCallback callback, string filter = "All Files|*.*")
{
System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog();
openFileDialog.Filter = filter;
if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
callback(openFileDialog.FileName);
}
}
public static void pathSelect(PathSelectCallback callback)
{
System.Windows.Forms.FolderBrowserDialog folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();
folderBrowserDialog.Description = Properties.Resources.select_save_path;
if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
callback(folderBrowserDialog.SelectedPath);
}
}
public static DateTime timeStamp2DataTime(Int64 timestamp)
{
Int64 begtime = timestamp * 10000000;
DateTime dt_1970 = new DateTime(1970, 1, 1, 8, 0, 0);
long tricks_1970 = dt_1970.Ticks;
long time_tricks = tricks_1970 + begtime;
DateTime dt = new DateTime(time_tricks);
return dt;
}
public static string byte2AUnit(ulong size)
{
if (size > 1024 * 1024 * 1024)
return (int)((double)size / 1024 / 1024 / 1024 * 100) / 100.0 + " GB";
if (size > 1024 * 1024)
return (int)((double)size / 1024 / 1024 * 100) / 100.0 + " MB";
if (size > 1024)
return (int)((double)size / 1024 * 100) / 100.0 + " KB";
return size + " B";
}
}
}