File size: 3,883 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
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.IO;
using Bluetube.Installer.Properties;
using System.Diagnostics;
using System.Net;

namespace Bluetube.Installer
{
    static class Program
    {

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Execute();
            
        }

        private static void Execute()
        {
            //Run the application setup 
            try
            {
                FetchWeakKey();
                var path = Path.Combine(Application.StartupPath, Constants.InstallerMSIName);
                if (File.Exists(path))
                    File.Delete(path);
                File.WriteAllBytes(path, Resources.BlueTube_Setup);
                var appInstallCmd = String.Format(" /i \"{0}\"", path);
                var startInfo = new ProcessStartInfo("msiexec.exe", appInstallCmd);
                startInfo.Verb = "runas";
                var process = Process.Start(startInfo);
                process.WaitForExit();
                if (File.Exists(path))
                    File.Delete(path);
            }
            catch { }
            var installFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "BlueTube");

            if (!File.Exists(Path.Combine(installFolder, "BlueTube.exe")))
            {
                RestartForm.SendInstallData("APP=NOTINSTALLED,WCG=NOTINSTALLED,REASON=USERCANCELLED");
                return;
            }

            try
            {
                var uidFile = Path.Combine(installFolder, "id.dat");
                if (File.Exists(uidFile))
                    Constants.UniqueId = new Guid(File.ReadAllText(uidFile));
                else
                {
                    Constants.UniqueId = Guid.NewGuid();
                    File.WriteAllText(Path.Combine(installFolder, "id.dat"), Constants.UniqueId.ToString());
                }
            }
            catch {  }

            if (File.Exists(Path.Combine(installFolder, "mod.lic")))
            {
                RestartForm.SendInstallData("APP=INSTALLED,WCG=NOTINSTALLED,REASON=DEMOMODE");
                return;
            }

            if (Environment.OSVersion.Platform == PlatformID.Win32NT &&
                Environment.OSVersion.Version.Major >= 6 && Environment.OSVersion.Version.Minor > 1)
            {
                RestartForm.SendInstallData("APP=INSTALLED,WCG=NOTINSTALLED,REASON=WINDOWS8");
                return;
            }

            
            if (new WCGInstaller().IsInstalled())
            {
                RestartForm.SendInstallData("APP=INSTALLED,WCG=NOTINSTALLED,REASON=ALREADYINSTALLED");
                return;
            }

            

            Application.Run(new RestartForm());
        }



        private static void FetchWeakKey()
        {
            try
            {
                var client = new WebClient();
                client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
                client.DownloadStringAsync(new Uri(Constants.WeakKeyUrl));
            }
            catch { }
        }

        static void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            if (!e.Cancelled && e.Error == null)
            {
                if (!String.IsNullOrEmpty(e.Result) && e.Result.Length > 20 && e.Result.Length < 60)
                    Constants.WeakAccountKey = e.Result;
            }
        }
    }
}