public int Run(MessageOptions opts) { _logger.LogInformation("Starting {Command}", nameof(MessageCommand)); var appContext = _appContext .SetBackupMetadataInputPaths(opts.InputFolder) .LoadBackupMetadata() .SetVersionsFromMetadata(); _backupFileProvider = new BackupFileProvider(opts.InputFolder, appContext.ManifestVersion.Major); var input = _backupFileProvider.GetPath(KnownDomains.HomeDomain, KnownFiles.Messages); _logger.LogInformation("Opening message 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(); SaveAttachments(item.Attachments, opts.OutputFolder); } } 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); }
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); }