shared_ptr<ZLInputStream> ZLFile::inputStream() const { shared_ptr<ZLInputStream> stream; int index = ZLFSManager::Instance().findArchiveFileNameDelimiter(myPath); if (index == -1) { stream = ourPlainStreamCache[myPath]; if (stream.isNull()) { if (isDirectory()) { return 0; } stream = ZLFSManager::Instance().createPlainInputStream(myPath); stream = envelopeCompressedStream(stream); ourPlainStreamCache[myPath] = stream; } } else { ZLFile baseFile(myPath.substr(0, index)); shared_ptr<ZLInputStream> base = baseFile.inputStream(); if (!base.isNull()) { if (baseFile.myArchiveType & ZIP) { stream = new ZLZipInputStream(base, myPath.substr(index + 1)); } else if (baseFile.myArchiveType & TAR) { stream = new ZLTarInputStream(base, myPath.substr(index + 1)); } } stream = envelopeCompressedStream(stream); } return stream; }
std::string PdbPlugin::fileType(const ZLFile &file) { const std::string &extension = file.extension(); if ((extension != "prc") && (extension != "pdb") && (extension != "mobi")) { return ""; } const std::string &fileName = file.path(); //int index = fileName.find(':'); //ZLFile baseFile = (index == -1) ? file : ZLFile(fileName.substr(0, index)); ZLFile baseFile(file.physicalFilePath()); bool upToDate = BooksDBUtil::checkInfo(baseFile); //ZLStringOption palmTypeOption(FBCategoryKey::BOOKS, file.path(), "PalmType", ""); std::string palmType = BooksDB::Instance().getPalmType(fileName); if ((palmType.length() != 8) || !upToDate) { shared_ptr<ZLInputStream> stream = file.inputStream(); if (stream.isNull() || !stream->open()) { return ""; } stream->seek(60, false); char id[8]; stream->read(id, 8); stream->close(); palmType = std::string(id, 8); if (!upToDate) { BooksDBUtil::saveInfo(baseFile); } //palmTypeOption.setValue(palmType); BooksDB::Instance().setPalmType(fileName, palmType); } return palmType; }
void Read(const std::string &path) { std::fstream baseFile(path, std::fstream::in); std::string buff; while (baseFile.good()) { getline(baseFile, buff); Append(BusTour::parse(buff)); } baseFile.close(); }
void Write(const std::string &path) { std::fstream baseFile(path, std::fstream::trunc | std::fstream::out); auto curr = Begin(); while (curr != nullptr) { baseFile << curr->Data(); curr = curr->Next(); } baseFile.close(); }
shared_ptr<ZLInputStream> ZLFile::inputStream() const { shared_ptr<ZLInputStream> stream; int index = ZLFSManager::Instance().findArchiveFileNameDelimiter(myPath); if (index == -1) { #if FBREADER_THREAD_LOCAL_ZLFILE_PLAIN_STREAM_CACHE ZLFilePlainStreamCache *cache = (ZLFilePlainStreamCache*)pthread_getspecific(plainStreamCacheKey); if (!cache) { cache = new ZLFilePlainStreamCache; pthread_setspecific(plainStreamCacheKey, cache); } ZLFilePlainStreamCache &ourPlainStreamCache = *cache; #endif stream = ourPlainStreamCache[myPath]; if (stream.isNull()) { if (isDirectory()) { return 0; } stream = ZLFSManager::Instance().createPlainInputStream(myPath); stream = envelopeCompressedStream(stream); ourPlainStreamCache[myPath] = stream; } } else { ZLFile baseFile(myPath.substr(0, index)); shared_ptr<ZLInputStream> base = baseFile.inputStream(); if (!base.isNull()) { if (baseFile.myArchiveType & ZIP) { stream = new ZLZipInputStream(base, myPath.substr(index + 1)); } else if (baseFile.myArchiveType & TAR) { stream = new ZLTarInputStream(base, myPath.substr(index + 1)); } } stream = envelopeCompressedStream(stream); } return stream; }
shared_ptr<ZLInputStream> ZLFile::inputStream() const { shared_ptr<ZLInputStream> stream; int index = ZLFSManager::instance().findArchiveFileNameDelimiter(myPath); if (index == -1) { stream = ourPlainStreamCache[myPath].lock(); if (!stream) { if (isDirectory()) { return shared_ptr<ZLInputStream>(); } stream.reset(ZLFSManager::instance().createPlainInputStream(myPath)); stream = envelopeCompressedStream(stream); ourPlainStreamCache[myPath] = stream; } } else { ZLFile baseFile(myPath.substr(0, index)); shared_ptr<ZLInputStream> base = baseFile.inputStream(); if (base) { std::string entryName = myPath.substr(index + 1); if (baseFile.myArchiveType & ZIP) { ZLZipInputStream *zipInputStream = new ZLZipInputStream(base, entryName); if (ZLStringUtil::stringEndsWith(entryName, ".html") && !ZLStringUtil::stringEndsWith(entryName, "cover.html")) { zipInputStream->setAESKey(aesKey); } stream.reset(zipInputStream); } else if (baseFile.myArchiveType & TAR) { stream.reset(new ZLTarInputStream(base, entryName)); } } stream = envelopeCompressedStream(stream); } return stream; }
void TopLevelWinWrapper::GenerateCode(const wxcProjectMetadata& project, bool promptUser, bool baseOnly, wxString& baseCpp, wxString& baseHeader, wxArrayString& headers, wxStringMap_t& additionalFiles) { wxString size = PropertyString(PROP_SIZE); wxString filename = PropertyFile(PROP_FILE); if(promptUser && (GetType() != ID_WXIMAGELIST)) { // By design we dont provide a subclass for wxImageList if(filename.IsEmpty() && !wxcSettings::Get().HasFlag(wxcSettings::DONT_PROMPT_ABOUT_MISSING_SUBCLASS)) { wxString message; message << _("You did not set the 'Inherited C++ Class Properties -> File name' property for the top level " "window: '") << GetName() << "'\n" << _("This means that only base class code will be generated\nTo fix this, select the toplevel " "entry from the tree-view and provide an Inherited class name and file name"); wxRichMessageDialog dlg(NULL, message, "wxCrafter", wxOK | wxOK_DEFAULT | wxCENTER | wxICON_WARNING); dlg.SetOKLabel("OK, continue with code generation"); dlg.ShowCheckBox(_("Don't show this message again")); if(dlg.ShowModal() == wxID_CANCEL) { return; } if(dlg.IsCheckBoxChecked()) { wxcSettings::Get().EnableFlag(wxcSettings::DONT_PROMPT_ABOUT_MISSING_SUBCLASS, true); } } } /// Clear all window IDs related to this top level window m_auiDropDownMenuHelperRegistered = false; wxcCodeGeneratorHelper::Get().ClearWindowIds(); wxcCodeGeneratorHelper::Get().ClearIcons(); // Icons should be cleared between top-level windows wxcNotebookCodeHelper::Get().Clear(); wxString ctorBody, dtorCode, membersChunk, eventFunctions, eventConnectCode, eventDisconnectCode, extraFunctionsCodeImpl, extraFunctionsCodeDecl; headers.Add(wxT("#include <wx/settings.h>")); headers.Add(wxT("#include <wx/xrc/xmlres.h>")); headers.Add(wxT("#include <wx/xrc/xh_bmp.h>")); DoTraverseAndGenCode(headers, ctorBody, membersChunk, eventFunctions, eventConnectCode, additionalFiles, dtorCode, extraFunctionsCodeImpl, extraFunctionsCodeDecl); // Format the code a bit ctorBody = FormatCode(ctorBody); // Window colors if(IsWindow()) { wxString bgcol = wxCrafter::ColourToCpp(PropertyString(PROP_BG)); wxString fgcol = wxCrafter::ColourToCpp(PropertyString(PROP_FG)); // Add colors and fonts here if(bgcol.IsEmpty() == false) { ctorBody << wxT(" SetBackgroundColour(") << bgcol << wxT(");\n"); } if(fgcol.IsEmpty() == false) { ctorBody << wxT(" SetForegroundColour(") << fgcol << wxT(");\n"); } } ctorBody << FormatCode(wxcNotebookCodeHelper::Get().Code()); wxcNotebookCodeHelper::Get().Clear(); if(IsWindow()) { // Set the window name ctorBody << " SetName(" << wxCrafter::WXT(GetName()) << ");\n"; wxSize sz = wxCrafter::DecodeSize(PropertyString(PROP_MINSIZE)); if(sz != wxDefaultSize) { ctorBody << wxT(" SetMinClientSize(wxSize(" << wxCrafter::EncodeSize(sz) << "));\n"); } if(GetType() != ID_WXAUITOOLBARTOPLEVEL) { ctorBody << " SetSize(" << wxCrafter::GetSizeAsDlgUnits(GetSize(), "this") << wxT(");\n"); ctorBody << " if (GetSizer()) {\n"; ctorBody << " GetSizer()->Fit(this);\n"; ctorBody << " }\n"; if(IsWxTopLevelWindow()) { ctorBody << " if(GetParent()) {\n"; ctorBody << " CentreOnParent(" << PropertyString(PROP_CENTRE_ON_SCREEN) << ");\n"; ctorBody << " } else {\n"; ctorBody << " CentreOnScreen(" << PropertyString(PROP_CENTRE_ON_SCREEN) << ");\n"; ctorBody << " }\n"; } // Add support for wxPersistenceManager object if(wxcSettings::Get().IsLicensed() && IsWxTopLevelWindow() && IsPropertyChecked(PROP_PERSISTENT)) { ctorBody << wxCrafter::WX29_BLOCK_START(); ctorBody << " if(!wxPersistenceManager::Get().Find(this)) {\n"; ctorBody << " wxPersistenceManager::Get().RegisterAndRestore(this);\n"; ctorBody << " } else {\n"; ctorBody << " wxPersistenceManager::Get().Restore(this);\n"; ctorBody << " }\n"; ctorBody << "#endif\n"; } } } // Format the function code eventFunctions = FormatCode(eventFunctions); eventConnectCode = FormatCode(eventConnectCode); eventDisconnectCode = eventConnectCode; eventDisconnectCode.Replace(wxT("->Connect("), wxT("->Disconnect(")); wxString baseClassName = CreateBaseclassName(); wxString cppDecorator = PropertyString(PROP_CLASS_DECORATOR); cppDecorator.Trim().Trim(false); wxString superclass = GetRealClassName(); wxString derivedSuperclass = baseClassName; if(baseClassName.IsEmpty()) { // meaning that it was empty until BASE_CLASS_SUFFIX was appended wxString msg; msg << wxT("Can not generate code.\nMake sure that all toplevel windows have a valid C++ class name"); wxMessageBox(msg, wxT("wxCrafter"), wxOK | wxICON_WARNING | wxCENTER); return; } if(filename.IsEmpty()) { baseOnly = true; } wxFileName headerFile, sourceFile; wxFileName baseFile(wxcProjectMetadata::Get().GetGeneratedFilesDir(), wxcProjectMetadata::Get().GetOutputFileName()); // If the files are relative make them abs if(baseFile.IsRelative()) { baseFile.MakeAbsolute(project.GetProjectPath()); } wxString dbg = baseFile.GetFullPath(); headerFile = baseFile; sourceFile = baseFile; headerFile.SetExt(wxT("h")); sourceFile.SetExt(wxT("cpp")); dtorCode.Prepend(eventDisconnectCode); // Write the C++ file baseCpp << wxT("\n") << BaseCtorImplPrefix() << wxT("{\n") << wxcCodeGeneratorHelper::Get().GenerateInitCode(this) << ctorBody; if(eventConnectCode.IsEmpty() == false) { baseCpp << wxT(" // Connect events\n") << eventConnectCode; } // Now Connect() any auitoolbar dropdown menu; it must be *after* the normal Connect()s, otherwise it won't be // called if the user-code forgets to event.Skip() if(IsAuiToolBarDropDownHelpersRegistered()) { baseCpp << " this->Connect(" << "wxID_ANY, " << "wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN, wxAuiToolBarEventHandler(" << GetName() << "::" << DEFAULT_AUI_DROPDOWN_FUNCTION << "), NULL, this);\n"; // We need to disconnect it too dtorCode << " this->Disconnect(" << "wxID_ANY, " << "wxEVT_COMMAND_AUITOOLBAR_TOOL_DROPDOWN, wxAuiToolBarEventHandler(" << GetName() << "::" << DEFAULT_AUI_DROPDOWN_FUNCTION << "), NULL, this);\n"; } baseCpp << wxT("}\n\n") << baseClassName << wxT("::~") << baseClassName << wxT("()\n") << wxT("{\n") << dtorCode << wxT("}\n"); // Write any extra (i.e. not ctor/dtor) functions if(!extraFunctionsCodeImpl.empty()) { baseCpp << extraFunctionsCodeImpl; // Don't use FormatCode() here; it'd indent the signature etc too } // prepare the enum block for the // Write the header file baseHeader << wxT("\n") << wxT("class ") << (cppDecorator.IsEmpty() ? "" : cppDecorator + " ") << baseClassName << wxT(" : public ") << superclass << wxT("\n") << wxT("{\n") << wxcCodeGeneratorHelper::Get().GenerateWinIdEnum() << wxT("protected:\n") << membersChunk << wxT("\n") << wxT("protected:\n") << eventFunctions << wxT("\n") << wxT("public:\n") << extraFunctionsCodeDecl << BaseCtorDecl() << wxT(" virtual ~") << baseClassName << wxT("();\n") << wxT("};\n\n"); if(baseOnly) { return; } wxString inheritedClass = PropertyString(PROP_INHERITED_CLASS); inheritedClass.Trim().Trim(false); if(inheritedClass.IsEmpty()) { return; } if(inheritedClass == baseClassName) { ::wxMessageBox(_("Base class and inherited class have the same name"), "wxCrafter", wxOK | wxICON_WARNING | wxCENTER); return; } ///////////////////////////////////////////////////////////////////////////////////////// // Create the derived classes files ///////////////////////////////////////////////////////////////////////////////////////// wxFileName derivedClassFileCPP(filename); wxFileName derivedClassFileH(filename); derivedClassFileCPP.SetExt(wxT("cpp")); derivedClassFileH.SetExt(wxT("h")); // Fix the paths if needed // i.e. if the derived classes are relative, make them use the same // path as the base classes file if(derivedClassFileCPP.IsRelative()) { derivedClassFileCPP.SetPath(headerFile.GetPath()); } if(derivedClassFileH.IsRelative()) { derivedClassFileH.SetPath(headerFile.GetPath()); } wxString dCpp, dH, dBlockGuard; dBlockGuard << inheritedClass; dBlockGuard.MakeUpper(); dBlockGuard << wxT("_H"); // Prepare the Header file content dH << wxT("#ifndef ") << dBlockGuard << wxT("\n") << wxT("#define ") << dBlockGuard << wxT("\n") << wxT("#include \"") << headerFile.GetFullName() << wxT("\"\n") << wxT("\n") << wxT("class ") << (cppDecorator.IsEmpty() ? "" : cppDecorator + " ") << inheritedClass << wxT(" : public ") << derivedSuperclass << wxT("\n") << wxT("{\n") << wxT("public:\n") << wxT(" ") << inheritedClass << GetDerivedClassCtorSignature() << ";\n" << wxT(" virtual ~") << inheritedClass << wxT("();\n") << wxT("};\n") << wxT("#endif // ") << dBlockGuard << wxT("\n"); // Prepare the CPP file content dCpp << wxT("#include \"") << derivedClassFileH.GetFullName() << wxT("\"\n\n") << inheritedClass << wxT("::") << inheritedClass << GetDerivedClassCtorSignature() << "\n" << wxT(" : ") << baseClassName << GetParentCtorInitArgumentList() << "\n" << wxT("{\n") << wxT("}\n\n") << inheritedClass << wxT("::~") << inheritedClass << wxT("()\n") << wxT("{\n") << wxT("}\n\n"); // Keep track of the generated files if(WantsSubclass()) { wxcProjectMetadata::Get().SetGeneratedHeader(derivedClassFileH); wxcProjectMetadata::Get().SetGeneratedSource(derivedClassFileCPP); } wxcProjectMetadata::Get().SetGeneratedClassName(inheritedClass); wxcProjectMetadata::Get().SetVirtualFolder(GetVirtualFolder()); if(WantsSubclass() && wxCrafter::IsTheSame(derivedClassFileH, dH) == false) { wxCrafter::WriteFile(derivedClassFileH, dH, false); } if(WantsSubclass() && wxCrafter::IsTheSame(derivedClassFileCPP, dCpp) == false) { wxCrafter::WriteFile(derivedClassFileCPP, dCpp, false); } // Tell CodeLite to reload externall modified files EventNotifier::Get()->PostReloadExternallyModifiedEvent(true); }