From 59364bb27244806040e0896b8566562c4ede468f Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Sat, 1 Jul 2006 00:54:33 +0000 Subject: [PATCH] File attachment loading/saving supposedly all done Originally committed to SVN as r442. --- core/ass_attachment.cpp | 33 ++++++++---- core/ass_file.cpp | 112 +++++++++++++++++++++++----------------- 2 files changed, 86 insertions(+), 59 deletions(-) diff --git a/core/ass_attachment.cpp b/core/ass_attachment.cpp index cc4800616..ff877e617 100644 --- a/core/ass_attachment.cpp +++ b/core/ass_attachment.cpp @@ -106,12 +106,18 @@ const wxString AssAttachment::GetEntryData() { entryData += filename + _T("\r\n"); // Read three bytes - while (pos+3 <= size) { + while (pos < size) { + // Number to read + int read = size - pos; + if (read > 3) read = 3; + // Read source src[0] = dat[pos]; - src[1] = dat[pos+1]; - src[2] = dat[pos+2]; - pos += 3; + if (read >= 2) src[1] = dat[pos+1]; + else src[1] = 0; + if (read == 3) src[2] = dat[pos+2]; + else src[2] = 0; + pos += read; // Codify dst[0] = src[0] >> 2; @@ -119,13 +125,16 @@ const wxString AssAttachment::GetEntryData() { dst[2] = ((src[1] & 0xF) << 2) | ((src[2] & 0xC0) >> 6); dst[3] = src[2] & 0x3F; + // Number to write + int toWrite = read+1; + // Convert to text - for (int i=0;i<4;i++) { + for (int i=0;i 4) read = 4; int nbytes; // At least four, proceed normally - if (left >= 4) { + if (read >= 2) { // Move 4 bytes from buffer to src - for (int i=0;i<4;i++) { + for (int i=0;i 0) && (dataLen <= 80); + for (size_t i=0;i= 97) validData = false; + } + + // Is the filename line? + bool isFilename = (data.Left(10) == _T("fontname: ") && group == _T("[Fonts]")) || (data.Left(10) == _T("filename: ") && group == _T("[Graphics]")); + + // The attachment file is static, since it is built through several calls to this + // After it's done building, it's reset to NULL + static AssAttachment *attach = NULL; + + // Attachment exists, and data is over + if (attach && (!validData || isFilename)) { + attach->Finish(); + keepGroup.Clear(); + group = origGroup; + Line.push_back(attach); + attach = NULL; + } + + // Create attachment if needed + if (isFilename) { + attach = new AssAttachment(data.Mid(10)); + attach->StartMS = lasttime; + attach->group = group; + keepGroup = group; + return lasttime; + } + + // Valid data? + if (validData) { + // Insert data + attach->AddData(data); + + // Done building + if (data.Length() < 80) { + attach->Finish(); + keepGroup.Clear(); + group = origGroup; + entry = attach; + attach = NULL; + } + + // Not done + else { + return lasttime; + } + } + } // Dialogue if (group == _T("[Events]")) { @@ -270,54 +334,6 @@ int AssFile::AddLine (wxString data,wxString group,int lasttime,bool &IsSSA) { } } - // Attachment - else if (group == _T("[Fonts]") || group == _T("[Graphics]")) { - // Check if it's valid data - size_t dataLen = data.Length(); - bool validData = (dataLen > 0) && (dataLen <= 80); - for (size_t i=0;i= 97) validData = false; - } - - // Is the filename line? - bool isFilename = (data.Left(10) == _T("fontname: ") && group == _T("[Fonts]")) || (data.Left(10) == _T("filename: ") && group == _T("[Graphics]")); - - // The attachment file is static, since it is built through several calls to this - // After it's done building, it's reset to NULL - static AssAttachment *attach = NULL; - - // Attachment exists, and data is over - if (attach && (!validData || isFilename)) { - attach->Finish(); - Line.push_back(attach); - attach = NULL; - } - - // Create attachment if needed - if (isFilename) { - attach = new AssAttachment(data.Mid(10)); - attach->StartMS = lasttime; - attach->group = group; - return lasttime; - } - - // Valid data? - if (validData) { - // Insert data - attach->AddData(data); - - // Done building - if (data.Length() < 80) { - attach->Finish(); - entry = attach; - attach = NULL; - } - - // Not done - else return lasttime; - } - } - // Script info else if (group == _T("[Script Info]")) { // Comment