aboutsummaryrefslogtreecommitdiff
path: root/source/WindowsFormsApplication1/Apps/Shiftnet.cs
blob: 017377cb11e869c1aef0c7ac1197f2cd8e78221a (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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;

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

        private void MainForm_Load(object sender, EventArgs e)
        {
            InitialSetup();
        }

        public void InitialSetup()
        {
            pnlcontrols.BackColor = API.CurrentSkin.titlebarcolour;
            wbshiftnet.DocumentText = WebLayer.VisitSite("shiftnet://main");
            txtaddress.Text = WebLayer.LastUrl;
        }

        private void LinkInterceptor(object sender, WebBrowserNavigatingEventArgs e)
        {
            var url = e.Url.OriginalString;
            if (url != "about:blank")
            {
                var surl = url.Replace("http://", "shiftnet://");
                wbshiftnet.DocumentText = WebLayer.VisitSite(surl);
                txtaddress.Text = WebLayer.LastUrl;
            }
        }

        private void btngo_Click(object sender, EventArgs e)
        {
            if (txtaddress.Text.ToLower().StartsWith("shiftnet://"))
            {
                wbshiftnet.DocumentText = WebLayer.VisitSite(txtaddress.Text);
                txtaddress.Text = WebLayer.LastUrl;
            }
            else
            {
                wbshiftnet.DocumentText = WebLayer.VisitSite("shiftnet://not_found");
                txtaddress.Text = WebLayer.LastUrl;
            }
        }

        private void btnhome_Click(object sender, EventArgs e)
        {
            wbshiftnet.DocumentText = WebLayer.VisitSite("shiftnet://main");
            txtaddress.Text = WebLayer.LastUrl;
        }

        private void txtaddress_TextChanged(object sender, EventArgs e)
        {

        }
    }

    public class WebLayer
    {
        public static String serverurl = "http://playshiftos.ml";
        private static string HtmlTemplate = "<html><head><title>Shiftnet Page</title><link rel=\"stylesheet\" href=\"" + serverurl + "/shiftnet.css\"/></head><body>#BODY#</body></html>";
        public static string LastUrl = null;

        public static string VisitSite(string url)
        {
            var wc = new WebClient();
            if (url.ToLower().EndsWith(".stml") || url.ToLower().EndsWith(".rnp"))
            {
                try
                {
                    string content = wc.DownloadString(url.Replace("shiftnet://", serverurl  + "/shiftnet/www/"));
                    if (content.StartsWith("<!STML>"))
                    {
                        LastUrl = url;
                        return HtmlTemplate.Replace("#BODY#", content.Replace("<!STML>", ""));
                    }
                    else
                    {
                        LastUrl = "shiftnet:not_found";

                        return HtmlTemplate.Replace("#BODY#", "That page was not found.");
                    }
                }
                catch 
                {
                    LastUrl = "shiftnet://not_found";
                    return HtmlTemplate.Replace("#BODY#", "That page was not found.");
                }
            }
            else
            {
                if (url.EndsWith("/"))
                {
                    return VisitSite(url + "home.rnp");
                }
                else
                {
                    return VisitSite(url + "/home.rnp");
                }

            }
        }
    }

}