private ArchiveListingReaderV1(ArchiveAccessor accessor, Action<long> progressIncrement, Action<long> progressTotalChanged)
 {
     _accessor = accessor;
     _progressIncrement = progressIncrement;
     _progressTotalChanged = progressTotalChanged;
     _input = accessor.ExtractListing();
 }
Exemple #2
0
 private ArchiveListingReaderV1(ArchiveAccessor accessor, Action <long> progressIncrement, Action <long> progressTotalChanged)
 {
     _accessor             = accessor;
     _progressIncrement    = progressIncrement;
     _progressTotalChanged = progressTotalChanged;
     _input = accessor.ExtractListing();
 }
Exemple #3
0
        private Stream Decrypt(out ArchiveListingHeaderV2 header)
        {
            Stream result = _accessor.ExtractListing();

            try
            {
                header = result.ReadContent <ArchiveListingHeaderV2>();
                if (header.IsValid(result.Length))
                {
                    header.IsEncrypted = false;
                    return(result);
                }

                /*using (*/
                TempFileProvider tmpProvider = new TempFileProvider(_accessor.ListingEntry.Name /*"filelist"*/, ".win32.bin");/*)*/
                {
                    using (Stream output = tmpProvider.Create())
                    {
                        output.WriteContent(header);
                        result.CopyTo(output);
                        result.SafeDispose();
                    }

                    Process decrypter = new Process
                    {
                        StartInfo = new ProcessStartInfo()
                        {
                            FileName               = @"Resources\Executable\ffxiiicrypt.exe",
                            Arguments              = "-d \"" + tmpProvider.FilePath + "\" 2",
                            CreateNoWindow         = true,
                            UseShellExecute        = false,
                            RedirectStandardOutput = true,
                            RedirectStandardError  = true
                        }
                    };
                    decrypter.Start();
                    Task <string> erroMessage   = decrypter.StandardError.ReadToEndAsync();
                    Task <string> outputMessage = decrypter.StandardOutput.ReadToEndAsync();
                    decrypter.WaitForExit();
                    if (decrypter.ExitCode != 0)
                    {
                        StringBuilder sb = new StringBuilder("Decryption error! Code: ");
                        sb.AppendLine(decrypter.ExitCode.ToString());
                        sb.AppendLine("Error: ");
                        sb.AppendLine(erroMessage.Result);
                        sb.AppendLine("Output: ");
                        sb.AppendLine(outputMessage.Result);

                        throw new InvalidDataException(sb.ToString());
                    }

                    result             = tmpProvider.OpenRead();
                    header             = result.ReadContent <ArchiveListingHeaderV2>();
                    header.IsEncrypted = true;
                    if (!header.IsValid(result.Length))
                    {
                        throw new InvalidDataException();
                    }
                }

                return(result);
            }
            catch
            {
                result.SafeDispose();
                throw;
            }
        }