Ejemplo n.º 1
0
        private void SaveAttachments(SmsAttachment[] items, string outputFolder)
        {
            foreach (var item in items)
            {
                if (string.IsNullOrEmpty(item.FileName) == false)
                {
                    _logger.LogInformation("Saving attachment '{InputFileName}','{TransferName}',MIME type='{MimeType}'", item.FileName, item.TransferName, item.MimeType);

                    var fileName  = item.FileName.RemovePrefix("~/");
                    var inputFile = _backupFileProvider.GetPath(KnownDomains.MediaDomain, fileName);

                    _logger.LogInformation("Saving attachment '{InputFile}' to folder '{OutputFolder}'", inputFile, outputFolder);
                    HtmlGenerator.SaveAttachmentAs(inputFile, outputFolder, item.TransferName);
                }
                else
                {
                    _logger.LogWarning("Missing file name for attachment with Id={Id}", item.Id);
                }
            }
        }
Ejemplo n.º 2
0
        public int Run(MessageOptions opts)
        {
            _logger.LogInformation("Starting {Command}", nameof(MessageCommand));

            var appContext = _appContext
                             .SetBackupMetadataInputPaths(opts.InputFolder)
                             .LoadBackupMetadata()
                             .SetVersionsFromMetadata()
                             .SetManifestEntriesFileInputPath(opts.InputFolder)
                             .AddManifestEntries();

            var backupFileProvider = new BackupFileProvider(opts.InputFolder, appContext.ManifestVersion.Major);

            var input = backupFileProvider.GetPath("3d0d7e5fb2ce288813306e4d4636395e047a3d28");

            _logger.LogInformation("Opening SMS database '{Source}'", input);
            using (var repository = new SmsRepository(SqliteRepository.GetConnectionString(input)))
            {
                var items = repository.GetAllItems().ToList();

                if (items.Any())
                {
                    HtmlGenerator.SaveCss(opts.OutputFolder, "bootstrap.min.css");
                    HtmlGenerator.SaveCss(opts.OutputFolder, "bootstrap-theme.min.css");
                    HtmlGenerator.SaveCss(opts.OutputFolder, "site.css");

                    foreach (var item in items)
                    {
                        if (item.CacheHasAttachments)
                        {
                            item.Attachments = repository.GetMessageAttachments(item.Id).ToArray();

                            foreach (var attachment in item.Attachments)
                            {
                                string fileName = attachment.FileName;

                                if (string.IsNullOrEmpty(fileName) == false && fileName.StartsWith("~/"))
                                {
                                    string toHash = KnownDomains.MediaDomain + KnownDomains.DomainSeparator + fileName.Remove(0, 2);

                                    var hash = CommonHelpers.Sha1HashAsHexString(toHash);

                                    var inputFile = backupFileProvider.GetPath(hash);

                                    HtmlGenerator.SaveAttachmentAs(inputFile, opts.OutputFolder, attachment.TransferName);
                                }
                            }
                        }
                    }

                    var generator = new HtmlGenerator("Message Index", () =>
                    {
                        return(ProcessMessagesByChatIdentifier(items, opts.OutputFolder));
                    });

                    generator.SaveAs(opts.OutputFolder, "index.html");
                }
            }

            _logger.LogInformation("Completed {Command}", nameof(MessageCommand));
            return(0);
        }