Fix FILE_ID.DIZ (and other) display issues when ANSI is stored with specific term width in SAUCE

+ Preserve SAUCE records of desc/long_desc during import (in meta)
* Use SAUCE term width for ANSI Prep when displaying desc
This commit is contained in:
Bryan Ashby 2018-12-29 13:15:58 -07:00
parent 046550842b
commit 6b02ddbdae
6 changed files with 59 additions and 22 deletions

View File

@ -413,16 +413,23 @@ exports.getModule = class FileAreaList extends MenuModule {
// //
const desc = controlCodesToAnsi(self.currentFileEntry.desc); const desc = controlCodesToAnsi(self.currentFileEntry.desc);
if(desc.length != self.currentFileEntry.desc.length || isAnsi(desc)) { if(desc.length != self.currentFileEntry.desc.length || isAnsi(desc)) {
descView.setAnsi( const opts = {
desc,
{
prepped : false, prepped : false,
forceLineTerm : true forceLineTerm : true
}, };
() => {
return callback(null); //
// if SAUCE states a term width, honor it else we may see
// display corruption
//
const sauceTermWidth = _.get(self.currentFileEntry.meta, 'desc_sauce.Character.characterWidth');
if(_.isNumber(sauceTermWidth)) {
opts.termWidth = sauceTermWidth;
} }
);
descView.setAnsi(desc, opts, () => {
return callback(null);
});
} else { } else {
descView.setText(self.currentFileEntry.desc); descView.setText(self.currentFileEntry.desc);
return callback(null); return callback(null);

View File

@ -16,6 +16,7 @@ const wordWrapText = require('./word_wrap.js').wordWrapText;
const StatLog = require('./stat_log.js'); const StatLog = require('./stat_log.js');
const UserProps = require('./user_property.js'); const UserProps = require('./user_property.js');
const SysProps = require('./system_property.js'); const SysProps = require('./system_property.js');
const SAUCE = require('./sauce.js');
// deps // deps
const _ = require('lodash'); const _ = require('lodash');
@ -386,15 +387,26 @@ function extractAndProcessDescFiles(fileEntry, filePath, archiveEntries, cb) {
return next(null); return next(null);
} }
SAUCE.readSAUCE(data, (err, sauce) => {
if(sauce) {
// if we have SAUCE, this information will be kept as well,
// but separate/pre-parsed.
const metaKey = `desc${'descLong' === descType ? '_long' : ''}_sauce`;
fileEntry.meta[metaKey] = JSON.stringify(sauce);
}
// //
// Assume FILE_ID.DIZ, NFO files, etc. are CP437. // Assume FILE_ID.DIZ, NFO files, etc. are CP437; we need
// to decode to a native format for storage
// //
// :TODO: This isn't really always the case - how to handle this? We could do a quick detection... // :TODO: This isn't really always the case - how to handle this? We could do a quick detection...
fileEntry[descType] = iconv.decode(sliceAtSauceMarker(data, 0x1a), 'cp437'); const decodedData = iconv.decode(data, 'cp437');
fileEntry[descType] = sliceAtSauceMarker(decodedData, 0x1a);
fileEntry[`${descType}Src`] = 'descFile'; fileEntry[`${descType}Src`] = 'descFile';
return next(null); return next(null);
}); });
}); });
});
}, () => { }, () => {
// cleanup but don't wait // cleanup but don't wait
temptmp.cleanup( paths => { temptmp.cleanup( paths => {

View File

@ -39,6 +39,8 @@ const FILE_WELL_KNOWN_META = {
tic_desc : null, // TIC "Desc" tic_desc : null, // TIC "Desc"
tic_ldesc : null, // TIC "Ldesc" joined by '\n' tic_ldesc : null, // TIC "Ldesc" joined by '\n'
session_temp_dl : (v) => parseInt(v) ? true : false, session_temp_dl : (v) => parseInt(v) ? true : false,
desc_sauce : (s) => JSON.parse(s) || {},
desc_long_sauce : (s) => JSON.parse(s) || {},
}; };
module.exports = class FileEntry { module.exports = class FileEntry {

View File

@ -567,8 +567,8 @@ function MultiLineEditTextView(options) {
ansiPrep( ansiPrep(
ansi, ansi,
{ {
termWidth : this.client.term.termWidth, termWidth : options.termWidth || this.client.term.termWidth,
termHeight : this.client.term.termHeight, termHeight : options.termHeight || this.client.term.termHeight,
cols : this.dimens.width, cols : this.dimens.width,
rows : 'auto', rows : 'auto',
startCol : this.position.col, startCol : this.position.col,

View File

@ -259,8 +259,10 @@ function scanFileAreaForChanges(areaInfo, options, cb) {
if( tagsEq && if( tagsEq &&
fileEntry.desc === existingEntry.desc && fileEntry.desc === existingEntry.desc &&
fileEntry.descLong == existingEntry.descLong && fileEntry.descLong === existingEntry.descLong &&
fileEntry.meta.est_release_year == existingEntry.meta.est_release_year) fileEntry.meta.est_release_year === existingEntry.meta.est_release_year &&
fileEntry.meta.desc_sauce === existingEntry.meta.desc_sauce
)
{ {
console.info('Dupe'); console.info('Dupe');
return nextFile(null); return nextFile(null);
@ -276,6 +278,10 @@ function scanFileAreaForChanges(areaInfo, options, cb) {
existingEntry.meta.est_release_year = fileEntry.meta.est_release_year; existingEntry.meta.est_release_year = fileEntry.meta.est_release_year;
} }
if(fileEntry.meta.desc_sauce) {
existingEntry.meta.desc_sauce = fileEntry.meta.desc_sauce;
}
updateTags(existingEntry); updateTags(existingEntry);
finalizeEntryAndPersist(true, existingEntry, descHandler, err => { finalizeEntryAndPersist(true, existingEntry, descHandler, err => {

View File

@ -163,7 +163,7 @@ function parseCharacterSAUCE(sauce) {
result.fileType = SAUCE_CHARACTER_FILE_TYPES[sauce.fileType] || 'Unknown'; result.fileType = SAUCE_CHARACTER_FILE_TYPES[sauce.fileType] || 'Unknown';
if(sauce.fileType === 0 || sauce.fileType === 1 || sauce.fileType === 2) { if(sauce.fileType === 0 || sauce.fileType === 1 || sauce.fileType === 2) {
// convience: create ansiFlags // convenience: create ansiFlags
sauce.ansiFlags = sauce.flags; sauce.ansiFlags = sauce.flags;
let i = 0; let i = 0;
@ -175,6 +175,16 @@ function parseCharacterSAUCE(sauce) {
if(fontName.length > 0) { if(fontName.length > 0) {
result.fontName = fontName; result.fontName = fontName;
} }
const setDimen = (v, field) => {
const i = parseInt(v, 10);
if(!isNaN(i)) {
result[field] = i;
}
};
setDimen(sauce.tinfo1, 'characterWidth');
setDimen(sauce.tinfo2, 'characterHeight');
} }
return result; return result;