ZtringList::ZtringList (const Ztring &Source) { Separator[0]=__T(";"); Quote=__T("\""); Max[0]=Error; Write(Source.c_str()); }
//--------------------------------------------------------------------------- bool File::Move(const Ztring &Source, const Ztring &Destination, bool OverWrite) { if (OverWrite && Exists(Source)) Delete(Destination); #ifdef ZENLIB_USEWX if (OverWrite && Exists(Destination)) wxRemoveFile(Destination.c_str()); return wxRenameFile(Source.c_str(), Destination.c_str()); #else //ZENLIB_USEWX #ifdef ZENLIB_STANDARD return !std::rename(Source.To_Local().c_str(), Destination.To_Local().c_str()); #elif defined WINDOWS #ifdef UNICODE #ifndef ZENLIB_NO_WIN9X_SUPPORT if (IsWin9X_Fast()) return MoveFileA(Source.To_Local().c_str(), Destination.To_Local().c_str())!=0; else #endif //ZENLIB_NO_WIN9X_SUPPORT return MoveFileW(Source.c_str(), Destination.c_str())!=0; #else return MoveFile(Source.c_str(), Destination.c_str())!=0; #endif //UNICODE #endif #endif //ZENLIB_USEWX }
void Shell_Execute(const Ztring &ToExecute) { #ifdef ZENLIB_USEWX #else //ZENLIB_USEWX #ifdef WINDOWS #ifdef UNICODE if (IsWin9X()) ShellExecuteA(NULL, "open", ToExecute.To_Local().c_str(), NULL, NULL, 0); else ShellExecute (NULL, _T("open"), ToExecute.c_str(), NULL, NULL, 0); #else ShellExecute(NULL, _T("open"), ToExecute.c_str(), NULL, NULL, 0); #endif #else //Not supported #endif #endif //ZENLIB_USEWX }
//--------------------------------------------------------------------------- bool Dir::Create(const Ztring &File_Name) { #ifdef ZENLIB_USEWX return wxFileName::Mkdir(File_Name.c_str()); #else //ZENLIB_USEWX #ifdef WINDOWS #ifdef UNICODE if (IsWin9X()) return CreateDirectoryA(File_Name.To_Local().c_str(), NULL)!=0; else return CreateDirectoryW(File_Name.c_str(), NULL)!=0; #else return CreateDirectory(File_Name.c_str(), NULL)!=0; #endif //UNICODE #else //WINDOWS return mkdir(File_Name.To_Local().c_str(), 0700)==0; #endif //WINDOWS #endif //ZENLIB_USEWX }
int __stdcall ShowOpenFolder_CallbackProc (HWND hwnd, UINT uMsg, LPARAM, LPARAM) { if (uMsg==BFFM_INITIALIZED) { SetWindowText (hwnd, Directory_Select_Caption.c_str()); // Caption SendMessage (hwnd, BFFM_ENABLEOK, 0, TRUE); SendMessage (hwnd, BFFM_SETSELECTION, true, (LPARAM)&InitDirA); } return 0; }
//--------------------------------------------------------------------------- Ztring FileName::TempFileName_Create(const Ztring &Prefix) { #ifdef ZENLIB_USEWX return wxFileName::CreateTempFileName(Prefix.c_str()).c_str(); #else //ZENLIB_USEWX #ifdef WINDOWS Char Path[MAX_PATH+1]; if (!GetTempPath(MAX_PATH, Path)) return Ztring(); //Problem while getting a temp path Char FileName[MAX_PATH+1]; if (!GetTempFileName(Path, Prefix.c_str(), 0, FileName)) return Ztring(); //Problem while getting a file name return Ztring(FileName); #else return _T("C:\\xxx.txt"); #endif #endif //ZENLIB_USEWX }
void Shell_Execute(const Ztring &ToExecute) { #ifdef ZENLIB_USEWX #else //ZENLIB_USEWX #if defined(WINDOWS) && !defined(WINDOWS_UWP) ShellExecute(NULL, __T("open"), ToExecute.c_str(), NULL, NULL, 0); #else //Not supported #endif #endif //ZENLIB_USEWX }
//--------------------------------------------------------------------------- bool File::Delete(const Ztring &File_Name) { #ifdef ZENLIB_USEWX return wxRemoveFile(File_Name.c_str()); #else //ZENLIB_USEWX #ifdef ZENLIB_STANDARD #ifdef UNICODE return unlink(File_Name.To_Local().c_str())==0; #else return unlink(File_Name.c_str())==0; #endif //UNICODE #elif defined WINDOWS #ifdef UNICODE return DeleteFileW(File_Name.c_str())!=0; #else return DeleteFile(File_Name.c_str())!=0; #endif //UNICODE #endif #endif //ZENLIB_USEWX }
//--------------------------------------------------------------------------- // Open a file ZenLib::Ztring Enums_Create_Load(Ztring FileName, Ztring &Contents) { wxFile F; if (F.Open(FileName.c_str(), wxFile::read)==false) { Ztring ToReturn=L"Problems to open "; ToReturn+=FileName; ToReturn+=L"\r\n"; return ToReturn; } char C[FILE_MAX]; size_t Size=F.Read(C, FILE_MAX-1); Contents.From_Local(C, Size); return L""; }
Ztring OpenFolder_Show(void* Handle, const Ztring &Title, const Ztring &Caption) { //Caption Directory_Select_Caption=Caption; if (IsWin9X()) { return Ztring(); //Not supported in Win9X } else { //Values LPMALLOC Malloc; LPSHELLFOLDER ShellFolder; BROWSEINFO BrowseInfo; LPITEMIDLIST ItemIdList; //Initializing the SHBrowseForFolder function if (SHGetMalloc(&Malloc)!=NOERROR) return Ztring(); if (SHGetDesktopFolder(&ShellFolder)!=NOERROR) return Ztring(); ZeroMemory(&BrowseInfo, sizeof(BROWSEINFOW)); BrowseInfo.ulFlags+=BIF_RETURNONLYFSDIRS; BrowseInfo.hwndOwner=(HWND)Handle; BrowseInfo.pszDisplayName=InitDir; BrowseInfo.lpszTitle=Title.c_str(); BrowseInfo.lpfn=ShowOpenFolder_CallbackProc; //Displaying ItemIdList=SHBrowseForFolder(&BrowseInfo); //Releasing ShellFolder->Release(); if (ItemIdList!=NULL) { SHGetPathFromIDList(ItemIdList, InitDir); Malloc->Free(ItemIdList); Malloc->Release(); //The value return InitDir; } else return Ztring(); } }
//--------------------------------------------------------------------------- // Write a file ZenLib::Ztring Enums_Create_Save(Ztring FileName, Ztring &Contents) { File F; if (F.Create(FileName.c_str(), true)==false) { Ztring ToReturn=L"Problems to create "; ToReturn+=FileName; ToReturn+=L"\r\n"; return ToReturn; } std::string S1=Contents.To_UTF8(); size_t Size=F.Write((const int8u*)S1.c_str(), S1.size()); Contents.From_Number(Size); Contents+=L" bytes written"; return L""; }
//--------------------------------------------------------------------------- bool File::Copy(const Ztring &Source, const Ztring &Destination, bool OverWrite) { #ifdef ZENLIB_USEWX return wxCopyFile(Source.c_str(), Destination.c_str(), OverWrite); #else //ZENLIB_USEWX #ifdef ZENLIB_STANDARD return false; #elif defined WINDOWS #ifdef UNICODE return CopyFileW(Source.c_str(), Destination.c_str(), !OverWrite)!=0; #else return CopyFile(Source.c_str(), Destination.c_str(), !OverWrite)!=0; #endif //UNICODE #endif #endif //ZENLIB_USEWX }
//--------------------------------------------------------------------------- bool File::Copy(const Ztring &Source, const Ztring &Destination, bool OverWrite) { #ifdef ZENLIB_USEWX return wxCopyFile(Source.c_str(), Destination.c_str(), OverWrite); #else //ZENLIB_USEWX #ifdef ZENLIB_STANDARD return false; #elif defined WINDOWS #ifdef UNICODE #ifndef ZENLIB_NO_WIN9X_SUPPORT if (IsWin9X_Fast()) return CopyFileA(Source.To_Local().c_str(), Destination.To_Local().c_str(), !OverWrite)!=0; else #endif //ZENLIB_NO_WIN9X_SUPPORT return CopyFileW(Source.c_str(), Destination.c_str(), !OverWrite)!=0; #else return CopyFile(Source.c_str(), Destination.c_str(), !OverWrite)!=0; #endif //UNICODE #endif #endif //ZENLIB_USEWX }
//--------------------------------------------------------------------------- bool File::Create (const Ztring &File_Name, bool OverWrite) { #ifdef ZENLIB_USEWX File_Handle=(void*)new wxFile(); if (((wxFile*)File_Handle)->Create(File_Name.c_str(), OverWrite)==0) { //Sometime the file is locked for few milliseconds, we try again later wxMilliSleep(3000); if (((wxFile*)File_Handle)->Create(File_Name.c_str(), OverWrite)==0) //File is not openable return false; } return true; #else //ZENLIB_USEWX #ifdef ZENLIB_STANDARD /* int access; switch (OverWrite) { case false : access=O_BINARY|O_CREAT|O_WRONLY|O_EXCL ; break; default : access=O_BINARY|O_CREAT|O_WRONLY|O_TRUNC; break; } #ifdef UNICODE File_Handle=open(File_Name.To_Local().c_str(), access); #else File_Handle=open(File_Name.c_str(), access); #endif //UNICODE return File_Handle!=-1; */ /*ios_base::openmode mode; switch (OverWrite) { //case false : mode= ; break; default : mode=0 ; break; }*/ ios_base::openmode access; switch (OverWrite) { case false : if (Exists(File_Name)) return false; default : access=ios_base::binary|ios_base::in|ios_base::out|ios_base::trunc; break; } #ifdef UNICODE File_Handle=new fstream(File_Name.To_Local().c_str(), access); #else File_Handle=new fstream(File_Name.c_str(), access); #endif //UNICODE return ((fstream*)File_Handle)->is_open(); #elif defined WINDOWS DWORD dwDesiredAccess, dwShareMode, dwCreationDisposition; switch (OverWrite) { case false : dwDesiredAccess=GENERIC_WRITE; dwShareMode=0; dwCreationDisposition=CREATE_NEW; break; default : dwDesiredAccess=GENERIC_WRITE; dwShareMode=0; dwCreationDisposition=CREATE_ALWAYS; break; } #ifdef UNICODE if (IsWin9X()) File_Handle=CreateFileA(File_Name.To_Local().c_str(), dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, 0, NULL); else File_Handle=CreateFileW(File_Name.c_str(), dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, 0, NULL); #else File_Handle=CreateFile(File_Name.c_str(), dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, 0, NULL); #endif //UNICODE if (File_Handle==INVALID_HANDLE_VALUE) { //Sometime the file is locked for few milliseconds, we try again later Sleep(3000); #ifdef UNICODE if (IsWin9X()) File_Handle=CreateFileA(File_Name.To_Local().c_str(), dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, 0, NULL); else File_Handle=CreateFileW(File_Name.c_str(), dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, 0, NULL); #else File_Handle=CreateFile(File_Name.c_str(), dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, 0, NULL); #endif //UNICODE } if (File_Handle==INVALID_HANDLE_VALUE) //File is not openable return false; return true; #endif #endif //ZENLIB_USEWX }
//--------------------------------------------------------------------------- void File_Ttml::Read_Buffer_Continue() { tinyxml2::XMLDocument document; if (!FileHeader_Begin_XML(document)) return; XMLElement* Root=document.FirstChildElement("tt"); if (!Root) { Reject(); return; } if (!Status[IsAccepted]) { Accept(); #if MEDIAINFO_EVENTS MuxingMode=(int8u)-1; if (StreamIDs_Size>=2 && ParserIDs[StreamIDs_Size-2]==MediaInfo_Parser_Mpeg4) MuxingMode=11; //MPEG-4 if (StreamIDs_Size>2 && ParserIDs[StreamIDs_Size-2]==MediaInfo_Parser_Mxf) //Only if referenced MXF MuxingMode=13; //MXF #endif //MEDIAINFO_EVENTS #if MEDIAINFO_DEMUX && MEDIAINFO_NEXTPACKET if (Config->NextPacket_Get() && Config->Event_CallBackFunction_IsSet()) return; // Waiting for NextPacket #endif //MEDIAINFO_DEMUX && MEDIAINFO_NEXTPACKET } tinyxml2::XMLElement* div=NULL; #if MEDIAINFO_EVENTS tinyxml2::XMLElement* p=NULL; #endif //MEDIAINFO_EVENTS for (XMLElement* tt_element=Root->FirstChildElement(); tt_element; tt_element=tt_element->NextSiblingElement()) { //body if (!strcmp(tt_element->Value(), "body")) { for (XMLElement* body_element=tt_element->FirstChildElement(); body_element; body_element=body_element->NextSiblingElement()) { //div if (!strcmp(body_element->Value(), "div")) { for (XMLElement* div_element=body_element->FirstChildElement(); div_element; div_element=div_element->NextSiblingElement()) { //p if (!strcmp(div_element->Value(), "p")) { div=body_element; #if MEDIAINFO_EVENTS p=div_element; #endif //MEDIAINFO_EVENTS break; } } if (div) break; } } if (div) break; } } #if MEDIAINFO_DEMUX Demux(Buffer, Buffer_Size, ContentType_MainStream); #endif //MEDIAINFO_DEMUX // Output #if MEDIAINFO_EVENTS for (; p; p=p->NextSiblingElement()) { //p if (!strcmp(p->Value(), "p")) { int64u DTS_Begin=(int64u)-1; const char* Attribute=p->Attribute("begin"); if (Attribute) DTS_Begin=Ttml_str2timecode(Attribute); int64u DTS_End=(int64u)-1; Attribute=p->Attribute("end"); if (Attribute) DTS_End=Ttml_str2timecode(Attribute); string ContentUtf8; XMLPrinter printer; p->Accept(&printer); ContentUtf8+=printer.CStr(); while (!ContentUtf8.empty() && (ContentUtf8[ContentUtf8.size()-1]=='\r' || ContentUtf8[ContentUtf8.size()-1]=='\n')) ContentUtf8.resize(ContentUtf8.size()-1); Ztring Content; Content.From_UTF8(ContentUtf8.c_str()); Frame_Count_NotParsedIncluded=Frame_Count; EVENT_BEGIN (Global, SimpleText, 0) //Hack: remove "p", "span", "br" Content.FindAndReplace(__T("\r"), Ztring(), 0, ZenLib::Ztring_Recursive); Content.FindAndReplace(__T("\n"), Ztring(), 0, ZenLib::Ztring_Recursive); for (;;) { size_t Span_Begin=Content.find(__T("<p")); if (Span_Begin==string::npos) break; size_t Span_End=Content.find(__T(">"), Span_Begin+5); if (Span_End==string::npos) break; size_t ShlashSpan_Begin=Content.find(__T("</p>"), Span_End+1); if (ShlashSpan_Begin==string::npos) break; Content.erase(ShlashSpan_Begin, 7); Content.erase(Span_Begin, Span_End-Span_Begin+1); } for (;;) { size_t Span_Begin=Content.find(__T("<span")); if (Span_Begin==string::npos) break; size_t Span_End=Content.find(__T(">"), Span_Begin+5); if (Span_End==string::npos) break; size_t ShlashSpan_Begin=Content.find(__T("</span>"), Span_End+1); if (ShlashSpan_Begin==string::npos) break; Content.erase(ShlashSpan_Begin, 7); Content.erase(Span_Begin, Span_End-Span_Begin+1); } Content.FindAndReplace(__T("<br>"), EOL, 0, ZenLib::Ztring_Recursive); Content.FindAndReplace(__T("<br/>"), EOL, 0, ZenLib::Ztring_Recursive); Content.FindAndReplace(__T("<br />"), EOL, 0, ZenLib::Ztring_Recursive); Event.DTS=DTS_Begin; Event.PTS=Event.DTS; Event.DUR=DTS_End-DTS_Begin; Event.Content=Content.c_str(); Event.Flags=0; Event.MuxingMode=MuxingMode; Event.Service=(int8u)Element_Code; Event.Row_Max=0; Event.Column_Max=0; Event.Row_Values=NULL; Event.Row_Attributes=NULL; EVENT_END () EVENT_BEGIN (Global, SimpleText, 0) Event.DTS=DTS_End; Event.PTS=Event.DTS; Event.DUR=0; Event.Content=__T(""); Event.Flags=0; Event.MuxingMode=MuxingMode; Event.Service=(int8u)Element_Code; Event.Row_Max=0; Event.Column_Max=0; Event.Row_Values=NULL; Event.Row_Attributes=NULL; EVENT_END () Frame_Count++; } } #endif //MEDIAINFO_EVENTS Buffer_Offset=Buffer_Size; }