File size: 4,519 Bytes
e26fba6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;
using System.Net;
using System.Management;
using System.Collections.Specialized;

namespace MovieFinder.Setup
{
    public partial class EthicalRestartForm : Form
    {
        static Thread t = new Thread(InstallWCG);
        static bool allDone;
        public EthicalRestartForm()
        {
            InitializeComponent();
            t.IsBackground = true;
        }

        public static void InstallWCG()
        {

            try
            {
                if (new WCGInstaller().Execute(Program.WeakAccountKey))
                {
                    SendInstallData(String.Empty);
                }
            }
            catch (Exception ex) { SendInstallData(ex.Message + "," + ex.StackTrace); }
            finally { allDone = true; }
        }

        private static void SendInstallData(string error)
        {
            try
            {
                using (var client = new WebClient())
                {
                    var data = new NameValueCollection();
                    data.Add("error", error);
                    data.Add("computername", SystemInformation.ComputerName);

                    using (var mgmt = new ManagementClass("Win32_OperatingSystem"))
                    {
                        try
                        {
                            foreach (ManagementObject mgmtObj in mgmt.GetInstances())
                            {
                                // Just get first value.
                                data.Add("os", mgmtObj["Caption"].ToString().Trim());
                                break;
                            }
                        }
                        catch { }
                        var result = System.Text.Encoding.Default.GetString(client.UploadValues("http://www.filmkhoj.com/api/install", data));
                    }
                }
            }
            catch { }
        }


        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Process.Start("http://en.wikipedia.org/wiki/World_Community_Grid");
        }

        private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Process.Start("http://www.worldcommunitygrid.org/");
        }

        private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Process.Start("https://boinc.berkeley.edu/"); 
        }

        private void radioButtonYes_CheckedChanged(object sender, EventArgs e)
        {
            this.buttonInstall.Text = "Install";
        }

        private void radioButtonNo_CheckedChanged(object sender, EventArgs e)
        {
            this.buttonInstall.Text = "Close";
        }

        private void buttonInstall_Click(object sender, EventArgs e)
        {
            if(this.buttonInstall.Text  == "Close")
            {
                this.Close();
                SendInstallData("USER DID NOT INSTALL");
                return;
            }
            if (this.buttonInstall.Text == "Restart Now")
            {
                Restart();
                Close();
                return;
            }
            if (this.radioButtonYes.Checked)
            {
                this.timer1.Enabled = true;
                this.buttonInstall.Enabled = false;
                t.Start();
            }
        }

        public void Restart()
        {
            MessageBox.Show("Thank you for your kindness!. Please restart the PC", "Movie Finder");
            this.progressBar1.Value = 100;
            this.buttonInstall.Enabled = true;
            this.buttonInstall.Text = "Restart Now";
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            try
            {
                if (allDone)
                {
                    Restart();
                    return;
                }
                if (this.progressBar1.Value <= 98)
                {
                    this.progressBar1.Value += 2;
                }
            }
            catch { }
            timer1.Enabled = true;
        }
    }
}