Exemplo n.º 1
0
        private void btnDecryptAndSave_Click(object sender, EventArgs e)
        {
            rtbResult.Clear();

            //Decrypt a single encrypted file
            if (rbSingleFile.Checked)
            {
                SaveFileDialog dialog = new SaveFileDialog();
                dialog.Filter = "Xml files|*.xml";

                if (dialog.ShowDialog() != DialogResult.Cancel)
                {
                    if (DecryptionHelper.DecryptSingleFile(dialog.FileName, fileName))
                    {
                        rtbResult.AppendText($"{fileName} was successfully decrypted and saved as {dialog.FileName}.");
                    }
                }
            }
            //Decrypt Blackbox files from MilkoStream.
            else if (rbBlackBox.Checked)
            {
                SaveFileDialog dialog = new SaveFileDialog();
                dialog.Filter = "Text files|*.txt";
                if (dialog.ShowDialog() != DialogResult.Cancel)
                {
                    DecrompressionHelper.Decompress(dialog.FileName, fileName);
                }
            }
            //Decrypt a sample export file from Mosaic
            else if (rbSampleExportFile.Checked)
            {
                helper            = new DataFileHelper(fileName);
                destinationfolder = Path.Combine(Path.GetDirectoryName(fileName), "DecryptedRawFiles");
                DecryptSamplesFromDataFile();
                DecryptSettingsFilesFromDataFile(false);

                if (instrumentComboBox.Text != "Other")
                {
                    XmlHelper.DestinationFolder = destinationfolder;
                    XmlHelper.WriteToCsvFile(instrumentComboBox.Text);
                }
            }
            //Decrypt a selftest that is exported from Mosaic
            else
            {
                helper            = new DataFileHelper(fileName, true);
                destinationfolder = Path.Combine(Path.GetDirectoryName(fileName), "DecryptedRawFiles");
                DecryptSelfTestFromDataFile();
                DecryptSettingsFilesFromDataFile(true);
            }
        }
Exemplo n.º 2
0
        private void DecryptSamplesFromDataFile()
        {
            List <SampleContent> samples = helper.GetSamples();

            if (!Directory.Exists(destinationfolder))
            {
                Directory.CreateDirectory(destinationfolder);
            }

            int sampleNumber = 0;

            foreach (var sample in samples)
            {
                sampleNumber++;

                foreach (var sampleRawDataContent in sample.RawDataContents)
                {
                    string extention             = sampleRawDataContent.Identification.Equals("JpegPicture") ? "jpeg" : "xml";
                    string decryptedFileName     = $"{sample}_{sampleRawDataContent}.{extention}";
                    string decryptedFilePathName = Path.Combine(destinationfolder, decryptedFileName);
                    string readFileName          = Path.Combine(Path.GetDirectoryName(fileName), sampleRawDataContent.DataFileName);

                    if (new[] { "JpegPicture", "ForeignObjectData" }.Contains(sampleRawDataContent.Identification))
                    {
                        CopyFile(readFileName, decryptedFilePathName, decryptedFileName);
                    }
                    else if (sampleRawDataContent.Identification.Equals("ABS_SCAN"))
                    {
                        DecrompressionHelper.Decompress(decryptedFilePathName, readFileName);
                    }
                    else if (DecryptionHelper.DecryptSingleFile(decryptedFilePathName, readFileName))
                    {
                        rtbResult.AppendText($"{decryptedFileName}.xml succesfully decrypted.\n");
                    }
                }
            }
        }