Ejemplo n.º 1
0
        /// <summary>
        /// send the content of the filepath trough the socket per chunk
        /// </summary>
        /// <param name="s">socket that's open where to send the file</param>
        /// <param name="filePath">path of the file</param>
        private void sendThroughSocket(Socket s, string filePath)
        {
            ProgressDialogue progressDialogue = new ProgressDialogue("Uploading...", "transfering...", 0);
            Thread           threadProgress;

            threadProgress = new Thread(() => UploadProgressBarThread(progressDialogue));
            threadProgress.IsBackground = true;
            threadProgress.Start();

            Thread.Sleep(500);
            using (var file = File.OpenRead(filePath))
            {
                byte[] sendBuffer          = new byte[BUFFER_SIZE];
                long   bytesLeftToTransmit = file.Length;
                double fileLengthMo        = (double)file.Length / 1000000;
                while (bytesLeftToTransmit > 0)
                {
                    int dataToSend = file.Read(sendBuffer, 0, sendBuffer.Length);
                    bytesLeftToTransmit -= dataToSend;
                    s.Send(sendBuffer);
                    int percentage = Convert.ToInt32((((double)file.Length - (double)bytesLeftToTransmit) / (double)file.Length) * (double)100);
                    progressDialogue.SetProgress(percentage);
                    progressDialogue.ChangeText("Uploading...\n" + (((double)file.Length - (double)bytesLeftToTransmit) / 1000000).ToString("f2") + " / " + fileLengthMo.ToString("f2") + "Mo");
                }
                sendBuffer = null;
                progressDialogue.CloseForm();
            }
        }
Ejemplo n.º 2
0
        public Form1()
        {
            InitializeComponent();
            LoadTheme();
            udpClient.Client.Bind(new IPEndPoint(IPAddress.Any.Address, PORT));
            IPEndPoint from = new IPEndPoint(0, 0);

            //Thread tSendInfo = new Thread(() => SendWhoIAm.sendWhoIam(udpClient,PORT,from));
            //tSendInfo.Start();
            tRecieveInfo = new Thread(() => MachineDiscoverer.send(udpClient, PORT, from, this));
            tRecieveInfo.IsBackground = true;
            tRecieveInfo.Start();
            pcs                   = new List <Machine>();
            pDialogue             = new ProgressDialogue("transfer", "transfer", 0);
            lblCredits.ForeColor  = Theme.textColor;
            lblSettings.ForeColor = Theme.textColor;
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Executes a series of mod operations (uninstall, install)
        /// </summary>
        private static void ExecuteOperations(IEnumerable <ModOperation.ModOperation> operations)
        {
            if (App.Current.Settings.GameLocationOrError is null)
            {
                return;
            }

            var ops = operations.Distinct(new ModOperationEqualityComparer()).ToArray();

            ProgressDialogue progressDialogue = null;
            var error    = false;
            var errIndex = -1;

            App.RunInMainThread(() =>
            {
                progressDialogue = new ProgressDialogue {
                    Title = "Executing operations"
                };
                App.Current.QueueDialog(progressDialogue);
            });
            for (var i = 0; i < ops.Length; i++)
            {
                var op = ops[i];
                op.ProgressDialogueCallback = (progress, message) => App.RunInMainThread(() =>
                {
                    var oneOp = 1d / ops.Length;
                    progressDialogue.ProgressBar.Value = oneOp * i + oneOp * progress;
                    progressDialogue.Message.Text      = message;
                });

                try
                {
                    op.Run().GetAwaiter().GetResult();
                    if (!op.Completed)
                    {
                        errIndex = i;
                        break;
                    }
                }
                catch (Exception e)
                {
                    error = true;
                    App.Current.DiagnosticInfoCollector.SentryLogException(e);
                    DiagnosticInfoCollector.WriteExceptionToDisk(e);
                    break;
                }
            }

            App.RunInMainThread(() =>
            {
                progressDialogue.IsPrimaryButtonEnabled = true;
                progressDialogue.ProgressBar.Visibility = Visibility.Collapsed;
                if (error)
                {
                    progressDialogue.Title        = "Error";
                    progressDialogue.Message.Text = "An exception has occured and the operation was not completed. An exception file was saved to the application's folder. Please submit it to the developers.";
                }
                else if (errIndex != -1)
                {
                    progressDialogue.Title        = "Error";
                    progressDialogue.Message.Text = $"An operation did not complete successfully:\n{ops[errIndex].Message}";
                }
                else
                {
                    progressDialogue.Message.Text      = $"{ops.Length} operation(s) completed successfully!";
                    progressDialogue.ProgressBar.Value = 1;
                }
            });

            ModRepository.Instance.WriteCache();
        }
Ejemplo n.º 4
0
 private void DownloadProgressBarThread(ProgressDialogue pDialogue)
 {
     pDialogue.ShowDialog();
 }
Ejemplo n.º 5
0
        //write the received file
        public void WriteFile(string path)
        {
            this.clientSocket.Send(Encoding.UTF8.GetBytes("accepted<EOF>"));
            bool   isConvertible = false;
            double length        = 0;
            int    operation     = 1;

            ProgressDialogue progressDialogue = new ProgressDialogue("Downloading...", "transfering...", 0);
            Thread           threadProgress;

            threadProgress = new Thread(() => DownloadProgressBarThread(progressDialogue));
            threadProgress.IsBackground = true;
            threadProgress.Start();

            while (!isConvertible)
            {
                try
                {
                    length        = Convert.ToDouble((double)nbo / operation);
                    isConvertible = true;
                }
                catch (OverflowException e)
                {
                    isConvertible = false;
                    if (operation == 1)
                    {
                        operation = 1024;
                    }
                    else
                    {
                        operation = Convert.ToInt32(Math.Pow(operation, 2));
                    }
                }
            }
            FileInfo   info               = new FileInfo(path);
            FileStream Stream             = new FileStream(path, FileMode.Create);
            double     bytesLeftToReceive = length;

            byte[] receiveBuffer = new byte[5000000];
            int    offset        = 0;

            //receive the file content
            while (bytesLeftToReceive > 0)
            {
                int bytesRead = clientSocket.Receive(receiveBuffer);
                //if we don't do that the file will have a lot of zeroes at the end because it will read all the receiveBuffer
                if (bytesRead / operation > bytesLeftToReceive)
                {
                    Stream.Write(receiveBuffer, 0, Convert.ToInt32(bytesLeftToReceive * operation));
                }
                else
                {
                    Stream.Write(receiveBuffer, 0, bytesRead);
                }
                bytesLeftToReceive -= bytesRead / operation;

                int percentage = Convert.ToInt32((((double)nbo - (double)bytesLeftToReceive) / (double)nbo) * (double)100);
                progressDialogue.SetProgress(percentage);
                progressDialogue.ChangeText("Downloading...\n" + (((double)nbo - (double)bytesLeftToReceive) / 1000000).ToString("f2") + " / " + ((double)nbo / 1000000).ToString("f2") + "Mo");

                //receivedMsg.AddRange(bytes);
            }
            progressDialogue.CloseForm();
            receiveBuffer = null;
            Stream.Close();
            //check checksum
            Console.WriteLine(checksum);
            if (this.checksum != "null" && useChecksum)
            {
                if (!this.checksum.Equals(getChecksum(path)))
                {
                    mainForm.ShowError("the received file is not the same as the sending one");
                }
            }
            receiveFinished = true;
        }