-
-
Notifications
You must be signed in to change notification settings - Fork 302
Expand file tree
/
Copy pathImportDialog.cs
More file actions
98 lines (83 loc) · 3.16 KB
/
ImportDialog.cs
File metadata and controls
98 lines (83 loc) · 3.16 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
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinDynamicDesktop.COM;
namespace WinDynamicDesktop
{
public partial class ImportDialog : Form
{
private static readonly Func<string, string> _ = Localization.GetTranslation;
private Queue<string> importQueue;
private int numJobs;
public bool thumbnailsLoaded = false;
public ImportDialog()
{
InitializeComponent();
Localization.TranslateForm(this);
this.FormClosing += OnFormClosing;
ThemeLoader.taskbarHandle = this.Handle;
}
public void InitImport(List<string> themePaths)
{
ThemeManager.importMode = true;
importQueue = new Queue<string>(themePaths);
numJobs = importQueue.Count;
Task.Run(() => ImportNext());
}
private void ImportNext()
{
if (ThemeManager.importPaths.Count > 0)
{
foreach (string themePath in ThemeManager.importPaths)
{
importQueue.Enqueue(themePath);
}
numJobs += ThemeManager.importPaths.Count;
ThemeManager.importPaths.Clear();
}
this.Invoke(new Action(() => UpdateTotalPercentage(0)));
if (importQueue.Count > 0)
{
string themePath = importQueue.Peek();
this.Invoke(new Action(() =>
label1.Text = string.Format(_("Importing theme from {0}..."), Path.GetFileName(themePath))));
ThemeResult result = ThemeManager.ImportTheme(themePath);
result.Match(e => this.Invoke(new Action(() => ThemeLoader.HandleError(e))),
theme => ThemeManager.importedThemes.Add(theme));
importQueue.Dequeue();
ImportNext();
}
else
{
this.Invoke(new Action(() =>
{
label1.Text = _("Generating thumbnails, please wait...");
this.Close();
}));
}
}
private void UpdateTotalPercentage(int themePercentage)
{
int percentage = ((numJobs - importQueue.Count) * 100 + themePercentage) / numJobs;
progressBar1.Invoke(new Action(() =>
{
progressBar1.Value = percentage;
progressBar1.Refresh();
TaskbarProgress.SetValue(this.Handle, percentage, 100);
}));
}
private void OnFormClosing(object sender, FormClosingEventArgs e)
{
ThemeManager.importMode = false;
if (thumbnailsLoaded)
{
ThemeLoader.taskbarHandle = IntPtr.Zero;
}
}
}
}