예제 #1
0
        private void UploadMenuClick(object sender, EventArgs e)
        {
            if (UploadDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    var bytes = File.ReadAllBytes(UploadDialog.FileName);
                    if (bytes.Length == 0 || bytes.Length > (short.MaxValue * 2) || bytes.Length % 2 != 0)
                    {
                        Interface.ShowMessage("Upload", "Invalid file size.");
                        return;
                    }

                    var shorts = new short[bytes.Length / 2];
                    Buffer.BlockCopy(bytes, 0, shorts, 0, bytes.Length);

                    var uploadPacket = new Network.Packets.Upload();
                    uploadPacket.Program = shorts;
                    Client.Send(uploadPacket);
                }
                catch (Exception er)
                {
                    Interface.ShowMessage("Upload", string.Format("Failed to upload program: {0}", er));
                }
            }
        }
예제 #2
0
        private void UploadMenuClick(object sender, EventArgs e)
        {
            if (UploadDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    var bytes = File.ReadAllBytes(UploadDialog.FileName);
                    if (bytes.Length == 0 || bytes.Length > (short.MaxValue * 2) || bytes.Length % 2 != 0)
                    {
                        Interface.ShowMessage("Upload", "Invalid file size.");
                        return;
                    }

                    var shorts = new short[bytes.Length / 2];
                    Buffer.BlockCopy(bytes, 0, shorts, 0, bytes.Length);

                    var uploadPacket = new Network.Packets.Upload();
                    uploadPacket.Program = shorts;
                    Client.Send(uploadPacket);
                }
                catch (Exception er)
                {
                    Interface.ShowMessage("Upload", string.Format("Failed to upload program: {0}", er));
                }
            }
        }