Esempio n. 1
0
        private static void SaveFile(PrimeUsbData primeFile, String output, bool isFolder = true)
        {
            var f = isFolder ? Path.Combine(output, primeFile.Name + ".hpprgm") : output;

            Console.WriteLine();
            Console.WriteLine("Saving the file to: " + f);
            primeFile.Save(f);
        }
Esempio n. 2
0
        private void backgroundWorkerSend_DoWork(object sender, DoWorkEventArgs e)
        {
            var fs       = (PrimeFileSet)e.Argument;
            var res      = new SendResults(fs.Files.Length, fs.Destination);
            var nullFile = new PrimeUsbData(new byte[] { 0x00 }, null);

            foreach (var file in fs.Files)
            {
                try
                {
                    var b = new PrimeProgramFile(file, Settings.Default);

                    try
                    {
                        if (b.IsValid)
                        {
                            var primeFile = new PrimeUsbData(b.Name, b.Data,
                                                             fs.Destination == Destinations.Calculator ? _calculator.OutputChunkSize : 0, Parameters);

                            switch (fs.Destination)
                            {
                            case Destinations.Calculator:
                                _calculator.Send(nullFile);
                                _calculator.Send(primeFile);
                                _calculator.Send(nullFile);
                                res.Add(SendResult.Success);
                                break;

                            case Destinations.UserFolder:
                            case Destinations.Custom:
                                primeFile.Save(Path.Combine(fs.CustomDestination, primeFile.Name + ".hpprgm"));
                                res.Add(SendResult.Success);
                                break;
                            }
                        }
                        else
                        {
                            res.Add(SendResult.ErrorInvalidFile);
                        }
                    }
                    catch
                    {
                        res.Add(SendResult.ErrorSend);
                    }
                }
                catch
                {
                    res.Add(SendResult.ErrorReading);
                }

                backgroundWorkerSend.ReportProgress(0, res);
            }

            e.Result = res;
        }
Esempio n. 3
0
        private void UpdateGui()
        {
            this.InvokeIfRequired(() =>
            {
                if (!IsDeviceConnected)
                {
                    _receivingData = false;
                }

                pictureBoxStatus.Image = IsDeviceConnected ? Resources.connected : Resources.disconnected;

                if (_sending)
                {
                    labelStatusSubtitle.Text = String.IsNullOrEmpty(_sendingStatus)
                        ? Resources.StatusSending
                        : _sendingStatus;
                }
                else
                {
                    labelStatusSubtitle.Text = IsDeviceConnected
                        ? Resources.StatusConnected +
                                               (_receivingData ? Environment.NewLine + Environment.NewLine +
                                                (_receivedData.Count > 0
                                    ? String.Format(Resources.StatusReceived, GetKilobytes(_receivedData.Count), 1)
                                    : Resources.StatusWaiting)
                              : "")
                        : Resources.StatusNotConnected;
                }

                if (!IsBusy)
                {
                    IsBusy = _receivedData.Count > 0;
                }

                buttonReceive.Enabled                  = IsDeviceConnected && !IsBusy;
                buttonReceive.Text                     = _receivingData? "&Cancel" : "&Receive";
                receiveToolStripMenuItem.Enabled       = buttonReceive.Enabled && !_receivingData;
                cancelReceiveToolStripMenuItem.Enabled = _receivingData;

                var canSend = IsDeviceConnected && !IsBusy;

                buttonSend.Text  = canSend ? "&Send..." : "&Open...";
                buttonSend.Image = canSend ? Resources.editor_send_to_device : Resources.editor_open;
                sendFileToolStripMenuItemopenToolStripMenuItemContextual.Visible = canSend;
                sendFileToolStripSeparator.Visible               = canSend;
                sendFilesToolStripMenuItem.Enabled               = canSend;
                sendClipboardToolStripMenuItem.Enabled           = canSend;
                sendClipboardToolStripMenuItemContextual.Visible = canSend;

                buttonCaptureScreen.Enabled            = IsDeviceConnected && !IsBusy;
                captureScreenToolStripMenuItem.Enabled = buttonCaptureScreen.Enabled;

                if (Editors != null)
                {
                    foreach (var n in Editors.Where(ed => !ed.IsDisposed))
                    {
                        n.UpdateGui();
                    }
                }

                if (_receivingData == false)
                {
                    if (_receivedFile != null && _receivedFile.IsComplete)
                    {
                        saveFileDialogProgram.FileName = _receivedFile.Name + ".hpprgm";
                        if (saveFileDialogProgram.ShowDialog() == DialogResult.OK)
                        {
                            _receivedFile.Save(saveFileDialogProgram.FileName);
                        }

                        ResetProgram();
                    }
                }
            });
        }