Implemented direct saving to memory for asa
Originally committed to SVN as r897.
This commit is contained in:
parent
f711887167
commit
7a209feb22
3 changed files with 49 additions and 7 deletions
|
@ -143,8 +143,8 @@ void AssFile::Load (const wxString _filename,const wxString charset,bool addToRe
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////
|
////////////////////////////
|
||||||
// Chooses format to save in
|
// Save a file to Hard Disk
|
||||||
void AssFile::Save(wxString _filename,bool setfilename,bool addToRecent,const wxString encoding) {
|
void AssFile::Save(wxString _filename,bool setfilename,bool addToRecent,const wxString encoding) {
|
||||||
// Finds last dot
|
// Finds last dot
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
@ -177,6 +177,46 @@ void AssFile::Save(wxString _filename,bool setfilename,bool addToRecent,const wx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////
|
||||||
|
// Saves a file to a ram vector
|
||||||
|
void AssFile::SaveMemory(std::vector<char> &dst,const wxString encoding) {
|
||||||
|
// Set encoding
|
||||||
|
wxString enc = encoding;
|
||||||
|
if (enc.IsEmpty()) enc = _T("UTF-8");
|
||||||
|
if (enc != _T("UTF-8")) throw _T("Memory writer only supports UTF-8 for now.");
|
||||||
|
|
||||||
|
// Prepare vector
|
||||||
|
dst.clear();
|
||||||
|
dst.reserve(0x4000);
|
||||||
|
|
||||||
|
// Write file
|
||||||
|
entryIter cur;
|
||||||
|
unsigned int lineSize = 0;
|
||||||
|
unsigned int targetSize = 0;
|
||||||
|
unsigned int pos = 0;
|
||||||
|
wxCharBuffer buffer;
|
||||||
|
for (cur=Line.begin();cur!=Line.end();cur++) {
|
||||||
|
// Convert
|
||||||
|
wxString temp = (*cur)->GetEntryData() + _T("\r\n");
|
||||||
|
buffer = temp.mb_str(wxConvUTF8);
|
||||||
|
lineSize = strlen(buffer);
|
||||||
|
|
||||||
|
// Raise capacity if needed
|
||||||
|
targetSize = dst.size() + lineSize;
|
||||||
|
if (dst.capacity() < targetSize) {
|
||||||
|
unsigned int newSize = dst.capacity();
|
||||||
|
while (newSize < targetSize) newSize *= 2;
|
||||||
|
dst.reserve(newSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Append line
|
||||||
|
pos = dst.size();
|
||||||
|
dst.resize(targetSize);
|
||||||
|
memcpy(&dst[pos],buffer,lineSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////
|
////////////////////////////////////////////
|
||||||
// Exports file with proper transformations
|
// Exports file with proper transformations
|
||||||
void AssFile::Export(wxString _filename) {
|
void AssFile::Export(wxString _filename) {
|
||||||
|
|
|
@ -93,6 +93,7 @@ public:
|
||||||
wxString GetString(); // Returns the whole file as a single string
|
wxString GetString(); // Returns the whole file as a single string
|
||||||
void Load(wxString file,wxString charset=_T(""),bool addToRecent=true); // Load from a file
|
void Load(wxString file,wxString charset=_T(""),bool addToRecent=true); // Load from a file
|
||||||
void Save(wxString file,bool setfilename=false,bool addToRecent=true,const wxString encoding=_T("")); // Save to a file. Pass true to second argument if this isn't a copy
|
void Save(wxString file,bool setfilename=false,bool addToRecent=true,const wxString encoding=_T("")); // Save to a file. Pass true to second argument if this isn't a copy
|
||||||
|
void SaveMemory(std::vector<char> &dst,const wxString encoding=_T("")); // Save to a memory string
|
||||||
void Export(wxString file); // Saves exported copy, with effects applied
|
void Export(wxString file); // Saves exported copy, with effects applied
|
||||||
void AddToRecent(wxString file); // Adds file name to list of recently opened files
|
void AddToRecent(wxString file); // Adds file name to list of recently opened files
|
||||||
bool CanSave(); // Returns true if the file can be saved in its current format
|
bool CanSave(); // Returns true if the file can be saved in its current format
|
||||||
|
|
|
@ -97,18 +97,19 @@ CSRISubtitlesProvider::~CSRISubtitlesProvider() {
|
||||||
// Load subtitles
|
// Load subtitles
|
||||||
void CSRISubtitlesProvider::LoadSubtitles(AssFile *subs) {
|
void CSRISubtitlesProvider::LoadSubtitles(AssFile *subs) {
|
||||||
// Close
|
// Close
|
||||||
// HACK: REMOVE THE FOLLOWING LINE
|
|
||||||
if (instance) return;
|
|
||||||
if (instance) csri_close(instance);
|
if (instance) csri_close(instance);
|
||||||
instance = NULL;
|
instance = NULL;
|
||||||
|
|
||||||
// Prepare subtitles
|
// Prepare subtitles
|
||||||
wxString subsfilename = VideoContext::Get()->GetTempWorkFile();
|
//wxString subsfilename = VideoContext::Get()->GetTempWorkFile();
|
||||||
subs->Save(subsfilename,false,false,_T("UTF-8"));
|
//subs->Save(subsfilename,false,false,_T("UTF-8"));
|
||||||
|
std::vector<char> data;
|
||||||
|
subs->SaveMemory(data,_T("UTF-8"));
|
||||||
delete subs;
|
delete subs;
|
||||||
|
|
||||||
// Open
|
// Open
|
||||||
instance = csri_open_file(csri_renderer_default(),subsfilename.mb_str(wxConvUTF8),NULL);
|
//instance = csri_open_file(csri_renderer_default(),subsfilename.mb_str(wxConvUTF8),NULL);
|
||||||
|
instance = csri_open_mem(csri_renderer_default(),&data[0],data.size(),NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue