-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathMainWindow.xaml.cs
244 lines (206 loc) · 8.75 KB
/
MainWindow.xaml.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
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
using FreeAdobe.src;
using FreeAdobe.src.model;
using FreeAdobe.src.view;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace FreeAdobe
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
private static List<PatchInfo> patchInfos;
private List<AdobeProductBean> adobeProductBeans = new List<AdobeProductBean>();
public MainWindow()
{
InitializeComponent();
initView();
startCheck();
}
private void initView() {
patchInfos = AdobePatchUtil.loadAllProduct();
HashSet<string> productSet = new HashSet<string>();
foreach (PatchInfo info in patchInfos)
{
if (!productSet.Contains(info.Product + info.Version)) {
productSet.Add(info.Product+info.Version);
adobeProductBeans.Add(new AdobeProductBean(info.Product, info.Version, "resources/" + info.ProductName + ".png", info.ProductName + " " + info.Version, "", "https://www.baidu.com",info.LaunchPath));
}
}
lbProduct.ItemsSource = adobeProductBeans;
}
private void btnPatch_Click(object sender, RoutedEventArgs e)
{
Button btn = sender as Button;
AdobeProductBean bean = btn.DataContext as AdobeProductBean;
if (bean != null) {
if (!File.Exists(bean.LaunchPath))
{
HelpWindow helpWindow = new HelpWindow("提示", "软件未安装,或者未安装在默认目录,请按照以下提示使用\n\n" +
"1、去Adobe官网下载CreativeCloud并且安装\n" +
"2、通过CreativeCloud下载你想要的应用比如Photoshop(需要登陆CreativeCloud)\n" +
"3、在本软件内找到你下载的版本,点击优化即可使用\n" +
"4、注意不要更改adobe系列软件的安装目录\n" +
"5、点击确定按钮去官网下载CreativeCloud", new HelperHandler("help"));
helpWindow.Show();
}
else
{
try
{
bool succ = AdobePatchUtil.patchProduct(bean.Product, bean.Version);
if (succ)
{
alert(bean.Name + "优化成功,已经可以正常使用");
}
else
{
alert(bean.Name + "优化失败,可能已经优化过,请启动尝试。如果未优化成功请联系开发者反馈");
}
}
catch(Exception e1) {
alert(bean.Name + "发生未知错误,请联系开发者反馈:"+e1.ToString());
}
}
}
}
private void btnLaunch_Click(object sender, RoutedEventArgs e) {
Button btn = sender as Button;
AdobeProductBean bean = btn.DataContext as AdobeProductBean;
if (bean != null) {
if (!File.Exists(bean.LaunchPath))
{
HelpWindow helpWindow = new HelpWindow("提示", "软件未安装,或者未安装在默认目录,请按照以下提示使用\n\n1、去Adobe官网下载CreativeCloud并且安装\n" +
"2、通过CreativeCloud下载你想要的应用比如Photoshop(需要登陆CreativeCloud)\n" +
"3、在本软件内找到你下载的版本,点击优化即可使用\n" +
"4、注意不要更改adobe系列软件的安装目录\n" +
"5、点击确定按钮去官网下载CreativeCloud", new HelperHandler("help"));
helpWindow.Show();
}
else {
Process.Start(bean.LaunchPath);
}
}
}
private void btnClose_Click(object sender, RoutedEventArgs e)
{
System.Environment.Exit(0);
}
private void btnMinus_Click(object sender, RoutedEventArgs e)
{
this.WindowState = WindowState.Minimized;
}
private void MoveMainWindow(object sender, MouseButtonEventArgs e)
{
base.DragMove();
}
private static void alert(string notice) {
MessageBox.Show(notice,"提醒");
}
private void btnHelp_Click(object sender, RoutedEventArgs e)
{
HelpWindow helpWindow = new HelpWindow("帮助", "使用方式如下:\n1、去Adobe官网下载CreativeCloud并且安装\n" +
"2、通过CreativeCloud下载你想要的应用比如Photoshop(需要登陆CreativeCloud)\n" +
"3、在本软件内找到你下载的版本,点击优化即可使用\n" +
"4、注意不要更改adobe系列软件的安装目录\n" +
"5、点击确定按钮去官网下载CreativeCloud", new HelperHandler("help"));
helpWindow.Show();
}
class HelperHandler : NotifyEventListener
{
string eventType;
public HelperHandler(string eventType)
{
this.eventType = eventType;
}
public void onCancelClicked(object msg)
{
if (eventType.Equals("verify")||eventType.Equals("enable")||eventType.Equals("update")) {
Environment.Exit(0);
}
}
public void onOkClicked(object msg)
{
if (eventType.Equals("help"))
{
Process.Start("https://creativecloud.adobe.com/apps/download/creative-cloud?locale=zh-cn");
}
else if (eventType.Equals("update")) {
Process.Start(startConfigBean.Download);
}
else if (eventType.Equals("enable"))
{
Environment.Exit(0);
}
else if (eventType.Equals("verify"))
{
string code=(string)msg;
if (!code.Equals("从来不想")) {
Environment.Exit(0);
}
}
}
}
private void btnLogo_Click(object sender, RoutedEventArgs e)
{
Process.Start("https://bestyize.github.io/adobe/freeadobe/");
}
private static StartConfigBean startConfigBean;
private void startCheck() {
Task updateTask = new Task(() =>
{
startConfigBean = StartCheck.doCheck();
this.Dispatcher.BeginInvoke(new Action(() =>
{
if (startConfigBean != null)
{
HelperHandler handler = new HelperHandler("null");
bool show = false;
if (startConfigBean.Enable.Equals("0"))
{
//弹窗暂停使用
handler = new HelperHandler("enable");
show = true;
}
else if (startConfigBean.Verify.Equals("1"))
{
//弹窗提示用户输入密码
handler = new HelperHandler("verify");
show = true;
}
else if (startConfigBean.Version.CompareTo("1.0") > 0)
{
//弹窗提示更新
handler = new HelperHandler("update");
show = true;
}
if (show) {
HelpWindow helpWindow = new HelpWindow(startConfigBean.Title, startConfigBean.Notice, handler);
helpWindow.Show();
}
}
else
{
}
}));
});
updateTask.Start();
}
}
}