コード例 #1
0
        void login_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            mainForm.statusBar.Value = 0;
            if (e.Error != null)
            {
                MessageBox.Show(e.Error.Message);
            }
            mainForm.result = e.Result;

            if (mainForm.result.Contains(':'))
            {
                mainForm.rememberMe.save();

                String[] output = mainForm.result.Split(':');
                if (mainForm.mojangAccount)
                {
                    mainForm.username = output[2];
                }
                mainForm.sessionID = output[3];
                mainForm.version   = output[0];

                if (mainForm.snapshotButton.Checked)
                {
                    mainForm.path = mainForm.rootPath + "snapshot/.minecraft/bin/";
                    Environment.SetEnvironmentVariable("APPDATA", mainForm.rootPath + "snapshot/");
                    if (mainForm.updateButton.Checked == true)
                    {
                        Snapshot snapshot = new Snapshot(mainForm);
                        snapshot.detectSnapshotVersion();
                    }
                    else
                    {
                        mainForm.launchMinecraft();
                    }
                }
                else if (mainForm.normalButton.Checked)
                {
                    mainForm.path = mainForm.rootPath + "normal/.minecraft/bin/";
                    Environment.SetEnvironmentVariable("APPDATA", mainForm.rootPath + "normal/");
                    if (mainForm.updateButton.Checked == true)
                    {
                        mainForm.link = mainForm.downloadlink + "minecraft.jar";
                        Download download = new Download(mainForm);
                        download.downloadAndInstall();
                    }
                    else
                    {
                        mainForm.launchMinecraft();
                    }
                }
            }
            else if (mainForm.result.Contains("Bad"))
            {
                mainForm.statusLabel.Text = "Incorrect username or password.";
            }
            else
            {
                mainForm.statusLabel.Text = mainForm.result;
            }
        }
コード例 #2
0
        public void downloadAndInstall() {

            WebClient client = new WebClient();
            client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressChanged);
            client.DownloadFileCompleted += new AsyncCompletedEventHandler(Download_DownloadFileCompleted);

            if (!Directory.Exists(path))
                Directory.CreateDirectory(path);

            if (!File.Exists(Path.Combine(path,version + ".txt"))) {
                if (File.Exists(Path.Combine(path, "minecraft.jar"))) {
                    DialogResult result = MessageBox.Show("There is an update available, Do you want to update?", "Update available", MessageBoxButtons.YesNo);
                    if (result == DialogResult.Yes) {
                        using (StreamWriter sw = File.CreateText(Path.Combine(path, version + ".txt"))) {
                            sw.Write(link);
                            sw.Close();
                        }
                        mainForm.statusLabel.Text = "Downloading minecraft.jar";
                        client.DownloadFileAsync(new Uri(link), Path.Combine(path, "minecraft.jar"));
                    }
                    else {
                        if (!File.Exists(path + "dependancy.txt")) {
                            using (StreamWriter sw = File.CreateText(Path.Combine(path, "dependancy.txt"))) {
                                sw.Write(link);
                                sw.Close();
                            }
                            downloadAndInstallDependancys();
                        }
                        else {
                            mainForm.launchMinecraft();
                        }
                    }
                }
                else {
                    using (StreamWriter sw = File.CreateText(Path.Combine(path, version + ".txt"))) {
                        sw.Write(link);
                        sw.Close();
                    }
                    mainForm.statusLabel.Text = "Downloading minecraft.jar";
                    client.DownloadFileAsync(new Uri(link), Path.Combine(path, "minecraft.jar"));
                }
            }
            else {
                if (!File.Exists(path + "dependancy.txt")) {
                    using (StreamWriter sw = File.CreateText(Path.Combine(path, "dependancy.txt"))) {
                        sw.Write(link);
                        sw.Close();
                    }
                    downloadAndInstallDependancys();
                }
                else {
                    mainForm.launchMinecraft();
                }
            }
        }