forked from WinDurango/WinDurango.UI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppTile.xaml.cs
More file actions
339 lines (294 loc) · 13 KB
/
AppTile.xaml.cs
File metadata and controls
339 lines (294 loc) · 13 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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media.Imaging;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Core;
using Windows.Foundation;
using Windows.Storage.Streams;
using WinDurango.UI.Dialogs;
using WinDurango.UI.Pages;
using WinDurango.UI.Pages.Dialog;
using WinDurango.UI.Settings;
using WinDurango.UI.Utils;
namespace WinDurango.UI.Controls
{
public sealed partial class AppTile
{
private Package _package;
private readonly string _familyName;
private string _Name;
private string _Publisher;
private string _Version;
private Uri _Logo;
private AppListEntry appListEntry;
private async void HandleUnregister(object sender, SplitButtonClickEventArgs e)
{
if ((bool)unregisterCheckbox.IsChecked)
{
var confirmation =
new Confirmation(Localization.Locale.GetLocalizedText("/Packages/UninstallConfirmation", _Name),
"Uninstall?");
Dialog.BtnClicked answer = await confirmation.Show();
if (answer != Dialog.BtnClicked.Yes)
return;
confirmation.Remove();
}
if ((bool)unpatchCheckbox.IsChecked && await WinDurangoPatcher.UnpatchPackage(_package, null))
{
await WinDurangoPatcher.UnpatchPackage(_package, null);
}
if ((bool)unregisterCheckbox.IsChecked)
{
var controller = new ProgressDialog($"Uninstalling {_Name}...", $"Uninstalling {_Name}", isIndeterminate: true).GetController();
await controller.CreateAsync(async () =>
{
await Packages.RemovePackage(_package, controller);
});
NoticeDialog good = new NoticeDialog($"{_Name} has been uninstalled.", "Uninstalled");
await good.ShowAsync();
}
App.InstalledPackages.RemovePackage(_package);
_ = App.MainWindow.AppsListPage.InitAppListAsync();
}
private void OpenFolder(object sender, RoutedEventArgs e)
{
Logger.WriteDebug($"Opening app installation folder {_package.InstalledPath}");
_ = Process.Start(new ProcessStartInfo(_package.InstalledPath) { UseShellExecute = true });
}
private async void ShowNotImplemented(object sender, RoutedEventArgs e)
{
Logger.WriteWarning($"Not implemented");
NoticeDialog impl = new NoticeDialog($"This feature has not been implemented yet.", "Not Implemented");
await impl.ShowAsync();
}
private async void ShowModManager(object sender, RoutedEventArgs e)
{
PageDialog pgd = new PageDialog(typeof(ModManPage), _package.InstalledPath, $"Installed mods for {_package.DisplayName}");
pgd.XamlRoot = App.MainWindow.Content.XamlRoot;
await pgd.ShowAsync();
}
private async void ShowSaveManager(object sender, RoutedEventArgs e)
{
PageDialog pgd = new PageDialog(typeof(SaveManagerPage), _familyName, $"{_package.DisplayName} saves");
pgd.XamlRoot = App.MainWindow.Content.XamlRoot;
await pgd.ShowAsync();
}
private async void RepatchPackage(object sender, RoutedEventArgs args)
{
var progress = new ProgressDialog($"Repatching {_Name}...", $"Repatching {_Name}", isIndeterminate: true).GetController();
await progress.CreateAsync(async () =>
{
await WinDurangoPatcher.UnpatchPackage(_package, progress);
await WinDurangoPatcher.PatchPackage(_package, true, progress);
});
NoticeDialog good = new NoticeDialog($"WinDurango was reinstalled in package {_Name}", "Reinstalled");
await good.ShowAsync();
App.MainWindow.ReloadAppList();
}
private async void UnpatchPackage(object sender, RoutedEventArgs args)
{
var progress = new ProgressDialog($"Unpatching {_Name}...", $"Unpatching {_Name}", isIndeterminate: true).GetController();
await progress.CreateAsync(async () =>
{
await WinDurangoPatcher.UnpatchPackage(_package, progress);
});
if (!progress.Failed)
{
NoticeDialog good = new NoticeDialog($"WinDurango has been uninstalled from package {_Name}", "Uninstalled");
await good.ShowAsync();
}
App.MainWindow.ReloadAppList();
}
// BUG: calling second time after failure does not show the failure dialog?
private async void PatchPackage(object sender, RoutedEventArgs args)
{
var progress = new ProgressDialog($"Patching {_Name}...", $"Patching {_Name}", isIndeterminate: true).GetController();
await progress.CreateAsync(async () =>
{
await WinDurangoPatcher.PatchPackage(_package, false, progress);
});
if (!progress.Failed)
{
NoticeDialog good = new NoticeDialog($"WinDurango has been installed in package {_Name}", "Installed");
await good.ShowAsync();
}
App.MainWindow.ReloadAppList();
}
// TODO: This can probably be improved
public AppTile(string familyName)
{
_familyName = familyName;
this.InitializeComponent();
_package = Packages.GetPackageByFamilyName(_familyName);
try
{
_Name = _package.DisplayName ?? _package.Id.Name;
}
catch
{
_Name = _package.Id.Name;
}
_Publisher = _package.PublisherDisplayName ?? _package.Id.PublisherId;
_Version = $"{_package.Id.Version.Major.ToString() ?? "U"}.{_package.Id.Version.Minor.ToString() ?? "U"}.{_package.Id.Version.Build.ToString() ?? "U"}.{_package.Id.Version.Revision.ToString() ?? "U"}";
_Logo = _package.Logo;
ManifestInfo mfInfo = _package.GetProperties();
string ss = String.Empty;
// TODO: This seems slow.
if (!string.IsNullOrEmpty(mfInfo.SplashScreen))
{
ss = Path.Combine(_package.InstalledPath, mfInfo.SplashScreen);
// if it doesn't exist it probably has some scale thing
if (!File.Exists(ss))
{
for (int i = 100; i < 400; i += 100)
{
string path = Path.Combine(_package.InstalledPath, Path.GetDirectoryName(mfInfo.SplashScreen), Path.GetFileNameWithoutExtension(mfInfo.SplashScreen) + $".scale-{i}.png");
if (File.Exists(path))
{
ss = path;
break;
}
}
}
} else if (!string.IsNullOrEmpty(mfInfo.WideLogo))
{
ss = Path.Combine(_package.InstalledPath, mfInfo.WideLogo);
// if it doesn't exist it probably has some scale thing
if (!File.Exists(ss))
{
for (int i = 100; i < 400; i += 100)
{
string path = Path.Combine(_package.InstalledPath, Path.GetDirectoryName(mfInfo.WideLogo), Path.GetFileNameWithoutExtension(mfInfo.WideLogo) + $".scale-{i}.png");
if (File.Exists(path))
{
ss = path;
break;
}
}
}
}
IReadOnlyList<AppListEntry> appListEntries = null;
try
{
appListEntries = _package.GetAppListEntries();
}
catch
{
Logger.WriteWarning($"Could not get the applist entries of \"{_Name}\"");
}
appListEntry = appListEntries?.FirstOrDefault() ?? null;
if (appListEntry == null)
Logger.WriteWarning($"Could not get the applist entry of \"{_Name}\"");
if (String.IsNullOrEmpty(ss) || !File.Exists(ss))
{
try
{
if (appListEntry != null)
{
RandomAccessStreamReference logoStream = appListEntry.DisplayInfo.GetLogo(new Size(320, 180));
BitmapImage logoImage = new();
using IRandomAccessStream stream = logoStream.OpenReadAsync().GetAwaiter().GetResult();
logoImage.SetSource(stream);
appLogo.Source = logoImage;
}
else
{
BitmapImage logoImage = new(_Logo);
appLogo.Source = logoImage;
}
}
catch (Exception)
{
BitmapImage logoImage = new(_Logo);
appLogo.Source = logoImage;
}
}
else
{
appLogo.Source = new BitmapImage(new Uri(ss));
}
infoExpander.Header = _Name;
MenuFlyout rcFlyout = new();
bool isPatched = false;
installedPackage instPackage = App.InstalledPackages.GetPackage(_package.Id.FamilyName);
if (instPackage != null)
isPatched = instPackage.IsPatched;
MenuFlyoutItem patchButton = new MenuFlyoutItem
{
Text = isPatched ? "Repatch" : "Patch",
Name = "patchButton"
};
if (isPatched)
{
patchButton.Click += RepatchPackage;
MenuFlyoutItem unpatchButton = new MenuFlyoutItem
{
Text = "Unpatch",
Name = "unpatchButton"
};
unpatchButton.Click += UnpatchPackage;
rcFlyout.Items.Add(unpatchButton);
}
else
{
patchButton.Click += PatchPackage;
}
rcFlyout.Items.Add(patchButton);
expanderVersion.Text = $"Publisher: {_Publisher}\nVersion {_Version}";
RightTapped += (sender, e) =>
{
rcFlyout.ShowAt(sender as FrameworkElement, e.GetPosition(sender as UIElement));
};
startButton.Tapped += (_, _) => StartApp();
}
public async void ShowControllerInteractDialog()
{
ContentDialog dialog = new ContentDialog();
dialog.XamlRoot = App.MainWindow.Content.XamlRoot;
dialog.Title = _package.DisplayName;
StackPanel optionsPanel = new StackPanel();
optionsPanel.HorizontalAlignment = HorizontalAlignment.Center;
dialog.Content = optionsPanel;
TextBlock textBlock = new TextBlock();
textBlock.Text = "NON-FUNCTIONAL";
// todo: onclick for all
// we need to either move the uninstall options somewhere else or figure out a way to make it work with controller
Button uninstallButton = new Button();
uninstallButton.Content = "Uninstall";
uninstallButton.Margin = new Thickness(0, 0, 0, 10);
Button manageSavesButton = new Button();
manageSavesButton.Content = "Manage saves";
manageSavesButton.Margin = new Thickness(0, 0, 0, 10);
Button manageModsButton = new Button();
manageModsButton.Content = "Manage mods";
manageModsButton.Margin = new Thickness(0, 0, 0, 10);
optionsPanel.Children.Add(textBlock);
optionsPanel.Children.Add(uninstallButton);
optionsPanel.Children.Add(manageSavesButton);
optionsPanel.Children.Add(manageModsButton);
await dialog.ShowAsync();
}
public async void StartApp()
{
if (_package.Status.LicenseIssue)
{
Logger.WriteError($"Could not launch {_Name} due to licensing issue.");
_ = new NoticeDialog($"There is a licensing issue... Do you own this package?", $"Could not launch {_Name}").ShowAsync();
return;
}
if (appListEntry == null)
{
_ = new NoticeDialog($"Could not get the applist entry of \"{_Name}\"", $"Could not launch {_Name}").ShowAsync();
return;
}
Logger.WriteInformation($"Launching {_Name}");
if (await appListEntry.LaunchAsync() == false)
_ = new NoticeDialog($"Failed to launch \"{_Name}\"!", $"Could not launch {_Name}").ShowAsync();
}
}
}