aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.WinForms/ShiftnetSites/MainHomepage.cs
blob: 6e692a720ccebaafe125160b04a4fa6cdb705785 (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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ShiftOS.Engine;
using ShiftOS.WinForms.Tools;
using System.Reflection;
using System.IO;

namespace ShiftOS.WinForms.ShiftnetSites
{
    [ShiftnetSite("shiftnet/main", "Main Site", "The main Shiftnet hub.")]
    public partial class MainHomepage : UserControl, IShiftnetSite
    {
        public MainHomepage()
        {
            InitializeComponent();
        }

        public event Action GoBack;
        public event Action<string> GoToUrl;

        public void OnSkinLoad()
        {
            ControlManager.SetupControls(this);
        }

        public void OnUpgrade()
        {
            
        }

        public void Setup()
        {
            //Get the Fundamentals List
            flfundamentals.Controls.Clear();
            foreach (var exe in Directory.GetFiles(Environment.CurrentDirectory))
            {
                if (exe.EndsWith(".exe") || exe.EndsWith(".dll"))
                {
                    try
                    {
                        var asm = Assembly.LoadFile(exe);
                        foreach (var type in asm.GetTypes())
                        {
                            if (type.GetInterfaces().Contains(typeof(IShiftnetSite)))
                            {
                                if (type.BaseType == typeof(UserControl))
                                {
                                    var attribute = type.GetCustomAttributes(false).FirstOrDefault(x => x is ShiftnetSiteAttribute) as ShiftnetSiteAttribute;
                                    if (attribute != null)
                                    {
                                        if (Shiftorium.UpgradeAttributesUnlocked(type))
                                        {
                                            if (type.GetCustomAttributes(false).FirstOrDefault(x => x is ShiftnetFundamentalAttribute) != null)
                                            {
                                                var dash = new Label();
                                                dash.Text = " - ";
                                                dash.AutoSize = true;
                                                flfundamentals.Controls.Add(dash);
                                                dash.Show();
                                                var link = new LinkLabel();
                                                link.Text = attribute.Name;
                                                link.Click += (o, a) =>
                                                {
                                                    GoToUrl?.Invoke(attribute.Url);
                                                };
                                                flfundamentals.Controls.Add(link);
                                                flfundamentals.SetFlowBreak(link, true);
                                                link.Show();
                                                link.LinkColor = SkinEngine.LoadedSkin.ControlTextColor;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch { }
                }
            }

        }
    }
}

//I COMMITTED MYSELF, RYLAN!