CHMFileInfo::FileNames CHMFileInfo::sectionNames(shared_ptr<ZLInputStream> base) const { FileNames names; shared_ptr<ZLInputStream> stringsStream = entryStream(base, "/#STRINGS"); if (!stringsStream.isNull() && stringsStream->open()) { std::vector<std::string> fileNames; int tocIndex = -1; int indexIndex = -1; for (int i = 0; i < 12; ++i) { std::string argument = readNTString(*stringsStream); if (argument.empty() || (argument[argument.length() - 1] == '/')) { continue; } if (myRecords.find(argument) == myRecords.end()) { continue; } if ((tocIndex == -1) && ZLStringUtil::stringEndsWith(argument, ".hhc")) { tocIndex = fileNames.size(); names.TOC = argument; } else if ((indexIndex == -1) && ZLStringUtil::stringEndsWith(argument, ".hhk")) { indexIndex = fileNames.size(); names.Index = argument; } fileNames.push_back(argument); } std::size_t startIndex = std::max(3, std::max(tocIndex, indexIndex) + 1); if (startIndex < 11) { if (startIndex < fileNames.size()) { names.Start = fileNames[startIndex]; } if (startIndex + 1 < fileNames.size()) { names.Home = fileNames[startIndex + 1]; } } stringsStream->close(); } if (names.TOC.empty()) { for (RecordMap::const_iterator it = myRecords.begin(); it != myRecords.end(); ++it) { if (ZLStringUtil::stringEndsWith(it->first, ".hhc")) { names.TOC = it->first; break; } } } if (names.empty()) { for (RecordMap::const_iterator it = myRecords.begin(); it != myRecords.end(); ++it) { if ((ZLStringUtil::stringEndsWith(it->first, ".htm")) || (ZLStringUtil::stringEndsWith(it->first, ".html"))) { names.Start = it->first; break; } } } return names; }
void K3bCddbLocalSubmit::doSubmit() { QString path = m_cddbDir; if( path.startsWith( "~" ) ) path.replace( 0, 1, QDir::homeDirPath() + "/" ); else if( !path.startsWith( "/" ) ) path.prepend( QDir::homeDirPath() + "/" ); if( path[path.length()-1] != '/' ) path.append( "/" ); if( !QFile::exists( path ) && !QDir().mkdir( path ) ) { kdDebug() << "(K3bCddbLocalSubmit) could not create directory: " << path << endl; setError( IO_ERROR ); emit submitFinished( this ); return; } if( QFile::exists( path ) ) { // if the category dir does not exists // create it path += resultEntry().category; if( !QFile::exists( path ) ) { if( !QDir().mkdir( path ) ) { kdDebug() << "(K3bCddbLocalSubmit) could not create directory: " << path << endl; setError( IO_ERROR ); emit submitFinished( this ); return; } } // we always overwrite existing entries path += "/" + resultEntry().discid; QFile entryFile( path ); if( entryFile.exists() ) { kdDebug() << "(K3bCddbLocalSubmit) file already exists: " << path << endl; } if( !entryFile.open( IO_WriteOnly ) ) { kdDebug() << "(K3bCddbLocalSubmit) could not create file: " << path << endl; setError( IO_ERROR ); emit submitFinished( this ); } else { kdDebug() << "(K3bCddbLocalSubmit) creating file: " << path << endl; QTextStream entryStream( &entryFile ); entryStream.setEncoding( QTextStream::UnicodeUTF8 ); entryStream << resultEntry().rawData; entryFile.close(); setError( SUCCESS ); emit submitFinished( this ); } } else { kdDebug() << "(K3bCddbLocalSubmit) could not find directory: " << path << endl; setError( IO_ERROR ); emit infoMessage( i18n("Could not find directory: %1").arg(path) ); emit submitFinished( this ); } }