bool LyXVC::registrer() { FileName const filename = owner_->fileName(); // there must be a file to save if (!filename.isReadableFile()) { Alert::error(_("Document not saved"), _("You must save the document " "before it can be registered.")); return false; } // it is very likely here that the vcs is not created yet... if (!vcs) { //check in the root directory of the document FileName const cvs_entries(onlyPath(filename.absFileName()) + "/CVS/Entries"); FileName const svn_entries(onlyPath(filename.absFileName()) + "/.svn/entries"); FileName const git_index(onlyPath(filename.absFileName()) + "/.git/index"); if (git_index.isReadableFile()) { LYXERR(Debug::LYXVC, "LyXVC: registering " << to_utf8(filename.displayName()) << " with GIT"); vcs.reset(new GIT(git_index, owner_)); } else if (svn_entries.isReadableFile()) { LYXERR(Debug::LYXVC, "LyXVC: registering " << to_utf8(filename.displayName()) << " with SVN"); vcs.reset(new SVN(svn_entries, owner_)); } else if (cvs_entries.isReadableFile()) { LYXERR(Debug::LYXVC, "LyXVC: registering " << to_utf8(filename.displayName()) << " with CVS"); vcs.reset(new CVS(cvs_entries, owner_)); } else { LYXERR(Debug::LYXVC, "LyXVC: registering " << to_utf8(filename.displayName()) << " with RCS"); vcs.reset(new RCS(FileName(), owner_)); } } LYXERR(Debug::LYXVC, "LyXVC: registrer"); docstring response; bool ok = Alert::askForText(response, _("LyX VC: Initial description"), _("(no initial description)")); if (!ok) { LYXERR(Debug::LYXVC, "LyXVC: user cancelled"); vcs.reset(0); return false; } if (response.empty()) response = _("(no initial description)"); vcs->registrer(to_utf8(response)); return true; }
// --- QGAMES::FormBuilder::FormBuilder (const std::string& fDef) : _definitions (), _forms (), _definitionFile (fDef), _basePath (onlyPath (fDef)) { if (_basePath == std::string (__NULL_STRING__)) _basePath = std::string ("."); }
// --- QGAMES::ObjectBuilder::ObjectBuilder (const std::string& mDef, QGAMES::FormBuilder* f) : _objects (), _basePath (__NULL_STRING__), _formBuilder (f), // It is optional, but no background object can be built up without it! _fileName (mDef), _alreadyLoaded (false) { _basePath = onlyPath (mDef); if (_basePath == std::string (__NULL_STRING__)) _basePath = std::string ("."); }
/** copy file \p sourceFile to \p destFile. If \p force is false, the user * will be asked before existing files are overwritten. If \p only_tmp * is true, then only copy files that are in our tmp dir (to avoid other files * overwriting themselves). * \return * - SUCCESS if this file got copied * - FORCE if subsequent calls should not ask for confirmation before * overwriting files anymore. * - CANCEL if the export should be cancelled */ CopyStatus copyFile(string const & format, FileName const & sourceFile, FileName const & destFile, string const & latexFile, bool force, bool only_tmp) { CopyStatus ret = force ? FORCE : SUCCESS; // This check could be changed to // boost::filesystem::equivalent(sourceFile, destFile) if export to // other directories than the document directory is desired. // Also don't overwrite files that already exist and are identical // to the source files. if ((only_tmp && !prefixIs(onlyPath(sourceFile.absFileName()), package().temp_dir().absFileName())) || sourceFile.checksum() == destFile.checksum()) return ret; if (!force) { switch(checkOverwrite(destFile)) { case 0: return SUCCESS; case 1: ret = SUCCESS; break; case 2: ret = FORCE; break; default: return CANCEL; } } Mover const & mover = getMover(format); if (!mover.copy(sourceFile, destFile, latexFile)) Alert::error(_("Couldn't copy file"), bformat(_("Copying %1$s to %2$s failed."), makeDisplayPath(sourceFile.absFileName()), makeDisplayPath(destFile.absFileName()))); return ret; }
// --- QGAMES::BoardBuilder::BoardBuilder (const std::string& fDef) : _definitions (), _boards (), _basePath (onlyPath (fDef)) { if (_basePath == std::string (__NULL_STRING__)) _basePath = std::string ("."); TiXmlDocument doc (fDef.c_str ()); int e = doc.LoadFile (); assert (e); // Is it a valid doc? TiXmlElement* rootElement = doc.RootElement (); assert (rootElement); // One element minimum... for (TiXmlElement* defElement = rootElement -> FirstChildElement (); defElement != NULL; defElement = defElement -> NextSiblingElement ()) { QGAMES::BoardBuilder::BoardDefinition def = readBoardDefinition (defElement); assert (def._id != -1); _definitions.insert (QGAMES::BoardBuilder::Definitions::value_type (def._id, def)); } }
// --- void VSWContentPrjSaver::saveProject (VSWContentProjectPt cntPrj, const std::string& fName, QBOOLEAN saveAll) { #ifdef __DEBUGSYSTEM __KEEPENTRYSIMPLETRACE #endif // Gets the real name of the file... // Initialy it is the name received as parameter, // but it is null, it will be the name keeped // into the aditional data of the content project object. // if that data does not exist, it will be not possible to open the file // and an exception will be thrown. // The method can be used to save an to save as a content project. std::string fileName = fName; if (fName == std::string (__NULL_STRING__)) if (cntPrj -> _aditionalData.exists (std::string (__GENVALUE_DESCRIPTORPATH__))) fileName = cntPrj -> _aditionalData.getStr (std::string (__GENVALUE_DESCRIPTORPATH__)) -> value ().asString (); else throw VSWContentSaverError (__DATAEXCEP (_IMPOSIBLEOPENAFILE_TXTERROR_)); // Extract the location path of the reproduction project description file... std::string pathForFile = onlyPath (fileName); // Open the file. // If not an exception will be thrown... std::ofstream file; std::string txtToSave (__NULL_STRING__); file.open (fileName.c_str ()); if (!file) throw VSWContentSaverError (__DATAEXCEP (_IMPOSIBLEOPENAFILE_TXTERROR_)); // Save the contents, schedulings, and sequences, // and create the list of them for this file. try { // Gets the docType tag, only if exists... std::string docType (__NULL_STRING__); if (cntPrj -> _aditionalData.exists (std::string (__GENVALUE_DOCTYPENAME__))) docType = std::string ("<!DOCTYPE ") + std::string (cntPrj -> _aditionalData.getStr (std::string (__GENVALUE_DOCTYPENAME__)) -> value ().asString ()) + std::string (" SYSTEM \"") + relPathFor (cntPrj -> _aditionalData.getStr (std::string (__GENVALUE_DOCTYPEDTD__)) -> value ().asString (), pathForFile) + std::string ("\">\n"); txtToSave += std::string ("\t<") + std::string (__ELEMENTSXML_TAGNAME__) + std::string (">\n"); txtToSave += saveContents (cntPrj, pathForFile, saveAll); txtToSave += saveSequences (cntPrj, pathForFile, saveAll); txtToSave += saveSchedulings (cntPrj, pathForFile, saveAll); txtToSave += saveEvents (cntPrj); txtToSave += std::string ("\t</") + std::string (__ELEMENTSXML_TAGNAME__) + std::string (">\n"); txtToSave = // Saves the header, and the paths... std::string (__HEADERXML_TAGNAME__) + docType + std::string ("<") + std::string (__CONTENTPROJECTXML_TAGNAME__) + std::string (" name=\"") + cntPrj -> name () + std::string ("\">\n") + std::string ("\t<") + std::string (__PRJPATHXML_TAGNAME__) + std::string (">\n") + extractPathsFrom (cntPrj, pathForFile) + std::string ("\t</") + std::string (__PRJPATHXML_TAGNAME__) + std::string (">\n") + txtToSave + std::string ("</") + std::string (__CONTENTPROJECTXML_TAGNAME__) + std::string (">\n"); } catch (CMTYException& excep) { throw VSWContentSaverError (excep, /* more deep in the history */ __DATAEXCEP (_IMPOSIBLETOSAVEFILE_TXTERROR_)); } // Save the content... file << txtToSave; file.close (); // ...and finaly close the file. #ifdef __DEBUGSYSTEM __KEEPEXITSIMPLETRACE #endif }
string const doSubstitution(InsetExternalParams const & params, Buffer const & buffer, string const & s, bool use_latex_path, bool external_in_tmpdir, Substitute what) { Buffer const * masterBuffer = buffer.masterBuffer(); string const parentpath = external_in_tmpdir ? masterBuffer->temppath() : buffer.filePath(); string const filename = external_in_tmpdir ? params.filename.mangledFileName() : params.filename.outputFileName(parentpath); string const basename = changeExtension( onlyFileName(filename), string()); string const absname = makeAbsPath(filename, parentpath).absFileName(); string result = s; if (what != ALL_BUT_PATHS) { string const filepath = onlyPath(filename); string const abspath = onlyPath(absname); string const masterpath = external_in_tmpdir ? masterBuffer->temppath() : masterBuffer->filePath(); // FIXME UNICODE string relToMasterPath = onlyPath( to_utf8(makeRelPath(from_utf8(absname), from_utf8(masterpath)))); if (relToMasterPath == "./") relToMasterPath.clear(); // FIXME UNICODE string relToParentPath = onlyPath( to_utf8(makeRelPath(from_utf8(absname), from_utf8(parentpath)))); if (relToParentPath == "./") relToParentPath.clear(); result = subst_path(result, "$$FPath", filepath, use_latex_path, PROTECT_EXTENSION, ESCAPE_DOTS); result = subst_path(result, "$$AbsPath", abspath, use_latex_path, PROTECT_EXTENSION, ESCAPE_DOTS); result = subst_path(result, "$$RelPathMaster", relToMasterPath, use_latex_path, PROTECT_EXTENSION, ESCAPE_DOTS); result = subst_path(result, "$$RelPathParent", relToParentPath, use_latex_path, PROTECT_EXTENSION, ESCAPE_DOTS); if (FileName::isAbsolute(filename)) { result = subst_path(result, "$$AbsOrRelPathMaster", abspath, use_latex_path, PROTECT_EXTENSION, ESCAPE_DOTS); result = subst_path(result, "$$AbsOrRelPathParent", abspath, use_latex_path, PROTECT_EXTENSION, ESCAPE_DOTS); } else { result = subst_path(result, "$$AbsOrRelPathMaster", relToMasterPath, use_latex_path, PROTECT_EXTENSION, ESCAPE_DOTS); result = subst_path(result, "$$AbsOrRelPathParent", relToParentPath, use_latex_path, PROTECT_EXTENSION, ESCAPE_DOTS); } } if (what == PATHS) return result; result = subst_path(result, "$$FName", filename, use_latex_path, EXCLUDE_EXTENSION); result = subst_path(result, "$$Basename", basename, use_latex_path, PROTECT_EXTENSION, ESCAPE_DOTS); result = subst_path(result, "$$Extension", '.' + getExtension(filename), use_latex_path); result = subst_path(result, "$$Tempname", params.tempname().absFileName(), use_latex_path); result = subst_path(result, "$$Sysdir", package().system_support().absFileName(), use_latex_path); // Handle the $$Contents(filename) syntax if (contains(result, "$$Contents(\"")) { // Since use_latex_path may be true we must extract the file // name from s instead of result and do the substitutions // again, this time with use_latex_path false. size_t const spos = s.find("$$Contents(\""); size_t const send = s.find("\")", spos); string const file_template = s.substr(spos + 12, send - (spos + 12)); string const file = doSubstitution(params, buffer, file_template, false, external_in_tmpdir, what); string contents; FileName const absfile( makeAbsPath(file, masterBuffer->temppath())); if (absfile.isReadableFile()) // FIXME UNICODE contents = to_utf8(absfile.fileContents("UTF-8")); size_t const pos = result.find("$$Contents(\""); size_t const end = result.find("\")", pos); result.replace(pos, end + 2, contents); } return result; }