Ejemplo 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);
 }
Ejemplo 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;
        }