aboutsummaryrefslogtreecommitdiff
path: root/source/WindowsFormsApplication1/IconManager.cs
blob: 0f5002ecd1c7b256f9c0ec37e4c9c3e70fbfc78d (plain) (blame)
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ShiftOS
{
    public partial class IconManager : Form
    {
        public IconManager()
        {
            InitializeComponent();
        }

        private void IconManager_Load(object sender, EventArgs e)
        {
            GetAllIcons();
        }

        public void GetAllIcons()
        {
            pnlicons.Controls.Clear();
            pnlicons.Margin = new Padding(0);
            foreach(var kv in API.IconRegistry)
            {
                var ctrl = new IconControl();
                ctrl.Margin = new Padding(0);
                ctrl.IconName = kv.Key;
                ctrl.LargeImage = kv.Value;
                pnlicons.Controls.Add(ctrl);
                ctrl.Show();
            }
        }

        private void btnsave_Click(object sender, EventArgs e)
        {
            foreach (Control ctrl in pnlicons.Controls)
            {
                try
                {
                    IconControl ic = (IconControl)ctrl;
                    Skinning.Utilities.IconRegistry[ic.IconName] = ic.LargeImage;
                }
                catch(Exception ex)
                {
                    IconControl ic = (IconControl)ctrl;
                    Skinning.Utilities.IconRegistry.Add(ic.IconName, ic.LargeImage);
                }
            }

            var rnd = new Random();
            int cp = rnd.Next(0, 10);
            Skinning.Utilities.saveimages();
            API.AddCodepoints(cp);
            if(API.CurrentSession != null)
            {
                API.CurrentSession.SetupAppLauncher();
                API.CurrentSession.SetupDesktopIcons();
            }
            GetAllIcons();
            API.CreateInfoboxSession("Icon pack set.", $"Your icon pack has been set successfully. You have earned {cp} Codepoints.", infobox.InfoboxMode.Info);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            API.CreateFileSkimmerSession(".icn", File_Skimmer.FileSkimmerMode.Save);
            API.FileSkimmerSession.FormClosing += (object s, FormClosingEventArgs a) =>
            {
                var res = API.GetFSResult();
                if(res != "fail")
                {
                    ZipFile.CreateFromDirectory(Paths.Icons, res);
                }
            };
        }

        private void button1_Click(object sender, EventArgs e)
        {
            API.CreateFileSkimmerSession(".icn", File_Skimmer.FileSkimmerMode.Open);
            API.FileSkimmerSession.FormClosing += (object s, FormClosingEventArgs a) =>
            {
                var res = API.GetFSResult();
                if (res != "fail")
                {
                    if(Directory.Exists(Paths.Mod_Temp + "icn"))
                    {
                        Directory.Delete(Paths.Mod_Temp + "icn", true);
                    }
                    ZipFile.ExtractToDirectory(res, Paths.Mod_Temp + "icn");
                    foreach (var f in Directory.GetFiles(Paths.Mod_Temp + "icn"))
                    {
                        var finf = new FileInfo(f);
                        try
                        {
                            var bytes = File.ReadAllBytes(finf.FullName);
                            using (var stream = new MemoryStream(bytes))
                            {
                                API.IconRegistry[finf.Name] = Image.FromStream(stream);
                            }
                        }
                        catch (Exception ex)
                        {
                            API.IconRegistry.Add(finf.Name, Image.FromFile(finf.FullName));
                        }
                        finf = null;
                    }
                    if (API.CurrentSession != null)
                    {
                        API.CurrentSession.SetupAppLauncher();
                        API.CurrentSession.SetupDesktopIcons();
                    }
                    GetAllIcons();
                    Directory.Delete(Paths.Mod_Temp + "icn", true);
                }
            };
        }
    }
}