コード例 #1
0
        private void dgvMaps_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            LavaMapBrowserData map = GetSelectedLavaMap();

            if (map != null)
            {
                loadMapDetails(map, true);
            }
        }
コード例 #2
0
        private void loadMapDetails(LavaMapBrowserData map, bool thread = false)
        {
            if (this.loadingDet)
            {
                return;
            }
            if (thread)
            {
                detailsThread = new System.Threading.Thread(new System.Threading.ThreadStart(delegate
                {
                    loadMapDetails(map);
                }));
                detailsThread.Start();
                return;
            }

            try
            {
                this.loadingDet = true;
                Image img = null;

                if (this.InvokeRequired)
                {
                    this.Invoke(new MethodInvoker(delegate
                    {
                        txtDesc.Text = map.desc;
                    }));
                }
                else
                {
                    txtDesc.Text = map.desc;
                }

                using (WebClient WEB = new WebClient())
                    using (Stream stream = WEB.OpenRead(imgUrl + "?file=" + Heart.UrlEncode(map.image) + "&width=150&height=150&force&png"))
                        img = Image.FromStream(stream);

                if (this.InvokeRequired)
                {
                    this.Invoke(new MethodInvoker(delegate
                    {
                        pbImage.Width  = img.Width;
                        pbImage.Height = img.Height;
                        pbImage.Image  = img;
                    }));
                }
                else
                {
                    pbImage.Width  = img.Width;
                    pbImage.Height = img.Height;
                    pbImage.Image  = img;
                }
                this.loadingDet = false;
            }
            catch (Exception ex) { this.loadingDet = false; Server.ErrorLog(ex); MessageBox.Show("An unknown error occurred.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
        }
コード例 #3
0
            public override object GetValue(object component)
            {
                LavaMapBrowserData l = (LavaMapBrowserData)component;

                return(_method(l));
            }
コード例 #4
0
        private void downloadMap(LavaMapBrowserData mapData)
        {
            if (mapData == null)
            {
                return;
            }
            int    id   = mapData.id;
            string name = mapData.name.ToLower().Replace(" ", "_");

            downloadThread = new System.Threading.Thread(new System.Threading.ThreadStart(delegate
            {
                byte[] data;
                string dataStr;
                using (WebClient WEB = new WebClient())
                {
                    try
                    {
                        if (name == Server.mainLevel.name.ToLower())
                        {
                            MessageBox.Show("Error: You cannot overwrite the main level!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            goto end;
                        }
                        if (File.Exists("levels/" + name + ".lvl"))
                        {
                            if (MessageBox.Show("Map \"" + name + "\" already exists. Do you want to overwrite it?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No)
                            {
                                goto end;
                            }
                        }

                        data = WEB.DownloadData(downloadUrl + "?id=" + id + "&mode=lvl");
                        if (data.Length < 1)
                        {
                            MessageBox.Show("No data was recieved.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            goto end;
                        }
                        dataStr = new ASCIIEncoding().GetString(data).Trim();
                        if (dataStr.ToLower().StartsWith("error") || dataStr == "")
                        {
                            MessageBox.Show(dataStr, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            goto end;
                        }
                        FileStream fs = File.Create("levels/" + name + ".lvl");
                        fs.Write(data, 0, data.Length);
                        fs.Dispose();

                        data = WEB.DownloadData(downloadUrl + "?id=" + id + "&mode=properties");
                        if (data.Length < 1)
                        {
                            MessageBox.Show("No data was recieved.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            goto end;
                        }
                        dataStr = new ASCIIEncoding().GetString(data).Trim();
                        if (dataStr.ToLower().StartsWith("error"))
                        {
                            MessageBox.Show(dataStr, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            goto end;
                        }
                        fs = File.Create("properties/lavasurvival/" + name + ".properties");
                        fs.Write(data, 0, data.Length);
                        fs.Dispose();

                        MessageBox.Show("Map \"" + name + "\" has been downloaded!", "Complete", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        end:
                        downloadTextTimer.Stop();
                        downloadBtnReset();
                    }
                    catch (Exception ex) { Server.ErrorLog(ex); MessageBox.Show("An unknown error occurred.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
                }
            }));
            downloadThread.Start();

            btnDownload.Enabled = false;
            btnDownload.Text    = "Downloading   ";
            downloadTextTimer.Start();
        }